Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Aug 31, 2010, 3:37:40 AM (14 years ago)
Author:
landauf
Message:

merged consolecommands3 branch back to trunk.

note: the console command interface has changed completely, but the documentation is not yet up to date. just copy an existing command and change it to your needs, it's pretty self-explanatory. also the include files related to console commands are now located in core/command/. in the game it should work exactly like before, except for some changes in the auto-completion.

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/libraries/core/input/KeyBinderManager.cc

    r6417 r7284  
    3131#include "util/Debug.h"
    3232#include "util/Exception.h"
     33#include "util/ScopedSingletonManager.h"
    3334#include "core/ConfigValueIncludes.h"
    34 #include "core/ConsoleCommand.h"
    3535#include "core/CoreIncludes.h"
    36 #include "core/ScopedSingletonManager.h"
     36#include "core/LuaState.h"
     37#include "core/command/ConsoleCommand.h"
    3738#include "InputManager.h"
    3839#include "KeyDetector.h"
     
    4142{
    4243    ManageScopedSingleton(KeyBinderManager, ScopeID::Graphics, false);
     44
     45    static const std::string __CC_keybind_name = "keybind";
     46    static const std::string __CC_tkeybind_name = "tkeybind";
     47    static const std::string __CC_unbind_name = "unbind";
     48    static const std::string __CC_tunbind_name = "tunbind";
     49
     50    SetConsoleCommand(__CC_keybind_name,  &KeyBinderManager::keybind).defaultValues("").argumentCompleter(0, autocompletion::command());
     51    SetConsoleCommand(__CC_tkeybind_name, &KeyBinderManager::tkeybind).defaultValues("").argumentCompleter(0, autocompletion::command());
     52    SetConsoleCommand(__CC_unbind_name,   &KeyBinderManager::unbind).defaultValues("");
     53    SetConsoleCommand(__CC_tunbind_name,  &KeyBinderManager::tunbind).defaultValues("");
    4354
    4455    KeyBinderManager::KeyBinderManager()
     
    5162
    5263        // keybind console commands
    53         CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&KeyBinderManager::keybind,  this), "keybind" ))
    54             .defaultValues("");
    55         CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&KeyBinderManager::tkeybind, this), "tkeybind"))
    56             .defaultValues("");
    57         CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&KeyBinderManager::unbind, this), "unbind"))
    58             .defaultValues("");
    59         CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&KeyBinderManager::tunbind, this), "tunbind"))
    60             .defaultValues("");
     64        ModifyConsoleCommand(__CC_keybind_name ).setObject(this);
     65        ModifyConsoleCommand(__CC_tkeybind_name).setObject(this);
     66        ModifyConsoleCommand(__CC_unbind_name  ).setObject(this);
     67        ModifyConsoleCommand(__CC_tunbind_name ).setObject(this);
    6168
    6269        // Load default key binder
     
    6976        for (std::map<std::string, KeyBinder*>::const_iterator it = this->binders_.begin(); it != this->binders_.end(); ++it)
    7077            delete it->second;
     78
     79        // Reset console commands
     80        ModifyConsoleCommand(__CC_keybind_name ).setObject(0);
     81        ModifyConsoleCommand(__CC_tkeybind_name).setObject(0);
     82        ModifyConsoleCommand(__CC_unbind_name  ).setObject(0);
     83        ModifyConsoleCommand(__CC_tunbind_name ).setObject(0);
    7184    }
    7285
     
    156169        {
    157170            COUT(0) << "Press any button/key or move a mouse/joystick axis" << std::endl;
    158             KeyDetector::getInstance().setCallback(shared_ptr<Functor>(createFunctor(&KeyBinderManager::keybindKeyPressed, this)));
     171            KeyDetector::getInstance().setCallback(createFunctor(&KeyBinderManager::keybindKeyPressed, this));
    159172            InputManager::getInstance().enterState("detector");
    160173            this->command_ = command;
     
    187200        // else: A key was probably pressed within the same tick, ignore it.
    188201    }
     202
     203    void KeyBinderManager::registerKeybindCallback(LuaFunctor* function)
     204    {
     205        this->callbackFunction_ = function;
     206    }
    189207}
Note: See TracChangeset for help on using the changeset viewer.