Browse Source

Merge pull request #907 from diath/topbar_visibility_toggle

Add a keyboard shortcut to toggle topmenu visibility
Eduardo Bart 3 years ago
parent
commit
47766685d9
No account linked to committer's email address

+ 21
- 0
modules/client_topmenu/topmenu.lua View File

@@ -51,6 +51,8 @@ function init()
51 51
   pingLabel = topMenu:getChildById('pingLabel')
52 52
   fpsLabel = topMenu:getChildById('fpsLabel')
53 53
 
54
+  g_keyboard.bindKeyDown('Ctrl+Shift+T', toggle)
55
+
54 56
   if g_game.isOnline() then
55 57
     online()
56 58
   end
@@ -164,3 +166,22 @@ end
164 166
 function getTopMenu()
165 167
   return topMenu
166 168
 end
169
+
170
+function toggle()
171
+  local menu = getTopMenu()
172
+  if not menu then
173
+    return
174
+  end
175
+
176
+  if menu:isVisible() then
177
+    menu:hide()
178
+    modules.client_background.getBackground():addAnchor(AnchorTop, 'parent', AnchorTop)
179
+    modules.game_interface.getRootPanel():addAnchor(AnchorTop, 'parent', AnchorTop)
180
+    modules.game_interface.getShowTopMenuButton():show()
181
+  else
182
+    menu:show()
183
+    modules.client_background.getBackground():addAnchor(AnchorTop, 'topMenu', AnchorBottom)
184
+    modules.game_interface.getRootPanel():addAnchor(AnchorTop, 'topMenu', AnchorBottom)
185
+    modules.game_interface.getShowTopMenuButton():hide()
186
+  end
187
+end

+ 10
- 0
modules/game_interface/gameinterface.lua View File

@@ -5,6 +5,7 @@ gameMapPanel = nil
5 5
 gameRightPanel = nil
6 6
 gameLeftPanel = nil
7 7
 gameBottomPanel = nil
8
+showTopMenuButton = nil
8 9
 logoutButton = nil
9 10
 mouseGrabberWidget = nil
10 11
 countWindow = nil
@@ -56,6 +57,11 @@ function init()
56 57
   logoutButton = modules.client_topmenu.addLeftButton('logoutButton', tr('Exit'),
57 58
     '/images/topbuttons/logout', tryLogout, true)
58 59
 
60
+  showTopMenuButton = gameMapPanel:getChildById('showTopMenuButton')
61
+  showTopMenuButton.onClick = function()
62
+    modules.client_topmenu.toggle()
63
+  end
64
+
59 65
   setupViewMode(0)
60 66
 
61 67
   bindKeys()
@@ -815,6 +821,10 @@ function getBottomPanel()
815 821
   return gameBottomPanel
816 822
 end
817 823
 
824
+function getShowTopMenuButton()
825
+  return showTopMenuButton
826
+end
827
+
818 828
 function onLeftPanelVisibilityChange(leftPanel, visible)
819 829
   if not visible and g_game.isOnline() then
820 830
     local children = leftPanel:getChildren()

+ 9
- 2
modules/game_interface/gameinterface.otui View File

@@ -1,4 +1,3 @@
1
-
2 1
 GameSidePanel < UIMiniWindowContainer
3 2
   image-source: /images/ui/panel_side
4 3
   image-border: 4
@@ -33,6 +32,14 @@ UIWidget
33 32
     anchors.bottom: gameBottomPanel.top
34 33
     focusable: false
35 34
 
35
+    Button
36
+      id: showTopMenuButton
37
+      anchors.top: parent.top
38
+      anchors.left: parent.left
39
+      !text: tr('Show Top Menu')
40
+      height: 32
41
+      visible: false
42
+
36 43
   GameBottomPanel
37 44
     id: gameBottomPanel
38 45
     anchors.left: gameLeftPanel.right
@@ -73,4 +80,4 @@ UIWidget
73 80
   UIWidget
74 81
     id: mouseGrabber
75 82
     focusable: false
76
-    visible: false
83
+    visible: false

Loading…
Cancel
Save