Index: binaries/data/mods/mod/gui/common/modern/sprites.xml
===================================================================
--- binaries/data/mods/mod/gui/common/modern/sprites.xml (revision 19024)
+++ binaries/data/mods/mod/gui/common/modern/sprites.xml (working copy)
@@ -822,4 +822,16 @@
texture_size="0 0 24 24"
/>
+
+
+
+
+
+
Index: binaries/data/mods/mod/gui/gui.rnc
===================================================================
--- binaries/data/mods/mod/gui/gui.rnc (revision 19024)
+++ binaries/data/mods/mod/gui/gui.rnc (working copy)
@@ -107,6 +107,7 @@
attribute text_valign { valign }?&
attribute tooltip { text }?&
attribute tooltip_style { text }?
+ attribute width { xsd:decimal }?
##
# Objects #
Index: binaries/data/mods/mod/gui/gui.rng
===================================================================
--- binaries/data/mods/mod/gui/gui.rng (revision 19024)
+++ binaries/data/mods/mod/gui/gui.rng (working copy)
@@ -413,6 +413,11 @@
+
+
+
+
+
Index: binaries/data/mods/public/gui/options/options.js
===================================================================
--- binaries/data/mods/public/gui/options/options.js (revision 19024)
+++ binaries/data/mods/public/gui/options/options.js (working copy)
@@ -131,8 +131,55 @@
control.checked = checked;
control.onPress = onUpdate;
break;
+ case "slider":
+ control = Engine.GetGUIObjectByName(category + "Slider[" + i + "]");
+ let value;
+ let callbackFunction;
+ let minvalue;
+ let maxvalue;
+
+ for (let param of Object.keys(option.parameters))
+ {
+ switch (param)
+ {
+ case "config":
+ value = +Engine.ConfigDB_GetValue("user", key);
+ break;
+ case "function":
+ if (Engine[option.parameters.function])
+ callbackFunction = option.parameters.function;
+ break;
+ case "min":
+ minvalue = +option.parameters.min;
+ break;
+ case "max":
+ maxvalue = +option.parameters.max;
+ break;
+ default:
+ warn("Unknown option source type '" + param + "'");
+ }
+ }
+
+ onUpdate = function(key, callbackFunction, minvalue, maxvalue)
+ {
+ return function()
+ {
+ if (Engine.ConfigDB_GetValue("user", key) === this.value)
+ return;
+ Engine.ConfigDB_CreateValue("user", key, this.value);
+ Engine.ConfigDB_SetChanges("user", true);
+ if (callbackFunction)
+ Engine[callbackFunction](+this.value);
+ updateOptionPanel();
+ };
+ }(key, callbackFunction, minvalue, maxvalue);
+
+ control.value = value;
+ control.max_value = maxvalue;
+ control.min_value = minvalue;
+ control.onValueChange = onUpdate;
+ break;
case "number":
- // TODO: Slider
case "string":
control = Engine.GetGUIObjectByName(category + "Input[" + i + "]");
let caption;
@@ -310,7 +357,7 @@
// and the possible function calls (which are of number or string types)
if (control.parameters.function)
{
- if (control.type !== "string" && control.type !== "number")
+ if (control.type !== "string" && control.type !== "number" && control.type !== "slider")
{
warn("Invalid type option " + control.type + " defined with function for " + item + ": will not be reverted");
continue;
Index: binaries/data/mods/public/gui/options/options.json
===================================================================
--- binaries/data/mods/public/gui/options/options.json (revision 19024)
+++ binaries/data/mods/public/gui/options/options.json (working copy)
@@ -208,34 +208,34 @@
"soundSetting":
[
{
- "type": "number",
+ "type": "slider",
"label": "Master Gain",
"tooltip": "Master audio gain",
- "parameters": { "config": "sound.mastergain", "function": "SetMasterGain", "min": "0" }
+ "parameters": { "config": "sound.mastergain", "function": "SetMasterGain", "min": 0.0, "max": 10.0 }
},
{
- "type": "number",
+ "type": "slider",
"label": "Music Gain",
"tooltip": "In game music gain",
- "parameters": { "config": "sound.musicgain", "function": "SetMusicGain", "min": "0" }
+ "parameters": { "config": "sound.musicgain", "function": "SetMusicGain", "min": 0.0, "max": 10.0 }
},
{
- "type": "number",
+ "type": "slider",
"label": "Ambient Gain",
"tooltip": "In game ambient sound gain",
- "parameters": { "config": "sound.ambientgain", "function": "SetAmbientGain", "min": "0" }
+ "parameters": { "config": "sound.ambientgain", "function": "SetAmbientGain", "min": 0.0, "max": 10.0 }
},
{
- "type": "number",
+ "type": "slider",
"label": "Action Gain",
"tooltip": "In game unit action sound gain",
- "parameters": { "config": "sound.actiongain", "function": "SetActionGain", "min": "0" }
+ "parameters": { "config": "sound.actiongain", "function": "SetActionGain", "min": 0.0, "max": 10.0 }
},
{
- "type": "number",
+ "type": "slider",
"label": "UI Gain",
"tooltip": "UI sound gain",
- "parameters": { "config": "sound.uigain", "function": "SetUIGain", "min": "0" }
+ "parameters": { "config": "sound.uigain", "function": "SetUIGain", "min": 0.0, "max": 10.0 }
},
{
"type": "boolean",
Index: binaries/data/mods/public/gui/options/options.xml
===================================================================
--- binaries/data/mods/public/gui/options/options.xml (revision 19024)
+++ binaries/data/mods/public/gui/options/options.xml (working copy)
@@ -51,7 +51,7 @@
Index: source/gui/CGUI.cpp
===================================================================
--- source/gui/CGUI.cpp (revision 19024)
+++ source/gui/CGUI.cpp (working copy)
@@ -33,6 +33,7 @@
#include "CProgressBar.h"
#include "CRadioButton.h"
#include "CText.h"
+#include "CSlider.h"
#include "CTooltip.h"
#include "MiniMap.h"
@@ -312,6 +313,7 @@
AddObjectType("olist", &COList::ConstructObject);
AddObjectType("dropdown", &CDropDown::ConstructObject);
AddObjectType("tooltip", &CTooltip::ConstructObject);
+ AddObjectType("slider", &CSlider::ConstructObject);
}
void CGUI::Draw()
Index: source/gui/CSlider.cpp
===================================================================
--- source/gui/CSlider.cpp (revision 0)
+++ source/gui/CSlider.cpp (working copy)
@@ -0,0 +1,142 @@
+/* Copyright (C) 2016 Wildfire Games.
+ * This file is part of 0 A.D.
+ *
+ * 0 A.D. is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 0 A.D. is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with 0 A.D. If not, see .
+ */
+
+#include "precompiled.h"
+#include "CSlider.h"
+#include "GUI.h"
+#include "lib/ogl.h"
+#include "ps/CLogger.h"
+
+
+CSlider::CSlider()
+ : m_IsPressed(false), m_ButtonSide(0)
+{
+ AddSetting(GUIST_float, "value");
+ AddSetting(GUIST_float, "min_value");
+ AddSetting(GUIST_float, "max_value");
+ AddSetting(GUIST_int, "cell_id");
+ AddSetting(GUIST_CGUISpriteInstance, "sprite");
+ AddSetting(GUIST_CGUISpriteInstance, "sprite_bar");
+ AddSetting(GUIST_float, "width");
+
+ GUI::GetSetting(this, "value", m_Value);
+ GUI::GetSetting(this, "min_value", m_MinValue);
+ GUI::GetSetting(this, "max_value", m_MaxValue);
+ GUI::GetSetting(this, "width", m_ButtonSide);
+ m_Value = Clamp(m_Value, m_MinValue, m_MaxValue);
+}
+
+CSlider::~CSlider()
+{
+}
+
+void CSlider::HandleMessage(SGUIMessage& Message)
+{
+ switch (Message.type)
+ {
+ case GUIM_SETTINGS_UPDATED:
+ {
+ GUI::GetSetting(this, "value", m_Value);
+ GUI::GetSetting(this, "min_value", m_MinValue);
+ GUI::GetSetting(this, "max_value", m_MaxValue);
+ GUI::GetSetting(this, "width", m_ButtonSide);
+ m_Value = Clamp(m_Value, m_MinValue, m_MaxValue);
+ break;
+ }
+ case GUIM_MOUSE_WHEEL_DOWN:
+ {
+ if (m_IsPressed)
+ break;
+ m_Value = std::max(m_Value - 0.01f, m_MinValue);
+ UpdateValue();
+ break;
+ }
+ case GUIM_MOUSE_WHEEL_UP:
+ {
+ if (m_IsPressed)
+ break;
+ m_Value = std::min(m_Value + 0.01f, m_MaxValue);
+ UpdateValue();
+ break;
+ }
+ case GUIM_MOUSE_PRESS_LEFT:
+ {
+ if (GetButtonRect().PointInside(GetMousePos()))
+ {
+ m_Mouse = GetMousePos();
+ m_IsPressed = true;
+ }
+ break;
+ }
+ case GUIM_MOUSE_RELEASE_LEFT:
+ {
+ m_IsPressed = false;
+ break;
+ }
+ case GUIM_MOUSE_MOTION:
+ {
+ if (!MouseOver())
+ m_IsPressed = false;
+ if (m_IsPressed)
+ {
+ float ratio = (m_MaxValue - m_MinValue) / (m_CachedActualSize.GetWidth() - m_ButtonSide);
+ float difference = float(GetMousePos().x - m_Mouse.x) * ratio;
+ m_Mouse = GetMousePos();
+ m_Value = Clamp(m_Value + difference, m_MinValue, m_MaxValue);
+ UpdateValue();
+ }
+ break;
+ }
+ default:
+ break;
+ }
+}
+
+void CSlider::Draw()
+{
+ float bz = GetBufferedZ();
+
+ if (!GetGUI())
+ return;
+
+ CGUISpriteInstance* sprite;
+ CGUISpriteInstance* sprite_button;
+ int cell_id;
+ GUI::GetSettingPointer(this, "sprite_bar", sprite);
+ GUI::GetSettingPointer(this, "sprite", sprite_button);
+ GUI::GetSetting(this, "cell_id", cell_id);
+
+ CRect slider_line(m_CachedActualSize);
+ slider_line.left += m_ButtonSide / 2.0f;
+ slider_line.right -= m_ButtonSide / 2.0f;
+ GetGUI()->DrawSprite(*sprite, cell_id, bz, slider_line);
+ GetGUI()->DrawSprite(*sprite_button, cell_id, bz, GetButtonRect());
+}
+
+void CSlider::UpdateValue()
+{
+ GUI::SetSetting(this, "value", m_Value);
+ ScriptEvent("valuechange");
+}
+
+CRect CSlider::GetButtonRect()
+{
+ 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);
+}
Index: source/gui/CSlider.h
===================================================================
--- source/gui/CSlider.h (revision 0)
+++ source/gui/CSlider.h (working copy)
@@ -0,0 +1,65 @@
+/* Copyright (C) 2016 Wildfire Games.
+ * This file is part of 0 A.D.
+ *
+ * 0 A.D. is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 0 A.D. is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with 0 A.D. If not, see .
+ */
+
+#ifndef INCLUDED_CSLIDER
+#define INCLUDED_CSLIDER
+
+#include "GUI.h"
+
+/**
+ * Slider control.
+ *
+ * @see IGUIObject
+ */
+class CSlider : public IGUIObject
+{
+ GUI_OBJECT(CSlider)
+
+public:
+ CSlider();
+ virtual ~CSlider();
+
+protected:
+
+ /**
+ * @see IGUIObject#HandleMessage()
+ */
+ virtual void HandleMessage(SGUIMessage& Message);
+
+ /**
+ * Draws the Slider
+ */
+ virtual void Draw();
+
+ /**
+ * Change settings and send the script event
+ */
+ void UpdateValue();
+
+ CRect GetButtonRect();
+
+ float m_MinValue, m_MaxValue, m_Value;
+
+private:
+ bool m_IsPressed;
+
+ CPos m_Mouse;
+
+ float m_ButtonSide;
+};
+
+#endif // INCLUDED_CSLIDER