Changeset 5661
- Timestamp:
- Aug 19, 2009, 12:19:11 AM (15 years ago)
- Location:
- code/branches/resource2
- Files:
-
- 9 deleted
- 7 edited
- 4 moved
Legend:
- Unmodified
- Added
- Removed
-
code/branches/resource2/data/gui/layouts/MainMenu.layout
r5653 r5661 12 12 <Property Name="Text" Value="Standalone"/> 13 13 <Property Name="Disabled" Value="true"/> 14 <Event Name="Clicked" Function=" mainmenu_2.button_standalone_clicked"/>14 <Event Name="Clicked" Function="MainMenu.button_standalone_clicked"/> 15 15 </Window> 16 16 … … 20 20 <Property Name="UnifiedSize" Value="{{0.35,0},{0.33,0}}" /> 21 21 <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" /> 23 23 </Window> 24 24 … … 27 27 <Property Name="UnifiedSize" Value="{{0.15,0},{0.05,0}}"/> 28 28 <Property Name="Text" Value="Dedicated"/> 29 <Event Name="Clicked" Function=" mainmenu_2.button_dedicated_clicked"/>29 <Event Name="Clicked" Function="MainMenu.button_dedicated_clicked"/> 30 30 </Window> 31 31 … … 34 34 <Property Name="UnifiedSize" Value="{{0.15,0},{0.05,0}}"/> 35 35 <Property Name="Text" Value="Server"/> 36 <Event Name="Clicked" Function=" mainmenu_2.button_server_clicked"/>36 <Event Name="Clicked" Function="MainMenu.button_server_clicked"/> 37 37 </Window> 38 38 … … 41 41 <Property Name="UnifiedSize" Value="{{0.15,0},{0.05,0}}"/> 42 42 <Property Name="Text" Value="Client"/> 43 <Event Name="Clicked" Function=" mainmenu_2.button_client_clicked"/>43 <Event Name="Clicked" Function="MainMenu.button_client_clicked"/> 44 44 </Window> 45 45 … … 48 48 <Property Name="UnifiedSize" Value="{{0.15,0},{0.05,0}}"/> 49 49 <Property Name="Text" Value="Quit"/> 50 <Event Name="Clicked" Function=" mainmenu_2.button_quit_clicked"/>50 <Event Name="Clicked" Function="MainMenu.button_quit_clicked"/> 51 51 </Window> 52 52 </Window> -
code/branches/resource2/data/gui/scripts/BasicGUI.lua
r5653 r5661 3 3 local P = {} 4 4 if _REQUIREDNAME == nil then 5 gui= P5 BasicGUI = P 6 6 else 7 7 _G[_REQUIREDNAME] = P … … 40 40 end 41 41 42 return gui or _G[_REQUIREDNAME]42 return P -
code/branches/resource2/data/gui/scripts/InitialiseGUI.lua
r5653 r5661 14 14 15 15 loadedGUIs = {} 16 17 -- datapath is set before executing the script and points to media-folder18 package.path = package.path .. ";" .. datapath .. "gui/scripts/?.lua"19 16 20 17 -- 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 4 2 5 mainmenu_2 = P 3 BasicGUI = require("BasicGUI") 4 local P = BasicGUI:new() --inherit everything from the gui package 5 if _REQUIREDNAME == nil then 6 MainMenu = P 7 else 8 _G[_REQUIREDNAME] = P 9 end 6 10 7 P.filename = " mainmenu_2"8 P.layoutString = "MainMenu _2.layout"11 P.filename = "MainMenu" 12 P.layoutString = "MainMenu.layout" 9 13 10 14 function P:init() … … 85 89 end 86 90 87 return mainmenu_291 return P 88 92 -
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 3 2 4 PickupInventory = P 3 BasicGUI = require("BasicGUI") 4 local P = BasicGUI:new() --inherit everything from the gui package 5 if _REQUIREDNAME == nil then 6 PickupInventory = P 7 else 8 _G[_REQUIREDNAME] = P 9 end 5 10 6 11 P.filename = "PickupInventory" … … 61 66 end 62 67 63 return P ickupInventory68 return P -
code/branches/resource2/data/lua/LuaStateInit.lua
r5654 r5661 1 1 -- Note: luaState is a pointer to the LuaState instance that created this lua state 2 2 3 -- Redirect debug to print3 -- Save original print function in debug 4 4 debug = print 5 5 … … 23 23 resourceGroup = resourceGroup or "NoResourceGroupProvided" 24 24 luaState:doFile(filename, resourceGroup, bSearchOtherPaths) 25 -- Required because the C++ function cannot return whatever might be on the stack 26 return LuaStateReturnValue 25 27 end 28 original_dofile = dofile 26 29 dofile = doFile 27 30 … … 33 36 resourceGroup = resourceGroup or "NoResourceGroupProvided" 34 37 luaState:includeFile(filename, resourceGroup, bSearchOtherPaths) 38 -- Required because the C++ function cannot return whatever might be on the stack 39 return LuaStateReturnValue 35 40 end 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 48 old_require = require 49 require = 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] 68 end -
code/branches/resource2/src/core/GUIManager.cc
r5658 r5661 27 27 * 28 28 */ 29 30 /**31 @file32 @brief33 Implementation of the GUIManager class.34 */35 29 36 30 #include "GUIManager.h" … … 60 54 #include "Clock.h" 61 55 #include "LuaState.h" 56 #include "Resource.h" 62 57 63 58 namespace orxonox … … 115 110 116 111 // setup scripting 117 scriptModule_.reset(new LuaScriptModule());118 luaState_ = scriptModule_->getLuaState();112 luaState_.reset(new LuaState()); 113 scriptModule_.reset(new LuaScriptModule(luaState_->getInternalLuaState())); 119 114 120 115 // Create our own logger to specify the filepath … … 129 124 guiSystem_.reset(new System(guiRenderer_.get(), resourceProvider_, 0, scriptModule_.get())); 130 125 131 // do this after 'new CEGUI::Sytem' because that creates the lua state in the first place 132 LuaState::openToluaInterfaces(this->luaState_); 133 134 // initialise the basic lua code 135 this->loadLuaCode(); 136 } 137 138 /** 139 @brief 140 Destructor of the GUIManager 141 126 // Initialise the basic lua code 127 rootFileInfo_ = Resource::getInfo("InitialiseGUI.lua", "GUI"); 128 this->luaState_->doFile("InitialiseGUI.lua", "GUI", false); 129 } 130 131 /** 132 @brief 142 133 Basically shuts down CEGUI (member smart pointers) but first unloads our Tolua modules. 143 134 */ 144 135 GUIManager::~GUIManager() 145 136 { 146 // destroy our own tolua interfaces147 LuaState::closeToluaInterfaces(this->luaState_);148 }149 150 /**151 @brief152 Calls main Lua script153 @todo154 This function calls the main Lua script for our GUI.155 156 Additionally we set the datapath variable in Lua. This is needed so Lua can access the data used for the GUI.157 */158 void GUIManager::loadLuaCode()159 {160 // set datapath for GUI data161 lua_pushfstring(this->scriptModule_->getLuaState(), Core::getDataPathString().c_str());162 lua_setglobal(this->scriptModule_->getLuaState(), "datapath");163 // call main Lua script164 this->scriptModule_->executeScriptFile("loadGUI_3.lua", "GUI");165 137 } 166 138 … … 209 181 void GUIManager::executeCode(const std::string& str) 210 182 { 211 try 212 { 213 this->scriptModule_->executeString(str); 214 } 215 catch (const CEGUI::Exception& ex) 216 { 217 COUT(2) << "CEGUI Error: \"" << ex.getMessage() << "\" while executing code \"" << str << "\"" << std::endl; 218 } 219 catch (...) 220 { 221 COUT(2) << "Couldn't execute GUI related Lua code due to unknown reasons." << std::endl; 222 } 183 this->luaState_->doString(str, rootFileInfo_); 223 184 } 224 185 … … 234 195 void GUIManager::showGUI(const std::string& name) 235 196 { 236 this-> executeCode(std::string("showGUI(\"") + name + "\")");197 this->luaState_->doString("showGUI(\"" + name + "\")", rootFileInfo_); 237 198 } 238 199 -
code/branches/resource2/src/core/GUIManager.h
r5651 r5661 28 28 */ 29 29 30 /**31 @file32 @brief33 Declaration of the GUIManager class.34 */35 36 30 #ifndef _GUIManager_H__ 37 31 #define _GUIManager_H__ … … 43 37 #include <CEGUIForwardRefs.h> 44 38 #include <boost/scoped_ptr.hpp> 39 #include <boost/shared_ptr.hpp> 45 40 46 41 #include "util/OgreForwardRefs.h" … … 80 75 GUIManager(const GUIManager& instance); //!< private and undefined copy c'tor (this is a singleton class) 81 76 82 void loadLuaCode();83 84 77 // keyHandler functions 85 78 void keyPressed (const KeyEvent& evt); … … 93 86 94 87 scoped_ptr<CEGUI::OgreCEGUIRenderer> guiRenderer_; //!< CEGUI's interface to the Ogre Engine 88 scoped_ptr<LuaState> luaState_; //!< LuaState, access point to the Lua engine 95 89 scoped_ptr<CEGUI::LuaScriptModule> scriptModule_; //!< CEGUI's script module to use Lua 96 90 scoped_ptr<CEGUI::System> guiSystem_; //!< CEGUI's main system 91 shared_ptr<ResourceInfo> rootFileInfo_; //!< Resource information about the root script 97 92 Ogre::RenderWindow* renderWindow_; //!< Ogre's render window to give CEGUI access to it 98 93 CEGUI::ResourceProvider* resourceProvider_; //!< CEGUI's resource provider 99 94 CEGUI::Logger* ceguiLogger_; //!< CEGUI's logger to be able to log CEGUI errors in our log 100 lua_State* luaState_; //!< Lua state, access point to the Lua engine101 95 102 96 static GUIManager* singletonPtr_s; //!< Singleton reference to GUIManager -
code/branches/resource2/src/core/LuaState.cc
r5660 r5661 147 147 sourceFileInfo_ = sourceFileInfo; 148 148 149 //if (!bIsRunning_)150 //{151 // bIsRunning_ = true;152 153 149 int error = 0; 154 150 #if LUA_VERSION_NUM != 501 … … 163 159 // execute the chunk 164 160 if (error == 0) 165 error = lua_pcall(luaState_, 0, 0, 0);161 error = lua_pcall(luaState_, 0, 1, 0); 166 162 if (error != 0) 167 163 { … … 170 166 origin = " originating from " + sourceFileInfo_->filename; 171 167 COUT(2) << "Error in Lua-script" << origin << ": " << lua_tostring(luaState_, -1) << std::endl; 172 } 173 174 // bIsRunning_ = false; 175 //} 176 //else 177 //{ 178 // COUT(2) << "Warning: LuaState do function called while running!" << std::endl; 179 //} 168 // return value is nil 169 lua_pushnil(luaState_); 170 } 171 // push return value because it will get lost since the return value of this function is void 172 lua_setglobal(luaState_, "LuaStateReturnValue"); 180 173 181 174 // Load the old info again … … 191 184 { 192 185 OutputHandler::getOutStream().setOutputLevel(level) << message << std::endl; 186 } 187 188 bool LuaState::fileExists(const std::string& filename, const std::string& resourceGroup, bool bSearchOtherPaths) 189 { 190 shared_ptr<ResourceInfo> info = this->getFileInfo(filename, resourceGroup, bSearchOtherPaths); 191 if (info == NULL) 192 return false; 193 else 194 return true; 193 195 } 194 196 -
code/branches/resource2/src/core/LuaState.h
r5655 r5661 59 59 void doString(const std::string& code, shared_ptr<ResourceInfo> sourceFileInfo = shared_ptr<ResourceInfo>()); 60 60 61 void includeFile(const std::string& filename, const std::string& resourceGroup = "Gen real", bool bSearchOtherPaths = true); // tolua_export61 void includeFile(const std::string& filename, const std::string& resourceGroup = "General", bool bSearchOtherPaths = true); // tolua_export 62 62 void includeString(const std::string& code, shared_ptr<ResourceInfo> sourceFileInfo = shared_ptr<ResourceInfo>()); 63 63 64 64 void luaPrint(const std::string& str); // tolua_export 65 65 void luaLog(unsigned int level, const std::string& message); // tolua_export 66 bool fileExists(const std::string& filename, const std::string& resourceGroup = "General", bool bSearchOtherPaths = true); // tolua_export 66 67 67 68 const std::stringstream& getOutput() const { return output_; } -
code/branches/resource2/src/orxonox/gamestates/GSMainMenu.cc
r3370 r5661 70 70 { 71 71 // show main menu 72 GUIManager::getInstance().showGUI(" mainmenu_4");72 GUIManager::getInstance().showGUI("MainMenu"); 73 73 GUIManager::getInstance().setCamera(this->camera_); 74 74 GraphicsManager::getInstance().setCamera(this->camera_);
Note: See TracChangeset
for help on using the changeset viewer.