[Orxonox-commit 938] r5661 - in code/branches/resource2: data/gui/layouts data/gui/scripts data/lua src/core src/orxonox/gamestates
rgrieder at orxonox.net
rgrieder at orxonox.net
Wed Aug 19 00:19:12 CEST 2009
Author: rgrieder
Date: 2009-08-19 00:19:11 +0200 (Wed, 19 Aug 2009)
New Revision: 5661
Added:
code/branches/resource2/data/gui/layouts/MainMenu.layout
code/branches/resource2/data/gui/scripts/BasicGUI.lua
code/branches/resource2/data/gui/scripts/InitialiseGUI.lua
code/branches/resource2/data/gui/scripts/MainMenu.lua
Removed:
code/branches/resource2/data/gui/layouts/MainMenu.layout
code/branches/resource2/data/gui/layouts/MainMenu_2.layout
code/branches/resource2/data/gui/scripts/IConsole.lua
code/branches/resource2/data/gui/scripts/InstancedInit.lua
code/branches/resource2/data/gui/scripts/demo8.lua
code/branches/resource2/data/gui/scripts/gui.lua
code/branches/resource2/data/gui/scripts/inGameTest.lua
code/branches/resource2/data/gui/scripts/loadGUI.lua
code/branches/resource2/data/gui/scripts/loadGUI_2.lua
code/branches/resource2/data/gui/scripts/loadGUI_3.lua
code/branches/resource2/data/gui/scripts/mainmenu.lua
code/branches/resource2/data/gui/scripts/mainmenu_2.lua
code/branches/resource2/data/gui/scripts/mainmenu_3.lua
code/branches/resource2/data/gui/scripts/mainmenu_4.lua
Modified:
code/branches/resource2/data/gui/scripts/PickupInventory.lua
code/branches/resource2/data/lua/LuaStateInit.lua
code/branches/resource2/src/core/GUIManager.cc
code/branches/resource2/src/core/GUIManager.h
code/branches/resource2/src/core/LuaState.cc
code/branches/resource2/src/core/LuaState.h
code/branches/resource2/src/orxonox/gamestates/GSMainMenu.cc
Log:
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.
Deleted: code/branches/resource2/data/gui/layouts/MainMenu.layout
===================================================================
--- code/branches/resource2/data/gui/layouts/MainMenu.layout 2009-08-18 10:06:41 UTC (rev 5660)
+++ code/branches/resource2/data/gui/layouts/MainMenu.layout 2009-08-18 22:19:11 UTC (rev 5661)
@@ -1,47 +0,0 @@
-<?xml version="1.0" ?>
-<GUILayout>
- <Window Type="TaharezLook/StaticImage" Name="orxonox/Background">
- <Property Name="UnifiedSize" Value="{{1.0,0},{1.0,0}}"/>
- <Property Name="Image" Value="set:MainMenuBackground image:Background"/>
- <Property Name="FrameEnabled" Value="set:true"/>
- <Property Name="BackgroundEnabled" Value="set:false"/>
-
- <Window Type="TaharezLook/Button" Name="orxonox/StandaloneButton">
- <Property Name="UnifiedPosition" Value="{{0.11,0},{0.3,0}}"/>
- <Property Name="UnifiedSize" Value="{{0.15,0},{0.05,0}}"/>
- <Property Name="Text" Value="Standalone"/>
- <Event Name="Clicked" Function="button_standalone_clicked"/>
- </Window>
-
- <Window Type="TaharezLook/Listbox" Name="orxonox/LevelListbox">
- </Window>
-
- <Window Type="TaharezLook/Button" Name="orxonox/DedicatedButton">
- <Property Name="UnifiedPosition" Value="{{0.11,0},{0.376,0}}"/>
- <Property Name="UnifiedSize" Value="{{0.15,0},{0.05,0}}"/>
- <Property Name="Text" Value="Dedicated"/>
- <Event Name="Clicked" Function="button_dedicated_clicked"/>
- </Window>
-
- <Window Type="TaharezLook/Button" Name="orxonox/ServerButton">
- <Property Name="UnifiedPosition" Value="{{0.11,0},{0.452,0}}"/>
- <Property Name="UnifiedSize" Value="{{0.15,0},{0.05,0}}"/>
- <Property Name="Text" Value="Server"/>
- <Event Name="Clicked" Function="button_server_clicked"/>
- </Window>
-
- <Window Type="TaharezLook/Button" Name="orxonox/ClientButton">
- <Property Name="UnifiedPosition" Value="{{0.11,0},{0.528,0}}"/>
- <Property Name="UnifiedSize" Value="{{0.15,0},{0.05,0}}"/>
- <Property Name="Text" Value="Client"/>
- <Event Name="Clicked" Function="button_client_clicked"/>
- </Window>
-
- <Window Type="TaharezLook/Button" Name="orxonox/QuitButton">
- <Property Name="UnifiedPosition" Value="{{0.11,0},{0.604,0}}"/>
- <Property Name="UnifiedSize" Value="{{0.15,0},{0.05,0}}"/>
- <Property Name="Text" Value="Quit"/>
- <Event Name="Clicked" Function="button_quit_clicked"/>
- </Window>
- </Window>
-</GUILayout>
Copied: code/branches/resource2/data/gui/layouts/MainMenu.layout (from rev 5653, code/branches/resource2/data/gui/layouts/MainMenu_2.layout)
===================================================================
--- code/branches/resource2/data/gui/layouts/MainMenu.layout (rev 0)
+++ code/branches/resource2/data/gui/layouts/MainMenu.layout 2009-08-18 22:19:11 UTC (rev 5661)
@@ -0,0 +1,53 @@
+<?xml version="1.0" ?>
+<GUILayout>
+ <Window Type="TaharezLook/StaticImage" Name="orxonox/Background">
+ <Property Name="UnifiedSize" Value="{{1.0,0},{1.0,0}}"/>
+ <Property Name="Image" Value="set:MainMenuBackground image:Background"/>
+ <Property Name="FrameEnabled" Value="set:true"/>
+ <Property Name="BackgroundEnabled" Value="set:false"/>
+
+ <Window Type="TaharezLook/Button" Name="orxonox/StandaloneButton">
+ <Property Name="UnifiedPosition" Value="{{0.11,0},{0.3,0}}"/>
+ <Property Name="UnifiedSize" Value="{{0.15,0},{0.05,0}}"/>
+ <Property Name="Text" Value="Standalone"/>
+ <Property Name="Disabled" Value="true"/>
+ <Event Name="Clicked" Function="MainMenu.button_standalone_clicked"/>
+ </Window>
+
+ <Window Type="TaharezLook/Listbox" Name="orxonox/LevelListbox">
+ <Property Name="UnifiedPosition" Value="{{0.4,0},{0.3,0}}"/>
+ <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
+ <Property Name="UnifiedSize" Value="{{0.35,0},{0.33,0}}" />
+ <Property Name="Tooltip" Value="Available Levels." />
+ <Event Name="ItemSelectionChanged" Function="MainMenu.listbox_level_selectionchanged" />
+ </Window>
+
+ <Window Type="TaharezLook/Button" Name="orxonox/DedicatedButton">
+ <Property Name="UnifiedPosition" Value="{{0.11,0},{0.376,0}}"/>
+ <Property Name="UnifiedSize" Value="{{0.15,0},{0.05,0}}"/>
+ <Property Name="Text" Value="Dedicated"/>
+ <Event Name="Clicked" Function="MainMenu.button_dedicated_clicked"/>
+ </Window>
+
+ <Window Type="TaharezLook/Button" Name="orxonox/ServerButton">
+ <Property Name="UnifiedPosition" Value="{{0.11,0},{0.452,0}}"/>
+ <Property Name="UnifiedSize" Value="{{0.15,0},{0.05,0}}"/>
+ <Property Name="Text" Value="Server"/>
+ <Event Name="Clicked" Function="MainMenu.button_server_clicked"/>
+ </Window>
+
+ <Window Type="TaharezLook/Button" Name="orxonox/ClientButton">
+ <Property Name="UnifiedPosition" Value="{{0.11,0},{0.528,0}}"/>
+ <Property Name="UnifiedSize" Value="{{0.15,0},{0.05,0}}"/>
+ <Property Name="Text" Value="Client"/>
+ <Event Name="Clicked" Function="MainMenu.button_client_clicked"/>
+ </Window>
+
+ <Window Type="TaharezLook/Button" Name="orxonox/QuitButton">
+ <Property Name="UnifiedPosition" Value="{{0.11,0},{0.604,0}}"/>
+ <Property Name="UnifiedSize" Value="{{0.15,0},{0.05,0}}"/>
+ <Property Name="Text" Value="Quit"/>
+ <Event Name="Clicked" Function="MainMenu.button_quit_clicked"/>
+ </Window>
+ </Window>
+</GUILayout>
Deleted: code/branches/resource2/data/gui/layouts/MainMenu_2.layout
===================================================================
--- code/branches/resource2/data/gui/layouts/MainMenu_2.layout 2009-08-18 10:06:41 UTC (rev 5660)
+++ code/branches/resource2/data/gui/layouts/MainMenu_2.layout 2009-08-18 22:19:11 UTC (rev 5661)
@@ -1,53 +0,0 @@
-<?xml version="1.0" ?>
-<GUILayout>
- <Window Type="TaharezLook/StaticImage" Name="orxonox/Background">
- <Property Name="UnifiedSize" Value="{{1.0,0},{1.0,0}}"/>
- <Property Name="Image" Value="set:MainMenuBackground image:Background"/>
- <Property Name="FrameEnabled" Value="set:true"/>
- <Property Name="BackgroundEnabled" Value="set:false"/>
-
- <Window Type="TaharezLook/Button" Name="orxonox/StandaloneButton">
- <Property Name="UnifiedPosition" Value="{{0.11,0},{0.3,0}}"/>
- <Property Name="UnifiedSize" Value="{{0.15,0},{0.05,0}}"/>
- <Property Name="Text" Value="Standalone"/>
- <Property Name="Disabled" Value="true"/>
- <Event Name="Clicked" Function="mainmenu_2.button_standalone_clicked"/>
- </Window>
-
- <Window Type="TaharezLook/Listbox" Name="orxonox/LevelListbox">
- <Property Name="UnifiedPosition" Value="{{0.4,0},{0.3,0}}"/>
- <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
- <Property Name="UnifiedSize" Value="{{0.35,0},{0.33,0}}" />
- <Property Name="Tooltip" Value="Available Levels." />
- <Event Name="ItemSelectionChanged" Function="mainmenu_2.listbox_level_selectionchanged" />
- </Window>
-
- <Window Type="TaharezLook/Button" Name="orxonox/DedicatedButton">
- <Property Name="UnifiedPosition" Value="{{0.11,0},{0.376,0}}"/>
- <Property Name="UnifiedSize" Value="{{0.15,0},{0.05,0}}"/>
- <Property Name="Text" Value="Dedicated"/>
- <Event Name="Clicked" Function="mainmenu_2.button_dedicated_clicked"/>
- </Window>
-
- <Window Type="TaharezLook/Button" Name="orxonox/ServerButton">
- <Property Name="UnifiedPosition" Value="{{0.11,0},{0.452,0}}"/>
- <Property Name="UnifiedSize" Value="{{0.15,0},{0.05,0}}"/>
- <Property Name="Text" Value="Server"/>
- <Event Name="Clicked" Function="mainmenu_2.button_server_clicked"/>
- </Window>
-
- <Window Type="TaharezLook/Button" Name="orxonox/ClientButton">
- <Property Name="UnifiedPosition" Value="{{0.11,0},{0.528,0}}"/>
- <Property Name="UnifiedSize" Value="{{0.15,0},{0.05,0}}"/>
- <Property Name="Text" Value="Client"/>
- <Event Name="Clicked" Function="mainmenu_2.button_client_clicked"/>
- </Window>
-
- <Window Type="TaharezLook/Button" Name="orxonox/QuitButton">
- <Property Name="UnifiedPosition" Value="{{0.11,0},{0.604,0}}"/>
- <Property Name="UnifiedSize" Value="{{0.15,0},{0.05,0}}"/>
- <Property Name="Text" Value="Quit"/>
- <Event Name="Clicked" Function="mainmenu_2.button_quit_clicked"/>
- </Window>
- </Window>
-</GUILayout>
Copied: code/branches/resource2/data/gui/scripts/BasicGUI.lua (from rev 5653, code/branches/resource2/data/gui/scripts/gui.lua)
===================================================================
--- code/branches/resource2/data/gui/scripts/BasicGUI.lua (rev 0)
+++ code/branches/resource2/data/gui/scripts/BasicGUI.lua 2009-08-18 22:19:11 UTC (rev 5661)
@@ -0,0 +1,42 @@
+-- gui.lua
+
+local P = {}
+if _REQUIREDNAME == nil then
+ BasicGUI = P
+else
+ _G[_REQUIREDNAME] = P
+end
+
+P.overlay = nil
+
+-- constructor of the GUI
+function P:new (gui, fname)
+ local newElement = { window = gui, filename = fname, visible = false } or {}
+ setmetatable(newElement, self) -- connects new element with class
+ self.__index = self
+ return newElement
+end
+
+function P:init()
+-- this function is empty and intended for inheriting GUIs to use
+end
+
+-- hide function for the GUI
+function P:hide ()
+ self.window:hide()
+ self.visible = false
+end
+
+-- show function for the GUI
+function P:show ()
+ self.window:show()
+ self.visible = true
+end
+
+function P:load ()
+ self.window = winMgr:loadWindowLayout(self.layoutString)
+ self:init()
+ return self
+end
+
+return P
Deleted: code/branches/resource2/data/gui/scripts/IConsole.lua
===================================================================
--- code/branches/resource2/data/gui/scripts/IConsole.lua 2009-08-18 10:06:41 UTC (rev 5660)
+++ code/branches/resource2/data/gui/scripts/IConsole.lua 2009-08-18 22:19:11 UTC (rev 5661)
@@ -1,50 +0,0 @@
---- Event Handlers ---
-
----------------------------------------------------------
---- Event to handle when "Return" is hit in the edit box
---- Input Window: Console/Frame/Input
----------------------------------------------------------
-function handleEntryAccepted(args)
- -- Get a pointer to the input editbox
- local input = this:getWindow()
- -- Get a pointer to the output MLEditbox
- local output = this:getWindow("Console/Frame/ConsoleText")
-
- -- Retrieve the Text from the edit box
- local instr = input:getText()
-
- -- Set the Editbox text to an empty string to clear out the entry
- input:setText("")
-
- -- set the text in the output box to its current text + the new text.
- output:setText(string.format("%s%s",output:getText(),instr))
-
- --Done!
-end
-
-function update(args)
- --Yatta! -- this is called every frame -- Put somthing interesting here!
-end
-
---- End Event Handlers ---
-
---- Entry Point ---
-local winMgr = CEGUI.WindowManager:getSingleton()
-
---- Load the xml for the instanced window we want, specifying true
---- indicates that we are making an instanced window and the system will
---- autogenerate a prefix for us.
-local root = winMgr:loadWindowLayout("Console.wnd",true)
-
---- Since we are just now creating this window, there is no 'this' pointer
---- for us to use. Instead since now we want to set the events we will use
---- the getChild function which will recursivly search from the given node down
---- until it find the window... it will throw an exception.
-root:getChild("Console/Frame/Input"):subscribeEvent("TextAccepted",handleEntryAccepted)
-
---- This event is the window update event, it is called every frame
-root:subscribeEvent("WindowUpdate",update)
-
--- Add it to the default GUI sheet
-CEGUI.System:getSingleton():getGUISheet():addChildWindow(root)
-
\ No newline at end of file
Copied: code/branches/resource2/data/gui/scripts/InitialiseGUI.lua (from rev 5653, code/branches/resource2/data/gui/scripts/loadGUI_3.lua)
===================================================================
--- code/branches/resource2/data/gui/scripts/InitialiseGUI.lua (rev 0)
+++ code/branches/resource2/data/gui/scripts/InitialiseGUI.lua 2009-08-18 22:19:11 UTC (rev 5661)
@@ -0,0 +1,84 @@
+local schemeMgr = CEGUI.SchemeManager:getSingleton()
+winMgr = CEGUI.WindowManager:getSingleton()
+local logger = CEGUI.Logger:getSingleton()
+local system = CEGUI.System:getSingleton()
+local cursor = CEGUI.MouseCursor:getSingleton()
+
+schemeMgr:loadScheme("TaharezLookSkin.scheme")
+-- load scheme with our own images
+schemeMgr:loadScheme("OrxonoxGUIScheme.scheme")
+
+system:setDefaultMouseCursor("TaharezLook", "MouseArrow")
+system:setDefaultFont("BlueHighway-12")
+system:setDefaultTooltip("TaharezLook/Tooltip")
+
+loadedGUIs = {}
+
+-- loads the GUI with the specified filename
+-- be sure to set the global variable "filename" before calling this function
+function loadGUI(filename)
+ -- check if it already exists
+ loadedGui = loadedGUIs[filename]
+ if loadedGui == nil then
+ loadedGuiNS = require(filename)
+ loadedGui = loadedGuiNS:load()
+ loadedGUIs[filename] = loadedGui
+ -- if there has no GUI been loaded yet, set new GUI as current
+ if table.getn(loadedGUIs) == 1 then
+ current = loadedGUIs[1]
+ showing = false
+ end
+ -- hide new GUI as we do not want to show it accidentially
+ loadedGui:hide()
+ end
+ return loadedGui
+end
+
+function showGUI(filename, ptr)
+ gui = showGUI(filename)
+ gui.overlay = ptr
+end
+
+-- shows the specified and loads it if not loaded already
+-- be sure to set the global variable "filename" before calling this function
+function showGUI(filename)
+ if current == nil or current.filename ~= filename then
+ current = loadedGUIs[filename]
+ if current == nil then
+ current = loadGUI(filename)
+ end
+ system:setGUISheet(current.window)
+ end
+ current:show()
+ showing = true
+ return current
+end
+
+function toggleGUI()
+ if showing == true then
+ current:hide()
+ cursor:hide()
+ showing = false
+ else
+ current:show()
+ cursor:show()
+ showing = true
+ end
+ return showing
+end
+
+function hideCursor()
+ cursor:hide()
+end
+
+function showCursor()
+ cursor:show()
+end
+
+function hideGUI(filename)
+ current = loadedGUIs[filename]
+ if current ~= nil then
+ current:hide()
+ showing = false
+ end
+end
Deleted: code/branches/resource2/data/gui/scripts/InstancedInit.lua
===================================================================
--- code/branches/resource2/data/gui/scripts/InstancedInit.lua 2009-08-18 10:06:41 UTC (rev 5660)
+++ code/branches/resource2/data/gui/scripts/InstancedInit.lua 2009-08-18 22:19:11 UTC (rev 5661)
@@ -1,19 +0,0 @@
---- Init Script for Instanced Windows Demo ---
-local guiSystem = CEGUI.System:getSingleton()
-local schemeMgr = CEGUI.SchemeManager:getSingleton()
-local winMgr = CEGUI.WindowManager:getSingleton()
-
--- Load a Scheme File
-schemeMgr:loadScheme("TaharezLook.scheme")
--- Setup Mouse Pointer
-guiSystem:setDefaultMouseCursor("TaharezLook", "MouseArrow")
--- Setup a DefaultSheet
-local root = winMgr:createWindow("DefaultWindow","RootNode")
-local xx = CEGUI.UDim(1,0)
-local yy = CEGUI.UDim(1,0)
-local zz = CEGUI.UVector2(xx,yy)
-root:setSize(zz)
-guiSystem:setGUISheet(root)
--- set the Tooltip type
-guiSystem:setDefaultTooltip("TaharezLook/Tooltip")
--- Done!
\ No newline at end of file
Copied: code/branches/resource2/data/gui/scripts/MainMenu.lua (from rev 5653, code/branches/resource2/data/gui/scripts/mainmenu_4.lua)
===================================================================
--- code/branches/resource2/data/gui/scripts/MainMenu.lua (rev 0)
+++ code/branches/resource2/data/gui/scripts/MainMenu.lua 2009-08-18 22:19:11 UTC (rev 5661)
@@ -0,0 +1,92 @@
+-- MainMenu.lua
+
+BasicGUI = require("BasicGUI")
+local P = BasicGUI:new() --inherit everything from the gui package
+if _REQUIREDNAME == nil then
+ MainMenu = P
+else
+ _G[_REQUIREDNAME] = P
+end
+
+P.filename = "MainMenu"
+P.layoutString = "MainMenu.layout"
+
+function P:init()
+ listbox = winMgr:getWindow("orxonox/LevelListbox")
+ preselect = orxonox.LevelManager:getInstance():getDefaultLevel()
+ orxonox.LevelManager:getInstance():compileAvailableLevelList()
+ local levelList = {}
+ local index = 0
+ local level = ""
+ while true do
+ level = orxonox.LevelManager:getInstance():getAvailableLevelListItem(index)
+ if level == "" then
+ break
+ end
+ table.insert(levelList, level)
+ index = index + 1
+ end
+ table.sort(levelList)
+ for k,v in pairs(levelList) do
+ item = CEGUI.createListboxTextItem(v)
+ item:setSelectionBrushImage("TaharezLook", "MultiListSelectionBrush")
+ CEGUI.toListbox(listbox):addItem(item)
+ if v .. ".oxw" == preselect then
+ listbox:setItemSelectState(item, true)
+ end
+ end
+end
+
+
+-- events for mainmenu
+function P.button_quit_clicked(e)
+ hideGUI()
+ orxonox.CommandExecutor:execute("exit")
+end
+
+function P.button_standalone_clicked(e)
+ choice = winMgr:getWindow("orxonox/LevelListbox"):getFirstSelectedItem()
+ if choice then
+ orxonox.LevelManager:getInstance():setDefaultLevel(choice:getText() .. ".oxw")
+ orxonox.CommandExecutor:execute("startGame")
+ toggleGUI()
+ end
+end
+
+function P.button_server_clicked(e)
+ choice = winMgr:getWindow("orxonox/LevelListbox"):getFirstSelectedItem()
+ if choice then
+ orxonox.LevelManager:getInstance():setDefaultLevel(choice:getText() .. ".oxw")
+ orxonox.CommandExecutor:execute("startServer")
+ toggleGUI()
+ end
+end
+
+function P.button_dedicated_clicked(e)
+ choice = winMgr:getWindow("orxonox/LevelListbox"):getFirstSelectedItem()
+ if choice then
+ orxonox.LevelManager:getInstance():setDefaultLevel(choice:getText() .. ".oxw")
+ orxonox.CommandExecutor:execute("startDedicated")
+ toggleGUI()
+ end
+end
+
+function P.button_client_clicked(e)
+ choice = winMgr:getWindow("orxonox/LevelListbox"):getFirstSelectedItem()
+ if choice then
+ orxonox.LevelManager:getInstance():setDefaultLevel(choice:getText() .. ".oxw")
+ orxonox.CommandExecutor:execute("startClient")
+ toggleGUI()
+ end
+end
+
+function P.listbox_level_selectionchanged(e)
+ if winMgr:getWindow("orxonox/LevelListbox"):getFirstSelectedItem() then
+ winMgr:getWindow("orxonox/StandaloneButton"):enable()
+ else
+ winMgr:getWindow("orxonox/StandaloneButton"):disable()
+ end
+end
+
+return P
+
Modified: code/branches/resource2/data/gui/scripts/PickupInventory.lua
===================================================================
--- code/branches/resource2/data/gui/scripts/PickupInventory.lua 2009-08-18 10:06:41 UTC (rev 5660)
+++ code/branches/resource2/data/gui/scripts/PickupInventory.lua 2009-08-18 22:19:11 UTC (rev 5661)
@@ -1,7 +1,12 @@
-gui = require("gui")
-local P = gui:new() --inherit everything from the gui package
+-- PickupInventory.lua
-PickupInventory = P
+BasicGUI = require("BasicGUI")
+local P = BasicGUI:new() --inherit everything from the gui package
+if _REQUIREDNAME == nil then
+ PickupInventory = P
+else
+ _G[_REQUIREDNAME] = P
+end
P.filename = "PickupInventory"
P.layoutString = "PickupInventory.layout"
@@ -60,4 +65,4 @@
self.lastUsableCount_ = orxonox.PickupInventory:getUsableCount()
end
-return PickupInventory
+return P
Deleted: code/branches/resource2/data/gui/scripts/demo8.lua
===================================================================
--- code/branches/resource2/data/gui/scripts/demo8.lua 2009-08-18 10:06:41 UTC (rev 5660)
+++ code/branches/resource2/data/gui/scripts/demo8.lua 2009-08-18 22:19:11 UTC (rev 5661)
@@ -1,83 +0,0 @@
------------------------------------------
--- Start of handler functions
------------------------------------------
------------------------------------------
--- Alpha slider handler (not used!)
------------------------------------------
-function sliderHandler(args)
- CEGUI.System:getSingleton():getGUISheet():setAlpha(CEGUI.toSlider(CEGUI.toWindowEventArgs(args).window):getCurrentValue())
-end
-
------------------------------------------
--- Handler to slide pane
---
--- Here we move the 'Demo8' sheet window
--- and re-position the scrollbar
------------------------------------------
-function panelSlideHandler(args)
- local scroller = CEGUI.toScrollbar(CEGUI.toWindowEventArgs(args).window)
- local demoWnd = CEGUI.WindowManager:getSingleton():getWindow("Demo8")
-
- local relHeight = demoWnd:getHeight():asRelative(demoWnd:getParentPixelHeight())
-
- scroller:setPosition(CEGUI.UVector2(CEGUI.UDim(0,0), CEGUI.UDim(scroller:getScrollPosition() / relHeight,0)))
- demoWnd:setPosition(CEGUI.UVector2(CEGUI.UDim(0,0), CEGUI.UDim(-scroller:getScrollPosition(),0)))
-end
-
------------------------------------------
--- Handler to set preview colour when
--- colour selector scrollers change
------------------------------------------
-function colourChangeHandler(args)
- local winMgr = CEGUI.WindowManager:getSingleton()
-
- local r = CEGUI.toScrollbar(winMgr:getWindow("Demo8/Window1/Controls/Red")):getScrollPosition()
- local g = CEGUI.toScrollbar(winMgr:getWindow("Demo8/Window1/Controls/Green")):getScrollPosition()
- local b = CEGUI.toScrollbar(winMgr:getWindow("Demo8/Window1/Controls/Blue")):getScrollPosition()
- local col = CEGUI.colour:new_local(r, g, b, 1)
- local crect = CEGUI.ColourRect(col)
-
- winMgr:getWindow("Demo8/Window1/Controls/ColourSample"):setProperty("ImageColours", CEGUI.PropertyHelper:colourRectToString(crect))
-end
-
-
------------------------------------------
--- Handler to add an item to the box
------------------------------------------
-function addItemHandler(args)
- local winMgr = CEGUI.WindowManager:getSingleton()
-
- local text = winMgr:getWindow("Demo8/Window1/Controls/Editbox"):getText()
- local cols = CEGUI.PropertyHelper:stringToColourRect(winMgr:getWindow("Demo8/Window1/Controls/ColourSample"):getProperty("ImageColours"))
-
- local newItem = CEGUI.createListboxTextItem(text, 0, nil, false, true)
- newItem:setSelectionBrushImage("TaharezLook", "MultiListSelectionBrush")
- newItem:setSelectionColours(cols)
-
- CEGUI.toListbox(winMgr:getWindow("Demo8/Window1/Listbox")):addItem(newItem)
-end
-
------------------------------------------
--- Script Entry Point
------------------------------------------
-local guiSystem = CEGUI.System:getSingleton()
-local schemeMgr = CEGUI.SchemeManager:getSingleton()
-local winMgr = CEGUI.WindowManager:getSingleton()
-
--- load our demo8 scheme
-schemeMgr:loadScheme("Demo8.scheme");
--- load our demo8 window layout
-local root = winMgr:loadWindowLayout("Demo8.layout")
--- set the layout as the root
-guiSystem:setGUISheet(root)
--- set default mouse cursor
-guiSystem:setDefaultMouseCursor("TaharezLook", "MouseArrow")
--- set the Tooltip type
-guiSystem:setDefaultTooltip("TaharezLook/Tooltip")
-
--- subscribe required events
-winMgr:getWindow("Demo8/ViewScroll"):subscribeEvent("ScrollPosChanged", "panelSlideHandler")
-winMgr:getWindow("Demo8/Window1/Controls/Blue"):subscribeEvent("ScrollPosChanged", "colourChangeHandler")
-winMgr:getWindow("Demo8/Window1/Controls/Red"):subscribeEvent("ScrollPosChanged", "colourChangeHandler")
-winMgr:getWindow("Demo8/Window1/Controls/Green"):subscribeEvent("ScrollPosChanged", "colourChangeHandler")
-winMgr:getWindow("Demo8/Window1/Controls/Add"):subscribeEvent("Clicked", "addItemHandler")
Deleted: code/branches/resource2/data/gui/scripts/gui.lua
===================================================================
--- code/branches/resource2/data/gui/scripts/gui.lua 2009-08-18 10:06:41 UTC (rev 5660)
+++ code/branches/resource2/data/gui/scripts/gui.lua 2009-08-18 22:19:11 UTC (rev 5661)
@@ -1,42 +0,0 @@
--- gui.lua
-
-local P = {}
-if _REQUIREDNAME == nil then
- gui = P
-else
- _G[_REQUIREDNAME] = P
-end
-
-P.overlay = nil
-
--- constructor of the GUI
-function P:new (gui, fname)
- local newElement = { window = gui, filename = fname, visible = false } or {}
- setmetatable(newElement, self) -- connects new element with class
- self.__index = self
- return newElement
-end
-
-function P:init()
--- this function is empty and intended for inheriting GUIs to use
-end
-
--- hide function for the GUI
-function P:hide ()
- self.window:hide()
- self.visible = false
-end
-
--- show function for the GUI
-function P:show ()
- self.window:show()
- self.visible = true
-end
-
-function P:load ()
- self.window = winMgr:loadWindowLayout(self.layoutString)
- self:init()
- return self
-end
-
-return gui or _G[_REQUIREDNAME]
Deleted: code/branches/resource2/data/gui/scripts/inGameTest.lua
===================================================================
--- code/branches/resource2/data/gui/scripts/inGameTest.lua 2009-08-18 10:06:41 UTC (rev 5660)
+++ code/branches/resource2/data/gui/scripts/inGameTest.lua 2009-08-18 22:19:11 UTC (rev 5661)
@@ -1 +0,0 @@
-layoutPath = "InGameTest.layout"
Deleted: code/branches/resource2/data/gui/scripts/loadGUI.lua
===================================================================
--- code/branches/resource2/data/gui/scripts/loadGUI.lua 2009-08-18 10:06:41 UTC (rev 5660)
+++ code/branches/resource2/data/gui/scripts/loadGUI.lua 2009-08-18 22:19:11 UTC (rev 5661)
@@ -1,106 +0,0 @@
-local schemeMgr = CEGUI.SchemeManager:getSingleton()
-local winMgr = CEGUI.WindowManager:getSingleton()
-local logger = CEGUI.Logger:getSingleton()
-local system = CEGUI.System:getSingleton()
-
-schemeMgr:loadScheme("TaharezLookSkin.scheme")
-system:setDefaultMouseCursor("TaharezLook", "MouseArrow")
-system:setDefaultFont("BlueHighway-12")
-
-
-local rootSheet = winMgr:createWindow("DefaultGUISheet", "orxonox/Sheet")
-
-local leftOffset = 0.11
-local topOffset = 0.3
-local distance = 0.076
-local index = 0
-
-local standalone = winMgr:createWindow("TaharezLook/Button", "orxonox/StandaloneButton")
-standalone:setText("Standalone")
-standalone:setSize(CEGUI.UVector2(CEGUI.UDim(0.15, 0), CEGUI.UDim(0.05, 0)))
-standalone:setPosition(CEGUI.UVector2(CEGUI.UDim(leftOffset, 0), CEGUI.UDim(topOffset + index * distance, 0)))
-standalone:subscribeEvent("Clicked","button_standalone_clicked")
-index = index + 1
-
-local dedicated = winMgr:createWindow("TaharezLook/Button", "orxonox/DedicatedButton")
-dedicated:setText("Dedicated")
-dedicated:setSize(CEGUI.UVector2(CEGUI.UDim(0.15, 0), CEGUI.UDim(0.05, 0)))
-dedicated:setPosition(CEGUI.UVector2(CEGUI.UDim(leftOffset, 0), CEGUI.UDim(topOffset + index * distance, 0)))
-dedicated:subscribeEvent("Clicked","button_dedicated_clicked")
-index = index + 1
-
-local server = winMgr:createWindow("TaharezLook/Button", "orxonox/ServerButton")
-server:setText("Server")
-server:setSize(CEGUI.UVector2(CEGUI.UDim(0.15, 0), CEGUI.UDim(0.05, 0)))
-server:setPosition(CEGUI.UVector2(CEGUI.UDim(leftOffset, 0), CEGUI.UDim(topOffset + index * distance, 0)))
-server:subscribeEvent("Clicked","button_server_clicked")
-index = index + 1
-
-local client = winMgr:createWindow("TaharezLook/Button", "orxonox/ClientButton")
-client:setText("Client")
-client:setSize(CEGUI.UVector2(CEGUI.UDim(0.15, 0), CEGUI.UDim(0.05, 0)))
-client:setPosition(CEGUI.UVector2(CEGUI.UDim(leftOffset, 0), CEGUI.UDim(topOffset + index * distance, 0)))
-client:subscribeEvent("Clicked","button_client_clicked")
-index = index + 1
-
-local quit = winMgr:createWindow("TaharezLook/Button", "orxonox/QuitButton")
-quit:setText("Quit")
-quit:setSize(CEGUI.UVector2(CEGUI.UDim(0.15, 0), CEGUI.UDim(0.05, 0)))
-quit:setPosition(CEGUI.UVector2(CEGUI.UDim(leftOffset, 0), CEGUI.UDim(topOffset + index * distance, 0)))
-quit:subscribeEvent("Clicked","button_quit_clicked")
-index = index + 1
-
-local backgroundImage = CEGUI.ImagesetManager:getSingleton():createImagesetFromImageFile("GUI/Background", "main_menu_1.jpg")
-local background = winMgr:createWindow("TaharezLook/StaticImage", "orxonox/Background")
-background:setProperty("FrameEnabled", "set: true")
-background:setProperty("BackgroundEnabled", "set: false")
-background:setProperty("Image", "set: GUI/Background image:full_image")
-
-rootSheet:addChildWindow(quit)
-rootSheet:addChildWindow(standalone)
-rootSheet:addChildWindow(server)
-rootSheet:addChildWindow(dedicated)
-rootSheet:addChildWindow(client)
-background:addChildWindow(rootSheet)
-
-
-function button_quit_clicked(e)
- hideGUI()
- orxonox.CommandExecutor:execute("exit")
-end
-
-function button_standalone_clicked(e)
- orxonox.CommandExecutor:execute("selectGameState standalone")
- hideGUI()
-end
-
-function button_server_clicked(e)
- orxonox.CommandExecutor:execute("selectGameState server")
- hideGUI()
-end
-
-function button_dedicated_clicked(e)
- orxonox.CommandExecutor:execute("selectGameState dedicated")
- hideGUI()
-end
-
-function button_client_clicked(e)
- orxonox.CommandExecutor:execute("selectGameState client")
- hideGUI()
-end
-
-showBackground = false
-
-function showMainMenu()
- if showBackground == true then
- system:setGUISheet(background)
- else
- system:setGUISheet(rootSheet)
- end
- return 0;
-end
-
-function hideGUI()
- system:setGUISheet(nil)
- orxonox.GUIManager:getInstance():hideGUI()
-end
Deleted: code/branches/resource2/data/gui/scripts/loadGUI_2.lua
===================================================================
--- code/branches/resource2/data/gui/scripts/loadGUI_2.lua 2009-08-18 10:06:41 UTC (rev 5660)
+++ code/branches/resource2/data/gui/scripts/loadGUI_2.lua 2009-08-18 22:19:11 UTC (rev 5661)
@@ -1,104 +0,0 @@
-local schemeMgr = CEGUI.SchemeManager:getSingleton()
-local winMgr = CEGUI.WindowManager:getSingleton()
-local logger = CEGUI.Logger:getSingleton()
-local system = CEGUI.System:getSingleton()
-local cursor = CEGUI.MouseCursor:getSingleton()
-
-schemeMgr:loadScheme("TaharezLookSkin.scheme")
--- load scheme with our own images
-schemeMgr:loadScheme("OrxonoxGUIScheme.scheme")
-
-system:setDefaultMouseCursor("TaharezLook", "MouseArrow")
-system:setDefaultFont("BlueHighway-12")
-
-local current = nil
-local loadedGUIs = {}
--- a bit more complex: GUI is now a class
-GUI = {}
-GUI.__index = GUI
-
--- hide function for the GUI
-GUI.hide = function (self)
- self.window:hide()
-end
-
--- show function for the GUI
-GUI.show = function (self)
- self.window:show()
-end
-
--- constructor of the GUI
-GUI.new = function (gui, fname)
- local newElement = { window = gui, filename = fname }
- setmetatable(newElement, GUI) -- connects new element with class
- return newElement
-end
-
-datapath = "" -- points to media-folder (set after loading the script)
-
--- loads the GUI with the specified filename
--- be sure to set the global variable "filename" before calling this function
-function loadGUI(filename)
- -- check if it already exists
- --gui = loadedGUIs:getGUIbyName(filename)
- gui = loadedGUIs[filename]
- if gui == nil then
- dofile(datapath .. "gui/scripts/" .. filename .. ".lua")
- win = winMgr:loadWindowLayout(layoutPath)
- gui = GUI.new(win, filename)
- loadedGUIs[filename] = gui
- -- if there has no GUI been loaded yet, set new GUI as current
- if table.getn(loadedGUIs) == 1 then
- current = loadedGUIs[1]
- showing = false
- end
- -- hide new GUI as we do not want to show it accidentially
- gui:hide()
- end
- return gui
-end
-
--- shows the specified and loads it if not loaded already
--- be sure to set the global variable "filename" before calling this function
-function showGUI(filename)
- if current == nil or current.filename ~= filename then
- if current ~= nil then
- end
- current = loadedGUIs[filename]
- if current == nil then
- current = loadGUI(filename)
- end
- system:setGUISheet(current.window)
- end
- current:show()
- showing = true
-end
-
-function toggleGUI()
- if showing == true then
- current:hide()
- cursor:hide()
- showing = false
- else
- current:show()
- cursor:show()
- showing = true
- end
- return showing
-end
-
-function hideCursor()
- cursor:hide()
-end
-
-function showCursor()
- cursor:show()
-end
-
-function hideGUI(filename)
- current = loadedGUIs[filename]
- if current ~= nil then
- current:hide()
- showing = false
- end
-end
Deleted: code/branches/resource2/data/gui/scripts/loadGUI_3.lua
===================================================================
--- code/branches/resource2/data/gui/scripts/loadGUI_3.lua 2009-08-18 10:06:41 UTC (rev 5660)
+++ code/branches/resource2/data/gui/scripts/loadGUI_3.lua 2009-08-18 22:19:11 UTC (rev 5661)
@@ -1,87 +0,0 @@
-local schemeMgr = CEGUI.SchemeManager:getSingleton()
-winMgr = CEGUI.WindowManager:getSingleton()
-local logger = CEGUI.Logger:getSingleton()
-local system = CEGUI.System:getSingleton()
-local cursor = CEGUI.MouseCursor:getSingleton()
-
-schemeMgr:loadScheme("TaharezLookSkin.scheme")
--- load scheme with our own images
-schemeMgr:loadScheme("OrxonoxGUIScheme.scheme")
-
-system:setDefaultMouseCursor("TaharezLook", "MouseArrow")
-system:setDefaultFont("BlueHighway-12")
-system:setDefaultTooltip("TaharezLook/Tooltip")
-
-loadedGUIs = {}
-
--- datapath is set before executing the script and points to media-folder
-package.path = package.path .. ";" .. datapath .. "gui/scripts/?.lua"
-
--- loads the GUI with the specified filename
--- be sure to set the global variable "filename" before calling this function
-function loadGUI(filename)
- -- check if it already exists
- loadedGui = loadedGUIs[filename]
- if loadedGui == nil then
- loadedGuiNS = require(filename)
- loadedGui = loadedGuiNS:load()
- loadedGUIs[filename] = loadedGui
- -- if there has no GUI been loaded yet, set new GUI as current
- if table.getn(loadedGUIs) == 1 then
- current = loadedGUIs[1]
- showing = false
- end
- -- hide new GUI as we do not want to show it accidentially
- loadedGui:hide()
- end
- return loadedGui
-end
-
-function showGUI(filename, ptr)
- gui = showGUI(filename)
- gui.overlay = ptr
-end
-
--- shows the specified and loads it if not loaded already
--- be sure to set the global variable "filename" before calling this function
-function showGUI(filename)
- if current == nil or current.filename ~= filename then
- current = loadedGUIs[filename]
- if current == nil then
- current = loadGUI(filename)
- end
- system:setGUISheet(current.window)
- end
- current:show()
- showing = true
- return current
-end
-
-function toggleGUI()
- if showing == true then
- current:hide()
- cursor:hide()
- showing = false
- else
- current:show()
- cursor:show()
- showing = true
- end
- return showing
-end
-
-function hideCursor()
- cursor:hide()
-end
-
-function showCursor()
- cursor:show()
-end
-
-function hideGUI(filename)
- current = loadedGUIs[filename]
- if current ~= nil then
- current:hide()
- showing = false
- end
-end
Deleted: code/branches/resource2/data/gui/scripts/mainmenu.lua
===================================================================
--- code/branches/resource2/data/gui/scripts/mainmenu.lua 2009-08-18 10:06:41 UTC (rev 5660)
+++ code/branches/resource2/data/gui/scripts/mainmenu.lua 2009-08-18 22:19:11 UTC (rev 5661)
@@ -1,27 +0,0 @@
-layoutPath = "MainMenu.layout"
-
--- events for mainmenu
-function button_quit_clicked(e)
- hideGUI()
- orxonox.CommandExecutor:execute("exit")
-end
-
-function button_standalone_clicked(e)
- orxonox.CommandExecutor:execute("startGame")
- toggleGUI()
-end
-
-function button_server_clicked(e)
- orxonox.CommandExecutor:execute("echo Not yet supported!")
- hideGUI()
-end
-
-function button_dedicated_clicked(e)
- orxonox.CommandExecutor:execute("echo Not yet supported!")
- hideGUI()
-end
-
-function button_client_clicked(e)
- orxonox.CommandExecutor:execute("echo Not yet supported!")
- hideGUI()
-end
Deleted: code/branches/resource2/data/gui/scripts/mainmenu_2.lua
===================================================================
--- code/branches/resource2/data/gui/scripts/mainmenu_2.lua 2009-08-18 10:06:41 UTC (rev 5660)
+++ code/branches/resource2/data/gui/scripts/mainmenu_2.lua 2009-08-18 22:19:11 UTC (rev 5661)
@@ -1,77 +0,0 @@
--- mainmenu_2.lua
-gui = require("gui")
-local P = gui:new() --inherit everything from the gui package
-
-mainmenu_2 = P
-
-P.filename = "mainmenu_2"
-P.layoutString = "MainMenu_2.layout"
-
-function P:init()
- listbox = winMgr:getWindow("orxonox/LevelListbox")
- preselect = orxonox.Game:getInstance():getLevel()
- orxonox.GUIManager:getInstance():getLevelList() --levellist variable ist set now
- table.sort(levellist)
- for k,v in pairs(levellist) do
- item = CEGUI.createListboxTextItem(v)
- item:setSelectionBrushImage("TaharezLook", "MultiListSelectionBrush")
- CEGUI.toListbox(listbox):addItem(item)
- if v .. ".oxw" == preselect then
- listbox:setItemSelectState(item, true)
- end
- end
-end
-
-
--- events for mainmenu
-function P.button_quit_clicked(e)
- hideGUI()
- orxonox.CommandExecutor:execute("exit")
-end
-
-function P.button_standalone_clicked(e)
- choice = winMgr:getWindow("orxonox/LevelListbox"):getFirstSelectedItem()
- if choice then
- orxonox.Game:getInstance():setLevel(choice:getText() .. ".oxw")
- orxonox.CommandExecutor:execute("startGame")
- toggleGUI()
- end
-end
-
-function P.button_server_clicked(e)
- choice = winMgr:getWindow("orxonox/LevelListbox"):getFirstSelectedItem()
- if choice then
- orxonox.Game:getInstance():setLevel(choice:getText() .. ".oxw")
- orxonox.CommandExecutor:execute("startServer")
- toggleGUI()
- end
-end
-
-function P.button_dedicated_clicked(e)
- choice = winMgr:getWindow("orxonox/LevelListbox"):getFirstSelectedItem()
- if choice then
- orxonox.Game:getInstance():setLevel(choice:getText() .. ".oxw")
- orxonox.CommandExecutor:execute("startDedicated")
- toggleGUI()
- end
-end
-
-function P.button_client_clicked(e)
- choice = winMgr:getWindow("orxonox/LevelListbox"):getFirstSelectedItem()
- if choice then
- orxonox.Game:getInstance():setLevel(choice:getText() .. ".oxw")
- orxonox.CommandExecutor:execute("startClient")
- toggleGUI()
- end
-end
-
-function P.listbox_level_selectionchanged(e)
- if winMgr:getWindow("orxonox/LevelListbox"):getFirstSelectedItem() then
- winMgr:getWindow("orxonox/StandaloneButton"):enable()
- else
- winMgr:getWindow("orxonox/StandaloneButton"):disable()
- end
-end
-
-return mainmenu_2
-
Deleted: code/branches/resource2/data/gui/scripts/mainmenu_3.lua
===================================================================
--- code/branches/resource2/data/gui/scripts/mainmenu_3.lua 2009-08-18 10:06:41 UTC (rev 5660)
+++ code/branches/resource2/data/gui/scripts/mainmenu_3.lua 2009-08-18 22:19:11 UTC (rev 5661)
@@ -1,77 +0,0 @@
--- mainmenu_2.lua
-gui = require("gui")
-local P = gui:new() --inherit everything from the gui package
-
-mainmenu_2 = P
-
-P.filename = "mainmenu_2"
-P.layoutString = "MainMenu_2.layout"
-
-function P:init()
- listbox = winMgr:getWindow("orxonox/LevelListbox")
- preselect = orxonox.LevelManager:getInstance():getDefaultLevel()
- orxonox.GUIManager:getInstance():getLevelList() --levellist variable ist set now
- table.sort(levellist)
- for k,v in pairs(levellist) do
- item = CEGUI.createListboxTextItem(v)
- item:setSelectionBrushImage("TaharezLook", "MultiListSelectionBrush")
- CEGUI.toListbox(listbox):addItem(item)
- if v .. ".oxw" == preselect then
- listbox:setItemSelectState(item, true)
- end
- end
-end
-
-
--- events for mainmenu
-function P.button_quit_clicked(e)
- hideGUI()
- orxonox.CommandExecutor:execute("exit")
-end
-
-function P.button_standalone_clicked(e)
- choice = winMgr:getWindow("orxonox/LevelListbox"):getFirstSelectedItem()
- if choice then
- orxonox.LevelManager:getInstance():setDefaultLevel(choice:getText() .. ".oxw")
- orxonox.CommandExecutor:execute("startGame")
- toggleGUI()
- end
-end
-
-function P.button_server_clicked(e)
- choice = winMgr:getWindow("orxonox/LevelListbox"):getFirstSelectedItem()
- if choice then
- orxonox.LevelManager:getInstance():setDefaultLevel(choice:getText() .. ".oxw")
- orxonox.CommandExecutor:execute("startServer")
- toggleGUI()
- end
-end
-
-function P.button_dedicated_clicked(e)
- choice = winMgr:getWindow("orxonox/LevelListbox"):getFirstSelectedItem()
- if choice then
- orxonox.LevelManager:getInstance():setDefaultLevel(choice:getText() .. ".oxw")
- orxonox.CommandExecutor:execute("startDedicated")
- toggleGUI()
- end
-end
-
-function P.button_client_clicked(e)
- choice = winMgr:getWindow("orxonox/LevelListbox"):getFirstSelectedItem()
- if choice then
- orxonox.LevelManager:getInstance():setDefaultLevel(choice:getText() .. ".oxw")
- orxonox.CommandExecutor:execute("startClient")
- toggleGUI()
- end
-end
-
-function P.listbox_level_selectionchanged(e)
- if winMgr:getWindow("orxonox/LevelListbox"):getFirstSelectedItem() then
- winMgr:getWindow("orxonox/StandaloneButton"):enable()
- else
- winMgr:getWindow("orxonox/StandaloneButton"):disable()
- end
-end
-
-return mainmenu_2
-
Deleted: code/branches/resource2/data/gui/scripts/mainmenu_4.lua
===================================================================
--- code/branches/resource2/data/gui/scripts/mainmenu_4.lua 2009-08-18 10:06:41 UTC (rev 5660)
+++ code/branches/resource2/data/gui/scripts/mainmenu_4.lua 2009-08-18 22:19:11 UTC (rev 5661)
@@ -1,88 +0,0 @@
--- mainmenu_2.lua
-gui = require("gui")
-local P = gui:new() --inherit everything from the gui package
-
-mainmenu_2 = P
-
-P.filename = "mainmenu_2"
-P.layoutString = "MainMenu_2.layout"
-
-function P:init()
- listbox = winMgr:getWindow("orxonox/LevelListbox")
- preselect = orxonox.LevelManager:getInstance():getDefaultLevel()
- orxonox.LevelManager:getInstance():compileAvailableLevelList()
- local levelList = {}
- local index = 0
- local level = ""
- while true do
- level = orxonox.LevelManager:getInstance():getAvailableLevelListItem(index)
- if level == "" then
- break
- end
- table.insert(levelList, level)
- index = index + 1
- end
- table.sort(levelList)
- for k,v in pairs(levelList) do
- item = CEGUI.createListboxTextItem(v)
- item:setSelectionBrushImage("TaharezLook", "MultiListSelectionBrush")
- CEGUI.toListbox(listbox):addItem(item)
- if v .. ".oxw" == preselect then
- listbox:setItemSelectState(item, true)
- end
- end
-end
-
-
--- events for mainmenu
-function P.button_quit_clicked(e)
- hideGUI()
- orxonox.CommandExecutor:execute("exit")
-end
-
-function P.button_standalone_clicked(e)
- choice = winMgr:getWindow("orxonox/LevelListbox"):getFirstSelectedItem()
- if choice then
- orxonox.LevelManager:getInstance():setDefaultLevel(choice:getText() .. ".oxw")
- orxonox.CommandExecutor:execute("startGame")
- toggleGUI()
- end
-end
-
-function P.button_server_clicked(e)
- choice = winMgr:getWindow("orxonox/LevelListbox"):getFirstSelectedItem()
- if choice then
- orxonox.LevelManager:getInstance():setDefaultLevel(choice:getText() .. ".oxw")
- orxonox.CommandExecutor:execute("startServer")
- toggleGUI()
- end
-end
-
-function P.button_dedicated_clicked(e)
- choice = winMgr:getWindow("orxonox/LevelListbox"):getFirstSelectedItem()
- if choice then
- orxonox.LevelManager:getInstance():setDefaultLevel(choice:getText() .. ".oxw")
- orxonox.CommandExecutor:execute("startDedicated")
- toggleGUI()
- end
-end
-
-function P.button_client_clicked(e)
- choice = winMgr:getWindow("orxonox/LevelListbox"):getFirstSelectedItem()
- if choice then
- orxonox.LevelManager:getInstance():setDefaultLevel(choice:getText() .. ".oxw")
- orxonox.CommandExecutor:execute("startClient")
- toggleGUI()
- end
-end
-
-function P.listbox_level_selectionchanged(e)
- if winMgr:getWindow("orxonox/LevelListbox"):getFirstSelectedItem() then
- winMgr:getWindow("orxonox/StandaloneButton"):enable()
- else
- winMgr:getWindow("orxonox/StandaloneButton"):disable()
- end
-end
-
-return mainmenu_2
-
Modified: code/branches/resource2/data/lua/LuaStateInit.lua
===================================================================
--- code/branches/resource2/data/lua/LuaStateInit.lua 2009-08-18 10:06:41 UTC (rev 5660)
+++ code/branches/resource2/data/lua/LuaStateInit.lua 2009-08-18 22:19:11 UTC (rev 5661)
@@ -1,6 +1,6 @@
-- Note: luaState is a pointer to the LuaState instance that created this lua state
--- Redirect debug to print
+-- Save original print function in debug
debug = print
-- Redirect print to the C++ print function
@@ -22,7 +22,10 @@
local bSearchOtherPaths = (resourceGroup == nil) or false
resourceGroup = resourceGroup or "NoResourceGroupProvided"
luaState:doFile(filename, resourceGroup, bSearchOtherPaths)
+ -- Required because the C++ function cannot return whatever might be on the stack
+ return LuaStateReturnValue
end
+original_dofile = dofile
dofile = doFile
-- Create includeFile function that preparses the file according
@@ -32,4 +35,34 @@
local bSearchOtherPaths = (resourceGroup == nil) or false
resourceGroup = resourceGroup or "NoResourceGroupProvided"
luaState:includeFile(filename, resourceGroup, bSearchOtherPaths)
+ -- Required because the C++ function cannot return whatever might be on the stack
+ return LuaStateReturnValue
end
+
+-- Replace require function with almost similar behaviour
+-- The difference is that you need to provide a resource group
+-- Default value there is the current one (if present) or else "General"
+-- But the loaded modules are then stored with only with the name (where name has no .lua extension)
+-- CAUTION: That also means that you need to take care of conflicting filenames among groups
+-- Furthermore the moduleName parameters is appended with the .lua extension when looking for the file
+old_require = require
+require = function(moduleName, resourceGroup)
+ local bSearchOtherPaths = (resourceGroup == nil) or false
+ resourceGroup = resourceGroup or "NoResourceGroupProvided"
+ if not luaState:fileExists(moduleName .. ".lua", resourceGroup, bSearchOtherPaths) then
+ return nil
+ end
+ if not _LOADED then
+ _LOADED = {}
+ end
+ if not _LOADED[moduleName] then
+ -- save old value
+ _REQUIREDNAME_OLD = _REQUIREDNAME
+ _REQUIREDNAME = moduleName
+ luaState:doFile(moduleName .. ".lua", resourceGroup, bSearchOtherPaths)
+ _LOADED[moduleName] = LuaStateReturnValue or true
+ -- restore old value
+ _REQUIREDNAME = _REQUIREDNAME_OLD
+ end
+ return _LOADED[moduleName]
+end
Modified: code/branches/resource2/src/core/GUIManager.cc
===================================================================
--- code/branches/resource2/src/core/GUIManager.cc 2009-08-18 10:06:41 UTC (rev 5660)
+++ code/branches/resource2/src/core/GUIManager.cc 2009-08-18 22:19:11 UTC (rev 5661)
@@ -27,12 +27,6 @@
*
*/
-/**
- at file
- at brief
- Implementation of the GUIManager class.
-*/
-
#include "GUIManager.h"
#include <memory>
@@ -59,6 +53,7 @@
#include "Core.h"
#include "Clock.h"
#include "LuaState.h"
+#include "Resource.h"
namespace orxonox
{
@@ -114,8 +109,8 @@
resourceProvider_->setDefaultResourceGroup("GUI");
// setup scripting
- scriptModule_.reset(new LuaScriptModule());
- luaState_ = scriptModule_->getLuaState();
+ luaState_.reset(new LuaState());
+ scriptModule_.reset(new LuaScriptModule(luaState_->getInternalLuaState()));
// Create our own logger to specify the filepath
std::auto_ptr<CEGUILogger> ceguiLogger(new CEGUILogger());
@@ -128,44 +123,21 @@
// create the CEGUI system singleton
guiSystem_.reset(new System(guiRenderer_.get(), resourceProvider_, 0, scriptModule_.get()));
- // do this after 'new CEGUI::Sytem' because that creates the lua state in the first place
- LuaState::openToluaInterfaces(this->luaState_);
-
- // initialise the basic lua code
- this->loadLuaCode();
+ // Initialise the basic lua code
+ rootFileInfo_ = Resource::getInfo("InitialiseGUI.lua", "GUI");
+ this->luaState_->doFile("InitialiseGUI.lua", "GUI", false);
}
/**
@brief
- Destructor of the GUIManager
-
Basically shuts down CEGUI (member smart pointers) but first unloads our Tolua modules.
*/
GUIManager::~GUIManager()
{
- // destroy our own tolua interfaces
- LuaState::closeToluaInterfaces(this->luaState_);
}
/**
@brief
- Calls main Lua script
- @todo
- This function calls the main Lua script for our GUI.
-
- Additionally we set the datapath variable in Lua. This is needed so Lua can access the data used for the GUI.
- */
- void GUIManager::loadLuaCode()
- {
- // set datapath for GUI data
- lua_pushfstring(this->scriptModule_->getLuaState(), Core::getDataPathString().c_str());
- lua_setglobal(this->scriptModule_->getLuaState(), "datapath");
- // call main Lua script
- this->scriptModule_->executeScriptFile("loadGUI_3.lua", "GUI");
- }
-
- /**
- @brief
used to tick the GUI
@param time
clock which provides time value for the GUI System
@@ -208,18 +180,7 @@
*/
void GUIManager::executeCode(const std::string& str)
{
- try
- {
- this->scriptModule_->executeString(str);
- }
- catch (const CEGUI::Exception& ex)
- {
- COUT(2) << "CEGUI Error: \"" << ex.getMessage() << "\" while executing code \"" << str << "\"" << std::endl;
- }
- catch (...)
- {
- COUT(2) << "Couldn't execute GUI related Lua code due to unknown reasons." << std::endl;
- }
+ this->luaState_->doString(str, rootFileInfo_);
}
/**
@@ -233,7 +194,7 @@
*/
void GUIManager::showGUI(const std::string& name)
{
- this->executeCode(std::string("showGUI(\"") + name + "\")");
+ this->luaState_->doString("showGUI(\"" + name + "\")", rootFileInfo_);
}
void GUIManager::keyPressed(const KeyEvent& evt)
Modified: code/branches/resource2/src/core/GUIManager.h
===================================================================
--- code/branches/resource2/src/core/GUIManager.h 2009-08-18 10:06:41 UTC (rev 5660)
+++ code/branches/resource2/src/core/GUIManager.h 2009-08-18 22:19:11 UTC (rev 5661)
@@ -27,12 +27,6 @@
*
*/
-/**
- at file
- at brief
- Declaration of the GUIManager class.
-*/
-
#ifndef _GUIManager_H__
#define _GUIManager_H__
@@ -42,6 +36,7 @@
#include <string>
#include <CEGUIForwardRefs.h>
#include <boost/scoped_ptr.hpp>
+#include <boost/shared_ptr.hpp>
#include "util/OgreForwardRefs.h"
#include "util/Singleton.h"
@@ -79,8 +74,6 @@
private:
GUIManager(const GUIManager& instance); //!< private and undefined copy c'tor (this is a singleton class)
- void loadLuaCode();
-
// keyHandler functions
void keyPressed (const KeyEvent& evt);
void keyReleased(const KeyEvent& evt);
@@ -92,12 +85,13 @@
void mouseScrolled (int abs, int rel);
scoped_ptr<CEGUI::OgreCEGUIRenderer> guiRenderer_; //!< CEGUI's interface to the Ogre Engine
+ scoped_ptr<LuaState> luaState_; //!< LuaState, access point to the Lua engine
scoped_ptr<CEGUI::LuaScriptModule> scriptModule_; //!< CEGUI's script module to use Lua
scoped_ptr<CEGUI::System> guiSystem_; //!< CEGUI's main system
+ shared_ptr<ResourceInfo> rootFileInfo_; //!< Resource information about the root script
Ogre::RenderWindow* renderWindow_; //!< Ogre's render window to give CEGUI access to it
CEGUI::ResourceProvider* resourceProvider_; //!< CEGUI's resource provider
CEGUI::Logger* ceguiLogger_; //!< CEGUI's logger to be able to log CEGUI errors in our log
- lua_State* luaState_; //!< Lua state, access point to the Lua engine
static GUIManager* singletonPtr_s; //!< Singleton reference to GUIManager
Modified: code/branches/resource2/src/core/LuaState.cc
===================================================================
--- code/branches/resource2/src/core/LuaState.cc 2009-08-18 10:06:41 UTC (rev 5660)
+++ code/branches/resource2/src/core/LuaState.cc 2009-08-18 22:19:11 UTC (rev 5661)
@@ -146,10 +146,6 @@
if (sourceFileInfo != NULL)
sourceFileInfo_ = sourceFileInfo;
- //if (!bIsRunning_)
- //{
- // bIsRunning_ = true;
-
int error = 0;
#if LUA_VERSION_NUM != 501
LoadS ls;
@@ -162,22 +158,19 @@
// execute the chunk
if (error == 0)
- error = lua_pcall(luaState_, 0, 0, 0);
+ error = lua_pcall(luaState_, 0, 1, 0);
if (error != 0)
{
std::string origin;
if (sourceFileInfo != NULL)
origin = " originating from " + sourceFileInfo_->filename;
COUT(2) << "Error in Lua-script" << origin << ": " << lua_tostring(luaState_, -1) << std::endl;
+ // return value is nil
+ lua_pushnil(luaState_);
}
+ // push return value because it will get lost since the return value of this function is void
+ lua_setglobal(luaState_, "LuaStateReturnValue");
- // bIsRunning_ = false;
- //}
- //else
- //{
- // COUT(2) << "Warning: LuaState do function called while running!" << std::endl;
- //}
-
// Load the old info again
sourceFileInfo_ = oldSourceFileInfo;
}
@@ -192,6 +185,15 @@
OutputHandler::getOutStream().setOutputLevel(level) << message << std::endl;
}
+ bool LuaState::fileExists(const std::string& filename, const std::string& resourceGroup, bool bSearchOtherPaths)
+ {
+ shared_ptr<ResourceInfo> info = this->getFileInfo(filename, resourceGroup, bSearchOtherPaths);
+ if (info == NULL)
+ return false;
+ else
+ return true;
+ }
+
#if LUA_VERSION_NUM != 501
const char * LuaState::lua_Chunkreader(lua_State *L, void *data, size_t *size)
{
Modified: code/branches/resource2/src/core/LuaState.h
===================================================================
--- code/branches/resource2/src/core/LuaState.h 2009-08-18 10:06:41 UTC (rev 5660)
+++ code/branches/resource2/src/core/LuaState.h 2009-08-18 22:19:11 UTC (rev 5661)
@@ -58,11 +58,12 @@
void doFile(const std::string& filename, const std::string& resourceGroup = "General", bool bSearchOtherPaths = true); // tolua_export
void doString(const std::string& code, shared_ptr<ResourceInfo> sourceFileInfo = shared_ptr<ResourceInfo>());
- void includeFile(const std::string& filename, const std::string& resourceGroup = "Genreal", bool bSearchOtherPaths = true); // tolua_export
+ void includeFile(const std::string& filename, const std::string& resourceGroup = "General", bool bSearchOtherPaths = true); // tolua_export
void includeString(const std::string& code, shared_ptr<ResourceInfo> sourceFileInfo = shared_ptr<ResourceInfo>());
void luaPrint(const std::string& str); // tolua_export
void luaLog(unsigned int level, const std::string& message); // tolua_export
+ bool fileExists(const std::string& filename, const std::string& resourceGroup = "General", bool bSearchOtherPaths = true); // tolua_export
const std::stringstream& getOutput() const { return output_; }
void clearOutput() { output_.clear(); } // tolua_export
Modified: code/branches/resource2/src/orxonox/gamestates/GSMainMenu.cc
===================================================================
--- code/branches/resource2/src/orxonox/gamestates/GSMainMenu.cc 2009-08-18 10:06:41 UTC (rev 5660)
+++ code/branches/resource2/src/orxonox/gamestates/GSMainMenu.cc 2009-08-18 22:19:11 UTC (rev 5661)
@@ -69,7 +69,7 @@
void GSMainMenu::activate()
{
// show main menu
- GUIManager::getInstance().showGUI("mainmenu_4");
+ GUIManager::getInstance().showGUI("MainMenu");
GUIManager::getInstance().setCamera(this->camera_);
GraphicsManager::getInstance().setCamera(this->camera_);
More information about the Orxonox-commit
mailing list