Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Aug 19, 2009, 12:19:11 AM (15 years ago)
Author:
rgrieder
Message:

Cleaned out the lua script files for the GUI.
Also replaced "require" function to support resources.
Fixed a problem with the return value of doFile, includeFile and require being discarded because the tolua binding is for a C++ function returning void.

Location:
code/branches/resource2/data
Files:
9 deleted
2 edited
4 moved

Legend:

Unmodified
Added
Removed
  • code/branches/resource2/data/gui/layouts/MainMenu.layout

    r5653 r5661  
    1212            <Property Name="Text" Value="Standalone"/>
    1313            <Property Name="Disabled" Value="true"/>
    14             <Event Name="Clicked" Function="mainmenu_2.button_standalone_clicked"/>
     14            <Event Name="Clicked" Function="MainMenu.button_standalone_clicked"/>
    1515        </Window>
    1616       
     
    2020            <Property Name="UnifiedSize" Value="{{0.35,0},{0.33,0}}" />
    2121            <Property Name="Tooltip" Value="Available Levels." />
    22             <Event Name="ItemSelectionChanged" Function="mainmenu_2.listbox_level_selectionchanged" />
     22            <Event Name="ItemSelectionChanged" Function="MainMenu.listbox_level_selectionchanged" />
    2323        </Window>
    2424       
     
    2727            <Property Name="UnifiedSize" Value="{{0.15,0},{0.05,0}}"/>
    2828            <Property Name="Text" Value="Dedicated"/>
    29             <Event Name="Clicked" Function="mainmenu_2.button_dedicated_clicked"/>
     29            <Event Name="Clicked" Function="MainMenu.button_dedicated_clicked"/>
    3030        </Window>
    3131       
     
    3434            <Property Name="UnifiedSize" Value="{{0.15,0},{0.05,0}}"/>
    3535            <Property Name="Text" Value="Server"/>
    36             <Event Name="Clicked" Function="mainmenu_2.button_server_clicked"/>
     36            <Event Name="Clicked" Function="MainMenu.button_server_clicked"/>
    3737        </Window>
    3838       
     
    4141            <Property Name="UnifiedSize" Value="{{0.15,0},{0.05,0}}"/>
    4242            <Property Name="Text" Value="Client"/>
    43             <Event Name="Clicked" Function="mainmenu_2.button_client_clicked"/>
     43            <Event Name="Clicked" Function="MainMenu.button_client_clicked"/>
    4444        </Window>
    4545       
     
    4848            <Property Name="UnifiedSize" Value="{{0.15,0},{0.05,0}}"/>
    4949            <Property Name="Text" Value="Quit"/>
    50             <Event Name="Clicked" Function="mainmenu_2.button_quit_clicked"/>
     50            <Event Name="Clicked" Function="MainMenu.button_quit_clicked"/>
    5151        </Window>
    5252    </Window>
  • code/branches/resource2/data/gui/scripts/BasicGUI.lua

    r5653 r5661  
    33local P = {}
    44if _REQUIREDNAME == nil then
    5     gui = P
     5    BasicGUI = P
    66else
    77    _G[_REQUIREDNAME] = P
     
    4040end
    4141
    42 return gui or _G[_REQUIREDNAME]
     42return P
  • code/branches/resource2/data/gui/scripts/InitialiseGUI.lua

    r5653 r5661  
    1414
    1515loadedGUIs = {}
    16 
    17 -- datapath is set before executing the script and points to media-folder
    18 package.path = package.path .. ";" .. datapath .. "gui/scripts/?.lua"
    1916
    2017-- loads the GUI with the specified filename
  • code/branches/resource2/data/gui/scripts/MainMenu.lua

    r5653 r5661  
    1 -- mainmenu_2.lua
    2 gui = require("gui")
    3 local P = gui:new() --inherit everything from the gui package
     1-- MainMenu.lua
    42
    5 mainmenu_2 = P
     3BasicGUI = require("BasicGUI")
     4local P = BasicGUI:new() --inherit everything from the gui package
     5if _REQUIREDNAME == nil then
     6    MainMenu = P
     7else
     8    _G[_REQUIREDNAME] = P
     9end
    610
    7 P.filename = "mainmenu_2"
    8 P.layoutString = "MainMenu_2.layout"
     11P.filename = "MainMenu"
     12P.layoutString = "MainMenu.layout"
    913
    1014function P:init()
     
    8589end
    8690
    87 return mainmenu_2
     91return P
    8892
  • code/branches/resource2/data/gui/scripts/PickupInventory.lua

    r5587 r5661  
    1 gui = require("gui")
    2 local P = gui:new() --inherit everything from the gui package
     1-- PickupInventory.lua
    32
    4 PickupInventory = P
     3BasicGUI = require("BasicGUI")
     4local P = BasicGUI:new() --inherit everything from the gui package
     5if _REQUIREDNAME == nil then
     6    PickupInventory = P
     7else
     8    _G[_REQUIREDNAME] = P
     9end
    510
    611P.filename = "PickupInventory"
     
    6166end
    6267
    63 return PickupInventory
     68return P
  • code/branches/resource2/data/lua/LuaStateInit.lua

    r5654 r5661  
    11-- Note: luaState is a pointer to the LuaState instance that created this lua state
    22
    3 -- Redirect debug to print
     3-- Save original print function in debug
    44debug = print
    55
     
    2323  resourceGroup = resourceGroup or "NoResourceGroupProvided"
    2424  luaState:doFile(filename, resourceGroup, bSearchOtherPaths)
     25  -- Required because the C++ function cannot return whatever might be on the stack
     26  return LuaStateReturnValue
    2527end
     28original_dofile = dofile
    2629dofile = doFile
    2730
     
    3336  resourceGroup = resourceGroup or "NoResourceGroupProvided"
    3437  luaState:includeFile(filename, resourceGroup, bSearchOtherPaths)
     38  -- Required because the C++ function cannot return whatever might be on the stack
     39  return LuaStateReturnValue
    3540end
     41
     42-- Replace require function with almost similar behaviour
     43-- The difference is that you need to provide a resource group
     44-- Default value there is the current one (if present) or else "General"
     45-- But the loaded modules are then stored with only with the name (where name has no .lua extension)
     46-- CAUTION: That also means that you need to take care of conflicting filenames among groups
     47-- Furthermore the moduleName parameters is appended with the .lua extension when looking for the file
     48old_require = require
     49require = function(moduleName, resourceGroup)
     50  local bSearchOtherPaths = (resourceGroup == nil) or false
     51  resourceGroup = resourceGroup or "NoResourceGroupProvided"
     52  if not luaState:fileExists(moduleName .. ".lua", resourceGroup, bSearchOtherPaths) then
     53    return nil
     54  end
     55  if not _LOADED then
     56    _LOADED = {}
     57  end
     58  if not _LOADED[moduleName] then
     59    -- save old value
     60    _REQUIREDNAME_OLD = _REQUIREDNAME
     61    _REQUIREDNAME = moduleName
     62    luaState:doFile(moduleName .. ".lua", resourceGroup, bSearchOtherPaths)
     63    _LOADED[moduleName] = LuaStateReturnValue or true
     64    -- restore old value
     65    _REQUIREDNAME = _REQUIREDNAME_OLD
     66  end
     67  return _LOADED[moduleName]
     68end
Note: See TracChangeset for help on using the changeset viewer.