浏览代码

Fixed lockup in removeResourcePath().
Fixed editor UI element priorities.
Added closebutton to the file selector.
Menus with popup activate from mouse press, not release.
Editor status display is split on two rows if width is less than 1024.
Increased default resolution to 800x600.
Removed test UI layouts.

Lasse Öörni 14 年之前
父节点
当前提交
a3150b5f11

+ 17 - 9
Bin/CoreData/Scripts/EditorCamera.as

@@ -159,17 +159,25 @@ void createStatsBar()
     @renderStatsText = Text();
     @cameraPosText = Text();
     
-    setupStatsBarText(renderStatsText, font, 0, HA_LEFT);
-    setupStatsBarText(cameraPosText, font, 0, HA_RIGHT);
+    if (uiRoot.getWidth() >= 1024)
+    {
+        setupStatsBarText(renderStatsText, font, 0, 20, HA_LEFT);
+        setupStatsBarText(cameraPosText, font, 0, 20, HA_RIGHT);
+    }
+    else
+    {
+        setupStatsBarText(renderStatsText, font, 0, 20, HA_LEFT);
+        setupStatsBarText(cameraPosText, font, 0, 32, HA_LEFT);
+    }
 }
 
-void setupStatsBarText(Text@ text, Font@ font, int xPos, HorizontalAlignment align)
+void setupStatsBarText(Text@ text, Font@ font, int x, int y, HorizontalAlignment align)
 {
-    text.setPosition(xPos, 20);
+    text.setPosition(x, y);
     text.setHorizontalAlignment(align);
     text.setFont(font, 9);
     text.setColor(Color(1, 1, 0));
-    text.setPriority(-10);
+    text.setPriority(-100);
     uiRoot.addChild(text);
 }
 
@@ -187,11 +195,11 @@ void updateStats(float timeStep)
     string xText = toString(cameraPos.x);
     string yText = toString(cameraPos.y);
     string zText = toString(cameraPos.z);
-    xText.resize(10);
-    yText.resize(10);
-    zText.resize(10);
+    xText.resize(8);
+    yText.resize(8);
+    zText.resize(8);
     
-    cameraPosText.setText("Physics: " + (runPhysics ? "Running   " : "Paused    ") + " Camera pos: " + xText + " " + yText + " " + zText);
+    cameraPosText.setText("Physics: " + (runPhysics ? "Running " : "Paused  ") + " Camera pos: " + xText + " " + yText + " " + zText + " ");
     
     renderStatsText.setSize(renderStatsText.getMinSize());
     cameraPosText.setSize(cameraPosText.getMinSize());

+ 0 - 1
Bin/CoreData/Scripts/EditorImportTundra.as

@@ -121,7 +121,6 @@ void importTundraScene(string fileName)
                 // Fix coordinate system
                 pos = Vector3(pos.x, pos.z, pos.y);
                 rot = Vector3(rot.x, -rot.z + 180, rot.y);
-                //scale = Vector3(scale.x, scale.y, scale.z);
             }
             
             compElem = compElem.getNextElement("component");

+ 8 - 5
Bin/CoreData/Scripts/EditorUI.as

@@ -8,6 +8,7 @@ array<string> uiSceneFilters = {"*.xml", "*.bin", "*.dat", "*.*"};
 array<string> tundraSceneFilter = {"*.txml"};
 array<string> uiAllFilter = {"*.*"};
 uint uiSceneFilter = 0;
+string uiScenePath;
 
 void createUI()
 {
@@ -43,9 +44,9 @@ void createCursor()
 void createMenuBar()
 {
     @uiMenuBar = BorderImage("MenuBar");
+    uiMenuBar.setEnabled(true);
     uiMenuBar.setStyle(uiStyle, "EditorMenuBar");
-    uiMenuBar.setLayout(LM_HORIZONTAL, 2, IntRect(2, 2, 2, 2));
-    uiMenuBar.setPriority(10);
+    uiMenuBar.setLayout(LM_HORIZONTAL, 4, IntRect(2, 2, 2, 2));
     uiRoot.addChild(uiMenuBar);
 
     {
@@ -204,7 +205,7 @@ void handleMenuSelected(StringHash eventType, VariantMap& eventData)
             
         if (action == "Open scene")
         {
-            createFileSelector("Open scene", "Open", "Cancel", getPath(sceneFileName), uiSceneFilters, uiSceneFilter);
+            createFileSelector("Open scene", "Open", "Cancel", uiScenePath, uiSceneFilters, uiSceneFilter);
             subscribeToEvent(uiFileSelector, "FileSelected", "handleOpenSceneFile");
         }
 
@@ -213,7 +214,7 @@ void handleMenuSelected(StringHash eventType, VariantMap& eventData)
 
         if (action == "Save scene as")
         {
-            createFileSelector("Save scene as", "Save", "Cancel", sceneFileName.empty() ? sceneResourcePath : getPath(sceneFileName), uiSceneFilters, uiSceneFilter);
+            createFileSelector("Save scene as", "Save", "Cancel", uiScenePath, uiSceneFilters, uiSceneFilter);
             uiFileSelector.setFileName(getFileNameAndExtension(sceneFileName));
             subscribeToEvent(uiFileSelector, "FileSelected", "handleSaveSceneFile");
         }
@@ -268,8 +269,9 @@ void handleMenuSelected(StringHash eventType, VariantMap& eventData)
 
 void handleOpenSceneFile(StringHash eventType, VariantMap& eventData)
 {
-    // Save filter for next time
+    // Save filter & path for next time
     uiSceneFilter = uiFileSelector.getFilterIndex();
+    uiScenePath = uiFileSelector.getPath();
     closeFileSelector();
 
     // Check for cancel
@@ -284,6 +286,7 @@ void handleSaveSceneFile(StringHash eventType, VariantMap& eventData)
 {
     // Save filter for next time
     uiSceneFilter = uiFileSelector.getFilterIndex();
+    uiScenePath = uiFileSelector.getPath();
     closeFileSelector();
 
     // Check for cancel

+ 1 - 3
Bin/CoreData/UI/CameraDialog.xml

@@ -7,9 +7,7 @@
         <element type="Text">
             <text value="Editor camera settings" />
         </element>
-        <element type="Button" style="CloseButton" name="CloseButton">
-            <fixedsize value="16 16" />
-        </element>
+        <element type="Button" style="CloseButton" name="CloseButton" />
     </element>
     <element type="BorderImage" style="EditorDivider">
         <fixedheight value="4" />

+ 1 - 3
Bin/CoreData/UI/ComponentWindow.xml

@@ -9,9 +9,7 @@
         <element type="Text" name="WindowTitle">
             <text value="Entity / component edit" />
         </element>
-        <element type="Button" style="CloseButton" name="CloseButton">
-            <fixedsize value="16 16" />
-        </element>
+        <element type="Button" style="CloseButton" name="CloseButton" />
     </element>
     <element type="BorderImage" style="EditorDivider">
         <fixedheight value="4" />

+ 5 - 1
Bin/CoreData/UI/DefaultStyle.xml

@@ -17,7 +17,7 @@
         <hoveroffset value="0 16" />
     </element>
     <element type="CloseButton">
-        <size value="16 16" />
+        <fixedsize value="16 16" />
         <texture name="Textures/UI.png" />
         <imagerect value="128 0 144 16" />
         <border value="4 4 4 4" />
@@ -357,6 +357,10 @@
         <font name="Cour.ttf" size="10" />
         <hovercolor value="0.45 0.70 0.45" />
     </element>
+    <element type="FileSelectorTitleLayout">
+        <fixedheight value="16" />
+        <layout spacing="4" />
+    </element>
     <element type="FileSelectorLayout">
         <layout spacing="4" />
     </element>

+ 1 - 3
Bin/CoreData/UI/SceneSettingsDialog.xml

@@ -7,9 +7,7 @@
         <element type="Text">
             <text value="Global scene settings" />
         </element>
-        <element type="Button" style="CloseButton" name="CloseButton">
-            <fixedsize value="16 16" />
-        </element>
+        <element type="Button" style="CloseButton" name="CloseButton" />
     </element>
     <element type="BorderImage" style="EditorDivider">
         <fixedheight value="4" />

+ 5 - 7
Bin/CoreData/UI/SceneWindow.xml

@@ -9,9 +9,7 @@
         <element type="Text">
             <text value="Scene hierarchy" />
         </element>
-        <element type="Button" style="CloseButton" name="CloseButton">
-            <fixedsize value="16 16" />
-        </element>
+        <element type="Button" style="CloseButton" name="CloseButton" />
     </element>
     <element type="BorderImage" style="EditorDivider">
         <fixedheight value="4" />
@@ -46,8 +44,8 @@
         <layout mode="horizontal" spacing="4" />
         <element type="Element" />
         <element type="DropDownList" name="NewEntityList">
-            <fixedwidth value="90" />
-            <layout border="4 5 4 4" />
+            <fixedsize value="90 22" />
+            <layout border="4 4 4 4" />
             <placeholder>
                 <visible enable="false" />
             </placeholder>
@@ -61,8 +59,8 @@
         </element>
         <element />
         <element type="DropDownList" name="NewComponentList">
-            <fixedwidth value="90" />
-            <layout border="4 5 4 4" />
+            <fixedsize value="90 22" />
+            <layout border="4 4 4 4" />
             <placeholder>
                 <visible enable="false" />
             </placeholder>

+ 0 - 36
Bin/Data/Scripts/GraphicsTest.as

@@ -326,42 +326,6 @@ void initUI()
     cursor.setStyleAuto(uiStyle);
     cursor.setPosition(renderer.getWidth() / 2, renderer.getHeight() / 2);
     ui.setCursor(cursor);
-
-    bool uiTest = false;
-    array<string> arguments = getArguments();
-    for (uint i = 0; i < arguments.size(); ++i)
-    {
-        if (arguments[i] == "-uitest")
-            uiTest = true;
-    }
-
-    if (!uiTest)
-        return;
-
-    XMLFile@ uiLayout = cache.getResource("XMLFile", "UI/TestLayout.xml");
-    UIElement@ layoutRoot = ui.loadLayout(uiLayout, uiStyle);
-    uiRoot.addChild(layoutRoot);
-
-    @fileSelector = FileSelector();
-    fileSelector.setStyle(uiStyle);
-    fileSelector.setTitle("Load file");
-    fileSelector.setButtonTexts("Load", "Cancel");
-    fileSelector.getWindow().setPosition(200, 100);
-
-    array<string> filters;
-    filters.resize(2);
-    filters[0] = "*.*";
-    filters[1] = "*.exe";
-    fileSelector.setFilters(filters, 0);
-
-    subscribeToEvent(fileSelector, "FileSelected", "handleFileSelected");
-
-}
-
-void handleFileSelected(StringHash eventType, VariantMap& eventData)
-{
-    unsubscribeFromEvent(fileSelector, "FileSelected");
-    @fileSelector = null;
 }
 
 void createCamera()

+ 0 - 161
Bin/Data/UI/TestLayout.xml

@@ -1,161 +0,0 @@
-<element type="Window">
-    <position value="50 50" />
-    <size value="400 300" />
-    <movable enable="true" />
-    <element type="Button">
-        <position value="10 10" />
-        <size value="100 40" />
-        <element type="Text">
-            <text value="TEST" />
-            <alignment horizontal="center" vertical="center" />
-        </element>
-    </element>
-    <element type="CheckBox">
-        <position value="10 100" />
-    </element>
-    <element type="CheckBox">
-        <position value="40 100" />
-    </element>
-    <element type="CheckBox">
-        <position value="10 130" />
-    </element>
-    <element type="CheckBox">
-        <position value="40 130" />
-    </element>
-    <element type="Text" name="PopupItem1">
-        <text value="Deferred" />
-        <hovercolor value="0.45 0.70 0.45" />
-    </element>
-    <element type="Text" name="PopupItem2">
-        <text value="Prepass" />
-        <hovercolor value="0.45 0.70 0.45" />
-    </element>
-    <element type="Text" name="PopupItem3">
-        <text value="Forward" />
-        <hovercolor value="0.45 0.70 0.45" />
-    </element>
-    <element type="DropDownList">
-        <position value="10 160" />
-        <size value="100 30" />
-        <resizepopup enable="true" />
-        <layout mode="horizontal" border="8 8 8 8" />
-        <popupitem name="PopupItem1" />
-        <popupitem name="PopupItem2" />
-        <popupitem name="PopupItem3" />
-        <popup>
-            <layout border="8 8 8 8" />
-        </popup>
-    </element>
-    <element type="Text" name="Item1">
-        <text value="Audio" />
-        <selectioncolor value="0.45 0.70 0.45" />
-    </element>
-    <element type="Text" name="Item2">
-        <text value="Common" />
-        <selectioncolor value="0.45 0.70 0.45" />
-    </element>
-    <element type="Text" name="Item3">
-        <text value="Engine" />
-        <selectioncolor value="0.45 0.70 0.45" />
-    </element>
-    <element type="Text" name="Item4">
-        <text value="Input" />
-        <selectioncolor value="0.45 0.70 0.45" />
-    </element>
-    <element type="Text" name="Item5">
-        <text value="Math" />
-        <selectioncolor value="0.45 0.70 0.45" />
-    </element>
-    <element type="Text" name="Item6">
-        <text value="Network" />
-        <selectioncolor value="0.45 0.70 0.45" />
-    </element>
-    <element type="Text" name="Item7">
-        <text value="Physics" />
-        <selectioncolor value="0.45 0.70 0.45" />
-    </element>
-    <element type="Text" name="Item8">
-        <text value="Renderer" />
-        <selectioncolor value="0.45 0.70 0.45" />
-    </element>
-    <element type="Text" name="Item9">
-        <text value="Resource" />
-        <selectioncolor value="0.45 0.70 0.45" />
-    </element>
-    <element type="Text" name="Item10">
-        <text value="Scene" />
-        <selectioncolor value="0.45 0.70 0.45" />
-    </element>
-    <element type="Text" name="Item11">
-        <text value="UI" />
-        <selectioncolor value="0.45 0.70 0.45" />
-    </element>
-    <element type="ListView">
-        <position value="150 100" />
-        <size value="212 112" />
-        <multiselect enable="true" />
-        <listitem name="Item1" />
-        <listitem name="Item2" />
-        <listitem name="Item3" />
-        <listitem name="Item4" />
-        <listitem name="Item5" />
-        <listitem name="Item6" />
-        <listitem name="Item7" />
-        <listitem name="Item8" />
-        <listitem name="Item9" />
-        <listitem name="Item10" />
-        <listitem name="Item11" />
-    </element>
-    <element type="LineEdit">
-        <position value="150 230" />
-        <size value="200 18" />
-        <dragdropmode value="sourceandtarget" />
-    </element>
-    <element type="LineEdit">
-        <position value="150 260" />
-        <size value="200 18" />
-        <dragdropmode value="sourceandtarget" />
-    </element>
-    <element type="Window" name="TestPopup">
-        <layout mode="vertical" spacing="4" border="8 8 8 8" />
-        <element type="Menu">
-            <layout mode="vertical" />
-            <element type="Text">
-                <text value="MenuItem3" />
-                <alignment horizontal="center" vertical="center" />
-            </element>
-        </element>
-        <element type="Menu">
-            <layout mode="vertical" />
-            <element type="Text">
-                <text value="MenuItem4" />
-                <alignment horizontal="center" vertical="center" />
-            </element>
-        </element>
-        <element type="Menu">
-            <layout mode="vertical" />
-            <element type="Text">
-                <text value="MenuItem5" />
-                <alignment horizontal="center" vertical="center" />
-            </element>
-        </element>
-    </element>
-    <element type="Menu">
-        <position value="150 10" />
-        <size value="80 16" />
-        <popup name="TestPopup" />
-        <popupoffset value="0 16" />
-        <element type="Text">
-            <text value="MenuItem1" />
-            <alignment horizontal="center" vertical="center" />
-        </element>
-    </element>
-    <element type="Menu">
-        <position value="150 40" />
-        <size value="80 16" />
-        <element type="Text">
-            <text value="MenuItem2" />
-            <alignment horizontal="center" vertical="center" />
-        </element>
-    </element>
-</element>

+ 0 - 25
Bin/Data/UI/TestLayout2.xml

@@ -1,25 +0,0 @@
-<element type="Window">
-    <position value="50 50" />
-    <size value="400 300" />
-    <movable enable="true" />
-    <resizable enable="true" />
-    <layout mode="vertical" border="4 4 4 4" spacing="2" />
-    <clipborder value="4 4 4 4" />
-    <element>
-        <clipchildren enable="true" />
-        <layout mode="vertical" />
-        <element type="Text">
-            <font name="courier.ttf" size="12" />
-            <text value="At some point the fire had started.\n  There was total chaos. The locks of the wooden barracks had been blown apart by gunfire from shotguns and assault rifles, and the trainees were pouring out in confusion. But the primary target still lay ahead.\n  The administrative building. Where the identities and evaluations of the trainees were stored.\n  That was first class knowledge. If the Agents could bring that knowledge to the public, and cross-reference the records - mostly boys of young age - with lists of known missing persons, then they could prove the existence of SCEPTRE." />
-            <wordwrap enable="true" />
-        </element>
-    </element>
-    <element type="Button">
-        <fixedsize value="100 30" />
-        <alignment horizontal="center" />
-        <element type="Text">
-            <text value="TEST" />
-            <alignment horizontal="center" vertical="center" />
-        </element>
-    </element>
-</element>

+ 0 - 77
Bin/Data/UI/TestLayout3.xml

@@ -1,77 +0,0 @@
-<element type="Window">
-    <position value="50 50" />
-    <size value="400 300" />
-    <movable enable="true" />
-    <resizable enable="true" />
-    <layout mode="vertical" border="8 8 8 8" spacing="8" />
-    <clipborder value="8 8 8 8" />
-    <minsize value="60 60" />
-    <element>
-        <layout mode="horizontal" spacing="8" />
-        <element type="Button">
-            <element type="Text">
-                <text value="TEST1" />
-                <alignment horizontal="center" vertical="center" />
-            </element>
-        </element>
-        <element type="Button">
-            <visible enable="false" />
-            <element type="Text">
-                <text value="TEST2" />
-                <alignment horizontal="center" vertical="center" />
-            </element>
-        </element>
-        <element type="Button">
-            <element type="Text">
-                <text value="TEST3" />
-                <alignment horizontal="center" vertical="center" />
-            </element>
-        </element>
-    </element>
-    <element>
-        <layout mode="horizontal" spacing="8" />
-    	<element type="Text" name="ScrollViewText">
-	        <position value="1 0" />
-	        <fixedwidth value="400" />
-	        <font name="times.ttf" size="12" />
-            <text value="At some point the fire had started.\n  There was total chaos. The locks of the wooden barracks had been blown apart by gunfire from shotguns and assault rifles, and the trainees were pouring out in confusion. But the primary target still lay ahead.\n  The administrative building. Where the identities and evaluations of the trainees were stored.\n  That was first class knowledge. If the Agents could bring that knowledge to the public, and cross-reference the records - mostly boys of young age - with lists of known missing persons, then they could prove the existence of SCEPTRE." />
-	        <wordwrap enable="true" />
-	    </element>
-        <element type="Button">
-            <element type="Text">
-                <text value="TEST4" />
-                <alignment horizontal="center" vertical="center" />
-            </element>
-        </element>
-    	<element type="ScrollView">
-	        <contentelement name="ScrollViewText" />
-	    </element>
-        <element type="Button">
-            <element type="Text">
-                <text value="TEST5" />
-                <alignment horizontal="center" vertical="center" />
-            </element>
-        </element>
-    </element>
-    <element>
-        <layout mode="horizontal" spacing="8" />
-        <element type="Button">
-            <element type="Text">
-                <text value="TEST6" />
-                <alignment horizontal="center" vertical="center" />
-            </element>
-        </element>
-        <element type="Button">
-            <element type="Text">
-                <text value="TEST7" />
-                <alignment horizontal="center" vertical="center" />
-            </element>
-        </element>
-        <element type="Button">
-            <element type="Text">
-                <text value="TEST8" />
-                <alignment horizontal="center" vertical="center" />
-            </element>
-        </element>
-    </element>
-</element>

+ 2 - 2
Engine/Renderer/Renderer.cpp

@@ -186,8 +186,8 @@ void Renderer::setMode(RenderMode mode, int width, int height, bool fullscreen,
         }
         else
         {
-            width = 640;
-            height = 480;
+            width = 800;
+            height = 600;
         }
     }
     

+ 2 - 2
Engine/Resource/ResourceCache.cpp

@@ -124,11 +124,11 @@ bool ResourceCache::addManualResource(Resource* resource)
 void ResourceCache::removeResourcePath(const std::string& path)
 {
     std::string fixedPath = toLower(fixPath(path));
-    for (std::vector<std::string>::iterator i = mResourcePaths.begin(); i != mResourcePaths.end();)
+    for (std::vector<std::string>::iterator i = mResourcePaths.begin(); i != mResourcePaths.end(); ++i)
     {
         if (toLower(*i) == fixedPath)
         {
-            i = mResourcePaths.erase(i);
+            mResourcePaths.erase(i);
             return;
         }
     }

+ 11 - 1
Engine/UI/FileSelector.cpp

@@ -58,8 +58,15 @@ FileSelector::FileSelector(UI* ui) :
     mWindow = new Window();
     mWindow->setLayout(LM_VERTICAL);
     
+    mTitleLayout = new UIElement();
+    mTitleLayout->setLayout(LM_HORIZONTAL);
+    mWindow->addChild(mTitleLayout);
+    
     mTitleText = new Text();
-    mWindow->addChild(mTitleText);
+    mTitleLayout->addChild(mTitleText);
+    
+    mCloseButton = new Button();
+    mTitleLayout->addChild(mCloseButton);
     
     mPathEdit = new LineEdit();
     mWindow->addChild(mPathEdit);
@@ -120,6 +127,7 @@ FileSelector::FileSelector(UI* ui) :
     subscribeToEvent(mFileList, EVENT_UNHANDLEDKEY, EVENT_HANDLER(FileSelector, handleFileListKey));
     subscribeToEvent(mOKButton, EVENT_RELEASED, EVENT_HANDLER(FileSelector, handleOKPressed));
     subscribeToEvent(mCancelButton, EVENT_RELEASED, EVENT_HANDLER(FileSelector, handleCancelPressed));
+    subscribeToEvent(mCloseButton, EVENT_RELEASED, EVENT_HANDLER(FileSelector, handleCancelPressed));
 }
 
 FileSelector::~FileSelector()
@@ -142,10 +150,12 @@ void FileSelector::setStyle(XMLFile* style)
     mWindow->setStyle(style, "FileSelector", cache);
     
     mTitleText->setStyle(style, "FileSelectorTitleText", cache);
+    mCloseButton->setStyle(style, "CloseButton", cache);
     
     mOKButtonText->setStyle(style, "FileSelectorButtonText", cache);
     mCancelButtonText->setStyle(style, "FileSelectorButtonText", cache);
     
+    mTitleLayout->setStyle(style, "FileSelectorTitleLayout", cache);
     mFileNameLayout->setStyle(style, "FileSelectorLayout", cache);
     mButtonLayout->setStyle(style, "FileSelectorLayout", cache);
     

+ 6 - 0
Engine/UI/FileSelector.h

@@ -89,6 +89,8 @@ public:
     Button* getOKButton() const { return mOKButton; }
     //! Return cancel button
     Button* getCancelButton() const { return mCancelButton; }
+    //! Return close button
+    Button* getCloseButton() const { return mCloseButton; }
     //! Return current path
     const std::string& getPath() const { return mPath; }
     //! Return current filename
@@ -126,6 +128,8 @@ private:
     SharedPtr<XMLFile> mStyle;
     //! Fileselector window
     SharedPtr<Window> mWindow;
+    //! Title layout
+    SharedPtr<UIElement> mTitleLayout;
     //! Window title text
     SharedPtr<Text> mTitleText;
     //! File list
@@ -144,6 +148,8 @@ private:
     SharedPtr<Button> mCancelButton;
     //! Cancel button text
     SharedPtr<Text> mCancelButtonText;
+    //! Close button
+    SharedPtr<Button> mCloseButton;
     //! Filename and filter layout
     SharedPtr<UIElement> mFileNameLayout;
     //! Button layout

+ 16 - 3
Engine/UI/Menu.cpp

@@ -37,7 +37,8 @@ Menu::Menu(const std::string& name) :
     mAcceleratorKey(0),
     mAcceleratorQualifiers(0)
 {
-    subscribeToEvent(this, EVENT_RELEASED, EVENT_HANDLER(Menu, handleReleased));
+    subscribeToEvent(this, EVENT_PRESSED, EVENT_HANDLER(Menu, handlePressedReleased));
+    subscribeToEvent(this, EVENT_RELEASED, EVENT_HANDLER(Menu, handlePressedReleased));
     subscribeToEvent(EVENT_UIMOUSECLICK, EVENT_HANDLER(Menu, handleFocusChanged));
     subscribeToEvent(EVENT_FOCUSCHANGED, EVENT_HANDLER(Menu, handleFocusChanged));
 }
@@ -144,8 +145,20 @@ void Menu::setAccelerator(int key, int qualifiers)
         unsubscribeFromEvent(EVENT_KEYDOWN);
 }
 
-void Menu::handleReleased(StringHash eventType, VariantMap& eventData)
+void Menu::handlePressedReleased(StringHash eventType, VariantMap& eventData)
 {
+    // If this menu shows a sublevel popup, react to button press. Else react to release
+    if (eventType == EVENT_PRESSED)
+    {
+        if (!mPopup)
+            return;
+    }
+    if (eventType == EVENT_RELEASED)
+    {
+        if (mPopup)
+            return;
+    }
+    
     // Toggle popup visibility if exists
     showPopup(!mShowPopup);
     
@@ -206,5 +219,5 @@ void Menu::handleKeyDown(StringHash eventType, VariantMap& eventData)
     // Activate if accelerator key pressed
     if ((eventData[P_KEY].getInt() == mAcceleratorKey) && (eventData[P_QUALIFIERS].getInt() == mAcceleratorQualifiers) &&
         (eventData[P_REPEAT].getBool() == false))
-        handleReleased(eventType, eventData);
+        handlePressedReleased(eventType, eventData);
 }

+ 2 - 2
Engine/UI/Menu.h

@@ -79,8 +79,8 @@ protected:
     int mAcceleratorQualifiers;
     
 private:
-    //! Handle press-release for confirming the selection
-    void handleReleased(StringHash eventType, VariantMap& eventData);
+    //! 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
     void handleFocusChanged(StringHash eventType, VariantMap& eventData);
     //! Handle keypress for checking accelerator