Jeck - Resolved issue 44 and issue 45.

* Options can now use specialized loading functions. OptionEnum should work now.
 * Options are now stored in memory as a map<integer,GameOption>.
This commit is contained in:
wagic.jeck
2009-09-23 00:24:43 +00:00
parent 433897bf38
commit e577f3e378
10 changed files with 650 additions and 244 deletions
+45 -45
View File
@@ -1,46 +1,46 @@
#ifndef _CREDITS_H_
#define _CREDITS_H_
#include <vector>
#include <string>
#include <JGE.h>
#include <JLBFont.h>
#include "../include/Player.h"
class GameApp;
using namespace std;
class CreditBonus{
public:
int value;
string text;
CreditBonus(int _value, string _text);
void Render(float x, float y, JLBFont * font);
};
class Credits{
private:
int isDifficultyUnlocked();
int isMomirUnlocked();
int isEvilTwinUnlocked();
int isRandomDeckUnlocked();
int unlockRandomSet();
public:
int value;
Player * p1, *p2;
GameApp * app;
int showMsg;
int unlocked;
JQuad * unlockedQuad;
JTexture * unlockedTex;
string unlockedString;
vector<CreditBonus *> bonus;
Credits();
~Credits();
void compute(Player * _p1, Player * _p2, GameApp * _app);
void Render();
};
#ifndef _CREDITS_H_
#define _CREDITS_H_
#include <vector>
#include <string>
#include <JGE.h>
#include <JLBFont.h>
#include "../include/Player.h"
class GameApp;
using namespace std;
class CreditBonus{
public:
int value;
string text;
CreditBonus(int _value, string _text);
void Render(float x, float y, JLBFont * font);
};
class Credits{
private:
int isDifficultyUnlocked();
int isMomirUnlocked();
int isEvilTwinUnlocked();
int isRandomDeckUnlocked();
int unlockRandomSet();
public:
int value;
Player * p1, *p2;
GameApp * app;
int showMsg;
int unlocked;
JQuad * unlockedQuad;
JTexture * unlockedTex;
string unlockedString;
vector<CreditBonus *> bonus;
Credits();
~Credits();
void compute(Player * _p1, Player * _p2, GameApp * _app);
void Render();
};
#endif
+139 -52
View File
@@ -14,25 +14,95 @@ using std::string;
#define PLAYER_SETTINGS "options.txt"
#define PLAYER_COLLECTION "collection.dat"
struct Options {
static const string MUSICVOLUME;
static const string SFXVOLUME;
static const string DIFFICULTY_MODE_UNLOCKED;
static const string MOMIR_MODE_UNLOCKED;
static const string EVILTWIN_MODE_UNLOCKED;
static const string RANDOMDECK_MODE_UNLOCKED;
static const string DIFFICULTY;
static const string CACHESIZE;
static const string PLASMAEFFECT;
static const string INTERRUPT_SECONDS;
static const string INTERRUPTMYSPELLS;
static const string INTERRUPTMYABILITIES;
static const string OSD;
static const string ACTIVE_PROFILE;
static const string ACTIVE_THEME;
static const string ACTIVE_MODE;
static const string CLOSEDHAND;
static const string HANDDIRECTION;
#define INVALID_OPTION -1
//Note to self-- provide some form of options initialization.
class Options {
public:
friend class GameSettings;
enum {
//Values /must/ match ordering in optionNames, or everything loads wrong.
//Profile settings
ACTIVE_THEME,
ACTIVE_MODE,
MUSICVOLUME,
SFXVOLUME,
DIFFICULTY,
PLASMAEFFECT,
OSD,
CLOSEDHAND,
HANDDIRECTION,
INTERRUPT_SECONDS,
//My interrupts
INTERRUPTMYSPELLS,
INTERRUPTMYABILITIES,
//Other interrupts
INTERRUPT_BEFOREBEGIN,
INTERRUPT_UNTAP,
INTERRUPT_UPKEEP,
INTERRUPT_DRAW,
INTERRUPT_FIRSTMAIN,
INTERRUPT_BEGINCOMBAT,
INTERRUPT_ATTACKERS,
INTERRUPT_BLOCKERS,
INTERRUPT_DAMAGE,
INTERRUPT_ENDCOMBAT,
INTERRUPT_SECONDMAIN,
INTERRUPT_ENDTURN,
INTERRUPT_CLEANUP,
INTERRUPT_AFTEREND,
//Global settings
ACTIVE_PROFILE,
DIFFICULTY_MODE_UNLOCKED,
MOMIR_MODE_UNLOCKED,
EVILTWIN_MODE_UNLOCKED,
RANDOMDECK_MODE_UNLOCKED,
CACHESIZE,
//Theme metrics. These will be phased out fairly soon.
THEME_METRICS, //Start of theme metrics.
LOADING_TC = THEME_METRICS,
STATS_TC,
SCROLLER_TC,
SCROLLER_FC,
MAINMENU_TC,
POPUP_MENU_FC,
POPUP_MENU_TC,
POPUP_MENU_TCH,
MSG_FAIL_TC,
OPTION_ITEM_FC,
OPTION_ITEM_TC,
OPTION_ITEM_TCH,
OPTION_HEADER_FC,
OPTION_HEADER_TC,
OPTION_SCROLLBAR_FC,
OPTION_SCROLLBAR_FCH,
OPTION_TAB_FC,
OPTION_TAB_FCH,
OPTION_TAB_TC,
OPTION_TAB_TCH,
OPTION_TEXT_TC,
OPTION_TEXT_FC,
KEY_TC,
KEY_TCH,
KEY_FC,
KEY_FCH,
KEYPAD_FC,
KEYPAD_FCH,
KEYPAD_TC,
LAST_NAMED, //Any option after this does not look up in optionNames.
SET_UNLOCKS = LAST_NAMED + 1, //For sets.
};
static int optionSet(int setID);
static int optionInterrupt(int gamePhase);
static int getID(string name);
static string getName(int option);
private:
static const char* optionNames[];
};
struct Metrics {
@@ -40,35 +110,37 @@ struct Metrics {
//*_FC is fill-color, *_FCH is highlighted fill color
//*_B and *_BH are for secondary text/fill colors, if needed
//*_X, *_Y, *_W, *_H are x, y, width and height.
static const string LOADING_TC;
static const string STATS_TC;
static const string SCROLLER_TC;
static const string SCROLLER_FC;
static const string MAINMENU_TC;
static const string POPUP_MENU_FC;
static const string POPUP_MENU_TC;
static const string POPUP_MENU_TCH;
static const string MSG_FAIL_TC;
static const string OPTION_ITEM_FC;
static const string OPTION_ITEM_TC;
static const string OPTION_ITEM_TCH;
static const string OPTION_HEADER_FC;
static const string OPTION_HEADER_TC;
static const string OPTION_SCROLLBAR_FC;
static const string OPTION_SCROLLBAR_FCH;
static const string OPTION_TAB_FC;
static const string OPTION_TAB_FCH;
static const string OPTION_TAB_TC;
static const string OPTION_TAB_TCH;
static const string OPTION_TEXT_TC;
static const string OPTION_TEXT_FC;
static const string KEY_TC;
static const string KEY_TCH;
static const string KEY_FC;
static const string KEY_FCH;
static const string KEYPAD_FC;
static const string KEYPAD_FCH;
static const string KEYPAD_TC;
enum {
LOADING_TC = Options::THEME_METRICS,
STATS_TC,
SCROLLER_TC,
SCROLLER_FC,
MAINMENU_TC,
POPUP_MENU_FC,
POPUP_MENU_TC,
POPUP_MENU_TCH,
MSG_FAIL_TC,
OPTION_ITEM_FC,
OPTION_ITEM_TC,
OPTION_ITEM_TCH,
OPTION_HEADER_FC,
OPTION_HEADER_TC,
OPTION_SCROLLBAR_FC,
OPTION_SCROLLBAR_FCH,
OPTION_TAB_FC,
OPTION_TAB_FCH,
OPTION_TAB_TC,
OPTION_TAB_TCH,
OPTION_TEXT_TC,
OPTION_TEXT_FC,
KEY_TC,
KEY_TCH,
KEY_FC,
KEY_FCH,
KEYPAD_FC,
KEYPAD_FCH,
KEYPAD_TC,
};
};
class GameOption {
@@ -83,6 +155,12 @@ public:
GameOption(int, string);
};
struct EnumDefinition {
int findIndex(int value);
typedef pair<int, string> assoc;
vector<assoc> values;
};
class GameOptions {
public:
@@ -90,13 +168,20 @@ class GameOptions {
int save();
int load();
static const char * phaseInterrupts[];
GameOption& operator[](string);
GameOption& operator[](int);
GameOptions(string filename);
~GameOptions();
private:
map<string,GameOption> values;
bool load_option(int id, string input); //Sends an option to the proper reader.
bool read_default(int id, string input);
bool read_enum(int id, string input, EnumDefinition * def);
bool save_option(std::ofstream * file, int id, string name, GameOption * opt); //Sends an option to the proper writer.
bool write_default(std::ofstream * file, string name, GameOption * opt);
bool write_enum(std::ofstream * file, string name, GameOption * opt, EnumDefinition * def);
map<int,GameOption> values;
};
class GameSettings{
@@ -124,11 +209,13 @@ public:
void checkProfile(); //Confirms that a profile is loaded and contains a collection.
void createUsersFirstDeck(int setId);
GameOption& operator[](string);
GameOption& operator[](int);
GameOptions* profileOptions;
GameOptions* globalOptions;
GameOptions* themeOptions;
static GameOption invalid_option;
private:
GameApp * theGame;
SimplePad * keypad;
+35 -17
View File
@@ -5,6 +5,7 @@
#include <vector>
#include <string>
#include "../include/GameApp.h"
#include "../include/GameOptions.h"
using std::string;
@@ -21,7 +22,8 @@ using std::string;
class OptionItem {
public:
string displayValue, id;
string displayValue;
int id;
int hasFocus;
bool canSelect;
bool bHidden;
@@ -29,7 +31,7 @@ public:
float width, height;
virtual ostream& toString(ostream& out)const;
OptionItem( string _id, string _displayValue);
OptionItem( int _id, string _displayValue);
virtual ~OptionItem() {};
virtual bool Selectable() {return (canSelect && !bHidden);};
@@ -52,9 +54,9 @@ class OptionInteger:public OptionItem{
string strDefault; //What to call the default value.
int maxValue, increment;
OptionInteger(string _id, string _displayValue, int _maxValue = 1, int _increment = 1, int _defV = 0, string _sDef = "");
OptionInteger(int _id, string _displayValue, int _maxValue = 1, int _increment = 1, int _defV = 0, string _sDef = "");
virtual void Reload() {if(id != "") value = options[id].number;};
virtual void Reload() {if(id != INVALID_OPTION) value = options[id].number;};
virtual void Render();
virtual void setData();
virtual void updateValue(){value+=increment; if (value>maxValue) value=0;};
@@ -64,19 +66,19 @@ class OptionInteger:public OptionItem{
class OptionString:public OptionItem{
public:
string value;
OptionString(string _id, string _displayValue);
OptionString(int _id, string _displayValue);
virtual void Render();
virtual void setData();
virtual void updateValue();
virtual void Reload() {if(id != "") value = options[id].str;};
virtual void Reload() {if(id != INVALID_OPTION) value = options[id].str;};
virtual ostream& toString(ostream& out) const;
bool bShowValue;
};
class OptionNewProfile:public OptionString{
public:
OptionNewProfile(string _id, string _displayValue) : OptionString(_id, _displayValue) {bShowValue=false;};
OptionNewProfile(string _displayValue) : OptionString(INVALID_OPTION, _displayValue) {bShowValue=false;};
virtual void updateValue();
virtual void Update(float dt);
virtual int Submode();
@@ -85,7 +87,7 @@ class OptionNewProfile:public OptionString{
class OptionHeader:public OptionItem{
public:
OptionHeader(string _displayValue): OptionItem("", _displayValue) { canSelect=false;};
OptionHeader(string _displayValue): OptionItem(INVALID_OPTION, _displayValue) { canSelect=false;};
virtual void Render();
virtual void setData() {};
virtual void updateValue() {};
@@ -93,7 +95,7 @@ class OptionHeader:public OptionItem{
class OptionText:public OptionItem{
public:
OptionText(string _displayValue): OptionItem("", _displayValue) { canSelect=false;};
OptionText(string _displayValue): OptionItem(INVALID_OPTION, _displayValue) { canSelect=false;};
virtual void Render();
virtual void setData() {};
virtual void updateValue() {};
@@ -105,7 +107,7 @@ class OptionSelect:public OptionItem{
vector<string> selections;
virtual void addSelection(string s);
OptionSelect(string _id, string _displayValue): OptionItem(_id, _displayValue) {value = 0;};
OptionSelect(int _id, string _displayValue): OptionItem(_id, _displayValue) {value = 0;};
virtual void Reload(){initSelections();};
virtual void Render();
virtual void setData();
@@ -118,7 +120,7 @@ class OptionSelect:public OptionItem{
class OptionDirectory:public OptionSelect{
public:
virtual void Reload();
OptionDirectory(string _root, string _id, string _displayValue);
OptionDirectory(string _root, int _id, string _displayValue);
private:
string root;
};
@@ -130,7 +132,7 @@ class OptionTheme:public OptionDirectory{
class OptionVolume: public OptionInteger{
public:
OptionVolume(string _id, string _displayName, bool _bMusic = false);
OptionVolume(int _id, string _displayName, bool _bMusic = false);
virtual void updateValue();
private:
bool bMusic;
@@ -208,27 +210,43 @@ class OptionsMenu
class OptionEnum : public OptionItem {
protected:
typedef pair<int, string> assoc;
unsigned index;
vector<assoc> values;
public:
OptionEnum(string id, string displayValue) : OptionItem(id, displayValue), index(0) {};
OptionEnum(int id, string displayValue);
virtual void Reload();
virtual void Render();
virtual void setData();
virtual void updateValue();
//ourDefined is a virtual wrapper for getDefinition()
virtual EnumDefinition * ourDefined() const {return getDefinition();};
static EnumDefinition * getDefinition();
virtual ostream& toString(ostream& out) const;
};
class OptionClosedHand : public OptionEnum {
public:
friend class GameSettings;
enum { INVISIBLE = 0, VISIBLE = 1 };
OptionClosedHand(string id, string displayValue);
OptionClosedHand(int id, string displayValue);
static EnumDefinition * getDefinition();
EnumDefinition * ourDefined() const { return getDefinition();};
private:
static EnumDefinition * definition;
};
class OptionHandDirection : public OptionEnum {
public:
friend class GameSettings;
enum { VERTICAL = 0, HORIZONTAL = 1};
OptionHandDirection(string id, string displayValue);
OptionHandDirection(int id, string displayValue);
static EnumDefinition * getDefinition();
EnumDefinition * ourDefined() const { return getDefinition();};
private:
static EnumDefinition * definition;
};
#endif