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:
parent
740d57a2c4
commit
2ff79baf26
@ -53,6 +53,11 @@
|
|||||||
|
|
||||||
<spacer width="50" height="2%" />
|
<spacer width="50" height="2%" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<spacer width="2%" height="10" />
|
||||||
|
|
||||||
|
<button id="rename_config" I18N="In the input configuration screen" text="Rename Configuration"/>
|
||||||
|
|
||||||
<spacer width="2%" height="10" />
|
<spacer width="2%" height="10" />
|
||||||
<label id="conflict" proportion="1" text="" word_wrap="true" align="center"/>
|
<label id="conflict" proportion="1" text="" word_wrap="true" align="center"/>
|
||||||
</div>
|
</div>
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#include "input/gamepad_android_config.hpp"
|
#include "input/gamepad_android_config.hpp"
|
||||||
#include "input/keyboard_config.hpp"
|
#include "input/keyboard_config.hpp"
|
||||||
#include "io/xml_node.hpp"
|
#include "io/xml_node.hpp"
|
||||||
|
#include "io/utf_writer.hpp"
|
||||||
#include "utils/log.hpp"
|
#include "utils/log.hpp"
|
||||||
|
|
||||||
#include <SKeyMap.h>
|
#include <SKeyMap.h>
|
||||||
@ -73,6 +74,7 @@ DeviceConfig::DeviceConfig()
|
|||||||
m_name = "";
|
m_name = "";
|
||||||
m_enabled = true;
|
m_enabled = true;
|
||||||
m_plugged = 0;
|
m_plugged = 0;
|
||||||
|
m_config_name= L"";
|
||||||
} // DeviceConfig
|
} // DeviceConfig
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
@ -291,7 +293,10 @@ bool DeviceConfig::doGetAction(Input::InputType type,
|
|||||||
void DeviceConfig::save (std::ofstream& stream)
|
void DeviceConfig::save (std::ofstream& stream)
|
||||||
{
|
{
|
||||||
stream << "enabled=\""
|
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?
|
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("name", &m_name);
|
||||||
config->get("enabled", &m_enabled);
|
config->get("enabled", &m_enabled);
|
||||||
|
config->getAndDecode("configName", &m_config_name);
|
||||||
bool error = false;
|
bool error = false;
|
||||||
for(unsigned int i=0; i<config->getNumNodes(); i++)
|
for(unsigned int i=0; i<config->getNumNodes(); i++)
|
||||||
{
|
{
|
||||||
|
@ -49,9 +49,12 @@ private:
|
|||||||
/** How many devices connected to the system which uses this config? */
|
/** How many devices connected to the system which uses this config? */
|
||||||
int m_plugged;
|
int m_plugged;
|
||||||
|
|
||||||
/** Name of this configuratiom. */
|
/** Internal name of this configuration. */
|
||||||
std::string m_name;
|
std::string m_name;
|
||||||
|
|
||||||
|
/** Name of this configuration (given by the user). */
|
||||||
|
irr::core::stringw m_config_name;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
Binding m_bindings[PA_COUNT];
|
Binding m_bindings[PA_COUNT];
|
||||||
@ -126,11 +129,11 @@ public:
|
|||||||
} // getNumberOfAxes
|
} // getNumberOfAxes
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
/** Sets the name of this device. */
|
/** Sets the internal name of this device. */
|
||||||
void setName(const std::string &name) { m_name = name; }
|
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; };
|
const std::string& getName() const { return m_name; };
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
@ -156,6 +159,14 @@ public:
|
|||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
/** Sets this config to be enabled or disabled. */
|
/** Sets this config to be enabled or disabled. */
|
||||||
void setEnabled(bool new_value) { m_enabled = new_value; }
|
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
|
}; // class DeviceConfig
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
#include "guiengine/widget.hpp"
|
#include "guiengine/widget.hpp"
|
||||||
#include "guiengine/widgets/button_widget.hpp"
|
#include "guiengine/widgets/button_widget.hpp"
|
||||||
#include "guiengine/widgets/label_widget.hpp"
|
#include "guiengine/widgets/label_widget.hpp"
|
||||||
|
#include "guiengine/widgets/text_box_widget.hpp"
|
||||||
#include "guiengine/widgets/list_widget.hpp"
|
#include "guiengine/widgets/list_widget.hpp"
|
||||||
#include "guiengine/widgets/ribbon_widget.hpp"
|
#include "guiengine/widgets/ribbon_widget.hpp"
|
||||||
#include "input/input_manager.hpp"
|
#include "input/input_manager.hpp"
|
||||||
@ -31,6 +32,7 @@
|
|||||||
#include "input/gamepad_device.hpp"
|
#include "input/gamepad_device.hpp"
|
||||||
#include "io/file_manager.hpp"
|
#include "io/file_manager.hpp"
|
||||||
#include "states_screens/dialogs/press_a_key_dialog.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_audio.hpp"
|
||||||
#include "states_screens/options/options_screen_general.hpp"
|
#include "states_screens/options/options_screen_general.hpp"
|
||||||
#include "states_screens/options/options_screen_input.hpp"
|
#include "states_screens/options/options_screen_input.hpp"
|
||||||
@ -637,6 +639,24 @@ void OptionsScreenDevice::eventCallback(Widget* widget,
|
|||||||
|
|
||||||
input_manager->getDeviceManager()->save();
|
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
|
} // eventCallback
|
||||||
|
|
||||||
|
@ -107,10 +107,19 @@ void OptionsScreenInput::buildDeviceList()
|
|||||||
{
|
{
|
||||||
const int icon = (config->isEnabled() ? 0 : 1);
|
const int icon = (config->isEnabled() ? 0 : 1);
|
||||||
|
|
||||||
// since irrLicht's list widget has the nasty tendency to put the
|
//Display the configName instead of default name if it exists
|
||||||
// icons very close to the text, I'm adding spaces to compensate.
|
if (!config->getConfigName().empty())
|
||||||
devices->addItem(internal_name, (core::stringw(" ") +
|
{
|
||||||
_("Keyboard %i", i)).c_str(), icon);
|
// 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
|
// Don't display the configuration if a matching device is not available
|
||||||
if (config->isPlugged())
|
if (config->isPlugged())
|
||||||
{
|
{
|
||||||
// since irrLicht's list widget has the nasty tendency to put the
|
irr::core::stringw name;
|
||||||
// icons very close to the text, I'm adding spaces to compensate.
|
|
||||||
irr::core::stringw name = (" " + config->getName()).c_str();
|
|
||||||
|
|
||||||
if (config->getNumberOfDevices() > 1)
|
//Display the configName instead of default name if it exists
|
||||||
|
if (!config->getConfigName().empty())
|
||||||
{
|
{
|
||||||
name += core::stringw(L" (x");
|
// since irrLicht's list widget has the nasty tendency to put the
|
||||||
name += config->getNumberOfDevices();
|
// icons very close to the text, I'm adding spaces to compensate.
|
||||||
name += core::stringw(L")");
|
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;
|
std::ostringstream gpname;
|
||||||
|
Loading…
Reference in New Issue
Block a user