1 /*=============================================================================
2 Blobby Volley 2
3 Copyright (C) 2006 Jonathan Sieber (jonathan_sieber@yahoo.de)
4 Copyright (C) 2006 Daniel Knobe (daniel-knobe@web.de)
5 
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10 
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15 
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 =============================================================================*/
20 
21 /**
22  * @file TextManager.h
23  * @brief Contains a class which handles different languages for text translations
24  */
25 
26 #pragma once
27 
28 #include <vector>
29 #include <string>
30 #include <map>
31 
32 /// \brief class for managing the text
33 /// \details multilanguage support
34 /// the string can be loaded from a xml file
35 /// <string english="english" translation="translation />
36 
37 class TextManager
38 {
39 	public:
40 		/// enumeration for strings
41 		enum STRING
42 		{
43 			// common labels
44 			LBL_OK,
45 			LBL_CANCEL,
46 			LBL_YES,
47 			LBL_NO,
48 			LBL_CONF_QUIT,
49 			LBL_CONTINUE,
50 
51 			// labels for main menu
52 			MNU_LABEL_ONLINE,
53 			MNU_LABEL_LAN,
54 			MNU_LABEL_START,
55 			MNU_LABEL_OPTIONS,
56 			MNU_LABEL_REPLAY,
57 			MNU_LABEL_CREDITS,
58 			MNU_LABEL_EXIT,
59 
60 			// credits
61 			CRD_PROGRAMMERS,
62 			CRD_GRAPHICS,
63 			CRD_THX,
64 
65 			// replays
66 			RP_SHOW_AGAIN,
67 			RP_PLAY,
68 			RP_DELETE,
69 			RP_INFO,
70 			RP_DURATION,
71 			RP_RESULT,
72 			RP_CHECKSUM,
73 			RP_VERSION,
74 			RP_FILE_OUTDATED,
75 			RP_FILE_CORRUPT,
76 			RP_SAVE_NAME,
77 			RP_WAIT_REPLAY,
78 			RP_SAVE,
79 
80 			// game texts
81 			GAME_WIN,
82 			GAME_TRY_AGAIN,
83 			GAME_WAITING,
84 			GAME_OPP_LEFT,
85 			GAME_PAUSED,
86 			GAME_QUIT,
87 
88 			// network texts
89 			NET_SERVER_SCAN,
90 			NET_DIRECT_CONNECT,
91 			NET_SERVER_INFO,
92 			NET_ACTIVE_GAMES,
93 			NET_WAITING_PLAYER,
94 			NET_HOST_GAME,
95 			NET_CONNECTING,
96 			NET_DISCONNECT,
97 			NET_CON_FAILED,
98 			NET_SERVER_FULL,
99 			NET_STAY_ON_SERVER,
100 			NET_RANDOM_OPPONENT,
101 			NET_SPEED,
102 			NET_RULES_TITLE,
103 			NET_RULES_BY,
104 			NET_CHALLENGE,
105 
106 			// options
107 			OP_TOUCH_TYPE,
108 			OP_TOUCH_ARROWS,
109 			OP_TOUCH_DIRECT,
110 			OP_INPUT_OP,
111 			OP_GFX_OP,
112 			OP_MISC,
113 			OP_VIDEO,
114 			OP_FULLSCREEN,
115 			OP_WINDOW,
116 			OP_RENDER_DEVICE,
117 			OP_SHOW_SHADOW,
118 			OP_BLOB_COLORS,
119 			OP_LEFT_PLAYER,
120 			OP_RIGHT_PLAYER,
121 			OP_RED,
122 			OP_GREEN,
123 			OP_BLUE,
124 			OP_MORPHING,
125 			OP_KEYBOARD,
126 			OP_MOUSE,
127 			OP_JOYSTICK,
128 			OP_JUMP_BUTTON,
129 			OP_SET_ALL,
130 			OP_LEFT_KEY,
131 			OP_RIGHT_KEY,
132 			OP_JUMP_KEY,
133 			OP_LEFT_BUTTON,
134 			OP_RIGHT_BUTTON,
135 			OP_PRESS_MOUSE_BUTTON,
136 			OP_PRESS_KEY_FOR,
137 			OP_MOVING_LEFT,
138 			OP_MOVING_RIGHT,
139 			OP_JUMPING,
140 			OP_PRESS_BUTTON_FOR,
141 			OP_BACKGROUND,
142 			OP_VOLUME,
143 			OP_MUTE,
144 			OP_FPS,
145 			OP_BLOOD,
146 			OP_NETWORK_SIDE,
147 			OP_LEFT,
148 			OP_RIGHT,
149 			OP_SPEED,
150 			OP_VSLOW,
151 			OP_SLOW,
152 			OP_DEFAULT,
153 			OP_FAST,
154 			OP_VFAST,
155 			OP_LANGUAGE,
156 			OP_DIFFICULTY,
157 			OP_WEAK,
158 			OP_MEDIUM,
159 			OP_STRONG,
160 			OP_RULES,
161 
162 			UPDATE_NOTIFICATION,
163 
164 			COUNT
165 		};
166 
167 		/// returns the string identified by str
168 		const std::string& getString(STRING str) const;
169 
170 		std::string getLang() const;
171 
172 		/// returns the mSingleton
173 		static const TextManager* getSingleton();
174 
175 		/// creates a textmanager for a particular language
176 		static TextManager* createTextManager(std::string langname);
177 
178 		/// switches the language
179 		static void switchLanguage(std::string langname);
180 
181 		/// map to map abbreviations to full name (e.g. de to deutsch)
182 		static std::map<std::string, std::string> language_names;
183 
184 	private:
185 		/// private construktor, use createTextManager
186 		TextManager(std::string l);
187 
188 		/// Singleton
189 		static TextManager* mSingleton;
190 
191 		/// vector with all strings
192 		std::vector<std::string> mStrings;
193 
194 		/// string with language name
195 		std::string lang;
196 
197 		/// loads the language data from an xml file
198 		bool loadFromXML(std::string file);
199 
200 		/// sets the strings to the default values
201 		void setDefault();
202 };
203