Implemented adding keyboard configs through the GUI
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@4357 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
@@ -165,6 +165,14 @@ void DeviceManager::addKeyboard(KeyboardDevice* d)
|
||||
{
|
||||
m_keyboards.push_back(d);
|
||||
}
|
||||
// -----------------------------------------------------------------------------
|
||||
void DeviceManager::addEmptyKeyboard()
|
||||
{
|
||||
KeyboardConfig* newConf = new KeyboardConfig();
|
||||
m_keyboard_configs.push_back(newConf);
|
||||
m_keyboards.push_back( new KeyboardDevice(newConf) );
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
void DeviceManager::addGamepad(GamePadDevice* d)
|
||||
{
|
||||
|
||||
@@ -86,6 +86,7 @@ public:
|
||||
bool getConfigForGamepad(const int sdl_id, GamepadConfig **config);
|
||||
|
||||
// ---- Keyboard(s) ----
|
||||
void addEmptyKeyboard();
|
||||
void addKeyboard(KeyboardDevice* d);
|
||||
int getKeyboardConfigAmount() const { return m_keyboard_configs.size(); }
|
||||
KeyboardDevice* getKeyboard(const int i) { return m_keyboards.get(i); }
|
||||
|
||||
@@ -19,8 +19,11 @@
|
||||
#include "config/player.hpp"
|
||||
#include "guiengine/engine.hpp"
|
||||
#include "guiengine/widget.hpp"
|
||||
#include "input/device_manager.hpp"
|
||||
#include "input/input_manager.hpp"
|
||||
#include "states_screens/dialogs/add_device_dialog.hpp"
|
||||
#include "states_screens/options_screen_players.hpp"
|
||||
#include "states_screens/options_screen_input.hpp"
|
||||
#include "states_screens/state_manager.hpp"
|
||||
#include "utils/string_utils.hpp"
|
||||
#include "utils/translation.hpp"
|
||||
@@ -92,17 +95,18 @@ GUIEngine::EventPropagation AddDeviceDialog::processEvent(std::string& eventSour
|
||||
|
||||
if (eventSource == "cancel")
|
||||
{
|
||||
// irrLicht is too stupid to remove focus from deleted widgets
|
||||
// so do it by hand
|
||||
//GUIEngine::getGUIEnv()->removeFocus( textCtrl->getIrrlichtElement() );
|
||||
//GUIEngine::getGUIEnv()->removeFocus( m_irrlicht_window );
|
||||
|
||||
ModalDialog::dismiss();
|
||||
return GUIEngine::EVENT_BLOCK;
|
||||
}
|
||||
else if (eventSource == "addkeyboard")
|
||||
{
|
||||
// TODO
|
||||
input_manager->getDeviceList()->addEmptyKeyboard();
|
||||
input_manager->getDeviceList()->serialize();
|
||||
ModalDialog::dismiss();
|
||||
|
||||
((OptionsScreenInput*)GUIEngine::getCurrentScreen())->rebuildDeviceList();
|
||||
|
||||
return GUIEngine::EVENT_BLOCK;
|
||||
}
|
||||
|
||||
return GUIEngine::EVENT_LET;
|
||||
|
||||
@@ -88,6 +88,46 @@ void OptionsScreenInput::updateInputButtons(DeviceConfig* config)
|
||||
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void OptionsScreenInput::buildDeviceList()
|
||||
{
|
||||
DynamicRibbonWidget* devices = this->getWidget<DynamicRibbonWidget>("devices");
|
||||
assert( devices != NULL );
|
||||
|
||||
const int keyboard_config_count = input_manager->getDeviceList()->getKeyboardConfigAmount();
|
||||
|
||||
for (int i=0; i<keyboard_config_count; i++)
|
||||
{
|
||||
//KeyboardConfig *config = input_manager->getDeviceList()->getKeyboardConfig(i);
|
||||
|
||||
std::ostringstream kbname;
|
||||
kbname << "keyboard" << i;
|
||||
const std::string internal_name = kbname.str();
|
||||
|
||||
|
||||
devices->addItem(StringUtils::insertValues(_("Keyboard %i"), i), internal_name, "/gui/keyboard.png");
|
||||
}
|
||||
|
||||
const int gpad_config_count = input_manager->getDeviceList()->getGamePadConfigAmount();
|
||||
|
||||
for (int i = 0; i < gpad_config_count; i++)
|
||||
{
|
||||
GamepadConfig *config = input_manager->getDeviceList()->getGamepadConfig(i);
|
||||
// Don't display the configuration if a matching device is not available
|
||||
if (config->isInUse())
|
||||
{
|
||||
const irr::core::stringw name = config->getName().c_str();
|
||||
|
||||
std::ostringstream gpname;
|
||||
gpname << "gamepad" << i;
|
||||
const std::string internal_name = gpname.str();
|
||||
|
||||
devices->addItem(name, internal_name, "/gui/gamepad.png");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
void OptionsScreenInput::init()
|
||||
{
|
||||
@@ -100,40 +140,8 @@ void OptionsScreenInput::init()
|
||||
|
||||
if (!this->m_inited)
|
||||
{
|
||||
const int keyboard_config_count = input_manager->getDeviceList()->getKeyboardConfigAmount();
|
||||
|
||||
for (int i=0; i<keyboard_config_count; i++)
|
||||
{
|
||||
//KeyboardConfig *config = input_manager->getDeviceList()->getKeyboardConfig(i);
|
||||
|
||||
std::ostringstream kbname;
|
||||
kbname << "keyboard" << i;
|
||||
const std::string internal_name = kbname.str();
|
||||
|
||||
|
||||
devices->addItem(StringUtils::insertValues(_("Keyboard %i"), i), internal_name, "/gui/keyboard.png");
|
||||
}
|
||||
|
||||
const int gpad_config_count = input_manager->getDeviceList()->getGamePadConfigAmount();
|
||||
|
||||
for (int i = 0; i < gpad_config_count; i++)
|
||||
{
|
||||
GamepadConfig *config = input_manager->getDeviceList()->getGamepadConfig(i);
|
||||
// Don't display the configuration if a matching device is not available
|
||||
if (config->isInUse())
|
||||
{
|
||||
const irr::core::stringw name = config->getName().c_str();
|
||||
|
||||
std::ostringstream gpname;
|
||||
gpname << "gamepad" << i;
|
||||
const std::string internal_name = gpname.str();
|
||||
|
||||
devices->addItem(name, internal_name, "/gui/gamepad.png");
|
||||
}
|
||||
}
|
||||
|
||||
buildDeviceList();
|
||||
this->m_inited = true;
|
||||
|
||||
}
|
||||
devices->updateItemDisplay();
|
||||
|
||||
@@ -142,6 +150,18 @@ void OptionsScreenInput::init()
|
||||
eventCallback(devices, name2, GUI_PLAYER_ID);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void OptionsScreenInput::rebuildDeviceList()
|
||||
{
|
||||
DynamicRibbonWidget* devices = this->getWidget<DynamicRibbonWidget>("devices");
|
||||
assert( devices != NULL );
|
||||
|
||||
devices->clearItems();
|
||||
buildDeviceList();
|
||||
devices->updateItemDisplay();
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
static PlayerAction binding_to_set;
|
||||
static std::string binding_to_set_button;
|
||||
|
||||
@@ -31,9 +31,10 @@ struct Input;
|
||||
|
||||
class OptionsScreenInput : public GUIEngine::Screen, public GUIEngine::ScreenSingleton<OptionsScreenInput>
|
||||
{
|
||||
void updateInputButtons(DeviceConfig* config);
|
||||
|
||||
OptionsScreenInput();
|
||||
|
||||
void updateInputButtons(DeviceConfig* config);
|
||||
void buildDeviceList();
|
||||
|
||||
public:
|
||||
friend class GUIEngine::ScreenSingleton<OptionsScreenInput>;
|
||||
@@ -41,7 +42,8 @@ public:
|
||||
void eventCallback(GUIEngine::Widget* widget, const std::string& name, const int playerID);
|
||||
|
||||
void gotSensedInput(Input* sensedInput);
|
||||
|
||||
void rebuildDeviceList();
|
||||
|
||||
void init();
|
||||
void tearDown();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user