Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
blob: dec78967143c8cdbb890fdb3cef799f32e5d33f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*
   core/descriptions.h
   This file is part of the Osirion project and is distributed under
   the terms of the GNU General Public License version 2
*/

#ifndef __INCLUDED_CORE_DESCRIPTIONS_H__
#define __INCLUDED_CORE_DESCRIPTIONS_H__

#include <string>
#include <list>
#include <iostream>

namespace core {
class ButtonDescription;
class MenuDescription;
}

#include "core/entity.h"
#include "model/model.h"
#include "filesystem/inifile.h"

namespace core {

/// description of a menu button
class ButtonDescription
{
public:
	enum Align {Center=0, Left=1, Right=2};

	enum CommandType {CommandNone=0, CommandGame=1, CommandMenu=2};

	ButtonDescription();
	~ButtonDescription();
	
	/* -- inspectors ------------------------------------------- */

	/// button text
	inline const std::string & text() const { return button_text; }

	/// button command type
	inline const CommandType command_type() const {return button_commandtype; }

	/// button command
	inline const std::string & command() const  { return button_command; }

	/// button info view model name
	inline const std::string & modelname() const  { return button_modelname; }

	/// button info view model
	inline const model::Model *model() { return button_model; }
	
	/// button text alignment
	inline Align alignment() const { return button_align; }

	/* -- mutators -------------------------------------------- */

	/// set button text
	void set_text(const std::string &text);

	/// set button command
	void set_command(const std::string &command, const CommandType command_type);

	/// set button name
	void set_modelname(const std::string &modelname);

	/// set text alignment
	void set_alignment(Align align);

private:
	std::string		button_text;
	CommandType		button_commandtype;
	std::string		button_command;
	std::string		button_modelname;
	Align			button_align;
	model::Model 		*button_model;
};

/// description of an entity menu
class MenuDescription
{
public:
	MenuDescription();
	~MenuDescription();

	typedef std::list<ButtonDescription *> Buttons;

	/* -- inspectors ------------------------------------------- */

	/// menu label
	inline const std::string & label() const { return menu_label; }

	/// menu text
	inline const std::string & text() const { return menu_text; }

	/// menu buttons
	inline Buttons &buttons() { return menu_buttons; }

	/* -- mutators -------------------------------------------- */

	/// set menu text
	void set_text(const std::string &text);

	/// set menu label
	void set_label(const std::string &label);

	/// add a menu button
	void add_button(ButtonDescription *button);

private:
	std::string		menu_label;
	std::string		menu_text;
	
	Buttons			menu_buttons;
};


/// descriptions loader class
class Descriptions {
public:
	/// read entity menus from ini file
	static bool load_entity_menus(core::Entity *entity, const std::string &menufilename);
	/// serialize entity menus to a stream
	static void serialize(MenuDescription *menu, std::ostream & os);
	/// read entity menus from a stream
	static MenuDescription * receive(std::istream &is);
};

}

#endif // __INCLUDED_CORE_DESCRIPTIONS_H__