Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/gamestates2/data/gui/scripts/InitialiseGUI.lua @ 6718

Last change on this file since 6718 was 6718, checked in by rgrieder, 14 years ago

Moved BasicGUI.lua to GUISheet.lua and derived MenuSheet.lua as well as HUDSheet.lua from it.
Also, to make a new GUI sheet, use either createHUDSheet or createMenuSheet.
Also removed bShowCursor from the showGUI function. This is now always a value directed by the GUI sheet.

  • Property svn:eol-style set to native
File size: 7.2 KB
RevLine 
[6595]1winMgr   = CEGUI.WindowManager:getSingleton()
2guiMgr   = orxonox.GUIManager:getInstance()
3inputMgr = orxonox.InputManager:getInstance()
4
[5491]5local schemeMgr = CEGUI.SchemeManager:getSingleton()
[6595]6local system    = CEGUI.System:getSingleton()
7local cursor    = CEGUI.MouseCursor:getSingleton()
[5491]8
[6595]9-- Load all required skins
10schemeMgr:loadScheme("TaharezGreenLook.scheme")
11--schemeMgr:loadScheme("TaharezLook.scheme")
12--schemeMgr:loadScheme("WindowsLook.scheme")
13--schemeMgr:loadScheme("VanillaLook.scheme")
14--schemeMgr:loadScheme("SleekSpaceLook.scheme")
15
16-- Connect skin specific window types with our own window types
17-- By loading a different file (if there is) you can change the skin
18-- of the menus or the HUD independently
19schemeMgr:loadScheme("TaharezGreenMenuWidgets.scheme")
20menuImageSet = "TaharezGreenLook"
21schemeMgr:loadScheme("TaharezGreenHUDWidgets.scheme")
22hudImageSet = "TaharezGreenLook"
23
24-- Just a remaining test hack
[5491]25schemeMgr:loadScheme("OrxonoxGUIScheme.scheme")
26
[6595]27system:setDefaultMouseCursor(menuImageSet, "MouseArrow")
[5491]28system:setDefaultFont("BlueHighway-12")
[6595]29system:setDefaultTooltip("MenuWidgets/Tooltip")
[5491]30
[6662]31local loadedSheets = {}
[6718]32local activeMenuSheets = {size = 0, topSheetTuple = nil}
33--activeHUDSheets  = {size = 0, topSheetTuple = nil}
[6662]34local root = nil
[5491]35
[6417]36-- Require all tools
37require("GUITools")
38
[6662]39
40-----------------------
41--- Local functions ---
42-----------------------
43
44-- Loads the GUI with the specified name
45-- The name corresponds to the filename of the *.lua and *.layout files
46-- but without the extension
47local function loadSheet(name)
48    -- Check if it has already been loaded
49    local sheet = loadedSheets[name]
50    if sheet == nil then
51        -- Load the sheet
52        sheet = require(name)
53        sheet:load()
54        loadedSheets[name] = sheet
55    end
56    return sheet
57end
58
59local function hideCursor()
60    if cursor:isVisible() then
61        cursor:hide()
62    end
63end
64
65local function showCursor()
66    if not cursor:isVisible() and orxonox.InputManager:getInstance():isMouseExclusive() then
67        cursor:show()
68    end
69end
70
[5491]71
[6662]72------------------------
73--- Global functions ---
74------------------------
75
76-- ?
[6718]77function showGUI(name, bHidePrevious, ptr)
78    local sheet = showGUI(name, bHidePrevious)
79    sheet.overlay = ptr
80    return sheet
[5491]81end
82
[6662]83-- Shows the specified menu sheet and loads it if neccessary
[6718]84function showGUI(name, bHidePrevious)
85    -- Get sheet (or load it)
86    local menuSheet = loadSheet(name)
87    if not menuSheet then
88        return nil
[5491]89    end
90
[6718]91    -- Use sheet's value if nil was provided
92    if bHidePrevious == nil then
93        bHidePrevious = menuSheet.bHidePrevious
94        assert(bHidePrevious ~= nil)
95    end
96
[6662]97    -- Hide if already displayed (to make sure it is up front in the end)
98    if activeMenuSheets[name] ~= nil then
99        hideGUI(name)
100    end
101
[6718]102    -- Add the sheet in a tuple of additional information
103    local sheetTuple =
104    {
105        ["sheet"]          = menuSheet,
106        ["bHidePrevious"]  = bHidePrevious
107    }
108    table.insert(activeMenuSheets, sheetTuple) -- indexed array access
109    activeMenuSheets[name] = sheetTuple -- name access
110    activeMenuSheets.size = activeMenuSheets.size + 1
111    activeMenuSheets.topSheetTuple = sheetTuple
112
[6662]113    if not root then
[6417]114        setBackground("")
115    end
116
[6662]117    -- Add sheet to the root window
118    root:addChildWindow(menuSheet.window)
119
120    -- Pause game control if this is the first menu to be displayed
121    -- HUGE HACK?
122    if activeMenuSheets.size == 0 then
123        orxonox.HumanController:pauseControl()
[6417]124    end
125
[6662]126    -- Handle input distribution
127    orxonox.InputManager:getInstance():enterState(menuSheet.inputState)
128
[6718]129    -- Only change cursor situation if menuSheet.tShowCursor ~= TriBool.Dontcare
130    if menuSheet.tShowCursor == TriBool.True then
[6417]131        showCursor()
[6718]132    elseif menuSheet.tShowCursor == TriBool.False then
[6417]133        hideCursor()
[5491]134    end
[6417]135
[6662]136    -- Hide all previous sheets if necessary
137    if bHidePrevious then
138        for i = 1, activeMenuSheets.size - 1 do
[6718]139            activeMenuSheets[i].sheet:hide()
[6417]140        end
141    end
[5491]142
[6662]143    menuSheet:show()
[6718]144
[6662]145    return menuSheet
[5491]146end
147
[6662]148function hideGUI(name)
149    local sheetTuple = activeMenuSheets[name]
150    if sheetTuple == nil then
151        return
[6417]152    end
[5491]153
[6662]154    -- Hide the sheet
[6718]155    sheetTuple.sheet:hide()
[6662]156
157    -- Show sheets that were hidden by the sheet to be removed
158    local i = activeMenuSheets.size
159    -- Only do something if all sheets on top of sheetTuple
[6718]160    -- have bHidePrevious == true and sheetTuple.bHidePrevious == true
[6662]161    while i > 0 do
[6718]162        if activeMenuSheets[i].bHidePrevious then
[6662]163            if activeMenuSheets[i] == sheetTuple then
164                i = i - 1
165                while i > 0 do
[6718]166                    activeMenuSheets[i].sheet:show()
167                    if activeMenuSheets[i].bHidePrevious then
[6662]168                        break
169                    end
170                    i = i - 1
[6417]171                end
172            end
[6662]173            break
[6417]174        end
[6662]175        i = i - 1
[6417]176    end
[6662]177
178    -- Remove sheet with its tuple from the table
[6718]179    root:removeChildWindow(sheetTuple.sheet.window)
[6671]180    table.remove(activeMenuSheets, table.findIndex(activeMenuSheets, sheetTuple))
[6662]181    activeMenuSheets[name] = nil
182    activeMenuSheets.size = activeMenuSheets.size - 1
[6718]183    activeMenuSheets.topSheetTuple = activeMenuSheets[activeMenuSheets.size]
[6662]184
185    -- Leave the input state
[6718]186    orxonox.InputManager:getInstance():leaveState(sheetTuple.sheet.inputState)
[6662]187   
[6718]188    -- CURSOR SHOWING
189    local i = activeMenuSheets.size
190    -- Find top most sheet that doesn't have tShowCusor == TriBool.Dontcare
191    while i > 0 and activeMenuSheets[i].sheet.tShowCursor == TriBool.Dontcare do
192        i = i - 1
193    end
194    if i > 0 and activeMenuSheets[i].sheet.tShowCursor == TriBool.True then
[6662]195        showCursor()
196    else
197        hideCursor()
198    end
199
200    -- Resume control if the last menu is hidden
201    if activeMenuSheets.size == 0 then
[6417]202        orxonox.HumanController:resumeControl()
203        hideCursor()
204    end
[5491]205end
[6417]206
[6662]207-- Hides all menu GUI sheets
[6417]208function hideAllGUIs()
[6662]209    while activeMenuSheets.size ~= 0 do
[6718]210        hideGUI(activeMenuSheets.topSheetTuple.sheet.name)
[6417]211    end
212end
213
214function keyESC()
[6662]215    -- HUGE, very HUGE hacks!
[6718]216    if activeMenuSheets.size == 1 and activeMenuSheets[1].sheet.name == "MainMenu" then
[6417]217        orxonox.execute("exit")
[6662]218    elseif activeMenuSheets.size > 0 then
[6718]219        orxonox.execute("hideGUI "..activeMenuSheets.topSheetTuple.sheet.name)
[6417]220    else
221        showGUI("InGameMenu")
222    end
223end
224
[6662]225function setBackground(name)
[6417]226    local newroot
227    if root ~= nil then
228        root:rename("oldRootWindow")
229    end
[6662]230    if name ~= "" then
231        newroot = winMgr:loadWindowLayout(name .. ".layout")
[6417]232        newroot:rename("AbsoluteRootWindow")
233        system:setGUISheet(newroot)
234    else
235        newroot = winMgr:createWindow("DefaultWindow", "AbsoluteRootWindow")
236        newroot:setProperty("Alpha", "0.0")
237        newroot:setSize(CEGUI.UVector2(CEGUI.UDim(1.0,0),CEGUI.UDim(1.0,0)))
238        system:setGUISheet(newroot)
239    end
240    if root ~= nil then
241        local child
242        while root:getChildCount()~=0 do
243            child = root:getChildAtIdx(0)
244            root:removeChildWindow(child)
245            newroot:addChildWindow(child)
246        end
247        winMgr:destroyWindow(root)
248    end
249    newroot:show()
250    root = newroot
251end
Note: See TracBrowser for help on using the repository browser.