Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/usability/data/gui/scripts/InGameMenu.lua @ 7922

Last change on this file since 7922 was 7922, checked in by landauf, 13 years ago

implemented new keyboard control of menu buttons with these new features:

  • more intuitive placement of buttons in table (row/column format instead of linear index)
  • no need to overwrite onShow() and onKeyPressed() functions, no need for P.buttonList
  • highlights the selected button in a different layout than mouse hovering
  • remembers the selection while moving through the menu hierarchy, but resets it if the menu is closed
  • allows preselected button (for example "Yes" in decision popup)
  • when opening a menu, the first selected button is not always the upper left, but instead depends on the pressed key (e.g. the 'up' key selects the button at the bottom, while the 'down' key selects the button at the top. once a button is selected, the keys behave as usual)

+ fixed wrong callback function in ingame menu

  • Property svn:eol-style set to native
File size: 1.5 KB
Line 
1-- InGameMenu.lua
2
3local P = createMenuSheet("InGameMenu")
4P.loadAlong = { "DecisionPopup" }
5
6function P.onLoad()
7    P.multiplayerMode = "startClient"
8
9    --button are arranged in a 4x1 matrix, the left lower item is nil
10    P:initButtons(4, 1)
11
12    P:setButton(1, 1, {
13            ["button"] = winMgr:getWindow("orxonox/InGameMenu_ReturnButton"),
14            ["callback"]  = P.button_return_clicked
15    })
16
17    P:setButton(2, 1, {
18            ["button"] = winMgr:getWindow("orxonox/InGameMenu_MainMenuButton"),
19            ["callback"]  = P.button_mainmenu_clicked
20    })
21
22    P:setButton(3, 1, {
23            ["button"] = winMgr:getWindow("orxonox/InGameMenu_SettingsButton"),
24            ["callback"]  = P.button_settings_clicked
25    })
26
27    P:setButton(4, 1, {
28            ["button"] = winMgr:getWindow("orxonox/InGameMenu_QuitButton"),
29            ["callback"]  = P.button_quit_clicked
30    })
31end
32
33function P.onShow()
34    if P:hasSelection() == false then
35        P:setSelection(1, 1)
36    end
37end
38
39-- events for ingamemenu
40function P.button_quit_clicked(e)
41    openDecisionPopup( "Do you really want to quit the game?", InGameMenu.callback )
42end
43
44function P.button_mainmenu_clicked(e)
45    orxonox.execute("startMainMenu")
46    hideMenuSheet("InGameMenu")
47end
48
49function P.button_settings_clicked(e)
50    showMenuSheet("SettingsMenu", true)
51end
52
53function P.button_return_clicked(e)
54    hideMenuSheet("InGameMenu")
55end
56
57function P.callback(doExit)
58    if doExit then
59        hideMenuSheet("InGameMenu")
60        orxonox.execute("exit")
61    else
62        P.onShow()
63    end
64end
65
66return P
67
Note: See TracBrowser for help on using the repository browser.