InGameEditor::InGameEditor(Context* context) : Object(context), mainEditorPlugin_(NULL) { editorData_ = new EditorSelection(context_); /// ResourcePickerManager is needed for the Attribute Inspector, so don't forget to init it context_->RegisterSubsystem(new ResourcePickerManager(context_)); ResourcePickerManager* resPickerMng = GetSubsystem<ResourcePickerManager>(); resPickerMng->Init(); /// cache some Subsystems cache_ = GetSubsystem<ResourceCache>(); ui_ = GetSubsystem<UI>(); graphics_ = GetSubsystem<Graphics>(); /// load default style files, can be edited afterwards defaultStyle_ = cache_->GetResource<XMLFile>("UI/IDEStyle.xml"); iconStyle_ = cache_->GetResource<XMLFile>("UI/IDEIcons.xml"); /// create main ui element rootUI_ = ui_->GetRoot()->CreateChild<UIElement>("InGameEditor"); rootUI_->SetSize(ui_->GetRoot()->GetSize()); rootUI_->SetTraversalMode(TM_DEPTH_FIRST); // This is needed for root-like element to prevent artifacts rootUI_->SetPriority(100); rootUI_->SetDefaultStyle(defaultStyle_); rootUI_->SetOpacity(0.65f); ////////////////////////////////////////////////////////////////////////// /// create menu bar with default menu entries menubar_ = MenuBarUI::Create(rootUI_, "EditorMenuBar"); menubar_->CreateMenu("File"); menubar_->CreateMenuItem("File", "Exit Editor", A_QUITEDITOR_VAR); menubar_->CreateMenu("Windows"); menubar_->CreateMenuItem("Windows", "Attribute", A_SHOWATTRIBUTE_VAR); menubar_->CreateMenuItem("Windows", "Hierarchy", A_SHOWHIERARCHY_VAR); SubscribeToEvent(menubar_, E_MENUBAR_ACTION, URHO3D_HANDLER(InGameEditor, HandleMenuBarAction)); ////////////////////////////////////////////////////////////////////////// /// create the hierarchy editor hierarchyWindow_ = rootUI_->CreateChild<HierarchyWindow>("SceneHierarchyWindow"); hierarchyWindow_->SetSize(200, 200); hierarchyWindow_->SetMovable(true); hierarchyWindow_->SetIconStyle(iconStyle_); hierarchyWindow_->SetTitle("Scene Hierarchy"); hierarchyWindow_->SetPosition(0, menubar_->GetHeight()); hierarchyWindow_->SetHeight(graphics_->GetHeight() - menubar_->GetHeight()); hierarchyWindow_->SetDefaultStyle(defaultStyle_); hierarchyWindow_->SetStyleAuto(); /// \todo // dont know why the auto style does not work ... hierarchyWindow_->SetTexture(cache_->GetResource<Texture2D>("Textures/UI.png")); hierarchyWindow_->SetImageRect(IntRect(48, 0, 64, 16)); hierarchyWindow_->SetBorder(IntRect(4, 4, 4, 4)); hierarchyWindow_->SetResizeBorder(IntRect(8, 8, 8, 8)); SubscribeToEvent(hierarchyWindow_->GetHierarchyList(), E_SELECTIONCHANGED, URHO3D_HANDLER(InGameEditor, HandleHierarchyListSelectionChange)); ////////////////////////////////////////////////////////////////////////// /// create the attribute editor attributeInspector_ = new AttributeInspector(context_); UIElement* attrinsp = attributeInspector_->Create(); rootUI_->AddChild(attrinsp); attrinsp->SetHeight(graphics_->GetHeight() - menubar_->GetHeight()); attrinsp->SetWidth(ATTRNAME_WIDTH * 2); attrinsp->SetPosition(graphics_->GetWidth() - ATTRNAME_WIDTH * 2, menubar_->GetHeight()); rootUI_->SetVisible(false); ////////////////////////////////////////////////////////////////////////// /// create view cameraNode_ = new Node(context_); camera_ = cameraNode_->CreateComponent<Camera>(); camera_->SetFarClip(1300.0f); // Set an initial position for the camera scene node above the plane cameraNode_->SetPosition(Vector3(0.0f, 8.0f, 0.0f)); ////////////////////////////////////////////////////////////////////////// /// create default editor plugins SharedPtr<PluginScene3DEditor> scene3dEditor(new PluginScene3DEditor(context_)); RegisterEditorPlugin(scene3dEditor); mainEditorPlugin_ = scene3dEditor; }
void Hello3DUI::HandleDragMove(StringHash eventType, VariantMap& eventData) { IntVector2 dragCurrentPosition = IntVector2(eventData["X"].GetInt(), eventData["Y"].GetInt()); UIElement* draggedElement = static_cast<UIElement*>(eventData["Element"].GetPtr()); draggedElement->SetPosition(dragCurrentPosition - dragBeginPosition_); }
void GameEconomicGameClientStateSplash::HandlerSplashUpdate(StringHash eventType, VariantMap& eventData) { /// Get Needed SubSystems ResourceCache* cache_ = GetSubsystem<ResourceCache>(); Renderer* renderer_ = GetSubsystem<Renderer>(); Graphics* graphics_ = GetSubsystem<Graphics>(); UI* ui_ = GetSubsystem<UI>(); /// Check scene status if(Existence -> scene_-> GetAsyncProgress()==1&&SplashTimer.GetMSec(false)>3600&&splashcompleted==false) { /// change splash splashcompleted = true; /// Create a scene node for the camera, which we will move around /// The camera will use default settings (1000 far clip distance, 45 degrees FOV, set aspect ratio automatically) Node * cameraNode_ = Existence -> scene_->GetChild("MainCamera", true); /// If camera exist change viewport if(cameraNode_) { /// Set up a viewport to the Renderer subsystem so that the 3D scene can be seen. We need to define the scene and the camera /// at minimum. Additionally we could configure the viewport screen size and the rendering path (eg. forward / deferred) to /// use, but now we just use full screen and default render path configured SetOrthographic ( in the engine command line options Existence -> viewport = new Viewport(context_, Existence->scene_, cameraNode_->GetComponent<Camera>()); renderer_->SetViewport(0, Existence->viewport); /// Get current rendering path Existence->effectRenderPath =Existence-> viewport->GetRenderPath() -> Clone(); /// loadd resources Existence->effectRenderPath->Append(cache_->GetResource<XMLFile>("PostProcess/Bloom.xml")); Existence->effectRenderPath->Append(cache_->GetResource<XMLFile>("PostProcess/FXAA2.xml")); /// Make the bloom mixing parameter more pronounced Existence->effectRenderPath->SetShaderParameter("BloomMix", Vector2(Existence->GameConfig->VideoBloomParam1, Existence->GameConfig->VideoBloomParam2)); Existence->effectRenderPath->SetEnabled("Bloom", false); Existence->effectRenderPath->SetEnabled("FXAA2", false); /// Pointer render path to new Existence->viewport->SetRenderPath(Existence->effectRenderPath); /// Turn on effects Existence->effectRenderPath->ToggleEnabled("Bloom"); Existence->effectRenderPath->ToggleEnabled("FXAA2"); } /// Change UI UIElement * uiRoot_ = ui_->GetRoot(); BorderImage * Splash = (BorderImage * ) uiRoot_ -> GetChild("Splash", true); if(Splash!=NULL) { /// Remove splash Splash -> Remove(); } /// Get rendering window size as floats float width = (float)graphics_->GetWidth(); float height = (float)graphics_->GetHeight(); /// Create LetterBox Sprite Sprite* LetterBoxSprite = new Sprite(context_); LetterBoxSprite->SetName("LetterBoxSprite"); /// Get letter box image Texture2D* texture = cache_ ->GetResource<Texture2D>("Resources/Textures/LetterBox.png"); /// Set letter box properties LetterBoxSprite->SetTexture(texture); // Set texture LetterBoxSprite->SetSize(width,height); LetterBoxSprite->SetAlignment(HA_CENTER, VA_CENTER); /// Create letter box image to UIElement UIElement * LetterBoxUIElement = new UIElement(context_); LetterBoxUIElement->AddChild(LetterBoxSprite); /// Add letter box UIElement to ui uiRoot_->AddChild(LetterBoxUIElement); /// Set style of UIElements LetterBoxUIElement->SetOpacity(.8); LetterBoxSprite->SetStyleAuto(); LetterBoxUIElement->SetStyleAuto(); /// Create HangarsSymbolSmall Sprite Sprite* HangarsSymbolSmallSprite = new Sprite(context_); HangarsSymbolSmallSprite->SetName("HangarsSymbolSmallSprite"); /// Get letter box image Texture2D* HangarsSymbolTexture = cache_ ->GetResource<Texture2D>("Resources/Textures/HangarsSymbolSmall.png"); /// Set letter box properties HangarsSymbolSmallSprite->SetTexture(HangarsSymbolTexture); // Set texture HangarsSymbolSmallSprite->SetSize(HangarsSymbolTexture->GetWidth()/2,HangarsSymbolTexture->GetHeight()/2); HangarsSymbolSmallSprite->SetAlignment(HA_LEFT, VA_TOP); /// Create letter box image to UIElement UIElement * HangarsSymbolSmallUIElement = new UIElement(context_); HangarsSymbolSmallUIElement->AddChild(HangarsSymbolSmallSprite); /// Add letter box UIElement to ui uiRoot_->AddChild(HangarsSymbolSmallUIElement); /// Set style of UIElements HangarsSymbolSmallUIElement->SetOpacity(.8); HangarsSymbolSmallUIElement->SetPosition((width/2)-((HangarsSymbolTexture->GetWidth()/2)/2),250); HangarsSymbolSmallSprite->SetStyleAuto(); HangarsSymbolSmallUIElement->SetStyleAuto(); /// Load fonts Font * Mionta = cache_ ->GetResource<Font>("Resources/Fonts/mionta.ttf"); Font * Neuton = cache_ ->GetResource<Font>("Resources/Fonts/Neuton-SC-Light.ttf"); /// Create logo text Text * LogoText = new Text(context_); LogoText -> SetTextAlignment(HA_CENTER); LogoText -> SetFont(Mionta,32); LogoText -> SetText("HANGARS"); LogoText -> SetColor(Color(.9f,.9f,.9f)); /// Create LetterBox UI Element UIElement * LogoTextUIElement = new UIElement(context_); LogoTextUIElement->AddChild(LogoText); /// Add to UI uiRoot_->AddChild(LogoTextUIElement); ///TitleText->SetStyleAuto(); LogoTextUIElement->SetStyleAuto(); /// Move text to a position LogoTextUIElement->SetPosition((width/2)-240,200); /// Create a event VariantMap gamestatechange; gamestatechange[GameState::P_CMD] = GAME_STATE_LOGIN; cout << "Debug: Attempt to send a state change" << endl; SendEvent(G_STATES_CHANGE,gamestatechange); } return ; }