|
@@ -1,5 +1,9 @@ |
1 |
1 |
|
using UnityEngine; |
2 |
2 |
|
using System.Collections; |
|
3 |
+ |
using System.Collections.Generic; |
|
4 |
+ |
using System.IO; |
|
5 |
+ |
using System.Xml; |
|
6 |
+ |
using System.Text; |
3 |
7 |
|
|
4 |
8 |
|
public class StartGameUI : MonoBehaviour |
5 |
9 |
|
{ |
|
@@ -8,13 +12,89 @@ |
8 |
12 |
|
public Transform selectShip; |
9 |
13 |
|
public Transform[] previewShips; |
10 |
14 |
|
public GameObject globalObject; |
11 |
|
- |
public enum UIState{SELECT_GAME,SELECT_SHIP,FREE_MAP}; |
12 |
|
- |
private Vector2 windowSize=new Vector2(400,350); |
|
15 |
+ |
public enum UIState{SELECT_GAME,SELECT_SHIP,FREE_MAP, LANGUAGE}; |
|
16 |
+ |
private Vector2 windowSize=new Vector2(400,450); |
13 |
17 |
|
private Rect windowRect; |
14 |
18 |
|
private Vector2 selectWindowSize = new Vector2(400,350); |
15 |
19 |
|
private Rect selectWindowRect; |
16 |
20 |
|
private UIState uiState=UIState.SELECT_GAME; |
17 |
21 |
|
private bool[] toggleValue; |
|
22 |
+ |
public TextAsset dictionary; |
|
23 |
+ |
public string languageName; |
|
24 |
+ |
public int currentLanguage; |
|
25 |
+ |
string button1; |
|
26 |
+ |
string button2; |
|
27 |
+ |
string button3; |
|
28 |
+ |
string button4; |
|
29 |
+ |
string button5; |
|
30 |
+ |
string button6; |
|
31 |
+ |
string label; |
|
32 |
+ |
string label2; |
|
33 |
+ |
string label3; |
|
34 |
+ |
List<Dictionary<string, string>> languages = new List<Dictionary<string, string>>(); |
|
35 |
+ |
Dictionary<string, string> obj; |
|
36 |
+ |
|
|
37 |
+ |
void Awake(){ |
|
38 |
+ |
Reader (); |
|
39 |
+ |
} |
|
40 |
+ |
|
|
41 |
+ |
void Update(){ |
|
42 |
+ |
languages [currentLanguage].TryGetValue ("Name", out languageName); |
|
43 |
+ |
languages [currentLanguage].TryGetValue ("button1", out button1); |
|
44 |
+ |
languages [currentLanguage].TryGetValue ("button2", out button2); |
|
45 |
+ |
languages [currentLanguage].TryGetValue ("button3", out button3); |
|
46 |
+ |
languages [currentLanguage].TryGetValue ("button4", out button4); |
|
47 |
+ |
languages [currentLanguage].TryGetValue ("button5", out button5); |
|
48 |
+ |
languages [currentLanguage].TryGetValue ("button6", out button6); |
|
49 |
+ |
languages [currentLanguage].TryGetValue ("label", out label); |
|
50 |
+ |
languages [currentLanguage].TryGetValue ("label2", out label2); |
|
51 |
+ |
languages [currentLanguage].TryGetValue ("label3", out label3); |
|
52 |
+ |
} |
|
53 |
+ |
|
|
54 |
+ |
void Reader() { |
|
55 |
+ |
XmlDocument XmlDoc = new XmlDocument (); |
|
56 |
+ |
XmlDoc.LoadXml (dictionary.text); |
|
57 |
+ |
XmlNodeList languagesList = XmlDoc.GetElementsByTagName ("language"); |
|
58 |
+ |
|
|
59 |
+ |
foreach(XmlNode languageValue in languagesList){ |
|
60 |
+ |
XmlNodeList languageContent = languageValue.ChildNodes; |
|
61 |
+ |
obj = new Dictionary<string, string>(); |
|
62 |
+ |
|
|
63 |
+ |
foreach(XmlNode Value in languageContent) { |
|
64 |
+ |
if (Value.Name == "Name") |
|
65 |
+ |
obj.Add(Value.Name, Value.InnerText); |
|
66 |
+ |
|
|
67 |
+ |
if (Value.Name == "button1") |
|
68 |
+ |
obj.Add(Value.Name, Value.InnerText); |
|
69 |
+ |
|
|
70 |
+ |
if (Value.Name == "button2") |
|
71 |
+ |
obj.Add(Value.Name, Value.InnerText); |
|
72 |
+ |
|
|
73 |
+ |
if (Value.Name == "button3") |
|
74 |
+ |
obj.Add(Value.Name, Value.InnerText); |
|
75 |
+ |
|
|
76 |
+ |
if (Value.Name == "button4") |
|
77 |
+ |
obj.Add(Value.Name, Value.InnerText); |
|
78 |
+ |
|
|
79 |
+ |
if (Value.Name == "button5") |
|
80 |
+ |
obj.Add(Value.Name, Value.InnerText); |
|
81 |
+ |
|
|
82 |
+ |
if (Value.Name == "button6") |
|
83 |
+ |
obj.Add(Value.Name, Value.InnerText); |
|
84 |
+ |
|
|
85 |
+ |
if (Value.Name == "label") |
|
86 |
+ |
obj.Add(Value.Name, Value.InnerText); |
|
87 |
+ |
|
|
88 |
+ |
if (Value.Name == "label2") |
|
89 |
+ |
obj.Add(Value.Name, Value.InnerText); |
|
90 |
+ |
|
|
91 |
+ |
if (Value.Name == "label3") |
|
92 |
+ |
obj.Add(Value.Name, Value.InnerText); |
|
93 |
+ |
} |
|
94 |
+ |
languages.Add(obj); |
|
95 |
+ |
} |
|
96 |
+ |
} |
|
97 |
+ |
|
18 |
98 |
|
void Start() |
19 |
99 |
|
{ |
20 |
100 |
|
if(GameObject.Find("GlobalObject")==null) |
|
@@ -38,7 +118,13 @@ |
38 |
118 |
|
if(uiState==UIState.SELECT_GAME)SelectGameUI(); |
39 |
119 |
|
else if(uiState==UIState.SELECT_SHIP)SelectShipUI(); |
40 |
120 |
|
else if(uiState==UIState.FREE_MAP)FreeMapUI(); |
|
121 |
+ |
else if(uiState==UIState.LANGUAGE)LanguageUI(); |
41 |
122 |
|
} |
|
123 |
+ |
|
|
124 |
+ |
void LanguageUI(){ |
|
125 |
+ |
windowRect = GUI.Window(2,windowRect,SelectLanguageWindow,""); |
|
126 |
+ |
} |
|
127 |
+ |
|
42 |
128 |
|
void SelectGameUI() |
43 |
129 |
|
{ |
44 |
130 |
|
windowRect = GUI.Window(0,windowRect,SelectGameWindow,""); |
|
@@ -70,6 +156,7 @@ |
70 |
156 |
|
ContinueGame(); |
71 |
157 |
|
} |
72 |
158 |
|
} |
|
159 |
+ |
|
73 |
160 |
|
void SelectGameWindow(int windowID) |
74 |
161 |
|
{ |
75 |
162 |
|
GUILayout.BeginHorizontal(); |
|
@@ -79,16 +166,16 @@ |
79 |
166 |
|
|
80 |
167 |
|
GUILayout.BeginHorizontal (); |
81 |
168 |
|
GUILayout.FlexibleSpace(); |
82 |
|
- |
GUILayout.Label("WELCOME","ShortLabel"); |
|
169 |
+ |
GUILayout.Label(label,"ShortLabel"); |
83 |
170 |
|
GUILayout.FlexibleSpace(); |
84 |
171 |
|
GUILayout.EndHorizontal (); |
85 |
|
- |
GUILayout.Space(15); |
|
172 |
+ |
GUILayout.Space(10); |
86 |
173 |
|
|
87 |
174 |
|
GUILayout.Label("", "Divider"); |
88 |
175 |
|
|
89 |
176 |
|
GUILayout.BeginHorizontal(); |
90 |
177 |
|
GUILayout.FlexibleSpace(); |
91 |
|
- |
if(GUILayout.Button("New Game","BigButton")) |
|
178 |
+ |
if(GUILayout.Button(button1,"BigButton")) |
92 |
179 |
|
{ |
93 |
180 |
|
NewGame(); |
94 |
181 |
|
} |
|
@@ -101,7 +188,7 @@ |
101 |
188 |
|
|
102 |
189 |
|
GUILayout.BeginHorizontal(); |
103 |
190 |
|
GUILayout.FlexibleSpace(); |
104 |
|
- |
if(GUILayout.Button("Continue","BigButton")) |
|
191 |
+ |
if(GUILayout.Button(button2,"BigButton")) |
105 |
192 |
|
{ |
106 |
193 |
|
ContinueGame(); |
107 |
194 |
|
} |
|
@@ -114,7 +201,20 @@ |
114 |
201 |
|
|
115 |
202 |
|
GUILayout.BeginHorizontal(); |
116 |
203 |
|
GUILayout.FlexibleSpace(); |
117 |
|
- |
if(GUILayout.Button(" Exit ","BigButton")) |
|
204 |
+ |
if(GUILayout.Button(button3,"BigButton")) |
|
205 |
+ |
{ |
|
206 |
+ |
Language(); |
|
207 |
+ |
} |
|
208 |
+ |
GUILayout.FlexibleSpace(); |
|
209 |
+ |
GUILayout.EndHorizontal(); |
|
210 |
+ |
|
|
211 |
+ |
GUILayout.Space(10); |
|
212 |
+ |
|
|
213 |
+ |
GUILayout.Label("", "Divider"); |
|
214 |
+ |
|
|
215 |
+ |
GUILayout.BeginHorizontal(); |
|
216 |
+ |
GUILayout.FlexibleSpace(); |
|
217 |
+ |
if(GUILayout.Button(button4,"BigButton")) |
118 |
218 |
|
{ |
119 |
219 |
|
ExitGame(); |
120 |
220 |
|
} |
|
@@ -137,7 +237,7 @@ |
137 |
237 |
|
|
138 |
238 |
|
GUILayout.BeginHorizontal (); |
139 |
239 |
|
GUILayout.FlexibleSpace(); |
140 |
|
- |
GUILayout.Label("SELECT YOUR SHIP","ShortLabel"); |
|
240 |
+ |
GUILayout.Label(label2,"ShortLabel"); |
141 |
241 |
|
GUILayout.FlexibleSpace(); |
142 |
242 |
|
GUILayout.EndHorizontal (); |
143 |
243 |
|
GUILayout.Space(15); |
|
@@ -146,7 +246,7 @@ |
146 |
246 |
|
|
147 |
247 |
|
GUILayout.BeginHorizontal(); |
148 |
248 |
|
GUILayout.FlexibleSpace(); |
149 |
|
- |
if(GUILayout.Button(" Start ","BigButton")) |
|
249 |
+ |
if(GUILayout.Button(button5,"BigButton")) |
150 |
250 |
|
{ |
151 |
251 |
|
FreeMap(); |
152 |
252 |
|
} |
|
@@ -159,7 +259,7 @@ |
159 |
259 |
|
|
160 |
260 |
|
GUILayout.BeginHorizontal(); |
161 |
261 |
|
GUILayout.FlexibleSpace(); |
162 |
|
- |
if(GUILayout.Button(" Back ","BigButton")) |
|
262 |
+ |
if(GUILayout.Button(button6,"BigButton")) |
163 |
263 |
|
{ |
164 |
264 |
|
uiState = UIState.SELECT_GAME; |
165 |
265 |
|
selectShip.gameObject.SetActive(false); |
|
@@ -173,7 +273,7 @@ |
173 |
273 |
|
|
174 |
274 |
|
GUILayout.BeginHorizontal(); |
175 |
275 |
|
GUILayout.FlexibleSpace(); |
176 |
|
- |
if(GUILayout.Button(" Exit ","BigButton")) |
|
276 |
+ |
if(GUILayout.Button(button4,"BigButton")) |
177 |
277 |
|
{ |
178 |
278 |
|
ExitGame(); |
179 |
279 |
|
} |
|
@@ -187,6 +287,67 @@ |
187 |
287 |
|
|
188 |
288 |
|
GUI.DragWindow(); |
189 |
289 |
|
} |
|
290 |
+ |
|
|
291 |
+ |
void SelectLanguageWindow(int windowID) |
|
292 |
+ |
{ |
|
293 |
+ |
GUILayout.BeginHorizontal(); |
|
294 |
+ |
GUILayout.Space(10); |
|
295 |
+ |
|
|
296 |
+ |
GUILayout.BeginVertical(); |
|
297 |
+ |
|
|
298 |
+ |
GUILayout.BeginHorizontal (); |
|
299 |
+ |
GUILayout.FlexibleSpace(); |
|
300 |
+ |
GUILayout.Label(label3,"ShortLabel"); |
|
301 |
+ |
GUILayout.FlexibleSpace(); |
|
302 |
+ |
GUILayout.EndHorizontal (); |
|
303 |
+ |
GUILayout.Space(15); |
|
304 |
+ |
|
|
305 |
+ |
GUILayout.Label("", "Divider"); |
|
306 |
+ |
|
|
307 |
+ |
GUILayout.BeginHorizontal(); |
|
308 |
+ |
GUILayout.FlexibleSpace(); |
|
309 |
+ |
if(GUILayout.Button(" English ","BigButton")) |
|
310 |
+ |
{ |
|
311 |
+ |
currentLanguage = 0; |
|
312 |
+ |
} |
|
313 |
+ |
GUILayout.FlexibleSpace(); |
|
314 |
+ |
GUILayout.EndHorizontal(); |
|
315 |
+ |
|
|
316 |
+ |
GUILayout.Space(10); |
|
317 |
+ |
|
|
318 |
+ |
GUILayout.Label("", "Divider"); |
|
319 |
+ |
|
|
320 |
+ |
GUILayout.BeginHorizontal(); |
|
321 |
+ |
GUILayout.FlexibleSpace(); |
|
322 |
+ |
if(GUILayout.Button(" Italian ","BigButton")) |
|
323 |
+ |
{ |
|
324 |
+ |
currentLanguage = 1; |
|
325 |
+ |
} |
|
326 |
+ |
GUILayout.FlexibleSpace(); |
|
327 |
+ |
GUILayout.EndHorizontal(); |
|
328 |
+ |
|
|
329 |
+ |
GUILayout.Space(10); |
|
330 |
+ |
|
|
331 |
+ |
GUILayout.Label("", "Divider"); |
|
332 |
+ |
|
|
333 |
+ |
GUILayout.BeginHorizontal(); |
|
334 |
+ |
GUILayout.FlexibleSpace(); |
|
335 |
+ |
if(GUILayout.Button(button6,"BigButton")) |
|
336 |
+ |
{ |
|
337 |
+ |
uiState = UIState.SELECT_GAME; |
|
338 |
+ |
selectShip.gameObject.SetActive(false); |
|
339 |
+ |
} |
|
340 |
+ |
GUILayout.FlexibleSpace(); |
|
341 |
+ |
GUILayout.EndHorizontal(); |
|
342 |
+ |
|
|
343 |
+ |
GUILayout.EndVertical(); |
|
344 |
+ |
|
|
345 |
+ |
GUILayout.Space(10); |
|
346 |
+ |
GUILayout.EndHorizontal(); |
|
347 |
+ |
|
|
348 |
+ |
GUI.DragWindow(); |
|
349 |
+ |
} |
|
350 |
+ |
|
190 |
351 |
|
void NewGame() |
191 |
352 |
|
{ |
192 |
353 |
|
uiState = UIState.SELECT_SHIP; |
|
@@ -207,6 +368,11 @@ |
207 |
368 |
|
selectShip.gameObject.SetActive(false); |
208 |
369 |
|
spaceMap.gameObject.SetActive(true); |
209 |
370 |
|
} |
|
371 |
+ |
|
|
372 |
+ |
void Language(){ |
|
373 |
+ |
uiState = UIState.LANGUAGE; |
|
374 |
+ |
} |
|
375 |
+ |
|
210 |
376 |
|
void ExitGame() |
211 |
377 |
|
{ |
212 |
378 |
|
Application.Quit(); |