Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/notifications/data/gui/scripts/SheetManager.lua @ 7339

Last change on this file since 7339 was 7339, checked in by dafrick, 14 years ago

Small fix.

  • Property svn:eol-style set to native
File size: 6.0 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-- ?
[7338]45function showMenuSheet(name, bHidePrevious, bNoInput, ptr)
46    local sheet = showMenuSheet(name, bHidePrevious, bNoInput)
[6718]47    sheet.overlay = ptr
48    return sheet
[5491]49end
50
[6662]51-- Shows the specified menu sheet and loads it if neccessary
[7338]52function showMenuSheet(name, bHidePrevious, bNoInput)
[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
[7338]65    if bNoInput == nil then
66        bNoInput = false
67    end
68
[6721]69    -- Pause game control if this is the first menu to be displayed
70    -- HUGE HACK?
71    if activeMenuSheets.size == 0 then
72        orxonox.HumanController:pauseControl()
73    end
74
[6662]75    -- Hide if already displayed (to make sure it is up front in the end)
76    if activeMenuSheets[name] ~= nil then
[6722]77        hideMenuSheet(name)
[6662]78    end
79
[7339]80    if bNoInput == false then
81        menuSheet.tShowCursor = TriBool.Dontcare
82    end
[7338]83
[6718]84    -- Add the sheet in a tuple of additional information
85    local sheetTuple =
86    {
87        ["sheet"]          = menuSheet,
[7338]88        ["bHidePrevious"]  = bHidePrevious,
89        ["bNoInput"]       = bNoInput
[6718]90    }
91    table.insert(activeMenuSheets, sheetTuple) -- indexed array access
92    activeMenuSheets[name] = sheetTuple -- name access
93    activeMenuSheets.size = activeMenuSheets.size + 1
94    activeMenuSheets.topSheetTuple = sheetTuple
95
[6662]96    -- Add sheet to the root window
[6737]97    menuSheetsRoot:addChildWindow(menuSheet.window)
[6662]98
99    -- Handle input distribution
[7338]100    if bNoInput == false then
101        inputMgr:enterState(menuSheet.inputState)
102    end
[6662]103
[6718]104    -- Only change cursor situation if menuSheet.tShowCursor ~= TriBool.Dontcare
105    if menuSheet.tShowCursor == TriBool.True then
[6417]106        showCursor()
[6718]107    elseif menuSheet.tShowCursor == TriBool.False then
[6417]108        hideCursor()
[5491]109    end
[6417]110
[6662]111    -- Hide all previous sheets if necessary
112    if bHidePrevious then
113        for i = 1, activeMenuSheets.size - 1 do
[6718]114            activeMenuSheets[i].sheet:hide()
[6417]115        end
116    end
[5491]117
[6662]118    menuSheet:show()
[6718]119
[6662]120    return menuSheet
[5491]121end
122
[6722]123function hideMenuSheet(name)
[6662]124    local sheetTuple = activeMenuSheets[name]
125    if sheetTuple == nil then
126        return
[6417]127    end
[5491]128
[6662]129    -- Hide the sheet
[6718]130    sheetTuple.sheet:hide()
[6662]131
132    -- Show sheets that were hidden by the sheet to be removed
133    local i = activeMenuSheets.size
134    -- Only do something if all sheets on top of sheetTuple
[6718]135    -- have bHidePrevious == true and sheetTuple.bHidePrevious == true
[6662]136    while i > 0 do
[6718]137        if activeMenuSheets[i].bHidePrevious then
[6662]138            if activeMenuSheets[i] == sheetTuple then
139                i = i - 1
140                while i > 0 do
[6718]141                    activeMenuSheets[i].sheet:show()
142                    if activeMenuSheets[i].bHidePrevious then
[6662]143                        break
144                    end
145                    i = i - 1
[6417]146                end
147            end
[6662]148            break
[6417]149        end
[6662]150        i = i - 1
[6417]151    end
[6662]152
153    -- Remove sheet with its tuple from the table
[6737]154    menuSheetsRoot:removeChildWindow(sheetTuple.sheet.window)
[6671]155    table.remove(activeMenuSheets, table.findIndex(activeMenuSheets, sheetTuple))
[6662]156    activeMenuSheets[name] = nil
157    activeMenuSheets.size = activeMenuSheets.size - 1
[6718]158    activeMenuSheets.topSheetTuple = activeMenuSheets[activeMenuSheets.size]
[6662]159
160    -- Leave the input state
[7338]161    if not sheetTuple.bNoInput then
162        inputMgr:leaveState(sheetTuple.sheet.inputState)
163    end
[6662]164   
[6718]165    -- CURSOR SHOWING
166    local i = activeMenuSheets.size
167    -- Find top most sheet that doesn't have tShowCusor == TriBool.Dontcare
168    while i > 0 and activeMenuSheets[i].sheet.tShowCursor == TriBool.Dontcare do
169        i = i - 1
170    end
171    if i > 0 and activeMenuSheets[i].sheet.tShowCursor == TriBool.True then
[6662]172        showCursor()
173    else
174        hideCursor()
175    end
176
177    -- Resume control if the last menu is hidden
178    if activeMenuSheets.size == 0 then
[6417]179        orxonox.HumanController:resumeControl()
180        hideCursor()
181    end
[5491]182end
[6417]183
[6662]184-- Hides all menu GUI sheets
[6722]185function hideAllMenuSheets()
[6662]186    while activeMenuSheets.size ~= 0 do
[6722]187        hideMenuSheet(activeMenuSheets.topSheetTuple.sheet.name)
[6417]188    end
189end
190
191function keyESC()
[6662]192    -- HUGE, very HUGE hacks!
[7338]193
194    -- Count the number of sheets that don't need input till the first that does.
195    local counter = activeMenuSheets.size
196    while counter > 0 and activeMenuSheets[counter].bNoInput do
197        counter = counter - 1
198    end
199
200    -- If the first sheet that needs input is the MainMenu.
201    if counter > 0 and activeMenuSheets.size == counter and activeMenuSheets[counter].sheet.name == "MainMenu" then
[6417]202        orxonox.execute("exit")
[7338]203    -- If there is at least one sheet that needs input.
204    elseif counter > 0 then
205        orxonox.execute("hideGUI "..activeMenuSheets[counter].sheet.name)
[6417]206    else
[6722]207        showMenuSheet("InGameMenu")
[6417]208    end
209end
210
[6737]211function setBackgroundImage(imageSet, imageName)
212    guiMgr:setBackgroundImage(imageSet, imageName)
[6417]213end
[6737]214
215----------------------
216--- Initialisation ---
217----------------------
218
219hideCursor()
Note: See TracBrowser for help on using the repository browser.