Add rename config option (#4233)

* Add rename config option

* xmlDe/Encode to deal with " character

* m_config_name string -> stringw

* wcslen() -> empty() , remove useless c_str()
This commit is contained in:
GuillaumeBft 2020-02-18 17:37:26 +01:00 committed by GitHub
parent 740d57a2c4
commit 2ff79baf26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 78 additions and 16 deletions

View File

@ -53,6 +53,11 @@
<spacer width="50" height="2%" />
</div>
<spacer width="2%" height="10" />
<button id="rename_config" I18N="In the input configuration screen" text="Rename Configuration"/>
<spacer width="2%" height="10" />
<label id="conflict" proportion="1" text="" word_wrap="true" align="center"/>
</div>

View File

@ -23,6 +23,7 @@
#include "input/gamepad_android_config.hpp"
#include "input/keyboard_config.hpp"
#include "io/xml_node.hpp"
#include "io/utf_writer.hpp"
#include "utils/log.hpp"
#include <SKeyMap.h>
@ -73,6 +74,7 @@ DeviceConfig::DeviceConfig()
m_name = "";
m_enabled = true;
m_plugged = 0;
m_config_name= L"";
} // DeviceConfig
// ------------------------------------------------------------------------
@ -291,7 +293,10 @@ bool DeviceConfig::doGetAction(Input::InputType type,
void DeviceConfig::save (std::ofstream& stream)
{
stream << "enabled=\""
<< (m_enabled ? "true\">\n" : "false\">\n");
<< (m_enabled ? "true\"" : "false\"")
<< " configName=\""
<< StringUtils::xmlEncode(m_config_name)
<< "\">\n ";
for(int n = 0; n < PA_COUNT; n++) // Start at 0?
{
@ -312,6 +317,7 @@ bool DeviceConfig::load(const XMLNode *config)
{
config->get("name", &m_name);
config->get("enabled", &m_enabled);
config->getAndDecode("configName", &m_config_name);
bool error = false;
for(unsigned int i=0; i<config->getNumNodes(); i++)
{

View File

@ -49,9 +49,12 @@ private:
/** How many devices connected to the system which uses this config? */
int m_plugged;
/** Name of this configuratiom. */
/** Internal name of this configuration. */
std::string m_name;
/** Name of this configuration (given by the user). */
irr::core::stringw m_config_name;
protected:
Binding m_bindings[PA_COUNT];
@ -126,11 +129,11 @@ public:
} // getNumberOfAxes
// ------------------------------------------------------------------------
/** Sets the name of this device. */
/** Sets the internal name of this device. */
void setName(const std::string &name) { m_name = name; }
// ------------------------------------------------------------------------
/** Returns the name for this device configuration. */
/** Returns the internal name for this device configuration. */
const std::string& getName() const { return m_name; };
// ------------------------------------------------------------------------
@ -156,6 +159,14 @@ public:
// ------------------------------------------------------------------------
/** Sets this config to be enabled or disabled. */
void setEnabled(bool new_value) { m_enabled = new_value; }
// ------------------------------------------------------------------------
/** Sets the name of this device configuration */
irr::core::stringw getConfigName() const { return m_config_name; }
// ------------------------------------------------------------------------
/** Returns the name of this device configuration */
void setConfigName( irr::core::stringw config_name ) { m_config_name = config_name; }
}; // class DeviceConfig
#endif

View File

@ -24,6 +24,7 @@
#include "guiengine/widget.hpp"
#include "guiengine/widgets/button_widget.hpp"
#include "guiengine/widgets/label_widget.hpp"
#include "guiengine/widgets/text_box_widget.hpp"
#include "guiengine/widgets/list_widget.hpp"
#include "guiengine/widgets/ribbon_widget.hpp"
#include "input/input_manager.hpp"
@ -31,6 +32,7 @@
#include "input/gamepad_device.hpp"
#include "io/file_manager.hpp"
#include "states_screens/dialogs/press_a_key_dialog.hpp"
#include "states_screens/dialogs/general_text_field_dialog.hpp"
#include "states_screens/options/options_screen_audio.hpp"
#include "states_screens/options/options_screen_general.hpp"
#include "states_screens/options/options_screen_input.hpp"
@ -637,6 +639,24 @@ void OptionsScreenDevice::eventCallback(Widget* widget,
input_manager->getDeviceManager()->save();
}
else if (name == "rename_config")
{
core::stringw configName = StringUtils::utf8ToWide(m_config->getName());
DeviceConfig *the_config = m_config; //Can't give variable m_config directly
new GeneralTextFieldDialog(configName, [] (const irr::core::stringw& text) {},
[the_config] (GUIEngine::LabelWidget* lw,
GUIEngine::TextBoxWidget* tb)->bool
{
core::stringw info = tb->getText();
if (info.empty())
return false;
the_config->setConfigName(info);
input_manager->getDeviceManager()->save();
return true;
});
}
} // eventCallback
@ -695,4 +715,4 @@ bool OptionsScreenDevice::conflictsBetweenKbdConfig(PlayerAction action,
}
}
return false;
} // conflictsBetweenKbdConfig
} // conflictsBetweenKbdConfig

View File

@ -107,10 +107,19 @@ void OptionsScreenInput::buildDeviceList()
{
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(), icon);
//Display the configName instead of default name if it exists
if (!config->getConfigName().empty())
{
// 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(" ") +
config->getConfigName()), icon);
}
else
{
devices->addItem(internal_name, (core::stringw(" ") +
_("Keyboard %i", i)).c_str(), icon);
}
}
}
@ -123,15 +132,26 @@ void OptionsScreenInput::buildDeviceList()
// Don't display the configuration if a matching device is not available
if (config->isPlugged())
{
// since irrLicht's list widget has the nasty tendency to put the
// icons very close to the text, I'm adding spaces to compensate.
irr::core::stringw name = (" " + config->getName()).c_str();
irr::core::stringw name;
if (config->getNumberOfDevices() > 1)
//Display the configName instead of default name if it exists
if (!config->getConfigName().empty())
{
name += core::stringw(L" (x");
name += config->getNumberOfDevices();
name += core::stringw(L")");
// since irrLicht's list widget has the nasty tendency to put the
// icons very close to the text, I'm adding spaces to compensate.
name = (core::stringw(" ") +
config->getConfigName());
}
else
{
name = (" " + config->getName()).c_str();
if (config->getNumberOfDevices() > 1)
{
name += core::stringw(L" (x");
name += config->getNumberOfDevices();
name += core::stringw(L")");
}
}
std::ostringstream gpname;