Skip to content

Commit

Permalink
Placeholder options screen
Browse files Browse the repository at this point in the history
  • Loading branch information
SupSuper committed Mar 17, 2019
1 parent e351651 commit 7cb225b
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 110 deletions.
83 changes: 35 additions & 48 deletions data/forms/options.form
Original file line number Diff line number Diff line change
Expand Up @@ -3,60 +3,47 @@
<form id="FORM_OPTIONSMENU">
<style minwidth="640" minheight="480">
<position x="centre" y="centre"/>
<size width="644" height="484"/>
<backcolour r="80" g="80" b="80"/>
<size width="640" height="480"/>
<graphic>
<imagex>TESTBACKGROUND</imagex>
<image>xcom3/ufodata/message.pcx</image>
<position x="2" y="2"/>
<position x="0" y="0"/>
<size width="640" height="480"/>
<scroll id="SCROLL_LISTPOSITION">
<position x="558" y="85"/>
<size width="16" height="350"/>
</scroll>
<listbox id="LISTBOX_OPTIONS" scrollbarid="SCROLL_LISTPOSITION">
<position x="23" y="68"/>
<size width="526" height="381"/>
<textbutton id="BUTTON_TEST_XCOMBASE" text="Tets XCom Base Screen">
<position x="right" y="bottom"/>
<size width="44" height="32"/>
<font>smalfont</font>
</textbutton>
<textbutton id="BUTTON_DEBUGGING" text="Debug Menu">
<position x="right" y="bottom"/>
<size width="44" height="32"/>
<font>smalfont</font>
</textbutton>
</listbox>
</graphic>
<graphicbutton id="BUTTON_QUIT">
<position x="604" y="446"/>
<size width="35" height="34"/>
<label text="OPTIONS">
<position x="113" y="0"/>
<size width="420" height="32"/>
<alignment horizontal="centre" vertical="centre"/>
<font>bigfont</font>
</label>
<scroll id="LISTBOX_SCROLL">
<position x="553" y="82"/>
<size width="26" height="356"/>
</scroll>
<listbox id="LISTBOX_OPTIONS" scrollbarid="LISTBOX_SCROLL">
<position x="28" y="74"/>
<size width="510" height="375"/>
<item size="21" spacing="4"/>
</listbox>
<graphicbutton id="LISTBOX_SCROLL_UP" scrollprev="LISTBOX_SCROLL">
<tooltip text="Scroll Up" font="smallset"/>
<position x="555" y="58"/>
<size width="22" height="21"/>
<image/>
<!-- FIXME: PAL_01 doesn't seem correct for all newbut.tab images? -->
<imagedepressed>pck:xcom3/ufodata/newbut.pck:xcom3/ufodata/newbut.tab:5:xcom3/ufodata/pal_01.dat</imagedepressed>
<imagedepressed>BUTTON_SCROLL_UP_DEPRESSED</imagedepressed>
</graphicbutton>
<graphicbutton id="LISTBOX_SCROLL_DOWN" scrollnext="LISTBOX_SCROLL">
<tooltip text="Scroll Down" font="smallset"/>
<position x="555" y="441"/>
<size width="22" height="21"/>
<image/>
<imagedepressed>BUTTON_SCROLL_DOWN_DEPRESSED</imagedepressed>
</graphicbutton>
<graphicbutton id="BUTTON_OK">
<position x="602" y="443"/>
<size width="40" height="40"/>
<image/>
<imagedepressed>BUTTON_OK_DEPRESSED</imagedepressed>
</graphicbutton>
<textedit id="TEXTEDIT_A">
<backcolour r="80" g="80" b="80" a="255"/>
<position x="0" y="bottom"/>
<size width="100" height="16"/>
<alignment horizontal="left" vertical="centre"/>
<font>smallset</font>
</textedit>
<textedit id="TEXTEDIT_B">
<backcolour r="80" g="80" b="80" a="255"/>
<position x="110" y="bottom"/>
<size width="100" height="16"/>
<alignment horizontal="left" vertical="centre"/>
<font>smallset</font>
</textedit>
<label id="LABEL_TESTXX" text="Vehicle Info">
<backcolour r="80" g="80" b="80" a="255"/>
<position x="right" y="top"/>
<size width="200" height="200"/>
<alignment horizontal="right" vertical="bottom"/>
<font>smalfont</font>
</label>
</style>
</form>
</openapoc>
78 changes: 46 additions & 32 deletions framework/configfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,27 @@ class ConfigFileImpl
for (auto &optPair : this->optionSections)
std::cout << optPair.second << "\n";
}

std::map<UString, std::vector<ConfigOption>> getOptions()
{
std::map<UString, std::vector<ConfigOption>> options;
for (auto &optPair : this->optionSections)
{
std::vector<ConfigOption> vec;
for (auto &opt : optPair.second.options())
{
std::string short_name = opt->long_name();
size_t dot = short_name.find_last_of('.');
if (dot != std::string::npos)
{
short_name = short_name.substr(dot + 1);
}
vec.emplace_back(ConfigOption(optPair.first, short_name, opt->description()));
}
options[optPair.first] = vec;
}
return options;
}
};

ConfigFile::ConfigFile() { this->pimpl.reset(new ConfigFileImpl()); }
Expand Down Expand Up @@ -432,66 +453,59 @@ bool ConfigFile::loaded() const { return this->pimpl->loaded(); }

void ConfigFile::showHelp() { this->pimpl->showHelp(); }

ConfigOptionString::ConfigOptionString(const UString section, const UString name,
const UString description, const UString defaultValue)
: section(section), name(name), description(description), defaultValue(defaultValue)
std::map<UString, std::vector<ConfigOption>> ConfigFile::getOptions()
{
config().addOptionString(section, name, "", description, defaultValue);
return this->pimpl->getOptions();
}

UString ConfigOptionString::get() const
ConfigOption::ConfigOption(const UString section, const UString name, const UString description)
: section(section), name(name), description(description)
{
}

UString ConfigOption::getKey() const
{
if (section.empty())
return config().getString(name);
return name;
else
return config().getString(section + "." + name);
return section + "." + name;
}

ConfigOptionString::ConfigOptionString(const UString section, const UString name,
const UString description, const UString defaultValue)
: ConfigOption(section, name, description), defaultValue(defaultValue)
{
config().addOptionString(section, name, "", description, defaultValue);
}

UString ConfigOptionString::get() const { return config().getString(getKey()); }

ConfigOptionInt::ConfigOptionInt(const UString section, const UString name,
const UString description, const int defaultValue)
: section(section), name(name), description(description), defaultValue(defaultValue)
: ConfigOption(section, name, description), defaultValue(defaultValue)
{
config().addOptionInt(section, name, "", description, defaultValue);
}

int ConfigOptionInt::get() const
{

if (section.empty())
return config().getInt(name);
else
return config().getInt(section + "." + name);
}
int ConfigOptionInt::get() const { return config().getInt(getKey()); }

ConfigOptionBool::ConfigOptionBool(const UString section, const UString name,
const UString description, const bool defaultValue)
: section(section), name(name), description(description), defaultValue(defaultValue)
: ConfigOption(section, name, description), defaultValue(defaultValue)
{
config().addOptionBool(section, name, "", description, defaultValue);
}

bool ConfigOptionBool::get() const
{
if (section.empty())
return config().getBool(name);
else

return config().getBool(section + "." + name);
}
bool ConfigOptionBool::get() const { return config().getBool(getKey()); }

ConfigOptionFloat::ConfigOptionFloat(const UString section, const UString name,
const UString description, const float defaultValue)
: ConfigOption(section, name, description), defaultValue(defaultValue)
{
config().addOptionFloat(section, name, "", description, defaultValue);
}

bool ConfigOptionFloat::get() const
{
if (section.empty())
return config().getFloat(name);
else
return config().getFloat(section + "." + name);
}
bool ConfigOptionFloat::get() const { return config().getFloat(getKey()); }

void validate(boost::any &v, const std::vector<std::string> &values, UString *, int)
{
Expand Down
33 changes: 20 additions & 13 deletions framework/configfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
#include "library/sp.h"
#include "library/strings.h"
#include <boost/any.hpp>
#include <map>
#include <vector>

namespace OpenApoc
{

class ConfigFileImpl;
class ConfigOption;

class ConfigFile
{
Expand Down Expand Up @@ -53,15 +56,28 @@ class ConfigFile
// invalid
void showHelp();

std::map<UString, std::vector<ConfigOption>> getOptions();

static ConfigFile &getInstance();
};

class ConfigOptionString
class ConfigOption
{
private:
UString section;
UString name;
UString description;

public:
ConfigOption(const UString section, const UString name, const UString description);
UString getName() const { return name; }
UString getDescription() const { return description; }
UString getKey() const;
};

class ConfigOptionString : public ConfigOption
{
private:
UString defaultValue;

public:
Expand All @@ -70,12 +86,9 @@ class ConfigOptionString
UString get() const;
};

class ConfigOptionInt
class ConfigOptionInt : public ConfigOption
{
private:
UString section;
UString name;
UString description;
int defaultValue;

public:
Expand All @@ -84,12 +97,9 @@ class ConfigOptionInt
int get() const;
};

class ConfigOptionBool
class ConfigOptionBool : public ConfigOption
{
private:
UString section;
UString name;
UString description;
bool defaultValue;

public:
Expand All @@ -98,12 +108,9 @@ class ConfigOptionBool
bool get() const;
};

class ConfigOptionFloat
class ConfigOptionFloat : public ConfigOption
{
private:
UString section;
UString name;
UString description;
float defaultValue;

public:
Expand Down
65 changes: 48 additions & 17 deletions game/ui/general/optionsmenu.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,62 @@
#include "game/ui/general/optionsmenu.h"
#include "forms/form.h"
#include "forms/label.h"
#include "forms/listbox.h"
#include "forms/textbutton.h"
#include "forms/textedit.h"
#include "forms/ui.h"
#include "framework/configfile.h"
#include "framework/event.h"
#include "framework/framework.h"
#include "framework/keycodes.h"
#include "game/ui/debugtools/debugmenu.h"

namespace OpenApoc
{

OptionsMenu::OptionsMenu() : Stage(), menuform(ui().getForm("options")) {}
OptionsMenu::OptionsMenu() : Stage(), menuform(ui().getForm("options"))
{
auto options = config().getOptions();
auto listbox = menuform->findControlTyped<ListBox>("LISTBOX_OPTIONS");
for (auto &section : options)
{
if (!section.first.empty())
{
listbox->addItem(mksp<TextButton>(section.first, ui().getFont("smalfont")));
for (auto &opt : section.second)
{
listbox->addItem(createOptionRow(opt));
}
}
}
}

OptionsMenu::~OptionsMenu() = default;

sp<Control> OptionsMenu::createOptionRow(const ConfigOption &option)
{
auto control = mksp<Control>();

const int HEIGHT = 21;

auto label = control->createChild<Label>(option.getName(), ui().getFont("smalfont"));
label->Location = {0, 0};
label->Size = {250, HEIGHT};
label->TextVAlign = VerticalAlignment::Centre;

/*
auto value = control->createChild<TextEdit>(config().getString(option.getKey()),
ui().getFont("smalfont"));
value->Location = {0, 0};
value->Size = {250, HEIGHT};
value->TextVAlign = VerticalAlignment::Centre;
*/

control->ToolTipText = option.getDescription();
control->ToolTipFont = ui().getFont("smallset");

return control;
}

void OptionsMenu::begin() {}

void OptionsMenu::pause() {}
Expand All @@ -36,16 +80,7 @@ void OptionsMenu::eventOccurred(Event *e)

if (e->type() == EVENT_FORM_INTERACTION && e->forms().EventFlag == FormEventType::ButtonClick)
{
if (e->forms().RaisedBy->Name == "BUTTON_TEST_XCOMBASE")
{
return;
}
if (e->forms().RaisedBy->Name == "BUTTON_DEBUGGING")
{
fw().stageQueueCommand({StageCmd::Command::PUSH, mksp<DebugMenu>()});
return;
}
if (e->forms().RaisedBy->Name == "BUTTON_QUIT")
if (e->forms().RaisedBy->Name == "BUTTON_OK")
{
fw().stageQueueCommand({StageCmd::Command::POP});
return;
Expand All @@ -55,11 +90,7 @@ void OptionsMenu::eventOccurred(Event *e)

void OptionsMenu::update() { menuform->update(); }

void OptionsMenu::render()
{
fw().stageGetPrevious(this->shared_from_this())->render();
menuform->render();
}
void OptionsMenu::render() { menuform->render(); }

bool OptionsMenu::isTransition() { return false; }

Expand Down
Loading

0 comments on commit 7cb225b

Please sign in to comment.