2013-06-19 01:12:30 +00:00
|
|
|
#include "GuiSettingsMenu.h"
|
|
|
|
#include "../Renderer.h"
|
|
|
|
#include "../Settings.h"
|
2013-06-19 21:02:42 +00:00
|
|
|
#include "../VolumeControl.h"
|
2013-06-19 01:12:30 +00:00
|
|
|
|
|
|
|
GuiSettingsMenu::GuiSettingsMenu(Window* window) : GuiComponent(window),
|
2013-08-07 05:41:55 +00:00
|
|
|
mList(window, Eigen::Vector2i(2, 4)),
|
2013-09-14 16:14:21 +00:00
|
|
|
mBox(mWindow, ":/frame.png", 0x444444FF),
|
2013-06-19 21:02:42 +00:00
|
|
|
mDrawFramerateSwitch(window),
|
|
|
|
mVolumeSlider(window, 0, 100, 1),
|
2013-08-07 05:41:55 +00:00
|
|
|
mDisableSoundsSwitch(window, false),
|
2013-06-19 21:02:42 +00:00
|
|
|
mSaveLabel(window)
|
2013-06-19 01:12:30 +00:00
|
|
|
{
|
2013-06-19 21:02:42 +00:00
|
|
|
loadStates();
|
|
|
|
|
2013-08-07 22:40:27 +00:00
|
|
|
addChild(&mBox);
|
2013-06-19 01:12:30 +00:00
|
|
|
addChild(&mList);
|
|
|
|
|
2013-07-10 11:29:43 +00:00
|
|
|
mList.setPosition(Renderer::getScreenWidth() / 4.0f, 0);
|
|
|
|
|
|
|
|
using namespace Eigen;
|
2013-06-19 01:12:30 +00:00
|
|
|
|
|
|
|
TextComponent* label = new TextComponent(mWindow);
|
|
|
|
label->setText("Draw Framerate: ");
|
|
|
|
label->setColor(0x0000FFFF);
|
2013-07-10 11:29:43 +00:00
|
|
|
mList.setEntry(Vector2i(0, 0), Vector2i(1, 1), label, false, ComponentListComponent::AlignRight, Matrix<bool, 1, 2>(true, true));
|
2013-06-19 01:12:30 +00:00
|
|
|
mLabels.push_back(label);
|
|
|
|
|
|
|
|
//drawFramerate switch
|
2013-07-10 11:29:43 +00:00
|
|
|
mList.setEntry(Vector2i(1, 0), Vector2i(1, 1), &mDrawFramerateSwitch, true, ComponentListComponent::AlignCenter, Matrix<bool, 1, 2>(true, true));
|
2013-06-19 01:12:30 +00:00
|
|
|
|
2013-08-07 05:41:55 +00:00
|
|
|
//volume label
|
2013-06-19 01:12:30 +00:00
|
|
|
label = new TextComponent(mWindow);
|
2013-06-19 21:02:42 +00:00
|
|
|
label->setText("System volume: ");
|
2013-06-19 01:12:30 +00:00
|
|
|
label->setColor(0x0000FFFF);
|
2013-08-07 05:41:55 +00:00
|
|
|
mLabels.push_back(label);
|
2013-07-10 11:29:43 +00:00
|
|
|
mList.setEntry(Vector2i(0, 1), Vector2i(1, 1), label, false, ComponentListComponent::AlignRight, Matrix<bool, 1, 2>(true, true));
|
2013-06-19 01:12:30 +00:00
|
|
|
|
|
|
|
//volume slider
|
2013-07-10 11:29:43 +00:00
|
|
|
mList.setEntry(Vector2i(1, 1), Vector2i(1, 1), &mVolumeSlider, true, ComponentListComponent::AlignCenter, Matrix<bool, 1, 2>(true, true));
|
2013-06-19 01:12:30 +00:00
|
|
|
|
2013-08-07 05:41:55 +00:00
|
|
|
//disable sounds
|
|
|
|
label = new TextComponent(mWindow);
|
|
|
|
label->setText("Disable sounds: ");
|
|
|
|
label->setColor(0x0000FFFF);
|
|
|
|
mLabels.push_back(label);
|
|
|
|
mList.setEntry(Vector2i(0, 2), Vector2i(1, 1), label, false, ComponentListComponent::AlignRight, Matrix<bool, 1, 2>(true, true));
|
|
|
|
|
|
|
|
mList.setEntry(Vector2i(1, 2), Vector2i(1, 1), &mDisableSoundsSwitch, true, ComponentListComponent::AlignCenter, Matrix<bool, 1, 2>(true, true));
|
|
|
|
|
|
|
|
|
2013-06-19 21:02:42 +00:00
|
|
|
//save label
|
|
|
|
mSaveLabel.setText("SAVE");
|
|
|
|
mSaveLabel.setColor(0x000000FF);
|
2013-08-07 05:41:55 +00:00
|
|
|
mList.setEntry(Vector2i(0, 3), Vector2i(2, 1), &mSaveLabel, true, ComponentListComponent::AlignCenter, Matrix<bool, 1, 2>(false, true));
|
2013-06-19 01:12:30 +00:00
|
|
|
|
2013-08-07 05:41:55 +00:00
|
|
|
//center list
|
2013-08-07 22:40:27 +00:00
|
|
|
mList.setPosition(Renderer::getScreenWidth() / 2 - mList.getSize().x() / 2, Renderer::getScreenHeight() / 2 - mList.getSize().y() / 2);
|
2013-08-18 14:16:11 +00:00
|
|
|
|
|
|
|
//set up borders/background
|
2013-09-14 16:14:21 +00:00
|
|
|
mBox.fitTo(mList.getSize(), mList.getPosition(), Eigen::Vector2f(8, 8));
|
2013-06-19 01:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GuiSettingsMenu::~GuiSettingsMenu()
|
|
|
|
{
|
|
|
|
for(auto iter = mLabels.begin(); iter != mLabels.end(); iter++)
|
|
|
|
{
|
|
|
|
delete *iter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GuiSettingsMenu::input(InputConfig* config, Input input)
|
|
|
|
{
|
|
|
|
//let our children (read: list) go first
|
|
|
|
if(GuiComponent::input(config, input))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if(config->isMappedTo("b", input) && input.value)
|
|
|
|
{
|
|
|
|
delete this;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-06-19 21:02:42 +00:00
|
|
|
if(config->isMappedTo("a", input) && mList.getSelectedComponent() == &mSaveLabel && input.value)
|
|
|
|
{
|
|
|
|
applyStates();
|
|
|
|
delete this;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-06-19 01:12:30 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GuiSettingsMenu::loadStates()
|
|
|
|
{
|
|
|
|
Settings* s = Settings::getInstance();
|
|
|
|
mDrawFramerateSwitch.setState(s->getBool("DRAWFRAMERATE"));
|
2013-06-19 21:02:42 +00:00
|
|
|
|
|
|
|
mVolumeSlider.setValue((float)VolumeControl::getInstance()->getVolume());
|
2013-08-07 05:41:55 +00:00
|
|
|
|
|
|
|
mDisableSoundsSwitch.setState(s->getBool("DISABLESOUNDS"));
|
2013-06-19 21:02:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GuiSettingsMenu::applyStates()
|
|
|
|
{
|
|
|
|
Settings* s = Settings::getInstance();
|
|
|
|
s->setBool("DRAWFRAMERATE", mDrawFramerateSwitch.getState());
|
|
|
|
|
|
|
|
VolumeControl::getInstance()->setVolume((int)mVolumeSlider.getValue());
|
|
|
|
|
2013-08-07 05:41:55 +00:00
|
|
|
s->setBool("DISABLESOUNDS", mDisableSoundsSwitch.getState());
|
|
|
|
|
2013-06-19 21:02:42 +00:00
|
|
|
s->saveFile();
|
2013-06-19 01:12:30 +00:00
|
|
|
}
|