Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jan 5, 2016, 11:18:27 AM (8 years ago)
Author:
landauf
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentationHS15/src/libraries/core/GUIManager.cc

    r10624 r11046  
    3636#include <OgreRenderWindow.h>
    3737
     38extern "C" {
     39#include <lua.h>
     40}
     41
    3842#if CEGUI_VERSION >= 0x000800
    3943#   include <CEGUI/DefaultLogger.h>
     
    251255    /*static*/ const std::string GUIManager::defaultScheme_ = "TaharezGreen"; //Alternative: Orxonox (not fully complete yet, see the graphics menu)
    252256
    253     SetConsoleCommand("showGUI", &GUIManager::showGUI).defaultValue(1, false).defaultValue(2, false);
    254     SetConsoleCommand("hideGUI", &GUIManager::hideGUI);
    255     SetConsoleCommand("toggleGUI", &GUIManager::toggleGUI).defaultValue(1, false).defaultValue(2, false);
     257    namespace autocompletion
     258    {
     259        /**
     260            @brief Returns the names of all currently existing OverlayGroups.
     261        */
     262        ARGUMENT_COMPLETION_FUNCTION_DECLARATION(guinames)();
     263        ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(guinames)()
     264        {
     265            ArgumentCompletionList names;
     266            const std::vector<std::string> guis = GUIManager::getInstance().getLoadedGUIs();
     267            for (size_t i = 0; i < guis.size(); ++i)
     268                names.push_back(ArgumentCompletionListElement(guis[i], getLowercase(guis[i])));
     269            return names;
     270        }
     271    }
     272
     273    SetConsoleCommand("showGUI", &GUIManager::showGUI).defaultValue(1, false).defaultValue(2, false)
     274            .argumentCompleter(0, autocompletion::guinames());
     275    SetConsoleCommand("hideGUI", &GUIManager::hideGUI)
     276            .argumentCompleter(0, autocompletion::guinames());
     277    SetConsoleCommand("toggleGUI", &GUIManager::toggleGUI).defaultValue(1, false).defaultValue(2, false)
     278            .argumentCompleter(0, autocompletion::guinames());
    256279
    257280    RegisterAbstractClass(GUIManager).inheritsFrom<WindowEventListener>();
     
    489512    {
    490513        this->luaState_->doString(str, rootFileInfo_);
     514    }
     515
     516    std::vector<std::string> GUIManager::getLoadedGUIs()
     517    {
     518        // TODO: is there a better way to read back a return value from lua? i.e. by using LuaState?
     519        lua_State* L = this->luaState_->getInternalLuaState();
     520
     521        // push function
     522        lua_getglobal(L, "getLoadedSheets");
     523
     524        // do the call (0 arguments, 1 result)
     525        if (lua_pcall(L, 0, 1, 0) != 0)
     526          orxout(internal_error) << "error running function: " << lua_tostring(L, -1) << endl;
     527
     528        // retrieve result
     529        if (!lua_isstring(L, -1))
     530          orxout(internal_error) << "function must return a string" << endl;
     531        std::string value = lua_tostring(L, -1);
     532        lua_pop(L, 1);
     533
     534        SubString tokens(value, ",");
     535        return tokens.getAllStrings();
    491536    }
    492537
Note: See TracChangeset for help on using the changeset viewer.