Browse Source

Rewrite node & component IDs when instantiating content from file.
Added choice to instantiate content as either replicated or local.
Fixed popup menu & editor hierarchy window update bugs.

Lasse Öörni 14 years ago
parent
commit
f58e2595bf

+ 13 - 9
Bin/Data/Scripts/Editor/EditorScene.as

@@ -13,7 +13,8 @@ Scene@ editorScene;
 
 String sceneFileName;
 String sceneResourcePath;
-String nodeFileName;
+String instantiateFileName;
+CreateMode instantiateMode = REPLICATED;
 bool sceneModified = false;
 bool runUpdate = false;
 
@@ -71,20 +72,19 @@ void CreateScene()
 
 void SetResourcePath(String newPath)
 {
-    newPath = AddTrailingSlash(newPath);
+    newPath = AddTrailingSlash(cache.GetPreferredResourceDir(newPath));
 
     if (newPath == sceneResourcePath)
         return;
 
     cache.ReleaseAllResources(false);
-
     // Remove the old scene resource path if any. However make sure that the default data paths do not get removed
     if (!sceneResourcePath.empty && sceneResourcePath.Find(fileSystem.programDir) < 0)
         cache.RemoveResourceDir(sceneResourcePath);
 
     cache.AddResourceDir(newPath);
     sceneResourcePath = newPath;
-    
+
     // If scenes were not loaded yet, default load/save to the resource path
     if (uiScenePath.empty)
         uiScenePath = newPath;
@@ -192,7 +192,7 @@ void LoadScene(const String&in fileName)
     editorScene.Clear();
 
     // Add the new resource path
-    SetResourcePath(cache.GetPreferredResourceDir(GetPath(fileName)));
+    SetResourcePath(GetPath(fileName));
 
     String extension = GetExtension(fileName);
     if (extension != ".xml")
@@ -247,19 +247,23 @@ void InstantiateNode(const String&in fileName)
     if (!file.open)
         return;
 
+    // Before instantiating, set resource path if empty
+    if (sceneResourcePath.empty)
+        SetResourcePath(GetPath(fileName));
+
     Vector3 position = GetNewNodePosition();
     Node@ newNode;
 
     String extension = GetExtension(fileName);
     if (extension != ".xml")
-        newNode = editorScene.Instantiate(file, position, Quaternion());
+        newNode = editorScene.Instantiate(file, position, Quaternion(), instantiateMode);
     else
-        newNode = editorScene.InstantiateXML(file, position, Quaternion());
+        newNode = editorScene.InstantiateXML(file, position, Quaternion(), instantiateMode);
 
     if (newNode !is null)
     {
         UpdateAndFocusNode(newNode);
-        nodeFileName = fileName;
+        instantiateFileName = fileName;
     }
 }
 
@@ -282,7 +286,7 @@ void SaveNode(const String&in fileName)
             xml.Save(file);
         }
 
-        nodeFileName = fileName;
+        instantiateFileName = fileName;
     }
 }
 

+ 3 - 0
Bin/Data/Scripts/Editor/EditorSceneWindow.as

@@ -186,6 +186,9 @@ void UpdateSceneWindowNodeOnly(uint itemIndex, Node@ node)
 void UpdateSceneWindowNode(Node@ node)
 {
     uint index = GetNodeListIndex(node);
+    if (index == NO_ITEM)
+        index = GetParentAddIndex(node);
+
     UpdateSceneWindowNode(index, node);
 }
 

+ 50 - 16
Bin/Data/Scripts/Editor/EditorUI.as

@@ -9,7 +9,6 @@ Array<String> uiAllFilter = {"*.*"};
 Array<String> uiScriptFilter = {"*.as", "*.*"};
 uint uiSceneFilter = 0;
 String uiScenePath;
-String uiNodePath;
 String uiImportPath;
 String uiScriptPath;
 
@@ -60,8 +59,15 @@ void CreateMenuBar()
         filePopup.AddChild(CreateMenuItem("Save scene", 'S', QUAL_CTRL));
         filePopup.AddChild(CreateMenuItem("Save scene as", 'S', QUAL_SHIFT | QUAL_CTRL));
         filePopup.AddChild(CreateMenuDivider());
-        filePopup.AddChild(CreateMenuItem("Load node", 0, 0));
-        filePopup.AddChild(CreateMenuItem("Save node", 0, 0));
+
+        Menu@ loadNodeMenu = CreateMenuItem("Instantiate node", 0, 0);
+        Window@ loadNodePopup = CreatePopup(loadNodeMenu);
+        loadNodeMenu.popupOffset = IntVector2(loadNodeMenu.width, 0);
+        loadNodePopup.AddChild(CreateMenuItem("As replicated", 0, 0));
+        loadNodePopup.AddChild(CreateMenuItem("As local", 0, 0));
+        filePopup.AddChild(loadNodeMenu);
+        
+        filePopup.AddChild(CreateMenuItem("Save node as", 0, 0));
         filePopup.AddChild(CreateMenuDivider());
         filePopup.AddChild(CreateMenuItem("Import model", 0, 0));
         filePopup.AddChild(CreateMenuItem("Import scene", 0, 0));
@@ -201,6 +207,27 @@ void UpdateWindowTitle()
     graphics.windowTitle = "Urho3D editor - " + sceneName;
 }
 
+Menu@ GetTopLevelMenu(Menu@ menu)
+{
+    for (;;)
+    {
+        UIElement@ menuParent = menu.parent;
+        if (menuParent is null)
+            break;
+
+        Menu@ nextMenu = menuParent.vars["Origin"].GetUIElement();
+        if (nextMenu is null)
+            break;
+        else
+            menu = nextMenu;
+    }
+
+    if (menu.parent is uiMenuBar)
+        return menu;
+    else
+        return null;
+}
+
 void HandleMenuSelected(StringHash eventType, VariantMap& eventData)
 {
     Menu@ menu = eventData["Element"].GetUIElement();
@@ -211,10 +238,9 @@ void HandleMenuSelected(StringHash eventType, VariantMap& eventData)
     if (action.empty)
         return;
 
-    // Close the menu now
-    UIElement@ menuParent = menu.parent;
-    Menu@ topLevelMenu = menuParent.vars["Origin"].GetUIElement();
-    if (topLevelMenu !is null)
+    Menu@ topLevelMenu = GetTopLevelMenu(menu);
+    // Close the top level menu now
+    if (topLevelMenu !is null && action != "Instantiate node") // Instantiate has a submenu, so do not close in that case
         topLevelMenu.showPopup = false;
 
     if (uiFileSelector is null)
@@ -238,16 +264,24 @@ void HandleMenuSelected(StringHash eventType, VariantMap& eventData)
             SubscribeToEvent(uiFileSelector, "FileSelected", "HandleSaveSceneFile");
         }
 
-        if (action == "Load node")
+        if (action == "As replicated")
         {
-            CreateFileSelector("Load node", "Load", "Cancel", uiNodePath, uiSceneFilters, uiSceneFilter);
-            SubscribeToEvent(uiFileSelector, "FileSelected", "HandleLoadNodeFile");
+            instantiateMode = REPLICATED;
+            CreateFileSelector("Instantiate node", "Load", "Cancel", uiScenePath, uiSceneFilters, uiSceneFilter);
+            SubscribeToEvent(uiFileSelector, "FileSelected", "HandleInstantiateNodeFile");
         }
 
-        if (action == "Save node" && selectedNodes.length == 1 && selectedNodes[0] !is editorScene)
+        if (action == "As local")
         {
-            CreateFileSelector("Save node", "Save", "Cancel", uiNodePath, uiSceneFilters, uiSceneFilter);
-            uiFileSelector.fileName = GetFileNameAndExtension(nodeFileName);
+            instantiateMode = LOCAL;
+            CreateFileSelector("Instantiate node", "Load", "Cancel", uiScenePath, uiSceneFilters, uiSceneFilter);
+            SubscribeToEvent(uiFileSelector, "FileSelected", "HandleInstantiateNodeFile");
+        }
+
+        if (action == "Save node as" && selectedNodes.length == 1 && selectedNodes[0] !is editorScene)
+        {
+            CreateFileSelector("Save node", "Save", "Cancel", uiScenePath, uiSceneFilters, uiSceneFilter);
+            uiFileSelector.fileName = GetFileNameAndExtension(instantiateFileName);
             SubscribeToEvent(uiFileSelector, "FileSelected", "HandleSaveNodeFile");
         }
 
@@ -344,11 +378,11 @@ void HandleSaveSceneFile(StringHash eventType, VariantMap& eventData)
     SaveScene(fileName);
 }
 
-void HandleLoadNodeFile(StringHash eventType, VariantMap& eventData)
+void HandleInstantiateNodeFile(StringHash eventType, VariantMap& eventData)
 {
     // Save filter for next time
     uiSceneFilter = uiFileSelector.filterIndex;
-    uiNodePath = uiFileSelector.path;
+    uiScenePath = uiFileSelector.path;
     CloseFileSelector();
 
     // Check for cancel
@@ -363,7 +397,7 @@ void HandleSaveNodeFile(StringHash eventType, VariantMap& eventData)
 {
     // Save filter for next time
     uiSceneFilter = uiFileSelector.filterIndex;
-    uiNodePath = uiFileSelector.path;
+    uiScenePath = uiFileSelector.path;
     CloseFileSelector();
 
     // Check for cancel

+ 1 - 1
Docs/ScriptAPI.dox

@@ -1339,7 +1339,7 @@ Methods:<br>
 - void StopAsyncLoading()
 - Node@ Instantiate(File@, const Vector3&, const Quaternion&, CreateMode arg3 = REPLICATED)
 - Node@ InstantiateXML(File@, const Vector3&, const Quaternion&, CreateMode arg3 = REPLICATED)
-- Node@ InstantiateXML(XMLFile@, const Vector3&, const Quaternion&, CreateMode arg3 = REPLICATED)
+- Node@ InstantiateXML(const XMLElement&, const Vector3&, const Quaternion&, CreateMode arg3 = REPLICATED)
 - void Clear()
 - void AddRequiredPackageFile(PackageFile@)
 - void ClearRequiredPackageFiles()

+ 1 - 9
Engine/Engine/SceneAPI.cpp

@@ -91,14 +91,6 @@ static Node* SceneInstantiateXML(File* file, const Vector3& position, const Quat
         return 0;
 }
 
-static Node* SceneInstantiateXMLFile(XMLFile* xmlFile, const Vector3& position, const Quaternion& rotation, CreateMode mode, Scene* ptr)
-{
-    if (xmlFile)
-        return ptr->InstantiateXML(xmlFile->GetRoot(), position, rotation, mode);
-    else
-        return 0;
-}
-
 static CScriptArray* SceneGetRequiredPackageFiles(Scene* ptr)
 {
     return VectorToHandleArray<PackageFile>(ptr->GetRequiredPackageFiles(), "Array<PackageFile@>");
@@ -139,7 +131,7 @@ static void RegisterScene(asIScriptEngine* engine)
     engine->RegisterObjectMethod("Scene", "void StopAsyncLoading()", asMETHOD(Scene, StopAsyncLoading), asCALL_THISCALL);
     engine->RegisterObjectMethod("Scene", "Node@+ Instantiate(File@+, const Vector3&in, const Quaternion&in, CreateMode mode = REPLICATED)", asFUNCTION(SceneInstantiate), asCALL_CDECL_OBJLAST);
     engine->RegisterObjectMethod("Scene", "Node@+ InstantiateXML(File@+, const Vector3&in, const Quaternion&in, CreateMode mode = REPLICATED)", asFUNCTION(SceneInstantiateXML), asCALL_CDECL_OBJLAST);
-    engine->RegisterObjectMethod("Scene", "Node@+ InstantiateXML(XMLFile@+, const Vector3&in, const Quaternion&in, CreateMode mode = REPLICATED)", asFUNCTION(SceneInstantiateXMLFile), asCALL_CDECL_OBJLAST);
+    engine->RegisterObjectMethod("Scene", "Node@+ InstantiateXML(const XMLElement&in, const Vector3&in, const Quaternion&in, CreateMode mode = REPLICATED)", asMETHODPR(Scene, InstantiateXML, (const XMLElement&, const Vector3&, const Quaternion&, CreateMode), Node*), asCALL_THISCALL);
     engine->RegisterObjectMethod("Scene", "void Clear()", asMETHOD(Scene, Clear), asCALL_THISCALL);
     engine->RegisterObjectMethod("Scene", "void AddRequiredPackageFile(PackageFile@+)", asMETHOD(Scene, AddRequiredPackageFile), asCALL_THISCALL);
     engine->RegisterObjectMethod("Scene", "void ClearRequiredPackageFiles()", asMETHOD(Scene, ClearRequiredPackageFiles), asCALL_THISCALL);

+ 9 - 8
Engine/Scene/Node.cpp

@@ -1009,7 +1009,7 @@ void Node::UpdateSmoothing(float constant, float squaredSnapThreshold)
         MarkDirty();
 }
 
-bool Node::Load(Deserializer& source, SceneResolver& resolver, bool readChildren)
+bool Node::Load(Deserializer& source, SceneResolver& resolver, bool readChildren, bool rewriteIDs)
 {
     // Remove all children and components first in case this is not a fresh load
     RemoveAllChildren();
@@ -1025,7 +1025,7 @@ bool Node::Load(Deserializer& source, SceneResolver& resolver, bool readChildren
         VectorBuffer compBuffer(source, source.ReadVLE());
         ShortStringHash compType = compBuffer.ReadShortStringHash();
         unsigned compID = compBuffer.ReadUInt();
-        Component* newComponent = CreateComponent(compType, compID, id_ < FIRST_LOCAL_ID ? REPLICATED : LOCAL);
+        Component* newComponent = CreateComponent(compType, rewriteIDs ? 0 : compID, id_ < FIRST_LOCAL_ID ? REPLICATED : LOCAL);
         if (newComponent)
         {
             resolver.AddComponent(compID, newComponent);
@@ -1041,16 +1041,16 @@ bool Node::Load(Deserializer& source, SceneResolver& resolver, bool readChildren
     for (unsigned i = 0; i < numChildren; ++i)
     {
         unsigned nodeID = source.ReadUInt();
-        Node* newNode = CreateChild(nodeID, id_ < FIRST_LOCAL_ID ? REPLICATED : LOCAL);
+        Node* newNode = CreateChild(rewriteIDs ? 0 : nodeID, id_ < FIRST_LOCAL_ID ? REPLICATED : LOCAL);
         resolver.AddNode(nodeID, newNode);
-        if (!newNode->Load(source, resolver))
+        if (!newNode->Load(source, resolver, readChildren, rewriteIDs))
             return false;
     }
     
     return true;
 }
 
-bool Node::LoadXML(const XMLElement& source, SceneResolver& resolver, bool readChildren)
+bool Node::LoadXML(const XMLElement& source, SceneResolver& resolver, bool readChildren, bool rewriteIDs)
 {
     // Remove all children and components first in case this is not a fresh load
     RemoveAllChildren();
@@ -1064,7 +1064,8 @@ bool Node::LoadXML(const XMLElement& source, SceneResolver& resolver, bool readC
     {
         String typeName = compElem.GetString("type");
         unsigned compID = compElem.GetInt("id");
-        Component* newComponent = CreateComponent(ShortStringHash(typeName), compID, id_ < FIRST_LOCAL_ID ? REPLICATED : LOCAL);
+        Component* newComponent = CreateComponent(ShortStringHash(typeName), rewriteIDs ? 0 : compID, id_ < FIRST_LOCAL_ID ?
+            REPLICATED : LOCAL);
         if (newComponent)
         {
             resolver.AddComponent(compID, newComponent);
@@ -1082,9 +1083,9 @@ bool Node::LoadXML(const XMLElement& source, SceneResolver& resolver, bool readC
     while (childElem)
     {
         unsigned nodeID = childElem.GetInt("id");
-        Node* newNode = CreateChild(nodeID, id_ < FIRST_LOCAL_ID ? REPLICATED : LOCAL);
+        Node* newNode = CreateChild(rewriteIDs ? 0 : nodeID, id_ < FIRST_LOCAL_ID ? REPLICATED : LOCAL);
         resolver.AddNode(nodeID, newNode);
-        if (!newNode->LoadXML(childElem, resolver))
+        if (!newNode->LoadXML(childElem, resolver, readChildren, rewriteIDs))
             return false;
         
         childElem = childElem.GetNext("node");

+ 2 - 2
Engine/Scene/Node.h

@@ -320,9 +320,9 @@ public:
     /// Update motion smoothing. Called by Scene.
     void UpdateSmoothing(float constant, float squaredSnapThreshold);
     /// Load components and optionally load child nodes.
-    bool Load(Deserializer& source, SceneResolver& resolver, bool loadChildren = true);
+    bool Load(Deserializer& source, SceneResolver& resolver, bool loadChildren = true, bool rewriteIDs = false);
     /// Load components from XML data and optionally load child nodes.
-    bool LoadXML(const XMLElement& source, SceneResolver& resolver, bool loadChildren = true);
+    bool LoadXML(const XMLElement& source, SceneResolver& resolver, bool loadChildren = true, bool rewriteIDs = false);
     
     /// User variables.
     VariantMap vars_;

+ 6 - 4
Engine/Scene/Scene.cpp

@@ -278,9 +278,10 @@ Node* Scene::Instantiate(Deserializer& source, const Vector3& position, const Qu
 {
     SceneResolver resolver;
     unsigned nodeID = source.ReadInt();
-    Node* node = CreateChild(nodeID, mode);
+    // Rewrite IDs when instantiating
+    Node* node = CreateChild(0, mode);
     resolver.AddNode(nodeID, node);
-    if (node->Load(source, resolver))
+    if (node->Load(source, resolver, true, true))
     {
         resolver.Resolve();
         node->ApplyAttributes();
@@ -307,9 +308,10 @@ Node* Scene::InstantiateXML(const XMLElement& source, const Vector3& position, c
 {
     SceneResolver resolver;
     unsigned nodeID = source.GetInt("id");
-    Node* node = CreateChild(nodeID, mode);
+    // Rewrite IDs when instantiating
+    Node* node = CreateChild(0, mode);
     resolver.AddNode(nodeID, node);
-    if (node->LoadXML(source, resolver))
+    if (node->LoadXML(source, resolver, true, true))
     {
         resolver.Resolve();
         node->ApplyAttributes();

+ 13 - 10
Engine/UI/LineEdit.cpp

@@ -56,6 +56,9 @@ LineEdit::LineEdit(Context* context) :
     cursor_->SetPriority(1); // Show over text
     AddChild(text_);
     AddChild(cursor_);
+    
+    SubscribeToEvent(this, E_FOCUSED, HANDLER(LineEdit, HandleFocused));
+    SubscribeToEvent(this, E_DEFOCUSED, HANDLER(LineEdit, HandleDefocused));
 }
 
 LineEdit::~LineEdit()
@@ -428,16 +431,6 @@ void LineEdit::OnChar(unsigned char c, int buttons, int qualifiers)
     }
 }
 
-void LineEdit::OnFocus()
-{
-    UpdateCursor();
-}
-
-void LineEdit::OnDefocus()
-{
-    text_->ClearSelection();
-}
-
 void LineEdit::SetText(const String& text)
 {
     if (text != line_)
@@ -562,3 +555,13 @@ unsigned LineEdit::GetCharIndex(const IntVector2& position)
     
     return M_MAX_UNSIGNED;
 }
+
+void LineEdit::HandleFocused(StringHash eventType, VariantMap& eventData)
+{
+    UpdateCursor();
+}
+
+void LineEdit::HandleDefocused(StringHash eventType, VariantMap& eventData)
+{
+    text_->ClearSelection();
+}

+ 6 - 4
Engine/UI/LineEdit.h

@@ -62,10 +62,6 @@ public:
     virtual void OnKey(int key, int buttons, int qualifiers);
     /// React to a key press translated to a character.
     virtual void OnChar(unsigned char c, int buttons, int qualifiers);
-    /// React to gaining focus.
-    virtual void OnFocus();
-    /// React to losing focus.
-    virtual void OnDefocus();
     
     /// %Set text.
     void SetText(const String& text);
@@ -141,4 +137,10 @@ protected:
     bool textSelectable_;
     /// Copy-paste enable flag.
     bool textCopyable_;
+    
+private:
+    /// Handle being focused.
+    void HandleFocused(StringHash eventType, VariantMap& eventData);
+    /// Handle being defocused.
+    void HandleDefocused(StringHash eventType, VariantMap& eventData);
 };

+ 15 - 13
Engine/UI/ListView.cpp

@@ -69,6 +69,8 @@ ListView::ListView(Context* context) :
     
     SubscribeToEvent(E_UIMOUSECLICK, HANDLER(ListView, HandleUIMouseClick));
     SubscribeToEvent(E_FOCUSCHANGED, HANDLER(ListView, HandleFocusChanged));
+    SubscribeToEvent(this, E_FOCUSED, HANDLER(ListView, HandleFocused));
+    SubscribeToEvent(this, E_DEFOCUSED, HANDLER(ListView, HandleDefocused));
 }
 
 ListView::~ListView()
@@ -258,19 +260,6 @@ void ListView::OnResize()
     contentElement_->SetWidth(scrollPanel_->GetWidth());
 }
 
-void ListView::OnFocus()
-{
-    UpdateSelectionEffect();
-}
-
-void ListView::OnDefocus()
-{
-    if (clearSelectionOnDefocus_)
-        ClearSelection();
-    
-    UpdateSelectionEffect();
-}
-
 void ListView::AddItem(UIElement* item)
 {
     InsertItem(contentElement_->GetNumChildren(), item);
@@ -816,3 +805,16 @@ void ListView::HandleFocusChanged(StringHash eventType, VariantMap& eventData)
         element = parent;
     }
 }
+
+void ListView::HandleFocused(StringHash eventType, VariantMap& eventData)
+{
+    UpdateSelectionEffect();
+}
+
+void ListView::HandleDefocused(StringHash eventType, VariantMap& eventData)
+{
+    if (clearSelectionOnDefocus_)
+        ClearSelection();
+    
+    UpdateSelectionEffect();
+}

+ 5 - 5
Engine/UI/ListView.h

@@ -60,10 +60,6 @@ public:
     virtual void OnKey(int key, int buttons, int qualifiers);
     /// React to resize.
     virtual void OnResize();
-    /// React to defocus.
-    virtual void OnDefocus();
-    /// React to focus.
-    virtual void OnFocus();
     
     /// Add item to the end of the list.
     void AddItem(UIElement* item);
@@ -161,6 +157,10 @@ protected:
 private:
     /// Handle global UI mouseclick to check for selection change.
     void HandleUIMouseClick(StringHash eventType, VariantMap& eventData);
-    /// Handle focus change to check whether an invisible item was focused.
+    /// Handle global focus change to check whether an invisible item was focused.
     void HandleFocusChanged(StringHash eventType, VariantMap& eventData);
+    /// Handle being focused.
+    void HandleFocused(StringHash eventType, VariantMap& eventData);
+    /// Handle being defocused.
+    void HandleDefocused(StringHash eventType, VariantMap& eventData);
 };

+ 15 - 7
Engine/UI/Menu.cpp

@@ -24,6 +24,7 @@
 #include "Precompiled.h"
 #include "Context.h"
 #include "InputEvents.h"
+#include "Log.h"
 #include "Menu.h"
 #include "UIEvents.h"
 
@@ -133,17 +134,24 @@ void Menu::ShowPopup(bool enable)
         popup_->SetPosition(GetScreenPosition() + popupOffset_);
         popup_->SetVisible(true);
         popup_->vars_[originHash] = (void*)this;
-        root->AddChild(popup_);
-        
-        // Set fixed high priority
-        popup_->SetBringToFront(false);
-        popup_->SetBringToBack(false);
+        if (popup_->GetParent() != root)
+            root->AddChild(popup_);
         popup_->BringToFront();
     }
     else
     {
         popup_->vars_[originHash].Clear();
-        root->RemoveChild(popup_);
+        popup_->SetVisible(false);
+        
+        // If the popup has child menus, hide their popups as well
+        PODVector<UIElement*> children;
+        popup_->GetChildren(children, true);
+        for (PODVector<UIElement*>::ConstIterator i = children.Begin(); i != children.End(); ++i)
+        {
+            Menu* menu = dynamic_cast<Menu*>(*i);
+            if (menu)
+                menu->ShowPopup(false);
+        }
     }
     
     showPopup_ = enable;
@@ -200,7 +208,7 @@ void Menu::HandleFocusChanged(StringHash eventType, VariantMap& eventData)
     UIElement* root = GetRoot();
     
     // If another element was focused due to the menu button being clicked, do not hide the popup
-    if (eventType == E_FOCUSCHANGED && static_cast<UIElement*>(eventData[P_ORIGINALELEMENT].GetPtr()))
+    if (eventType == E_FOCUSCHANGED && static_cast<UIElement*>(eventData[P_CLICKEDELEMENT].GetPtr()))
         return;
     
     // If clicked emptiness or defocused, hide the popup

+ 1 - 1
Engine/UI/Menu.h

@@ -82,7 +82,7 @@ protected:
 private:
     /// Handle press and release for selection and toggling popup visibility.
     void HandlePressedReleased(StringHash eventType, VariantMap& eventData);
-    /// Handle UI focus change to check for hiding the popup.
+    /// Handle global focus change to check for hiding the popup.
     void HandleFocusChanged(StringHash eventType, VariantMap& eventData);
     /// Handle keypress for checking accelerator.
     void HandleKeyDown(StringHash eventType, VariantMap& eventData);

+ 1 - 3
Engine/UI/UI.cpp

@@ -111,7 +111,7 @@ void UI::SetFocusElement(UIElement* element)
     using namespace FocusChanged;
     
     VariantMap eventData;
-    eventData[P_ORIGINALELEMENT] = (void*)element;
+    eventData[P_CLICKEDELEMENT] = (void*)element;
     
     if (element)
     {
@@ -130,7 +130,6 @@ void UI::SetFocusElement(UIElement* element)
     {
         UIElement* oldFocusElement = focusElement_;
         focusElement_.Reset();
-        oldFocusElement->OnDefocus();
         
         VariantMap focusEventData;
         focusEventData[Defocused::P_ELEMENT] = oldFocusElement;
@@ -141,7 +140,6 @@ void UI::SetFocusElement(UIElement* element)
     if (element && element->GetFocusMode() >= FM_FOCUSABLE)
     {
         focusElement_ = element;
-        element->OnFocus();
         
         VariantMap focusEventData;
         focusEventData[Focused::P_ELEMENT] = element;

+ 0 - 8
Engine/UI/UIElement.cpp

@@ -302,14 +302,6 @@ void UIElement::OnResize()
 {
 }
 
-void UIElement::OnFocus()
-{
-}
-
-void UIElement::OnDefocus()
-{
-}
-
 void UIElement::SetName(const String& name)
 {
     name_ = name;

+ 0 - 4
Engine/UI/UIElement.h

@@ -140,10 +140,6 @@ public:
     virtual void OnChar(unsigned char c, int buttons, int qualifiers);
     /// React to resize.
     virtual void OnResize();
-    /// React to gaining focus.
-    virtual void OnFocus();
-    /// React to losing focus.
-    virtual void OnDefocus();
     
     /// %Set name.
     void SetName(const String& name);

+ 1 - 1
Engine/UI/UIEvents.h

@@ -56,7 +56,7 @@ EVENT(E_DRAGDROPFINISH, DragDropFinish)
 EVENT(E_FOCUSCHANGED, FocusChanged)
 {
     PARAM(P_ELEMENT, Element);              // UIElement pointer
-    PARAM(P_ORIGINALELEMENT, Element);      // UIElement pointer
+    PARAM(P_CLICKEDELEMENT, ClickedElement); // UIElement pointer
 }
 
 /// UI element resized.