Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions msu/systems/mod_settings/elements/slider_setting.nut
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
::MSU.Class.SliderSetting <- class extends ::MSU.Class.RangeSetting
{
Values = null;
Labels = null;
static Type = "Slider";

constructor( _id, _value, _values, _labels = null, _name = null, _description = null )
{
if (_values.find(_value) == null)
{
::logError("SliderSetting: _value must be an element in _values");
throw ::MSU.Exception.KeyNotFound(_value);
}
if (_labels == null)
{
_labels = _values;
}
assert(_values.len() == _labels.len());

base.constructor(_id, _value, 0, _values.len() - 1, 1, _name, _description);
this.Values = _values;
this.Labels = _labels;
}

function getUIData( _flags = [] )
{
local ret = base.getUIData(_flags);
ret.values <- this.Values;
ret.labels <- this.Labels;
return ret;
}

function tostring()
{
local ret = base.tostring() + " | Values: \n";
foreach (value in this.Values)
{
ret += value + "\n";
}
ret += " | Labels: \n";
foreach (label in this.Labels)
{
ret += label + "\n";
}
return ret;
}

function flagDeserialize( _in )
{
base.flagDeserialize(_in);
if (this.Values.find(this.Value) == null)
{
::logError("Value \'" + this.Value + "\' not contained in array for setting " + this.getID() + " in mod " + this.getMod().getID());
this.reset();
}
}
}
5 changes: 5 additions & 0 deletions msu/systems/mod_settings/settings_page.nut
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@
return this.addElement(::MSU.Class.RangeSetting(_id, _value, _min, _max, _step, _name, _description));
}

function addSliderSetting( _id, _value, _values, _labels = null, _name = null, _description = null )
{
return this.addElement(::MSU.Class.SliderSetting(_id, _value, _values, _labels, _name, _description));
}

function addStringSetting( _id, _value, _name = null, _description = null )
{
return this.addElement(::MSU.Class.StringSetting(_id, _value, _name, _description));
Expand Down
28 changes: 28 additions & 0 deletions ui/mods/msu/mod_settings/slider_setting.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
var SliderSetting = function (_mod, _page, _setting, _parentDiv)
{
_setting.value = _setting.values.indexOf(_setting.value);
RangeSetting.call(this, _mod, _page, _setting, _parentDiv);
_setting.value = _setting.values[_setting.value];

// Only need to set it once
this.slider.attr({min: this.data.min, max: this.data.max, step: this.data.step});

this.layout.off("change");
this.layout.on("change", this.onChange.bind(this));
this.updateValue();
};
SliderSetting.prototype.__proto__ = RangeSetting.prototype;

SliderSetting.prototype.updateValue = function ()
{
var index = this.data.values.indexOf(this.data.value);
this.slider.val(index);
this.label.text('' + this.data.labels[index]);
};

SliderSetting.prototype.onChange = function ()
{
var index = parseInt(this.slider.val());
this.data.value = this.data.values[index];
this.label.text('' + this.data.labels[index]);
};