Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 11046


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.

Location:
code/branches/presentationHS15
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentationHS15/data/gui/scripts/SheetManager.lua

    r8729 r11046  
    2424        cursor:show()
    2525    end
     26end
     27
     28function getLoadedSheets()
     29    local names = ""
     30    for name, sheet in pairs(loadedSheets) do
     31        names = names .. name
     32        names = names .. ","
     33    end
     34    return names
    2635end
    2736
  • 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
  • code/branches/presentationHS15/src/libraries/core/GUIManager.h

    r9675 r11046  
    107107        void preUpdate(const Clock& time);
    108108
     109        std::vector<std::string> getLoadedGUIs();
     110
    109111        void loadGUI(const std::string& name);
    110112        static void showGUI(const std::string& name, bool bHidePrevious = false, bool bNoInput = false);
Note: See TracChangeset for help on using the changeset viewer.