Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/data/gui/scripts/SheetManager.lua @ 6958

Last change on this file since 6958 was 6746, checked in by rgrieder, 15 years ago

Merged gamestates2 branch back to trunk.
This brings in some heavy changes in the GUI framework.
It should also fix problems with triggered asserts in the InputManager.

Note: PickupInventory does not seem to work —> Segfault when showing because before, the owner in GUIOverlay::setGUIName is already NULL.
I haven't tested it before, so I can't tell whether it's my changes.

  • Property svn:eol-style set to native
File size: 5.4 KB
RevLine 
[6737]1-- SheetManager.lua
[6595]2
[6737]3local cursor = CEGUI.MouseCursor:getSingleton()
[6662]4local loadedSheets = {}
[6718]5local activeMenuSheets = {size = 0, topSheetTuple = nil}
[6737]6local menuSheetsRoot = guiMgr:getMenuRootWindow()
[5491]7
[6662]8-----------------------
9--- Local functions ---
10-----------------------
11
12local function hideCursor()
13    if cursor:isVisible() then
14        cursor:hide()
15    end
16end
17
18local function showCursor()
[6737]19    if not cursor:isVisible() and inputMgr:isMouseExclusive() then
[6662]20        cursor:show()
21    end
22end
23
[5491]24
[6662]25------------------------
26--- Global functions ---
27------------------------
28
[6737]29-- Loads the GUI with the specified name
30-- The name corresponds to the filename of the *.lua and *.layout files
31-- but without the extension
32function loadSheet(name)
33    -- Check if it has already been loaded
34    local sheet = loadedSheets[name]
35    if sheet == nil then
36        -- Load the sheet
37        sheet = require(name)
38        sheet:load()
39        loadedSheets[name] = sheet
40    end
41    return sheet
42end
43
[6662]44-- ?
[6722]45function showMenuSheet(name, bHidePrevious, ptr)
46    local sheet = showMenuSheet(name, bHidePrevious)
[6718]47    sheet.overlay = ptr
48    return sheet
[5491]49end
50
[6662]51-- Shows the specified menu sheet and loads it if neccessary
[6722]52function showMenuSheet(name, bHidePrevious)
[6737]53    if name == "" then
54        return nil
55    end
[6718]56    -- Get sheet (or load it)
57    local menuSheet = loadSheet(name)
[5491]58
[6718]59    -- Use sheet's value if nil was provided
60    if bHidePrevious == nil then
61        bHidePrevious = menuSheet.bHidePrevious
62        assert(bHidePrevious ~= nil)
63    end
64
[6721]65    -- Pause game control if this is the first menu to be displayed
66    -- HUGE HACK?
67    if activeMenuSheets.size == 0 then
68        orxonox.HumanController:pauseControl()
69    end
70
[6662]71    -- Hide if already displayed (to make sure it is up front in the end)
72    if activeMenuSheets[name] ~= nil then
[6722]73        hideMenuSheet(name)
[6662]74    end
75
[6718]76    -- Add the sheet in a tuple of additional information
77    local sheetTuple =
78    {
79        ["sheet"]          = menuSheet,
80        ["bHidePrevious"]  = bHidePrevious
81    }
82    table.insert(activeMenuSheets, sheetTuple) -- indexed array access
83    activeMenuSheets[name] = sheetTuple -- name access
84    activeMenuSheets.size = activeMenuSheets.size + 1
85    activeMenuSheets.topSheetTuple = sheetTuple
86
[6662]87    -- Add sheet to the root window
[6737]88    menuSheetsRoot:addChildWindow(menuSheet.window)
[6662]89
90    -- Handle input distribution
[6737]91    inputMgr:enterState(menuSheet.inputState)
[6662]92
[6718]93    -- Only change cursor situation if menuSheet.tShowCursor ~= TriBool.Dontcare
94    if menuSheet.tShowCursor == TriBool.True then
[6417]95        showCursor()
[6718]96    elseif menuSheet.tShowCursor == TriBool.False then
[6417]97        hideCursor()
[5491]98    end
[6417]99
[6662]100    -- Hide all previous sheets if necessary
101    if bHidePrevious then
102        for i = 1, activeMenuSheets.size - 1 do
[6718]103            activeMenuSheets[i].sheet:hide()
[6417]104        end
105    end
[5491]106
[6662]107    menuSheet:show()
[6718]108
[6662]109    return menuSheet
[5491]110end
111
[6722]112function hideMenuSheet(name)
[6662]113    local sheetTuple = activeMenuSheets[name]
114    if sheetTuple == nil then
115        return
[6417]116    end
[5491]117
[6662]118    -- Hide the sheet
[6718]119    sheetTuple.sheet:hide()
[6662]120
121    -- Show sheets that were hidden by the sheet to be removed
122    local i = activeMenuSheets.size
123    -- Only do something if all sheets on top of sheetTuple
[6718]124    -- have bHidePrevious == true and sheetTuple.bHidePrevious == true
[6662]125    while i > 0 do
[6718]126        if activeMenuSheets[i].bHidePrevious then
[6662]127            if activeMenuSheets[i] == sheetTuple then
128                i = i - 1
129                while i > 0 do
[6718]130                    activeMenuSheets[i].sheet:show()
131                    if activeMenuSheets[i].bHidePrevious then
[6662]132                        break
133                    end
134                    i = i - 1
[6417]135                end
136            end
[6662]137            break
[6417]138        end
[6662]139        i = i - 1
[6417]140    end
[6662]141
142    -- Remove sheet with its tuple from the table
[6737]143    menuSheetsRoot:removeChildWindow(sheetTuple.sheet.window)
[6671]144    table.remove(activeMenuSheets, table.findIndex(activeMenuSheets, sheetTuple))
[6662]145    activeMenuSheets[name] = nil
146    activeMenuSheets.size = activeMenuSheets.size - 1
[6718]147    activeMenuSheets.topSheetTuple = activeMenuSheets[activeMenuSheets.size]
[6662]148
149    -- Leave the input state
[6737]150    inputMgr:leaveState(sheetTuple.sheet.inputState)
[6662]151   
[6718]152    -- CURSOR SHOWING
153    local i = activeMenuSheets.size
154    -- Find top most sheet that doesn't have tShowCusor == TriBool.Dontcare
155    while i > 0 and activeMenuSheets[i].sheet.tShowCursor == TriBool.Dontcare do
156        i = i - 1
157    end
158    if i > 0 and activeMenuSheets[i].sheet.tShowCursor == TriBool.True then
[6662]159        showCursor()
160    else
161        hideCursor()
162    end
163
164    -- Resume control if the last menu is hidden
165    if activeMenuSheets.size == 0 then
[6417]166        orxonox.HumanController:resumeControl()
167        hideCursor()
168    end
[5491]169end
[6417]170
[6662]171-- Hides all menu GUI sheets
[6722]172function hideAllMenuSheets()
[6662]173    while activeMenuSheets.size ~= 0 do
[6722]174        hideMenuSheet(activeMenuSheets.topSheetTuple.sheet.name)
[6417]175    end
176end
177
178function keyESC()
[6662]179    -- HUGE, very HUGE hacks!
[6718]180    if activeMenuSheets.size == 1 and activeMenuSheets[1].sheet.name == "MainMenu" then
[6417]181        orxonox.execute("exit")
[6662]182    elseif activeMenuSheets.size > 0 then
[6743]183        orxonox.execute("hideGUI "..activeMenuSheets.topSheetTuple.sheet.name)
[6417]184    else
[6722]185        showMenuSheet("InGameMenu")
[6417]186    end
187end
188
[6737]189function setBackgroundImage(imageSet, imageName)
190    guiMgr:setBackgroundImage(imageSet, imageName)
[6417]191end
[6737]192
193----------------------
194--- Initialisation ---
195----------------------
196
197hideCursor()
Note: See TracBrowser for help on using the repository browser.