[Orxonox-commit 6389] r11046 - in code/branches/presentationHS15: data/gui/scripts src/libraries/core
landauf at orxonox.net
landauf at orxonox.net
Tue Jan 5 11:18:28 CET 2016
Author: landauf
Date: 2016-01-05 11:18:27 +0100 (Tue, 05 Jan 2016)
New Revision: 11046
Modified:
code/branches/presentationHS15/data/gui/scripts/SheetManager.lua
code/branches/presentationHS15/src/libraries/core/GUIManager.cc
code/branches/presentationHS15/src/libraries/core/GUIManager.h
Log:
added argument completion function for active gui sheets.
TODO:
a) there should be a better way to read back values from lua (i.e. by using LuaState instead of plain lua.h functions)
b) it shouldn't be necessary to call lua anyway to get the active gui sheets. the GUIManager should always know this.
Modified: code/branches/presentationHS15/data/gui/scripts/SheetManager.lua
===================================================================
--- code/branches/presentationHS15/data/gui/scripts/SheetManager.lua 2016-01-05 10:00:32 UTC (rev 11045)
+++ code/branches/presentationHS15/data/gui/scripts/SheetManager.lua 2016-01-05 10:18:27 UTC (rev 11046)
@@ -25,6 +25,15 @@
end
end
+function getLoadedSheets()
+ local names = ""
+ for name, sheet in pairs(loadedSheets) do
+ names = names .. name
+ names = names .. ","
+ end
+ return names
+end
+
-- Loads the GUI with the specified name
-- The name corresponds to the filename of the *.lua and *.layout files
-- but without the extension
Modified: code/branches/presentationHS15/src/libraries/core/GUIManager.cc
===================================================================
--- code/branches/presentationHS15/src/libraries/core/GUIManager.cc 2016-01-05 10:00:32 UTC (rev 11045)
+++ code/branches/presentationHS15/src/libraries/core/GUIManager.cc 2016-01-05 10:18:27 UTC (rev 11046)
@@ -35,6 +35,10 @@
#include <OgreRenderQueue.h>
#include <OgreRenderWindow.h>
+extern "C" {
+#include <lua.h>
+}
+
#if CEGUI_VERSION >= 0x000800
# include <CEGUI/DefaultLogger.h>
# include <CEGUI/Exceptions.h>
@@ -250,10 +254,29 @@
GUIManager* GUIManager::singletonPtr_s = 0;
/*static*/ const std::string GUIManager::defaultScheme_ = "TaharezGreen"; //Alternative: Orxonox (not fully complete yet, see the graphics menu)
- SetConsoleCommand("showGUI", &GUIManager::showGUI).defaultValue(1, false).defaultValue(2, false);
- SetConsoleCommand("hideGUI", &GUIManager::hideGUI);
- SetConsoleCommand("toggleGUI", &GUIManager::toggleGUI).defaultValue(1, false).defaultValue(2, false);
+ namespace autocompletion
+ {
+ /**
+ @brief Returns the names of all currently existing OverlayGroups.
+ */
+ ARGUMENT_COMPLETION_FUNCTION_DECLARATION(guinames)();
+ ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(guinames)()
+ {
+ ArgumentCompletionList names;
+ const std::vector<std::string> guis = GUIManager::getInstance().getLoadedGUIs();
+ for (size_t i = 0; i < guis.size(); ++i)
+ names.push_back(ArgumentCompletionListElement(guis[i], getLowercase(guis[i])));
+ return names;
+ }
+ }
+ SetConsoleCommand("showGUI", &GUIManager::showGUI).defaultValue(1, false).defaultValue(2, false)
+ .argumentCompleter(0, autocompletion::guinames());
+ SetConsoleCommand("hideGUI", &GUIManager::hideGUI)
+ .argumentCompleter(0, autocompletion::guinames());
+ SetConsoleCommand("toggleGUI", &GUIManager::toggleGUI).defaultValue(1, false).defaultValue(2, false)
+ .argumentCompleter(0, autocompletion::guinames());
+
RegisterAbstractClass(GUIManager).inheritsFrom<WindowEventListener>();
/**
@@ -490,6 +513,28 @@
this->luaState_->doString(str, rootFileInfo_);
}
+ std::vector<std::string> GUIManager::getLoadedGUIs()
+ {
+ // TODO: is there a better way to read back a return value from lua? i.e. by using LuaState?
+ lua_State* L = this->luaState_->getInternalLuaState();
+
+ // push function
+ lua_getglobal(L, "getLoadedSheets");
+
+ // do the call (0 arguments, 1 result)
+ if (lua_pcall(L, 0, 1, 0) != 0)
+ orxout(internal_error) << "error running function: " << lua_tostring(L, -1) << endl;
+
+ // retrieve result
+ if (!lua_isstring(L, -1))
+ orxout(internal_error) << "function must return a string" << endl;
+ std::string value = lua_tostring(L, -1);
+ lua_pop(L, 1);
+
+ SubString tokens(value, ",");
+ return tokens.getAllStrings();
+ }
+
/** Loads a GUI sheet by Lua script
@param name
The name of the GUI (like the script name, but without the extension)
Modified: code/branches/presentationHS15/src/libraries/core/GUIManager.h
===================================================================
--- code/branches/presentationHS15/src/libraries/core/GUIManager.h 2016-01-05 10:00:32 UTC (rev 11045)
+++ code/branches/presentationHS15/src/libraries/core/GUIManager.h 2016-01-05 10:18:27 UTC (rev 11046)
@@ -106,6 +106,8 @@
void preUpdate(const Clock& time);
+ std::vector<std::string> getLoadedGUIs();
+
void loadGUI(const std::string& name);
static void showGUI(const std::string& name, bool bHidePrevious = false, bool bNoInput = false);
void showGUIExtra(const std::string& name, const std::string& ptr, bool bHidePrevious = false, bool bNoInput = false);
More information about the Orxonox-commit
mailing list