Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9978 for code/trunk


Ignore:
Timestamp:
Jan 4, 2014, 9:48:04 PM (10 years ago)
Author:
landauf
Message:

added new keybind mode 'OnPressAndRelease' which triggers both when a button is pressed and when it's released.
pressed buttons send the value '1' to the bound console command, while released buttons send the value '0'.

Location:
code/trunk/src/libraries/core
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/libraries/core/CorePrereqs.h

    r9703 r9978  
    106106            OnHold,
    107107            OnRelease,
     108            OnPressAndRelease,
    108109            None
    109110        };
  • code/trunk/src/libraries/core/input/Button.cc

    r9667 r9978  
    138138                    else if (token == "onrelease")
    139139                        mode = KeybindMode::OnRelease;
     140                    else if (token == "onpressandrelease")
     141                        mode = KeybindMode::OnPressAndRelease;
    140142                    else if (token == "onhold")
    141143                        mode = KeybindMode::OnHold;
     
    216218                        {
    217219                            mode = eval.getConsoleCommand()->getKeybindMode();
    218                             commands[mode].push_back(cmd);
     220                            this->addCommand(cmd, mode, commands);
    219221                        }
    220222                    }
     
    232234                        cmd->setFixedKeybindMode(true);
    233235
    234                     commands[mode].push_back(cmd);
     236                    this->addCommand(cmd, mode, commands);
    235237                }
    236238            }
     
    251253    }
    252254
     255    inline void Button::addCommand(BaseCommand* cmd, KeybindMode::Value mode, std::vector<BaseCommand*> commands[3])
     256    {
     257        if (mode == KeybindMode::OnPressAndRelease)
     258        {
     259            BaseCommand* cmd2 = cmd->clone();
     260
     261            commands[KeybindMode::OnPress].push_back(cmd);
     262            commands[KeybindMode::OnRelease].push_back(cmd2); // clone
     263        }
     264        else
     265            commands[mode].push_back(cmd);
     266    }
     267
    253268    inline void Button::parseError(const std::string& message, bool serious)
    254269    {
  • code/trunk/src/libraries/core/input/Button.h

    r6536 r9978  
    7575    private:
    7676        void parseError(const std::string& message, bool serious);
     77        void addCommand(BaseCommand* cmd, KeybindMode::Value mode, std::vector<BaseCommand*> commands[3]);
    7778    };
    7879
  • code/trunk/src/libraries/core/input/InputCommands.h

    r7891 r9978  
    6767            { return this->bFixedKeybindMode_; }
    6868
     69        virtual BaseCommand* clone() = 0;
     70
    6971    private:
    7072        bool bFixedKeybindMode_;
     
    7678        bool execute(float abs = 1.0f, float rel = 1.0f);
    7779        CommandEvaluation* getEvaluation();
     80        virtual SimpleCommand* clone() { return new SimpleCommand(*this); }
    7881
    7982        CommandEvaluation evaluation_;
     
    103106        bool execute(float abs = 1.0f, float rel = 1.0f);
    104107        CommandEvaluation* getEvaluation();
     108        virtual ParamCommand* clone() { return new ParamCommand(*this); }
    105109
    106110        float scale_;
  • code/trunk/src/libraries/core/input/KeyBinder.h

    r7861 r9978  
    195195
    196196    inline void KeyBinder::buttonPressed (const KeyEvent& evt)
    197     { assert(!keys_[evt.getKeyCode()].name_.empty()); keys_[evt.getKeyCode()].execute(KeybindMode::OnPress); }
     197    { assert(!keys_[evt.getKeyCode()].name_.empty()); keys_[evt.getKeyCode()].execute(KeybindMode::OnPress, 1); }
    198198
    199199    inline void KeyBinder::buttonReleased(const KeyEvent& evt)
    200     { assert(!keys_[evt.getKeyCode()].name_.empty()); keys_[evt.getKeyCode()].execute(KeybindMode::OnRelease); }
     200    { assert(!keys_[evt.getKeyCode()].name_.empty()); keys_[evt.getKeyCode()].execute(KeybindMode::OnRelease, 0); }
    201201
    202202    inline void KeyBinder::buttonHeld    (const KeyEvent& evt)
     
    205205
    206206    inline void KeyBinder::buttonPressed (MouseButtonCode::ByEnum button)
    207     { mouseButtons_[button].execute(KeybindMode::OnPress); }
     207    { mouseButtons_[button].execute(KeybindMode::OnPress, 1); }
    208208
    209209    inline void KeyBinder::buttonReleased(MouseButtonCode::ByEnum button)
    210     { mouseButtons_[button].execute(KeybindMode::OnRelease); }
     210    { mouseButtons_[button].execute(KeybindMode::OnRelease, 0); }
    211211
    212212    inline void KeyBinder::buttonHeld    (MouseButtonCode::ByEnum button)
     
    215215
    216216    inline void KeyBinder::buttonPressed (unsigned int device, JoyStickButtonCode::ByEnum button)
    217     { (*joyStickButtons_[device])[button].execute(KeybindMode::OnPress); }
     217    { (*joyStickButtons_[device])[button].execute(KeybindMode::OnPress, 1); }
    218218
    219219    inline void KeyBinder::buttonReleased(unsigned int device, JoyStickButtonCode::ByEnum button)
    220     { (*joyStickButtons_[device])[button].execute(KeybindMode::OnRelease); }
     220    { (*joyStickButtons_[device])[button].execute(KeybindMode::OnRelease, 0); }
    221221
    222222    inline void KeyBinder::buttonHeld    (unsigned int device, JoyStickButtonCode::ByEnum button)
Note: See TracChangeset for help on using the changeset viewer.