Changeset 6737 for code/branches/gamestates2/data/gui/scripts
- Timestamp:
- Apr 16, 2010, 12:22:12 PM (15 years ago)
- Location:
- code/branches/gamestates2/data/gui/scripts
- Files:
-
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
code/branches/gamestates2/data/gui/scripts/InitialiseGUI.lua
r6722 r6737 1 winMgr = CEGUI.WindowManager:getSingleton() 2 guiMgr = orxonox.GUIManager:getInstance() 3 inputMgr = orxonox.InputManager:getInstance() 4 5 local schemeMgr = CEGUI.SchemeManager:getSingleton() 6 local system = CEGUI.System:getSingleton() 7 local cursor = CEGUI.MouseCursor:getSingleton() 1 -- Define some global shortcuts for common Managers 2 guiMgr = orxonox.GUIManager:getInstance() 3 inputMgr = orxonox.InputManager:getInstance() 4 schemeMgr = CEGUI.SchemeManager:getSingleton() 5 winMgr = CEGUI.WindowManager:getSingleton() 8 6 9 7 -- Load all required skins … … 25 23 schemeMgr:loadScheme("OrxonoxGUIScheme.scheme") 26 24 25 local system = CEGUI.System:getSingleton() 27 26 system:setDefaultMouseCursor(menuImageSet, "MouseArrow") 28 27 system:setDefaultFont("BlueHighway-12") 29 28 system:setDefaultTooltip("MenuWidgets/Tooltip") 30 29 31 local loadedSheets = {} 32 local activeMenuSheets = {size = 0, topSheetTuple = nil} 33 --activeHUDSheets = {size = 0, topSheetTuple = nil} 34 local root = nil 35 36 -- Require all tools 30 -- Convenience function and additional tools 37 31 require("GUITools") 38 39 40 -----------------------41 --- Local functions ---42 -----------------------43 44 -- Loads the GUI with the specified name45 -- The name corresponds to the filename of the *.lua and *.layout files46 -- but without the extension47 local function loadSheet(name)48 -- Check if it has already been loaded49 local sheet = loadedSheets[name]50 if sheet == nil then51 -- Load the sheet52 sheet = require(name)53 sheet:load()54 loadedSheets[name] = sheet55 end56 return sheet57 end58 59 local function hideCursor()60 if cursor:isVisible() then61 cursor:hide()62 end63 end64 65 local function showCursor()66 if not cursor:isVisible() and orxonox.InputManager:getInstance():isMouseExclusive() then67 cursor:show()68 end69 end70 71 72 ------------------------73 --- Global functions ---74 ------------------------75 76 -- ?77 function showMenuSheet(name, bHidePrevious, ptr)78 local sheet = showMenuSheet(name, bHidePrevious)79 sheet.overlay = ptr80 return sheet81 end82 83 -- Shows the specified menu sheet and loads it if neccessary84 function showMenuSheet(name, bHidePrevious)85 -- Get sheet (or load it)86 local menuSheet = loadSheet(name)87 if not menuSheet then88 return nil89 end90 91 -- Use sheet's value if nil was provided92 if bHidePrevious == nil then93 bHidePrevious = menuSheet.bHidePrevious94 assert(bHidePrevious ~= nil)95 end96 97 -- Pause game control if this is the first menu to be displayed98 -- HUGE HACK?99 if activeMenuSheets.size == 0 then100 orxonox.HumanController:pauseControl()101 end102 103 -- Hide if already displayed (to make sure it is up front in the end)104 if activeMenuSheets[name] ~= nil then105 hideMenuSheet(name)106 end107 108 -- Add the sheet in a tuple of additional information109 local sheetTuple =110 {111 ["sheet"] = menuSheet,112 ["bHidePrevious"] = bHidePrevious113 }114 table.insert(activeMenuSheets, sheetTuple) -- indexed array access115 activeMenuSheets[name] = sheetTuple -- name access116 activeMenuSheets.size = activeMenuSheets.size + 1117 activeMenuSheets.topSheetTuple = sheetTuple118 119 if not root then120 setBackground("")121 end122 123 -- Add sheet to the root window124 root:addChildWindow(menuSheet.window)125 126 -- Handle input distribution127 orxonox.InputManager:getInstance():enterState(menuSheet.inputState)128 129 -- Only change cursor situation if menuSheet.tShowCursor ~= TriBool.Dontcare130 if menuSheet.tShowCursor == TriBool.True then131 showCursor()132 elseif menuSheet.tShowCursor == TriBool.False then133 hideCursor()134 end135 136 -- Hide all previous sheets if necessary137 if bHidePrevious then138 for i = 1, activeMenuSheets.size - 1 do139 activeMenuSheets[i].sheet:hide()140 end141 end142 143 menuSheet:show()144 145 return menuSheet146 end147 148 function hideMenuSheet(name)149 local sheetTuple = activeMenuSheets[name]150 if sheetTuple == nil then151 return152 end153 154 -- Hide the sheet155 sheetTuple.sheet:hide()156 157 -- Show sheets that were hidden by the sheet to be removed158 local i = activeMenuSheets.size159 -- Only do something if all sheets on top of sheetTuple160 -- have bHidePrevious == true and sheetTuple.bHidePrevious == true161 while i > 0 do162 if activeMenuSheets[i].bHidePrevious then163 if activeMenuSheets[i] == sheetTuple then164 i = i - 1165 while i > 0 do166 activeMenuSheets[i].sheet:show()167 if activeMenuSheets[i].bHidePrevious then168 break169 end170 i = i - 1171 end172 end173 break174 end175 i = i - 1176 end177 178 -- Remove sheet with its tuple from the table179 root:removeChildWindow(sheetTuple.sheet.window)180 table.remove(activeMenuSheets, table.findIndex(activeMenuSheets, sheetTuple))181 activeMenuSheets[name] = nil182 activeMenuSheets.size = activeMenuSheets.size - 1183 activeMenuSheets.topSheetTuple = activeMenuSheets[activeMenuSheets.size]184 185 -- Leave the input state186 orxonox.InputManager:getInstance():leaveState(sheetTuple.sheet.inputState)187 188 -- CURSOR SHOWING189 local i = activeMenuSheets.size190 -- Find top most sheet that doesn't have tShowCusor == TriBool.Dontcare191 while i > 0 and activeMenuSheets[i].sheet.tShowCursor == TriBool.Dontcare do192 i = i - 1193 end194 if i > 0 and activeMenuSheets[i].sheet.tShowCursor == TriBool.True then195 showCursor()196 else197 hideCursor()198 end199 200 -- Resume control if the last menu is hidden201 if activeMenuSheets.size == 0 then202 orxonox.HumanController:resumeControl()203 hideCursor()204 end205 end206 207 -- Hides all menu GUI sheets208 function hideAllMenuSheets()209 while activeMenuSheets.size ~= 0 do210 hideMenuSheet(activeMenuSheets.topSheetTuple.sheet.name)211 end212 end213 214 function keyESC()215 -- HUGE, very HUGE hacks!216 if activeMenuSheets.size == 1 and activeMenuSheets[1].sheet.name == "MainMenu" then217 orxonox.execute("exit")218 elseif activeMenuSheets.size > 0 then219 orxonox.execute("hideMenuSheet "..activeMenuSheets.topSheetTuple.sheet.name)220 else221 showMenuSheet("InGameMenu")222 end223 end224 225 function setBackground(name)226 local newroot227 if root ~= nil then228 root:rename("oldRootWindow")229 end230 if name ~= "" then231 newroot = winMgr:loadWindowLayout(name .. ".layout")232 newroot:rename("AbsoluteRootWindow")233 system:setGUISheet(newroot)234 else235 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 end240 if root ~= nil then241 local child242 while root:getChildCount()~=0 do243 child = root:getChildAtIdx(0)244 root:removeChildWindow(child)245 newroot:addChildWindow(child)246 end247 winMgr:destroyWindow(root)248 end249 newroot:show()250 root = newroot251 end -
code/branches/gamestates2/data/gui/scripts/SheetManager.lua
r6722 r6737 1 winMgr = CEGUI.WindowManager:getSingleton() 2 guiMgr = orxonox.GUIManager:getInstance() 3 inputMgr = orxonox.InputManager:getInstance() 1 -- SheetManager.lua 4 2 5 local schemeMgr = CEGUI.SchemeManager:getSingleton() 6 local system = CEGUI.System:getSingleton() 7 local cursor = CEGUI.MouseCursor:getSingleton() 8 9 -- Load all required skins 10 schemeMgr: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 19 schemeMgr:loadScheme("TaharezGreenMenuWidgets.scheme") 20 menuImageSet = "TaharezGreenLook" 21 schemeMgr:loadScheme("TaharezGreenHUDWidgets.scheme") 22 hudImageSet = "TaharezGreenLook" 23 24 -- Just a remaining test hack 25 schemeMgr:loadScheme("OrxonoxGUIScheme.scheme") 26 27 system:setDefaultMouseCursor(menuImageSet, "MouseArrow") 28 system:setDefaultFont("BlueHighway-12") 29 system:setDefaultTooltip("MenuWidgets/Tooltip") 30 3 local cursor = CEGUI.MouseCursor:getSingleton() 31 4 local loadedSheets = {} 32 5 local activeMenuSheets = {size = 0, topSheetTuple = nil} 33 --activeHUDSheets = {size = 0, topSheetTuple = nil} 34 local root = nil 35 36 -- Require all tools 37 require("GUITools") 38 6 local menuSheetsRoot = guiMgr:getMenuRootWindow() 39 7 40 8 ----------------------- … … 42 10 ----------------------- 43 11 12 local function hideCursor() 13 if cursor:isVisible() then 14 cursor:hide() 15 end 16 end 17 18 local function showCursor() 19 if not cursor:isVisible() and inputMgr:isMouseExclusive() then 20 cursor:show() 21 end 22 end 23 24 25 ------------------------ 26 --- Global functions --- 27 ------------------------ 28 44 29 -- Loads the GUI with the specified name 45 30 -- The name corresponds to the filename of the *.lua and *.layout files 46 31 -- but without the extension 47 localfunction loadSheet(name)32 function loadSheet(name) 48 33 -- Check if it has already been loaded 49 34 local sheet = loadedSheets[name] … … 57 42 end 58 43 59 local function hideCursor()60 if cursor:isVisible() then61 cursor:hide()62 end63 end64 65 local function showCursor()66 if not cursor:isVisible() and orxonox.InputManager:getInstance():isMouseExclusive() then67 cursor:show()68 end69 end70 71 72 ------------------------73 --- Global functions ---74 ------------------------75 76 44 -- ? 77 45 function showMenuSheet(name, bHidePrevious, ptr) … … 83 51 -- Shows the specified menu sheet and loads it if neccessary 84 52 function showMenuSheet(name, bHidePrevious) 53 if name == "" then 54 return nil 55 end 85 56 -- Get sheet (or load it) 86 57 local menuSheet = loadSheet(name) 87 if not menuSheet then88 return nil89 end90 58 91 59 -- Use sheet's value if nil was provided … … 117 85 activeMenuSheets.topSheetTuple = sheetTuple 118 86 119 if not root then120 setBackground("")121 end122 123 87 -- Add sheet to the root window 124 root:addChildWindow(menuSheet.window)88 menuSheetsRoot:addChildWindow(menuSheet.window) 125 89 126 90 -- Handle input distribution 127 orxonox.InputManager:getInstance():enterState(menuSheet.inputState)91 inputMgr:enterState(menuSheet.inputState) 128 92 129 93 -- Only change cursor situation if menuSheet.tShowCursor ~= TriBool.Dontcare … … 177 141 178 142 -- Remove sheet with its tuple from the table 179 root:removeChildWindow(sheetTuple.sheet.window)143 menuSheetsRoot:removeChildWindow(sheetTuple.sheet.window) 180 144 table.remove(activeMenuSheets, table.findIndex(activeMenuSheets, sheetTuple)) 181 145 activeMenuSheets[name] = nil … … 184 148 185 149 -- Leave the input state 186 orxonox.InputManager:getInstance():leaveState(sheetTuple.sheet.inputState)150 inputMgr:leaveState(sheetTuple.sheet.inputState) 187 151 188 152 -- CURSOR SHOWING … … 223 187 end 224 188 225 function setBackground(name) 226 local newroot 227 if root ~= nil then 228 root:rename("oldRootWindow") 229 end 230 if name ~= "" then 231 newroot = winMgr:loadWindowLayout(name .. ".layout") 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 189 function setBackgroundImage(imageSet, imageName) 190 guiMgr:setBackgroundImage(imageSet, imageName) 251 191 end 192 193 ---------------------- 194 --- Initialisation --- 195 ---------------------- 196 197 hideCursor()
Note: See TracChangeset
for help on using the changeset viewer.