Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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'.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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    {
Note: See TracChangeset for help on using the changeset viewer.