Allow setting default config value inside stk-code

Share the restore code with android and iOS
This commit is contained in:
Benau 2019-10-22 01:43:09 +08:00
parent 17305a6cd8
commit 62d8a17152
3 changed files with 17 additions and 41 deletions

View File

@ -197,6 +197,7 @@ public:
void findYourDataInAnAttributeOf(const XMLNode* node); void findYourDataInAnAttributeOf(const XMLNode* node);
irr::core::stringc toString() const; irr::core::stringc toString() const;
void setDefaultValue(int v) { m_value = m_default_value = v; }
void revertToDefaults() { m_value = m_default_value; } void revertToDefaults() { m_value = m_default_value; }
int getDefaultValue() { return m_default_value; } int getDefaultValue() { return m_default_value; }
operator int() const { return m_value; } operator int() const { return m_value; }
@ -297,6 +298,7 @@ public:
irr::core::stringc toString() const; irr::core::stringc toString() const;
void revertToDefaults() { m_value = m_default_value; } void revertToDefaults() { m_value = m_default_value; }
void setDefaultValue(bool v) { m_value = m_default_value = v; }
operator bool() const { return m_value; } operator bool() const { return m_value; }
bool& operator=(const bool& v) { m_value = v; return m_value; } bool& operator=(const bool& v) { m_value = v; return m_value; }
@ -330,6 +332,7 @@ public:
irr::core::stringc toString() const; irr::core::stringc toString() const;
void revertToDefaults() { m_value = m_default_value; } void revertToDefaults() { m_value = m_default_value; }
void setDefaultValue(float v) { m_value = m_default_value = v; }
operator float() const { return m_value; } operator float() const { return m_value; }
float& operator=(const float& v) { m_value = v; return m_value; } float& operator=(const float& v) { m_value = v; return m_value; }

View File

@ -70,18 +70,18 @@ void override_default_params_for_mobile()
{ {
case ACONFIGURATION_SCREENSIZE_SMALL: case ACONFIGURATION_SCREENSIZE_SMALL:
case ACONFIGURATION_SCREENSIZE_NORMAL: case ACONFIGURATION_SCREENSIZE_NORMAL:
UserConfigParams::m_multitouch_scale = 1.3f; UserConfigParams::m_multitouch_scale.setDefaultValue(1.3f);
UserConfigParams::m_multitouch_sensitivity_x = 0.1f; UserConfigParams::m_multitouch_sensitivity_x.setDefaultValue(0.1f);
UserConfigParams::m_font_size = 5.0f; UserConfigParams::m_font_size = 5.0f;
break; break;
case ACONFIGURATION_SCREENSIZE_LARGE: case ACONFIGURATION_SCREENSIZE_LARGE:
UserConfigParams::m_multitouch_scale = 1.2f; UserConfigParams::m_multitouch_scale.setDefaultValue(1.2f);
UserConfigParams::m_multitouch_sensitivity_x = 0.15f; UserConfigParams::m_multitouch_sensitivity_x.setDefaultValue(0.15f);
UserConfigParams::m_font_size = 5.0f; UserConfigParams::m_font_size = 5.0f;
break; break;
case ACONFIGURATION_SCREENSIZE_XLARGE: case ACONFIGURATION_SCREENSIZE_XLARGE:
UserConfigParams::m_multitouch_scale = 1.1f; UserConfigParams::m_multitouch_scale.setDefaultValue(1.1f);
UserConfigParams::m_multitouch_sensitivity_x = 0.2f; UserConfigParams::m_multitouch_sensitivity_x.setDefaultValue(0.2f);
UserConfigParams::m_font_size = 4.0f; UserConfigParams::m_font_size = 4.0f;
break; break;
default: default:
@ -112,8 +112,8 @@ void getConfigForDevice(const char* dev)
if (device.find("iPhone") != std::string::npos) if (device.find("iPhone") != std::string::npos)
{ {
// Normal configuration default // Normal configuration default
UserConfigParams::m_multitouch_scale = 1.3f; UserConfigParams::m_multitouch_scale.setDefaultValue(1.3f);
UserConfigParams::m_multitouch_sensitivity_x = 0.1f; UserConfigParams::m_multitouch_sensitivity_x.setDefaultValue(0.1f);
UserConfigParams::m_font_size = 5.0f; UserConfigParams::m_font_size = 5.0f;
device.erase(0, 6); device.erase(0, 6);
auto versions = StringUtils::splitToUInt(device, ','); auto versions = StringUtils::splitToUInt(device, ',');
@ -136,16 +136,16 @@ void getConfigForDevice(const char* dev)
) )
{ {
// Those phones have small screen // Those phones have small screen
UserConfigParams::m_multitouch_scale = 1.45f; UserConfigParams::m_multitouch_scale.setDefaultValue(1.45f);
} }
} }
} }
else if (device.find("iPad") != std::string::npos) else if (device.find("iPad") != std::string::npos)
{ {
// Normal configuration default // Normal configuration default
UserConfigParams::m_multitouch_scale = 1.1f; UserConfigParams::m_multitouch_scale.setDefaultValue(1.1f);
UserConfigParams::m_multitouch_sensitivity_x = 0.2f; UserConfigParams::m_multitouch_sensitivity_x.setDefaultValue(0.2f);
UserConfigParams::m_font_size = 4.0f; UserConfigParams::m_font_size = 3.0f;
device.erase(0, 4); device.erase(0, 4);
auto versions = StringUtils::splitToUInt(device, ','); auto versions = StringUtils::splitToUInt(device, ',');
if (versions.size() == 2) if (versions.size() == 2)
@ -161,8 +161,8 @@ void getConfigForDevice(const char* dev)
{ {
// All iPod touch has small screen // All iPod touch has small screen
UserConfigParams::m_font_size = 5.0f; UserConfigParams::m_font_size = 5.0f;
UserConfigParams::m_multitouch_scale = 1.45f; UserConfigParams::m_multitouch_scale.setDefaultValue(1.45f);
UserConfigParams::m_multitouch_sensitivity_x = 0.1f; UserConfigParams::m_multitouch_sensitivity_x.setDefaultValue(0.1f);
device.erase(0, 4); device.erase(0, 4);
auto versions = StringUtils::splitToUInt(device, ','); auto versions = StringUtils::splitToUInt(device, ',');
if (versions.size() == 2) if (versions.size() == 2)

View File

@ -162,35 +162,8 @@ GUIEngine::EventPropagation MultitouchSettingsDialog::processEvent(
UserConfigParams::m_multitouch_deadzone.revertToDefaults(); UserConfigParams::m_multitouch_deadzone.revertToDefaults();
UserConfigParams::m_multitouch_inverted.revertToDefaults(); UserConfigParams::m_multitouch_inverted.revertToDefaults();
UserConfigParams::m_multitouch_controls.revertToDefaults(); UserConfigParams::m_multitouch_controls.revertToDefaults();
#ifdef ANDROID
int32_t screen_size = AConfiguration_getScreenSize(
global_android_app->config);
switch (screen_size)
{
case ACONFIGURATION_SCREENSIZE_SMALL:
case ACONFIGURATION_SCREENSIZE_NORMAL:
UserConfigParams::m_multitouch_scale = 1.3f;
UserConfigParams::m_multitouch_sensitivity_x = 0.1f;
break;
case ACONFIGURATION_SCREENSIZE_LARGE:
UserConfigParams::m_multitouch_scale = 1.2f;
UserConfigParams::m_multitouch_sensitivity_x = 0.15f;
break;
case ACONFIGURATION_SCREENSIZE_XLARGE:
UserConfigParams::m_multitouch_scale = 1.1f;
UserConfigParams::m_multitouch_sensitivity_x = 0.2f;
break;
default:
UserConfigParams::m_multitouch_scale.revertToDefaults();
UserConfigParams::m_multitouch_sensitivity_x.revertToDefaults();
break;
}
#else
UserConfigParams::m_multitouch_scale.revertToDefaults(); UserConfigParams::m_multitouch_scale.revertToDefaults();
UserConfigParams::m_multitouch_sensitivity_x.revertToDefaults(); UserConfigParams::m_multitouch_sensitivity_x.revertToDefaults();
#endif
if (StateManager::get()->getGameState() != GUIEngine::INGAME_MENU) if (StateManager::get()->getGameState() != GUIEngine::INGAME_MENU)
{ {