Index: binaries/data/mods/mod/gui/gui.rnc
===================================================================
--- binaries/data/mods/mod/gui/gui.rnc
+++ binaries/data/mods/mod/gui/gui.rnc
@@ -103,6 +103,7 @@
attribute sprite2_pressed { text }?&
attribute sprite_selectarea { text }?&
attribute square_side { xsd:decimal }?&
+ attribute step_width { xsd:decimal }?&
attribute textcolor { ccolor }?&
attribute textcolor_disabled { ccolor }?&
attribute textcolor_over { ccolor }?&
Index: binaries/data/mods/mod/gui/gui.rng
===================================================================
--- binaries/data/mods/mod/gui/gui.rng
+++ binaries/data/mods/mod/gui/gui.rng
@@ -410,6 +410,11 @@
+
+
+
+
+
Index: binaries/data/mods/public/gui/common/gamedescription.js
===================================================================
--- binaries/data/mods/public/gui/common/gamedescription.js
+++ binaries/data/mods/public/gui/common/gamedescription.js
@@ -196,31 +196,25 @@
let title = translateVictoryCondition(victoryCondition.Name);
if (victoryCondition.Name == "wonder")
- {
- let wonderDuration = Math.round(g_GameAttributes.settings.WonderDuration);
title = sprintf(
translatePluralWithContext(
"victory condition",
"Wonder (%(min)s minute)",
"Wonder (%(min)s minutes)",
- wonderDuration
+ g_GameAttributes.settings.WonderDuration
),
- { "min": wonderDuration });
- }
+ { "min": g_GameAttributes.settings.WonderDuration });
let isCaptureTheRelic = victoryCondition.Name == "capture_the_relic";
if (isCaptureTheRelic)
- {
- let relicDuration = Math.round(g_GameAttributes.settings.RelicDuration);
title = sprintf(
translatePluralWithContext(
"victory condition",
"Capture the Relic (%(min)s minute)",
"Capture the Relic (%(min)s minutes)",
- relicDuration
+ g_GameAttributes.settings.RelicDuration
),
- { "min": relicDuration });
- }
+ { "min": g_GameAttributes.settings.RelicDuration });
titles.push({
"label": title,
@@ -230,7 +224,7 @@
if (isCaptureTheRelic)
titles.push({
"label": translate("Relic Count"),
- "value": Math.round(g_GameAttributes.settings.RelicCount)
+ "value": g_GameAttributes.settings.RelicCount
});
if (victoryCondition.Name == "regicide")
@@ -275,17 +269,16 @@
"value": translate("If one player wins, his or her allies win too. If one group of allies remains, they win.")
});
- let ceasefire = Math.round(g_GameAttributes.settings.Ceasefire);
titles.push({
"label": translate("Ceasefire"),
"value":
- ceasefire == 0 ?
+ g_GameAttributes.settings.Ceasefire == 0 ?
translate("disabled") :
sprintf(translatePlural(
"For the first minute, other players will stay neutral.",
"For the first %(min)s minutes, other players will stay neutral.",
- ceasefire),
- { "min": ceasefire })
+ g_GameAttributes.settings.Ceasefire),
+ { "min": g_GameAttributes.settings.Ceasefire })
});
if (g_GameAttributes.map == "random")
Index: binaries/data/mods/public/gui/gamesetup/Pages/GameSetupPage/GameSettings/GameSettingControlSlider.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/Pages/GameSetupPage/GameSettings/GameSettingControlSlider.js
+++ binaries/data/mods/public/gui/gamesetup/Pages/GameSetupPage/GameSettings/GameSettingControlSlider.js
@@ -19,6 +19,8 @@
if (this.MaxValue !== undefined)
this.slider.max_value = this.MaxValue;
+
+ this.slider.step_size = this.StepSize;
}
setControl(gameSettingControlManager)
@@ -60,8 +62,11 @@
onValueChangeSuper()
{
- if (!this.isInGuiUpdate)
- this.onValueChange(this.slider.value);
+ if (this.isInGuiUpdate)
+ return;
+
+ let potency = Math.pow(10, this.DecimalPlaces);
+ this.onValueChange(Math.round(this.slider.value * potency) / potency);
}
onPress()
@@ -75,5 +80,6 @@
}
}
-GameSettingControlSlider.prototype.UnknownValue =
- translateWithContext("settings value", "Unknown");
+GameSettingControlSlider.prototype.StepSize = 1;
+
+GameSettingControlSlider.prototype.DecimalPlaces = 0;
Index: binaries/data/mods/public/gui/gamesetup/Pages/GameSetupPage/GameSettings/Single/Sliders/Ceasefire.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/Pages/GameSetupPage/GameSettings/Single/Sliders/Ceasefire.js
+++ binaries/data/mods/public/gui/gamesetup/Pages/GameSetupPage/GameSettings/Single/Sliders/Ceasefire.js
@@ -34,11 +34,10 @@
onGameAttributesBatchChange()
{
- let value = Math.round(g_GameAttributes.settings.Ceasefire);
+ let value = g_GameAttributes.settings.Ceasefire;
this.sprintfValue.minutes = value;
-
this.setSelectedValue(
- g_GameAttributes.settings.Ceasefire,
+ value,
value == 0 ?
this.NoCeasefireCaption :
sprintf(this.CeasefireCaption(value), this.sprintfValue));
@@ -50,11 +49,6 @@
this.gameSettingsControl.updateGameAttributes();
this.gameSettingsControl.setNetworkGameAttributes();
}
-
- onGameAttributesFinalize()
- {
- g_GameAttributes.settings.Ceasefire = Math.round(g_GameAttributes.settings.Ceasefire);
- }
};
GameSettingControls.Ceasefire.prototype.TitleCaption =
Index: binaries/data/mods/public/gui/gamesetup/Pages/GameSetupPage/GameSettings/Single/Sliders/RelicCount.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/Pages/GameSetupPage/GameSettings/Single/Sliders/RelicCount.js
+++ binaries/data/mods/public/gui/gamesetup/Pages/GameSetupPage/GameSettings/Single/Sliders/RelicCount.js
@@ -60,10 +60,10 @@
if (this.available)
{
- let value = Math.round(g_GameAttributes.settings.RelicCount);
+ let value = g_GameAttributes.settings.RelicCount;
this.sprintfValue.number = value;
this.setSelectedValue(
- g_GameAttributes.settings.RelicCount,
+ value,
value == 0 ? this.InstantVictory : sprintf(this.CaptionRelicCount(value), this.sprintfValue));
}
}
@@ -74,12 +74,6 @@
this.gameSettingsControl.updateGameAttributes();
this.gameSettingsControl.setNetworkGameAttributes();
}
-
- onGameAttributesFinalize()
- {
- if (this.available)
- g_GameAttributes.settings.RelicCount = Math.round(g_GameAttributes.settings.RelicCount);
- }
};
GameSettingControls.RelicCount.prototype.TitleCaption =
Index: binaries/data/mods/public/gui/gamesetup/Pages/GameSetupPage/GameSettings/Single/Sliders/RelicDuration.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/Pages/GameSetupPage/GameSettings/Single/Sliders/RelicDuration.js
+++ binaries/data/mods/public/gui/gamesetup/Pages/GameSetupPage/GameSettings/Single/Sliders/RelicDuration.js
@@ -60,10 +60,10 @@
if (this.available)
{
- let value = Math.round(g_GameAttributes.settings.RelicDuration);
+ let value = g_GameAttributes.settings.RelicDuration;
this.sprintfValue.min = value;
this.setSelectedValue(
- g_GameAttributes.settings.RelicDuration,
+ value,
value == 0 ? this.InstantVictory : sprintf(this.CaptionVictoryTime(value), this.sprintfValue));
}
}
@@ -74,12 +74,6 @@
this.gameSettingsControl.updateGameAttributes();
this.gameSettingsControl.setNetworkGameAttributes();
}
-
- onGameAttributesFinalize()
- {
- if (this.available)
- g_GameAttributes.settings.RelicDuration = Math.round(g_GameAttributes.settings.RelicDuration);
- }
};
GameSettingControls.RelicDuration.prototype.TitleCaption =
Index: binaries/data/mods/public/gui/gamesetup/Pages/GameSetupPage/GameSettings/Single/Sliders/SeaLevelRiseTime.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/Pages/GameSetupPage/GameSettings/Single/Sliders/SeaLevelRiseTime.js
+++ binaries/data/mods/public/gui/gamesetup/Pages/GameSetupPage/GameSettings/Single/Sliders/SeaLevelRiseTime.js
@@ -47,11 +47,10 @@
if (!this.values)
return;
- let value = Math.round(g_GameAttributes.settings.SeaLevelRiseTime);
+ let value = g_GameAttributes.settings.SeaLevelRiseTime;
this.sprintfValue.minutes = value;
-
this.setSelectedValue(
- g_GameAttributes.settings.SeaLevelRiseTime,
+ value,
sprintf(this.SeaLevelRiseTimeCaption(value), this.sprintfValue));
}
@@ -61,12 +60,6 @@
this.gameSettingsControl.updateGameAttributes();
this.gameSettingsControl.setNetworkGameAttributes();
}
-
- onGameAttributesFinalize()
- {
- if (this.values)
- g_GameAttributes.settings.SeaLevelRiseTime = Math.round(g_GameAttributes.settings.SeaLevelRiseTime);
- }
};
GameSettingControls.SeaLevelRiseTime.prototype.TitleCaption =
Index: binaries/data/mods/public/gui/options/options.js
===================================================================
--- binaries/data/mods/public/gui/options/options.js
+++ binaries/data/mods/public/gui/options/options.js
@@ -151,19 +151,27 @@
"configToValue": value => +value,
"valueToGui": (value, control) => {
control.value = +value;
+ control.children[0].caption = value;
+ },
+ "guiToValue": (control, option) => {
+ let potency = Math.pow(10, option.decimal_places || 0);
+ return Math.round(control.value * potency) / potency;
},
- "guiToValue": control => control.value,
"guiSetter": "onValueChange",
"initGUI": (option, control) => {
- control.max_value = option.max;
control.min_value = option.min;
+ control.max_value = option.max;
+ control.step_size = option.step_size || 1;
},
"tooltip": (value, option) =>
sprintf(translateWithContext("slider number", "Value: %(val)s (min: %(min)s, max: %(max)s)"), {
- "val": value.toFixed(2),
- "min": option.min.toFixed(2),
- "max": option.max.toFixed(2)
- })
+ "val": value,
+ "min": option.min,
+ "max": option.max
+ }),
+ "onGUISet": (value, control, option) => {
+ control.children[0].caption = value;
+ }
}
};
@@ -236,11 +244,14 @@
control[optionType.guiSetter] = function() {
- let value = optionType.guiToValue(control);
+ let value = optionType.guiToValue(control, option);
if (optionType.sanitizeValue)
optionType.sanitizeValue(value, control, option);
+ if (optionType.onGUISet)
+ optionType.onGUISet(value, control, option);
+
control.tooltip = option.tooltip + (optionType.tooltip ? "\n" + optionType.tooltip(value, option) : "");
Engine.ConfigDB_CreateValue("user", option.config, String(value));
Index: binaries/data/mods/public/gui/options/options.json
===================================================================
--- binaries/data/mods/public/gui/options/options.json
+++ binaries/data/mods/public/gui/options/options.json
@@ -69,7 +69,7 @@
]
},
{
- "type": "number",
+ "type": "slider",
"label": "Observer limit",
"tooltip": "Prevent further observers from joining if the limit is reached.",
"config": "network.observerlimit",
@@ -265,7 +265,9 @@
"config": "sound.mastergain",
"function": "SetMasterGain",
"min": 0,
- "max": 2
+ "max": 2,
+ "step_size": 0.01,
+ "decimal_places": 2
},
{
"type": "slider",
@@ -274,7 +276,9 @@
"config": "sound.musicgain",
"function": "SetMusicGain",
"min": 0,
- "max": 2
+ "max": 2,
+ "step_size": 0.01,
+ "decimal_places": 2
},
{
"type": "slider",
@@ -283,7 +287,9 @@
"config": "sound.ambientgain",
"function": "SetAmbientGain",
"min": 0,
- "max": 2
+ "max": 2,
+ "step_size": 0.01,
+ "decimal_places": 2
},
{
"type": "slider",
@@ -292,7 +298,9 @@
"config": "sound.actiongain",
"function": "SetActionGain",
"min": 0,
- "max": 2
+ "max": 2,
+ "step_size": 0.01,
+ "decimal_places": 2
},
{
"type": "slider",
@@ -301,7 +309,9 @@
"config": "sound.uigain",
"function": "SetUIGain",
"min": 0,
- "max": 2
+ "max": 2,
+ "step_size": 0.01,
+ "decimal_places": 2
},
{
"type": "boolean",
@@ -430,7 +440,7 @@
"max": 100
},
{
- "type": "number",
+ "type": "slider",
"label": "Batch training size",
"tooltip": "Number of units trained per batch by default.",
"config": "gui.session.batchtrainingsize",
@@ -443,7 +453,9 @@
"tooltip": "Number of times you have to scroll to increase/decrease the batchsize by 1.",
"config": "gui.session.scrollbatchratio",
"min": 0.1,
- "max": 30
+ "max": 30,
+ "step_size": 0.1,
+ "decimal_places": 2
},
{
"type": "boolean",
Index: binaries/data/mods/public/gui/options/options.xml
===================================================================
--- binaries/data/mods/public/gui/options/options.xml
+++ binaries/data/mods/public/gui/options/options.xml
@@ -26,14 +26,16 @@
Index: source/gui/ObjectTypes/CSlider.h
===================================================================
--- source/gui/ObjectTypes/CSlider.h
+++ source/gui/ObjectTypes/CSlider.h
@@ -48,28 +48,19 @@
/**
* Change settings and send the script event
*/
- void UpdateValue();
+ void UpdateValue(const float value);
CRect GetButtonRect() const;
- /**
- * @return ratio between the value of the slider and its actual size in the GUI
- */
- float GetSliderRatio() const;
-
- void IncrementallyChangeValue(const float value);
-
// Settings
- float m_ButtonSide;
+ float m_ButtonWidth;
i32 m_CellID;
float m_MinValue;
float m_MaxValue;
CGUISpriteInstance m_Sprite;
CGUISpriteInstance m_SpriteBar;
+ float m_StepSize;
float m_Value;
-
-private:
- CPos m_Mouse;
};
#endif // INCLUDED_CSLIDER
Index: source/gui/ObjectTypes/CSlider.cpp
===================================================================
--- source/gui/ObjectTypes/CSlider.cpp
+++ source/gui/ObjectTypes/CSlider.cpp
@@ -21,24 +21,29 @@
#include "gui/CGUI.h"
#include "maths/MathUtil.h"
+#include "ps/CLogger.h"
+
+#include
const CStr CSlider::EventNameValueChange = "ValueChange";
CSlider::CSlider(CGUI& pGUI)
: IGUIObject(pGUI),
IGUIButtonBehavior(*static_cast(this)),
- m_ButtonSide(),
+ m_ButtonWidth(),
m_CellID(),
m_MaxValue(),
m_MinValue(),
+ m_StepSize(1.0f),
m_Sprite(),
m_SpriteBar(),
m_Value()
{
- RegisterSetting("button_width", m_ButtonSide);
+ RegisterSetting("button_width", m_ButtonWidth);
RegisterSetting("cell_id", m_CellID);
RegisterSetting("max_value", m_MaxValue);
RegisterSetting("min_value", m_MinValue);
+ RegisterSetting("step_size", m_StepSize);
RegisterSetting("sprite", m_Sprite);
RegisterSetting("sprite_bar", m_SpriteBar);
RegisterSetting("value", m_Value);
@@ -56,17 +61,6 @@
IGUIButtonBehavior::ResetStates();
}
-float CSlider::GetSliderRatio() const
-{
- return (m_MaxValue - m_MinValue) / (m_CachedActualSize.GetWidth() - m_ButtonSide);
-}
-
-void CSlider::IncrementallyChangeValue(const float difference)
-{
- m_Value = Clamp(m_Value + difference, m_MinValue, m_MaxValue);
- UpdateValue();
-}
-
void CSlider::HandleMessage(SGUIMessage& Message)
{
IGUIObject::HandleMessage(Message);
@@ -76,21 +70,25 @@
{
case GUIM_SETTINGS_UPDATED:
{
+ if (Message.value == "step_size" && m_StepSize <= 0)
+ {
+ LOGERROR("Slider \"%s\" step_size must be positive!", GetPresentableName().c_str());
+ m_StepSize = 1.0f;
+ }
+
m_Value = Clamp(m_Value, m_MinValue, m_MaxValue);
break;
}
case GUIM_MOUSE_WHEEL_DOWN:
{
- if (m_Pressed)
- break;
- IncrementallyChangeValue(-0.01f);
+ if (!m_Pressed)
+ UpdateValue(m_Value - m_StepSize);
break;
}
case GUIM_MOUSE_WHEEL_UP:
{
- if (m_Pressed)
- break;
- IncrementallyChangeValue(0.01f);
+ if (!m_Pressed)
+ UpdateValue(m_Value + m_StepSize);
break;
}
case GUIM_MOUSE_PRESS_LEFT:
@@ -99,8 +97,9 @@
{
if (m_Pressed)
{
- m_Mouse = m_pGUI.GetMousePos();
- IncrementallyChangeValue((m_Mouse.x - GetButtonRect().CenterPoint().x) * GetSliderRatio());
+ const float valuePerPixel = (m_MaxValue - m_MinValue) / (m_CachedActualSize.GetWidth() - m_ButtonWidth);
+ const float pixelOffset = m_pGUI.GetMousePos().x - m_CachedActualSize.left - m_ButtonWidth / 2.0f;
+ UpdateValue(pixelOffset * valuePerPixel + m_MinValue);
}
break;
}
@@ -112,23 +111,32 @@
void CSlider::Draw()
{
CRect slider_line(m_CachedActualSize);
- slider_line.left += m_ButtonSide / 2.0f;
- slider_line.right -= m_ButtonSide / 2.0f;
+ slider_line.left += m_ButtonWidth / 2.0f;
+ slider_line.right -= m_ButtonWidth / 2.0f;
float bz = GetBufferedZ();
m_pGUI.DrawSprite(m_SpriteBar, m_CellID, bz, slider_line);
m_pGUI.DrawSprite(m_Sprite, m_CellID, bz, GetButtonRect());
}
-void CSlider::UpdateValue()
+void CSlider::UpdateValue(const float value)
{
- SetSetting("value", m_Value, true);
+ if (m_StepSize <= 0)
+ return;
+
+ const float valueStep = std::round((value - m_MinValue) / m_StepSize) * m_StepSize + m_MinValue;
+ const float valueClamped = Clamp(valueStep, m_MinValue, m_MaxValue);
+
+ if (valueClamped == m_Value)
+ return;
+
+ SetSetting("value", valueClamped, true);
ScriptEvent(EventNameValueChange);
}
CRect CSlider::GetButtonRect() const
{
- float ratio = m_MaxValue > m_MinValue ? (m_Value - m_MinValue) / (m_MaxValue - m_MinValue) : 0.0f;
- float x = m_CachedActualSize.left + ratio * (m_CachedActualSize.GetWidth() - m_ButtonSide);
- float y = m_CachedActualSize.top + (m_CachedActualSize.GetHeight() - m_ButtonSide) / 2.0;
- return CRect(x, y, x + m_ButtonSide, y + m_ButtonSide);
+ const float ratio = m_MaxValue > m_MinValue ? (m_Value - m_MinValue) / (m_MaxValue - m_MinValue) : 0.0f;
+ const float x = m_CachedActualSize.left + ratio * (m_CachedActualSize.GetWidth() - m_ButtonWidth);
+ const float y = m_CachedActualSize.top + (m_CachedActualSize.GetHeight() - m_ButtonWidth) / 2.0f;
+ return CRect(x, y, x + m_ButtonWidth, y + m_ButtonWidth);
}