blob: b1b090169ba35fe5406632a24ba972e4376b3615 (
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
/*
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/info.h"
#include "core/entity.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 text alignment
inline Align alignment() const {
return button_align;
}
/// button info record
inline const Info *info() const {
return button_info;
}
/* -- 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 text alignment
void set_alignment(Align align);
/// set info record
void set_info(const Info *info);
private:
std::string button_text;
CommandType button_commandtype;
std::string button_command;
Align button_align;
const Info *button_info;
};
/// 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__
|