Merge remote-tracking branch 'Alayan/DisableKeyboardConfig'
This commit is contained in:
commit
fc04eeade7
BIN
data/gui/keyboard_off.png
Normal file
BIN
data/gui/keyboard_off.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.5 KiB |
@ -32,22 +32,24 @@
|
||||
<spacer height="16" width="10"/>
|
||||
|
||||
<!-- List of key bindings -->
|
||||
<box proportion="8" width="75%" align="center" layout="vertical-row" padding="8">
|
||||
<box proportion="10" width="75%" align="center" layout="vertical-row" padding="8">
|
||||
<list id="actions" x="0" y="0" width="100%" height="100%"/>
|
||||
</box>
|
||||
|
||||
<!-- Bottom buttons -->
|
||||
|
||||
<spacer width="50" height="20" />
|
||||
<div proportion="2" width="100%" layout="horizontal-row">
|
||||
<spacer width="7" height="5"/>
|
||||
<div proportion="3" width="100%" layout="horizontal-row">
|
||||
<div height="100%" width="fit" layout="vertical-row">
|
||||
<button id="delete"
|
||||
I18N="In the input configuration screen" text="Delete Configuration"/>
|
||||
<spacer width="50" height="10" />
|
||||
<spacer width="50" height="3%" />
|
||||
<button id="disable_toggle"
|
||||
I18N="In the input configuration screen" text="Disable Configuration"/>
|
||||
<spacer width="50" height="3%" />
|
||||
<button id="back_to_device_list" I18N="In the input configuration screen" text="Back to device list"/>
|
||||
|
||||
<spacer width="50" height="10" />
|
||||
<spacer width="50" height="3%" />
|
||||
</div>
|
||||
<spacer width="20" height="10" />
|
||||
<label id="conflict" proportion="1" text="" word_wrap="true" align="center"/>
|
||||
|
@ -127,6 +127,15 @@ public:
|
||||
void addKeyboard(KeyboardDevice* d);
|
||||
void clearKeyboard();
|
||||
int getKeyboardAmount() { return m_keyboards.size(); }
|
||||
int getActiveKeyboardAmount()
|
||||
{
|
||||
int active = 0;
|
||||
for (unsigned int i=0;i<m_keyboard_configs.size();i++)
|
||||
{
|
||||
if (m_keyboard_configs[i].isEnabled()) active++;
|
||||
}
|
||||
return active;
|
||||
}
|
||||
int getKeyboardConfigAmount() const { return m_keyboard_configs.size(); }
|
||||
KeyboardDevice* getKeyboard(const int i) { return m_keyboards.get(i); }
|
||||
KeyboardConfig* getKeyboardConfig(const int i) { return m_keyboard_configs.get(i); }
|
||||
@ -190,4 +199,3 @@ public:
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -82,44 +82,81 @@ void OptionsScreenDevice::init()
|
||||
tabBar->select( "tab_controls", PLAYER_ID_GAME_MASTER );
|
||||
|
||||
ButtonWidget* delete_button = getWidget<ButtonWidget>("delete");
|
||||
if (!m_config->isKeyboard())
|
||||
ButtonWidget* disable_toggle = getWidget<ButtonWidget>("disable_toggle");
|
||||
|
||||
if (m_config->isGamePadAndroid())
|
||||
{
|
||||
core::stringw label = (m_config->isEnabled()
|
||||
? //I18N: button to disable a gamepad configuration
|
||||
_("Disable Device")
|
||||
: //I18N: button to enable a gamepad configuration
|
||||
_("Enable Device"));
|
||||
delete_button->setActive(false);
|
||||
disable_toggle->setActive(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
core::stringw label;
|
||||
|
||||
if (!m_config->isKeyboard())
|
||||
{
|
||||
// Only allow to enable or disable a gamepad,
|
||||
// as it is only in the list when connected
|
||||
delete_button->setActive(false);
|
||||
|
||||
label = (m_config->isEnabled()
|
||||
? //I18N: button to disable a gamepad configuration
|
||||
_("Disable Device")
|
||||
: //I18N: button to enable a gamepad configuration
|
||||
_("Enable Device"));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Don't allow deleting or disabling the last enabled config
|
||||
bool enable = (input_manager->getDeviceManager()
|
||||
->getActiveKeyboardAmount() > 1 ||
|
||||
!m_config->isEnabled());
|
||||
delete_button->setActive(enable);
|
||||
disable_toggle->setActive(enable);
|
||||
|
||||
label = (m_config->isEnabled()
|
||||
? //I18N: button to disable a keyboard configuration
|
||||
_("Disable Configuration")
|
||||
: //I18N: button to enable a keyboard configuration
|
||||
_("Enable Configuration"));
|
||||
}
|
||||
|
||||
// Make sure button is wide enough as the text is being changed away
|
||||
// from the original value
|
||||
core::dimension2d<u32> size =
|
||||
GUIEngine::getFont()->getDimension(label.c_str());
|
||||
const int needed = size.Width + delete_button->getWidthNeededAroundLabel();
|
||||
if (delete_button->m_w < needed) delete_button->m_w = needed;
|
||||
const int needed = size.Width + disable_toggle->getWidthNeededAroundLabel();
|
||||
if (disable_toggle->m_w < needed) disable_toggle->m_w = needed;
|
||||
|
||||
delete_button->setLabel(label);
|
||||
disable_toggle->setLabel(label);
|
||||
}
|
||||
else if (m_config->isGamePadAndroid())
|
||||
|
||||
// Make the three buttons the same length, not strictly needed but will
|
||||
// look nicer...
|
||||
ButtonWidget* backBtn = getWidget<ButtonWidget>("back_to_device_list");
|
||||
if (disable_toggle->m_w < delete_button->m_w)
|
||||
{
|
||||
delete_button->setLabel(_("Delete Configuration"));
|
||||
delete_button->setActive(false);
|
||||
disable_toggle->m_w = delete_button->m_w;
|
||||
}
|
||||
else
|
||||
{
|
||||
delete_button->setLabel(_("Delete Configuration"));
|
||||
// Don't allow deleting the last config
|
||||
delete_button->setActive(
|
||||
input_manager->getDeviceManager()->getKeyboardAmount() > 1);
|
||||
delete_button->m_w = disable_toggle->m_w;
|
||||
}
|
||||
// At this point, the delete button has the same width as the disable button.
|
||||
// One comparison is enough.
|
||||
if (backBtn->m_w < delete_button->m_w)
|
||||
{
|
||||
backBtn->m_w = delete_button->m_w;
|
||||
}
|
||||
else
|
||||
{
|
||||
disable_toggle->m_w = backBtn->m_w;
|
||||
delete_button->m_w = backBtn->m_w;
|
||||
}
|
||||
|
||||
// Make the two buttons the same length, not strictly needed but will
|
||||
// look nicer...
|
||||
ButtonWidget* backBtn = getWidget<ButtonWidget>("back_to_device_list");
|
||||
if (backBtn->m_w < delete_button->m_w) backBtn->m_w = delete_button->m_w;
|
||||
else delete_button->m_w = backBtn->m_w;
|
||||
|
||||
backBtn->moveIrrlichtElement();
|
||||
delete_button->moveIrrlichtElement();
|
||||
disable_toggle->moveIrrlichtElement();
|
||||
|
||||
LabelWidget* label = getWidget<LabelWidget>("title");
|
||||
label->setText( m_config->getName().c_str(), false );
|
||||
@ -159,12 +196,13 @@ void OptionsScreenDevice::init()
|
||||
actions->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
|
||||
actions->setSelectionID(0);
|
||||
|
||||
// Disable deletion keyboard configurations
|
||||
// Disable deleting or disabling configuration mid-race
|
||||
bool in_game = StateManager::get()->getGameState() == GUIEngine::INGAME_MENU;
|
||||
|
||||
if (in_game)
|
||||
{
|
||||
getWidget<ButtonWidget>("delete")->setActive(false);
|
||||
delete_button->setActive(false);
|
||||
disable_toggle->setActive(false);
|
||||
}
|
||||
} // init
|
||||
|
||||
@ -567,27 +605,33 @@ void OptionsScreenDevice::eventCallback(Widget* widget,
|
||||
}
|
||||
else if (name == "delete")
|
||||
{
|
||||
if (m_config->isKeyboard())
|
||||
// keyboard configs may be deleted
|
||||
// They should be the only one to have the button enabled
|
||||
//I18N: shown before deleting an input configuration
|
||||
new MessageDialog( _("Are you sure you want to permanently delete "
|
||||
"this configuration?"),
|
||||
MessageDialog::MESSAGE_DIALOG_CONFIRM, this, false );
|
||||
}
|
||||
else if (name == "disable_toggle")
|
||||
{
|
||||
// gamepad and keyboard configs may be disabled
|
||||
if (m_config->isEnabled()) m_config->setEnabled(false);
|
||||
else m_config->setEnabled(true);
|
||||
|
||||
// update widget label
|
||||
ButtonWidget* disable_toggle = getWidget<ButtonWidget>("disable_toggle");
|
||||
if (!m_config->isKeyboard())
|
||||
{
|
||||
// keyboard configs may be deleted
|
||||
//I18N: shown before deleting an input configuration
|
||||
new MessageDialog( _("Are you sure you want to permanently delete "
|
||||
"this configuration?"),
|
||||
MessageDialog::MESSAGE_DIALOG_CONFIRM, this, false );
|
||||
disable_toggle->setLabel(m_config->isEnabled() ? _("Disable Device")
|
||||
: _("Enable Device") );
|
||||
}
|
||||
else
|
||||
{
|
||||
// gamepad configs may be disabled
|
||||
if (m_config->isEnabled()) m_config->setEnabled(false);
|
||||
else m_config->setEnabled(true);
|
||||
|
||||
// update widget label
|
||||
ButtonWidget* delete_button = getWidget<ButtonWidget>("delete");
|
||||
delete_button->setLabel(m_config->isEnabled() ? _("Disable Device")
|
||||
: _("Enable Device") );
|
||||
|
||||
input_manager->getDeviceManager()->save();
|
||||
disable_toggle->setLabel(m_config->isEnabled() ? _("Disable Configuration")
|
||||
: _("Enable Configuration") );
|
||||
}
|
||||
|
||||
input_manager->getDeviceManager()->save();
|
||||
}
|
||||
|
||||
} // eventCallback
|
||||
|
@ -57,14 +57,16 @@ OptionsScreenInput::OptionsScreenInput() : Screen("options_input.stkgui")
|
||||
|
||||
void OptionsScreenInput::loadedFromFile()
|
||||
{
|
||||
video::ITexture* icon1 = irr_driver->getTexture( file_manager->getAsset(FileManager::GUI_ICON,"keyboard.png" ));
|
||||
video::ITexture* icon2 = irr_driver->getTexture( file_manager->getAsset(FileManager::GUI_ICON,"gamepad.png" ));
|
||||
video::ITexture* icon3 = irr_driver->getTexture( file_manager->getAsset(FileManager::GUI_ICON,"gamepad_off.png"));
|
||||
video::ITexture* icon1 = irr_driver->getTexture( file_manager->getAsset(FileManager::GUI,"keyboard.png" ));
|
||||
video::ITexture* icon2 = irr_driver->getTexture( file_manager->getAsset(FileManager::GUI,"keyboard_off.png" ));
|
||||
video::ITexture* icon3 = irr_driver->getTexture( file_manager->getAsset(FileManager::GUI,"gamepad.png" ));
|
||||
video::ITexture* icon4 = irr_driver->getTexture( file_manager->getAsset(FileManager::GUI,"gamepad_off.png"));
|
||||
|
||||
m_icon_bank = new irr::gui::STKModifiedSpriteBank( GUIEngine::getGUIEnv() );
|
||||
m_icon_bank->addTextureAsSprite(icon1);
|
||||
m_icon_bank->addTextureAsSprite(icon2);
|
||||
m_icon_bank->addTextureAsSprite(icon3);
|
||||
m_icon_bank->addTextureAsSprite(icon4);
|
||||
|
||||
// scale icons depending on screen resolution. the numbers below are a bit arbitrary
|
||||
const int screen_width = irr_driver->getFrameSize().Width;
|
||||
@ -99,14 +101,16 @@ void OptionsScreenInput::buildDeviceList()
|
||||
// since irrLicht's list widget has the nasty tendency to put the
|
||||
// icons very close to the text, I'm adding spaces to compensate.
|
||||
devices->addItem(internal_name, (core::stringw(" ") +
|
||||
_("Gamepad")).c_str(), 1 /* icon */);
|
||||
_("Gamepad")).c_str(), 2 /* icon */);
|
||||
}
|
||||
else
|
||||
{
|
||||
const int icon = (config->isEnabled() ? 0 : 1);
|
||||
|
||||
// since irrLicht's list widget has the nasty tendency to put the
|
||||
// icons very close to the text, I'm adding spaces to compensate.
|
||||
devices->addItem(internal_name, (core::stringw(" ") +
|
||||
_("Keyboard %i", i)).c_str(), 0 /* icon */);
|
||||
_("Keyboard %i", i)).c_str(), icon);
|
||||
}
|
||||
}
|
||||
|
||||
@ -134,7 +138,7 @@ void OptionsScreenInput::buildDeviceList()
|
||||
gpname << "gamepad" << i;
|
||||
const std::string internal_name = gpname.str();
|
||||
|
||||
const int icon = (config->isEnabled() ? 1 : 2);
|
||||
const int icon = (config->isEnabled() ? 2 : 3);
|
||||
|
||||
devices->addItem(internal_name, name, icon);
|
||||
} // if config->isPlugged
|
||||
@ -145,7 +149,7 @@ void OptionsScreenInput::buildDeviceList()
|
||||
if (touch_device != NULL)
|
||||
{
|
||||
devices->addItem("touch_device", (core::stringw(" ") +
|
||||
_("Touch Device")).c_str(), 1);
|
||||
_("Touch Device")).c_str(), 2);
|
||||
}
|
||||
} // buildDeviceList
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user