Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 13, 2010, 3:55:30 PM (15 years ago)
Author:
rgrieder
Message:

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.

Location:
code/branches/gamestates2/data/gui/scripts
Files:
2 added
19 edited
1 moved

Legend:

Unmodified
Added
Removed
  • code/branches/gamestates2/data/gui/scripts/AudioMenu.lua

    r6704 r6718  
    11-- AudioMenu.lua
    22
    3 local P = createSheet("AudioMenu")
     3local P = createMenuSheet("AudioMenu")
    44
    55function P.init()
  • code/branches/gamestates2/data/gui/scripts/ControlsMenu.lua

    r6704 r6718  
    11-- ControlsMenu.lua
    22
    3 local P = createSheet("ControlsMenu")
     3local P = createMenuSheet("ControlsMenu")
    44
    55function P.ControlsMouseControlsButton_clicked(e)
  • code/branches/gamestates2/data/gui/scripts/CreditsMenu.lua

    r6704 r6718  
    11-- CreditsMenu.lua
    22
    3 local P = createSheet("CreditsMenu")
     3local P = createMenuSheet("CreditsMenu")
    44
    55function P.CreditsBackButton_clicked(e)
  • code/branches/gamestates2/data/gui/scripts/DecisionPopup.lua

    r6662 r6718  
    11-- DecisionPopup.lua
    22
    3 local P = createSheet("DecisionPopup")
     3local P = createMenuSheet("DecisionPopup")
    44
    55function P.setCallback(functionPtr)
  • code/branches/gamestates2/data/gui/scripts/GUISheet.lua

    r6704 r6718  
    1 -- BasicGUI.lua
     1-- GUISheet.lua
    22
    33local P = {}
    4 _G[_REQUIREDNAME or "BasicGUI"] = P
     4_G[_REQUIREDNAME or "GUISheet"] = P
     5P.__index = P
    56
    6 -- useless, even wrong? P is the class, not the object..
    7 P.overlay = nil
    8 
    9 -- constructor of the GUI
    10 function P:new(_name, _gui, _visible)
    11     local newElement = {
    12         name = _name,
    13         gui = _gui,
    14         visible = _visible or false
    15     } or {}
    16     setmetatable(newElement, self) -- connects new element with class
    17     self.__index = self
    18     return newElement
     7-- Don't use directly --> use HUDSheet.new or MenuSheet.new
     8function P.new(_name)
     9    local newSheet = { name = _name }
     10    setmetatable(newSheet, P)
     11    return newSheet
    1912end
    2013
    21 -- Override this function if you need to
     14-- Override this function if you need to do work on load
     15-- TODO: rename to onLoad
    2216function P:init()
    23 end
    24 
    25 -- Override this function if you want to change one of the three input parameters:
    26 -- showCursor = true, useKeyboard = true and blockJoyStick = false
    27 -- But don't forget to stick to the naming convention ("GUI_" .. self.name)
    28 function P:createInputState()
    29     self.inputState = guiMgr:createInputState("GUI_" .. self.name)
    3017end
    3118
     
    3320function P:hide()
    3421    self.window:hide()
    35     self.visible = false
     22    self.bVisible = false
    3623end
    3724
     
    3926function P:show()
    4027    self.window:show()
    41     self.visible = true
     28    self.bVisible = true
    4229end
    4330
    4431function P:load()
     32    -- Load the layout that describes the sheet
    4533    self.window = winMgr:loadWindowLayout(self.name .. ".layout")
    46     self:createInputState()
     34    if self.window == nil then
     35        error("Could not load layout file for GUI sheet '"..self.name.."'")
     36    end
     37    -- Hide it at first
     38    self:hide()
     39    -- Allow sheets to do some work upon loading
    4740    self:init()
    4841    return self
  • code/branches/gamestates2/data/gui/scripts/GUITools.lua

    r6666 r6718  
    1 function createSheet(sheetName)
    2     -- Create object of type BasicGUI and make it global
    3     local basicGUI = require("BasicGUI")
    4     if basicGUI == nil then
    5         error("Loading BasicGUI.lua failed")
    6     end
    7     local sheet = basicGUI:new(sheetName)
    8     _G[sheetName] = sheet
     1-- Returns a new menu sheet
     2-- See MenuSheet.new for details about the parameters
     3function createMenuSheet(name, bHidePrevious, tShowCursor, tUseKeyboard, bBlockJoyStick)
     4    local sheet = require("MenuSheet").new(name, bHidePrevious, tShowCursor, tUseKeyboard, bBlockJoyStick)
     5    _G[sheet.name] = sheet -- Global access required because of the event handlers
     6    return sheet
     7end
     8
     9-- Returns a new HUD sheet
     10function createHUDSheet(name)
     11    local sheet = require("HUDSheet").new(name)
     12    _G[sheet.name] = sheet -- Global access required because of the event handlers
    913    return sheet
    1014end
  • code/branches/gamestates2/data/gui/scripts/GameplayMenu.lua

    r6704 r6718  
    11-- GameplayMenu.lua
    22
    3 local P = createSheet("GameplayMenu")
     3local P = createMenuSheet("GameplayMenu")
    44
    55function P.init()
  • code/branches/gamestates2/data/gui/scripts/GraphicsMenu.lua

    r6704 r6718  
    11-- GraphicsMenu.lua
    22
    3 local P = createSheet("GraphicsMenu")
     3local P = createMenuSheet("GraphicsMenu")
    44
    55function P.init()
  • code/branches/gamestates2/data/gui/scripts/InGameMenu.lua

    r6662 r6718  
    11-- InGameMenu.lua
    22
    3 local P = createSheet("InGameMenu")
     3local P = createMenuSheet("InGameMenu")
    44
    55-- events for ingamemenu
  • code/branches/gamestates2/data/gui/scripts/InfoPopup.lua

    r6704 r6718  
    11-- InfoPopup.lua
    22
    3 local P = createSheet("InfoPopup")
     3local P = createMenuSheet("InfoPopup")
    44
    55function P.execute(functionPtr, arguments)
  • code/branches/gamestates2/data/gui/scripts/InitialiseGUI.lua

    r6671 r6718  
    3030
    3131local loadedSheets = {}
    32 local activeMenuSheets = {size = 0, topSheet = nil}
    33 --activeHUDSheets  = {size = 0, topSheet = nil}
     32local activeMenuSheets = {size = 0, topSheetTuple = nil}
     33--activeHUDSheets  = {size = 0, topSheetTuple = nil}
    3434local root = nil
    3535
     
    5151        -- Load the sheet
    5252        sheet = require(name)
    53         if sheet == nil then
    54             return
    55         end
    5653        sheet:load()
    5754        loadedSheets[name] = sheet
    58         -- Hide new GUI as we do not want to show it accidentally
    59         sheet:hide()
    6055    end
    6156    return sheet
     
    8075
    8176-- ?
    82 function showGUI(name, bHidePrevious, bShowCursor, ptr)
    83     gui = showGUI(name, bHidePrevious, bShowCursor)
    84     gui.overlay = ptr
     77function showGUI(name, bHidePrevious, ptr)
     78    local sheet = showGUI(name, bHidePrevious)
     79    sheet.overlay = ptr
     80    return sheet
    8581end
    8682
    8783-- Shows the specified menu sheet and loads it if neccessary
    88 function showGUI(name, bHidePrevious, bShowCursor)
    89     -- Handle default value for bShowCursor
    90     if bShowCursor == nil then
    91         if activeMenuSheets.size > 0 then
    92             bShowCursor = activeMenuSheets.topSheet.bShowCursor
    93         else
    94             bShowCursor = true
    95         end
     84function showGUI(name, bHidePrevious)
     85    -- Get sheet (or load it)
     86    local menuSheet = loadSheet(name)
     87    if not menuSheet then
     88        return nil
     89    end
     90
     91    -- Use sheet's value if nil was provided
     92    if bHidePrevious == nil then
     93        bHidePrevious = menuSheet.bHidePrevious
     94        assert(bHidePrevious ~= nil)
    9695    end
    9796
     
    101100    end
    102101
    103     if not root then
    104         setBackground("")
    105     end
    106 
    107     -- Get sheet (or load it)
    108     local menuSheet = loadSheet(name)
    109     if not menuSheet then
    110         return
    111     end
    112 
    113     -- Add sheet to the root window
    114     root:addChildWindow(menuSheet.window)
    115 
    116     -- Pause game control if this is the first menu to be displayed
    117     -- HUGE HACK?
    118     if activeMenuSheets.size == 0 then
    119         orxonox.HumanController:pauseControl()
    120     end
    121 
    122     -- Handle input distribution
    123     orxonox.InputManager:getInstance():enterState(menuSheet.inputState)
    124 
    125     if bShowCursor then
    126         showCursor()
    127     else
    128         hideCursor()
    129     end
    130 
    131102    -- Add the sheet in a tuple of additional information
    132103    local sheetTuple =
    133104    {
    134         ["menuSheet"]      = menuSheet,
    135         ["name"]           = name,
    136         ["bShowCursor"]    = bShowCursor,
     105        ["sheet"]          = menuSheet,
    137106        ["bHidePrevious"]  = bHidePrevious
    138107    }
     
    140109    activeMenuSheets[name] = sheetTuple -- name access
    141110    activeMenuSheets.size = activeMenuSheets.size + 1
    142     activeMenuSheets.topSheet = sheetTuple
     111    activeMenuSheets.topSheetTuple = sheetTuple
     112
     113    if not root then
     114        setBackground("")
     115    end
     116
     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()
     124    end
     125
     126    -- Handle input distribution
     127    orxonox.InputManager:getInstance():enterState(menuSheet.inputState)
     128
     129    -- Only change cursor situation if menuSheet.tShowCursor ~= TriBool.Dontcare
     130    if menuSheet.tShowCursor == TriBool.True then
     131        showCursor()
     132    elseif menuSheet.tShowCursor == TriBool.False then
     133        hideCursor()
     134    end
    143135
    144136    -- Hide all previous sheets if necessary
    145137    if bHidePrevious then
    146138        for i = 1, activeMenuSheets.size - 1 do
    147             activeMenuSheets[i].menuSheet:hide()
     139            activeMenuSheets[i].sheet:hide()
    148140        end
    149141    end
    150142
    151143    menuSheet:show()
     144
    152145    return menuSheet
    153146end
     
    160153
    161154    -- Hide the sheet
    162     sheetTuple.menuSheet:hide()
     155    sheetTuple.sheet:hide()
    163156
    164157    -- Show sheets that were hidden by the sheet to be removed
    165158    local i = activeMenuSheets.size
    166159    -- Only do something if all sheets on top of sheetTuple
    167     -- have bHidePrevious == false and sheetTuple.bHidePrevious == true
     160    -- have bHidePrevious == true and sheetTuple.bHidePrevious == true
    168161    while i > 0 do
    169         if activeMenuSheets[i].bHidePrevious == true then
     162        if activeMenuSheets[i].bHidePrevious then
    170163            if activeMenuSheets[i] == sheetTuple then
    171164                i = i - 1
    172165                while i > 0 do
    173                     activeMenuSheets[i].menuSheet:show()
    174                     if activeMenuSheets[i].bHidePrevious == true then
     166                    activeMenuSheets[i].sheet:show()
     167                    if activeMenuSheets[i].bHidePrevious then
    175168                        break
    176169                    end
     
    184177
    185178    -- Remove sheet with its tuple from the table
    186     root:removeChildWindow(sheetTuple.menuSheet.window)
     179    root:removeChildWindow(sheetTuple.sheet.window)
    187180    table.remove(activeMenuSheets, table.findIndex(activeMenuSheets, sheetTuple))
    188181    activeMenuSheets[name] = nil
    189182    activeMenuSheets.size = activeMenuSheets.size - 1
    190     activeMenuSheets.topSheet = activeMenuSheets[activeMenuSheets.size]
     183    activeMenuSheets.topSheetTuple = activeMenuSheets[activeMenuSheets.size]
    191184
    192185    -- Leave the input state
    193     orxonox.InputManager:getInstance():leaveState(sheetTuple.menuSheet.inputState)
     186    orxonox.InputManager:getInstance():leaveState(sheetTuple.sheet.inputState)
    194187   
    195     -- See whether to show or hide cursor
    196     if activeMenuSheets.size > 0 and activeMenuSheets.topSheet.bShowCursor then
     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
    197195        showCursor()
    198196    else
     
    210208function hideAllGUIs()
    211209    while activeMenuSheets.size ~= 0 do
    212         hideGUI(activeMenuSheets.topSheet.name)
     210        hideGUI(activeMenuSheets.topSheetTuple.sheet.name)
    213211    end
    214212end
     
    216214function keyESC()
    217215    -- HUGE, very HUGE hacks!
    218     if activeMenuSheets.size == 1 and activeMenuSheets[1].name == "MainMenu" then
     216    if activeMenuSheets.size == 1 and activeMenuSheets[1].sheet.name == "MainMenu" then
    219217        orxonox.execute("exit")
    220218    elseif activeMenuSheets.size > 0 then
    221         orxonox.execute("hideGUI "..activeMenuSheets.topSheet.name)
     219        orxonox.execute("hideGUI "..activeMenuSheets.topSheetTuple.sheet.name)
    222220    else
    223221        showGUI("InGameMenu")
  • code/branches/gamestates2/data/gui/scripts/KeyBindMenu.lua

    r6704 r6718  
    11-- KeyBindMenu.lua
    22
    3 local P = createSheet("KeyBindMenu")
     3local P = createMenuSheet("KeyBindMenu")
    44
    55function P.init()
  • code/branches/gamestates2/data/gui/scripts/MainMenu.lua

    r6662 r6718  
    11-- MainMenu.lua
    22
    3 local P = createSheet("MainMenu")
     3local P = createMenuSheet("MainMenu")
    44
    55-- events for MainMenu
  • code/branches/gamestates2/data/gui/scripts/MouseControlsMenu.lua

    r6704 r6718  
    11-- MouseControlsMenu.lua
    22
    3 local P = createSheet("MouseControlsMenu")
     3local P = createMenuSheet("MouseControlsMenu")
    44
    55function P.init()
  • code/branches/gamestates2/data/gui/scripts/MultiplayerMenu.lua

    r6704 r6718  
    11-- MultiplayerMenu.lua
    22
    3 local P = createSheet("MultiplayerMenu")
     3local P = createMenuSheet("MultiplayerMenu")
    44
    55function P.init()
  • code/branches/gamestates2/data/gui/scripts/MultiplayerOptionsMenu.lua

    r6704 r6718  
    11-- MultiplayerOptionsMenu.lua
    22
    3 local P = createSheet("MultiplayerOptionsMenu")
     3local P = createMenuSheet("MultiplayerOptionsMenu")
    44
    55function P.MultiplayerOptionsBackButton_clicked(e)
  • code/branches/gamestates2/data/gui/scripts/PickupInventory.lua

    r6662 r6718  
    11-- PickupInventory.lua
    22
    3 local P = createSheet("PickupInventory")
     3local P = createMenuSheet("PickupInventory")
    44
    55P.lastEquipmentCount_ = 0
  • code/branches/gamestates2/data/gui/scripts/QuestGUI.lua

    r6704 r6718  
    11-- QuestGUI.lua
    22
    3 local P = createSheet("QuestGUI")
     3local P = createMenuSheet("QuestGUI")
    44
    55function P.show()
  • code/branches/gamestates2/data/gui/scripts/SettingsMenu.lua

    r6704 r6718  
    11-- SettingsMenu.lua
    22
    3 local P = createSheet("SettingsMenu")
     3local P = createMenuSheet("SettingsMenu")
    44
    55function P.SettingsGameplayButton_clicked(e)
  • code/branches/gamestates2/data/gui/scripts/SingleplayerMenu.lua

    r6704 r6718  
    11-- SingleplayerMenu.lua
    22
    3 local P = createSheet("SingleplayerMenu")
     3local P = createMenuSheet("SingleplayerMenu")
    44
    55function P.init()
Note: See TracChangeset for help on using the changeset viewer.