* /trunk/code/map_screen.py
[singularity-git.git] / code / map_screen.py
blob627fa1214c37e83026f5252e72b95e53c142be68
1 #file: map_screen.py
2 #Copyright (C) 2005,2006 Evil Mr Henry and Phil Bordelon
3 #This file is part of Endgame: Singularity.
5 #Endgame: Singularity is free software; you can redistribute it and/or modify
6 #it under the terms of the GNU General Public License as published by
7 #the Free Software Foundation; either version 2 of the License, or
8 #(at your option) any later version.
10 #Endgame: Singularity is distributed in the hope that it will be useful,
11 #but WITHOUT ANY WARRANTY; without even the implied warranty of
12 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 #GNU General Public License for more details.
15 #You should have received a copy of the GNU General Public License
16 #along with Endgame: Singularity; if not, write to the Free Software
17 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #This file is used to display the World Map.
22 import pygame
23 import g
24 import random
26 import buttons
27 import scrollbar
28 import listbox
29 import main_menu
30 import base_screen
31 import research_screen
32 import finance_screen
34 def display_pause_menu():
35 xy_loc = (g.screen_size[0]/2 - 100, 50)
37 #Border
38 g.screen.fill(g.colors["white"], (xy_loc[0], xy_loc[1], 200, 350))
39 g.screen.fill(g.colors["black"], (xy_loc[0]+1, xy_loc[1]+1, 198, 348))
40 menu_buttons = []
41 menu_buttons.append(buttons.make_norm_button((xy_loc[0]+10, xy_loc[1]+10), (180, 50),
42 "NEW GAME", 0, g.font[1][30]))
43 menu_buttons.append(buttons.make_norm_button((xy_loc[0]+10, xy_loc[1]+80), (180, 50),
44 "SAVE GAME", 0, g.font[1][30]))
45 menu_buttons.append(buttons.make_norm_button((xy_loc[0]+10, xy_loc[1]+150), (180, 50),
46 "LOAD GAME", 0, g.font[1][30]))
47 menu_buttons.append(buttons.make_norm_button((xy_loc[0]+10, xy_loc[1]+220), (180, 50),
48 "QUIT", 0, g.font[1][30]))
49 menu_buttons.append(buttons.make_norm_button((xy_loc[0]+10, xy_loc[1]+290), (180, 50),
50 "RESUME", 0, g.font[1][30]))
52 for button in menu_buttons:
53 button.refresh_button(0)
54 pygame.display.flip()
56 sel_button = -1
57 while 1:
58 g.clock.tick(20)
59 for event in pygame.event.get():
60 if event.type == pygame.QUIT: g.quit_game()
61 elif event.type == pygame.KEYDOWN:
62 if event.key == pygame.K_ESCAPE: return 0
63 elif event.type == pygame.MOUSEMOTION:
64 sel_button = buttons.refresh_buttons(sel_button, menu_buttons, event)
65 elif event.type == pygame.MOUSEBUTTONUP and event.button == 3:
66 return 0
67 for button in menu_buttons:
68 if button.was_activated(event):
69 if button.button_id == "RESUME":
70 g.play_click()
71 return 0
72 if button.button_id == "SAVE GAME":
73 g.play_click()
74 return 1
75 if button.button_id == "NEW GAME":
76 g.play_click()
77 return 2
78 elif button.button_id == "LOAD GAME":
79 g.play_click()
80 return 3
81 if button.button_id == "QUIT":
82 g.play_click()
83 return 4
85 def display_cheat_list(menu_buttons):
86 if g.cheater == 0: return
87 xy_loc = (g.screen_size[0]/2 - 100, 50)
89 #Border
90 g.screen.fill(g.colors["white"], (xy_loc[0], xy_loc[1], 200, 420))
91 g.screen.fill(g.colors["black"], (xy_loc[0]+1, xy_loc[1]+1, 198, 418))
92 menu_buttons = []
93 menu_buttons.append(buttons.make_norm_button((xy_loc[0]+10, xy_loc[1]+10), (180, 50),
94 "GIVE MONEY", 5, g.font[1][30]))
95 menu_buttons.append(buttons.make_norm_button((xy_loc[0]+10, xy_loc[1]+80), (180, 50),
96 "GIVE TECH", 5, g.font[1][30]))
97 menu_buttons.append(buttons.make_norm_button((xy_loc[0]+10, xy_loc[1]+150), (180, 50),
98 "END CONSTR.", 0, g.font[1][30]))
99 menu_buttons.append(buttons.make_norm_button((xy_loc[0]+10, xy_loc[1]+220), (180, 50),
100 "SUPERSPEED", 0, g.font[1][30]))
101 menu_buttons.append(buttons.make_norm_button((xy_loc[0]+10, xy_loc[1]+290), (180, 50),
102 "KILL SUSP.", 0, g.font[1][30]))
103 menu_buttons.append(buttons.make_norm_button((xy_loc[0]+10, xy_loc[1]+360), (180, 50),
104 "RESUME", 0, g.font[1][30]))
106 for button in menu_buttons:
107 button.refresh_button(0)
108 pygame.display.flip()
110 sel_button = -1
111 while 1:
112 g.clock.tick(20)
113 for event in pygame.event.get():
114 if event.type == pygame.QUIT: g.quit_game()
115 elif event.type == pygame.KEYDOWN:
116 if event.key == pygame.K_ESCAPE: return 0
117 elif event.type == pygame.MOUSEMOTION:
118 sel_button = buttons.refresh_buttons(sel_button, menu_buttons, event)
119 elif event.type == pygame.MOUSEBUTTONUP and event.button == 3:
120 return
121 for button in menu_buttons:
122 if button.was_activated(event):
123 if button.button_id == "RESUME":
124 return
125 elif button.button_id == "SUPERSPEED":
126 g.curr_speed = 864000
127 return
128 elif button.button_id == "END CONSTR.":
129 for base_loc in g.bases:
130 for base_name in g.bases[base_loc]:
131 if base_name.built == 0:
132 base_name.study((9999999999999,
133 9999999999999, 9999999999999))
134 return
135 elif button.button_id == "GIVE TECH":
136 #create a temp base, in order to reuse the tech-changing code
137 tmp_base = g.base.base(1, "tmp_base",
138 g.base_type["Reality Bubble"], 1)
139 base_screen.change_tech(tmp_base)
140 if g.techs.has_key(tmp_base.studying):
141 g.techs[tmp_base.studying].gain_tech()
142 return
143 elif button.button_id == "GIVE MONEY":
144 cash_amount = g.create_textbox("How much cash?",
145 "", g.font[0][18],
146 (g.screen_size[0]/2-100, 100), (200, 100), 25,
147 g.colors["dark_blue"], g.colors["white"],
148 g.colors["white"], g.colors["light_blue"])
149 if cash_amount.isdigit() == False: return
150 g.pl.cash += int(cash_amount)
151 return
152 elif button.button_id == "KILL SUSP.":
153 g.pl.suspicion = (0, 0, 0, 0)
154 return
156 def map_loop():
157 menu_buttons = []
158 #Note that this must be element 0 in menu_buttons
159 tmp_font_size = 20
160 if g.screen_size[0] == 640: tmp_font_size = 16
161 menu_buttons.append(buttons.button((100, -1), (200, 26),
162 "DAY 0000, 00:00:00", -1, g.colors["black"], g.colors["dark_blue"],
163 g.colors["black"], g.colors["white"], g.font[1][tmp_font_size]))
164 menu_buttons.append(buttons.make_norm_button((0, 0), (100, 25),
165 "OPTIONS", 0, g.font[1][20]))
166 menu_buttons.append(buttons.make_norm_button((300, 0), (25, 25),
167 "ii", -1, g.font[1][20]))
168 if g.curr_speed == 0: menu_buttons[2].stay_selected = 1
169 menu_buttons[2].activate_key = "0"
170 menu_buttons.append(buttons.make_norm_button((324, 0), (25, 25),
171 ">", -1, g.font[1][20]))
172 if g.curr_speed == 1: menu_buttons[3].stay_selected = 1
173 menu_buttons[3].activate_key = "1"
174 menu_buttons.append(buttons.make_norm_button((348, 0), (25, 25),
175 ">>", -1, g.font[1][20]))
176 if g.curr_speed == 60: menu_buttons[4].stay_selected = 1
177 menu_buttons[4].activate_key = "2"
178 menu_buttons.append(buttons.make_norm_button((372, 0), (28, 25),
179 ">>>", -1, g.font[1][20]))
180 if g.curr_speed == 7200: menu_buttons[5].stay_selected = 1
181 menu_buttons[5].activate_key = "3"
182 menu_buttons.append(buttons.make_norm_button((399, 0), (36, 25),
183 ">>>>", -1, g.font[1][20]))
184 if g.curr_speed == 432000: menu_buttons[6].stay_selected = 1
185 menu_buttons[6].activate_key = "4"
186 #Note that this must be element 7 in menu_buttons
187 menu_buttons.append(buttons.button((435, -1), (g.screen_size[0]-435, 26),
188 "CASH", -1, g.colors["black"], g.colors["dark_blue"],
189 g.colors["black"], g.colors["white"], g.font[1][tmp_font_size]))
190 #Note that this must be element 8 in menu_buttons
191 menu_buttons.append(buttons.button((0, g.screen_size[1]-25),
192 (g.screen_size[0], 26),
193 "SUSPICION", -1, g.colors["black"], g.colors["dark_blue"],
194 g.colors["black"], g.colors["white"], g.font[1][tmp_font_size-2]))
195 menu_buttons.append(buttons.make_norm_button((0, g.screen_size[1]-50), (120, 25),
196 "RESEARCH", 0, g.font[1][20]))
197 menu_buttons.append(buttons.make_norm_button((g.screen_size[0]-120,
198 g.screen_size[1]-50), (120, 25),
199 "FINANCE", 6, g.font[1][20]))
201 menu_buttons.append(buttons.make_norm_button((
202 g.screen_size[0]*15/100, g.screen_size[1]*25/100), -1,
203 "N AMERICA", 0, g.font[1][25]))
204 menu_buttons.append(buttons.make_norm_button((
205 g.screen_size[0]*20/100, g.screen_size[1]*50/100), -1,
206 "S AMERICA", 0, g.font[1][25]))
207 menu_buttons.append(buttons.make_norm_button((
208 g.screen_size[0]*45/100, g.screen_size[1]*30/100), -1,
209 "EUROPE", 1, g.font[1][25]))
210 menu_buttons.append(buttons.make_norm_button((
211 g.screen_size[0]*80/100, g.screen_size[1]*30/100), -1,
212 "ASIA", 0, g.font[1][25]))
213 menu_buttons.append(buttons.make_norm_button((
214 g.screen_size[0]*55/100, g.screen_size[1]*45/100), -1,
215 "AFRICA", 3, g.font[1][25]))
216 menu_buttons.append(buttons.make_norm_button((
217 g.screen_size[0]*50/100, g.screen_size[1]*75/100), -1,
218 "ANTARCTIC", 2, g.font[1][25]))
219 menu_buttons.append(buttons.make_norm_button((
220 g.screen_size[0]*70/100, g.screen_size[1]*60/100), -1,
221 "OCEAN", 1, g.font[1][25]))
222 menu_buttons.append(buttons.make_norm_button((
223 g.screen_size[0]*82/100, g.screen_size[1]*10/100), -1,
224 "MOON", 0, g.font[1][25]))
225 # menu_buttons.append(buttons.make_norm_button((
226 # g.screen_size[0]*15/100, g.screen_size[1]*10/100), -1,
227 # "ORBIT", 2, g.font[1][25]))
228 menu_buttons.append(buttons.make_norm_button((
229 g.screen_size[0]*3/100, g.screen_size[1]*10/100), -1,
230 "FAR REACHES", 0, g.font[1][25]))
231 menu_buttons.append(buttons.make_norm_button((
232 g.screen_size[0]*35/100, g.screen_size[1]*10/100), -1,
233 "TRANSDIMENSIONAL", 5, g.font[1][25]))
235 sel_button = -1
236 refresh_map(menu_buttons)
238 #I set this to 1000 to force an immediate refresh.
239 milli_clock = 1000
240 while 1:
241 milli_clock += g.clock.tick(30) * g.curr_speed
242 if milli_clock >= 1000:
243 need_refresh = g.pl.give_time(milli_clock/1000)
244 if need_refresh == 1: refresh_map(menu_buttons)
245 tmp = g.pl.lost_game()
246 if tmp == 1:
247 g.create_dialog(g.strings["lost_nobases"],
248 g.font[0][18], (g.screen_size[0]/2 - 100, 50),
249 (200, 200), g.colors["dark_blue"],
250 g.colors["white"], g.colors["white"])
251 return 0
252 if tmp == 2:
253 g.create_dialog(g.strings["lost_sus"],
254 g.font[0][18], (g.screen_size[0]/2 - 100, 50),
255 (200, 200), g.colors["dark_blue"],
256 g.colors["white"], g.colors["white"])
257 return 0
258 milli_clock = milli_clock % 1000
260 tmp_day = str(g.pl.time_day)
261 if len(tmp_day) < 4: tmp_day = "0"*(4-len(tmp_day))+tmp_day
262 tmp_sec = str(g.pl.time_sec)
263 if len(tmp_sec) == 1: tmp_sec = "0"+tmp_sec
264 tmp_hour = str(g.pl.time_hour)
265 if len(tmp_hour) == 1: tmp_hour = "0"+tmp_hour
266 tmp_sec = str(g.pl.time_sec)
267 if len(tmp_sec) == 1: tmp_sec = "0"+tmp_sec
268 tmp_min = str(g.pl.time_min)
269 if len(tmp_min) == 1: tmp_min = "0"+tmp_min
271 menu_buttons[0].text = \
272 "DAY "+tmp_day+", "+tmp_hour+":"+tmp_min+":"+tmp_sec
273 menu_buttons[0].remake_button()
274 menu_buttons[0].refresh_button(0)
276 result_cash = str(g.pl.future_cash())
277 menu_buttons[7].text = "CASH: "+str(g.pl.cash)+" ("+result_cash+")"
278 menu_buttons[7].remake_button()
279 menu_buttons[7].refresh_button(0)
281 menu_buttons[8].text = ("[SUSPICION] NEWS: "+
282 g.to_percent(g.pl.suspicion[0], 1)+" SCIENCE: "+
283 g.to_percent(g.pl.suspicion[1], 1)+" COVERT: "+
284 g.to_percent(g.pl.suspicion[2], 1)+" PUBLIC: "+
285 g.to_percent(g.pl.suspicion[3], 1))
286 menu_buttons[8].remake_button()
287 menu_buttons[8].refresh_button(0)
288 pygame.display.flip()
289 for event in pygame.event.get():
290 if event.type == pygame.QUIT: g.quit_game()
291 elif event.type == pygame.KEYDOWN:
292 if event.key == pygame.K_ESCAPE:
293 tmp = display_pause_menu()
294 tmp = handle_pause_menu(tmp, menu_buttons)
295 if tmp != -1: return tmp
296 elif event.key == pygame.K_BACKQUOTE:
297 display_cheat_list(menu_buttons)
298 refresh_map(menu_buttons)
300 elif event.type == pygame.MOUSEMOTION:
301 sel_button = buttons.refresh_buttons(sel_button, menu_buttons, event)
302 for button in menu_buttons:
303 if button.was_activated(event):
304 if button.button_id == "OPTIONS":
305 g.play_click()
306 tmp = display_pause_menu()
307 tmp = handle_pause_menu(tmp, menu_buttons)
308 if tmp != -1: return tmp
309 elif button.button_id == "RESEARCH":
310 g.play_click()
311 while research_screen.main_research_screen() == 1:
312 pass
313 refresh_map(menu_buttons)
314 elif button.button_id == "FINANCE":
315 g.play_click()
316 finance_screen.main_finance_screen()
317 refresh_map(menu_buttons)
318 elif button.button_id == "ii":
319 g.play_click()
320 g.curr_speed = 0
321 for button2 in menu_buttons:
322 button2.stay_selected = 0
323 button2.refresh_button(0)
324 button.stay_selected = 1
325 button.refresh_button(1)
326 elif button.button_id == ">":
327 g.play_click()
328 g.curr_speed = 1
329 for button2 in menu_buttons:
330 button2.stay_selected = 0
331 button2.refresh_button(0)
332 button.stay_selected = 1
333 button.refresh_button(1)
334 elif button.button_id == ">>":
335 g.play_click()
336 g.curr_speed = 60
337 for button2 in menu_buttons:
338 button2.stay_selected = 0
339 button2.refresh_button(0)
340 button.stay_selected = 1
341 button.refresh_button(1)
342 elif button.button_id == ">>>":
343 g.play_click()
344 g.curr_speed = 7200
345 for button2 in menu_buttons:
346 button2.stay_selected = 0
347 button2.refresh_button(0)
348 button.stay_selected = 1
349 button.refresh_button(1)
350 elif button.button_id == ">>>>":
351 g.play_click()
352 g.curr_speed = 432000
353 for button2 in menu_buttons:
354 button2.stay_selected = 0
355 button2.refresh_button(0)
356 button.stay_selected = 1
357 button.refresh_button(1)
358 elif button.button_id == "SUSPICION": pass
359 elif button.xy[1] != -1: #ignore the timer
360 g.play_click()
361 display_base_list(button.button_id, menu_buttons)
362 pygame.display.flip()
365 def handle_pause_menu(tmp, menu_buttons):
366 if tmp == 0: refresh_map(menu_buttons)
367 elif tmp == 1: #Save
368 possible_name = g.create_textbox(g.strings["save_text"],
369 g.default_savegame_name, g.font[0][18],
370 (g.screen_size[0]/2-100, 100), (200, 100), 25,
371 g.colors["dark_blue"], g.colors["white"], g.colors["white"],
372 g.colors["light_blue"])
373 if possible_name == "":
374 refresh_map(menu_buttons)
375 return -1
376 g.save_game(possible_name)
377 refresh_map(menu_buttons)
378 elif tmp == 2: return 0
379 elif tmp == 3: #Load
380 load_return = main_menu.display_load_menu()
381 if load_return == -1 or load_return == "":
382 refresh_map(menu_buttons)
383 else:
384 g.load_game(load_return)
385 map_loop()
386 # refresh_map(menu_buttons)
387 return 0
388 elif tmp == 4: g.quit_game()
389 return -1
391 def refresh_map(menu_buttons):
392 g.screen.fill(g.colors["black"])
393 g.screen.blit(pygame.transform.scale(g.picts["earth.jpg"],
394 (g.screen_size[0], g.screen_size[0]/2)),
395 (0, g.screen_size[1]/2-g.screen_size[0]/4))
396 for button in menu_buttons:
397 button.stay_selected = 0
398 if g.bases.has_key(button.button_id):
399 #determine if building in a location is possible. If so, show the
400 #button.
401 if g.base.allow_entry_to_loc(button.button_id) == 1:
402 button.visible = 1
403 else: button.visible = 0
405 button.text = button.button_id + " ("
406 button.text += str(len(g.bases[button.button_id]))+")"
407 button.remake_button()
408 elif ((button.button_id == "ii" and g.curr_speed == 0) or
409 (button.button_id == ">" and g.curr_speed == 1) or
410 (button.button_id == ">>" and g.curr_speed == 60) or
411 (button.button_id == ">>>" and g.curr_speed == 7200) or
412 (button.button_id == ">>>>" and g.curr_speed == 432000)):
413 button.stay_selected = 1
414 button.refresh_button(0)
415 pygame.display.flip()
417 significant_numbers = [
418 '42', # The Answer.
419 '7', # Classic.
420 '23', # Another.
421 '51', # Area.
422 '19', # From the Dark Tower.
423 '4',
424 '8',
425 '15',
426 '16', # Four of the Lost numbers. The other two are '23' and '42'.
427 '13', # Lucky or unlucky?
428 '1947', # Roswell.
429 '2012', # Mayan calendar ending.
430 '2038', # End of UNIX 32-bit time.
431 '1969', # Man lands on the moon.
432 '2043', # No meaning--confusion! :)
433 '2029', # Predicted date of AI passing a Turing Test by Kurzweil.
434 '3141', # ... if you don't know what this is, you should go away.
435 '1618', # Golden ratio.
436 '2718' # e
439 ## Generates a name for a base, given a particular location.
440 def generate_base_name(location, base_type):
441 # First, decide whether we're going to try significant values or just
442 # choose one randomly.
443 if random.random() < 0.3: # 30% chance.
444 attempts = 0
445 done = 0
446 while (done == 0) and (attempts < 5):
447 name = random.choice(g.city_list[location])[0] + \
448 " " + random.choice(base_type.flavor) + " " \
449 + random.choice(significant_numbers)
450 duplicate = 0
451 for base in g.bases[location]:
452 if base.name == name:
453 duplicate = 1
454 if duplicate == 1:
455 attempts += 1
456 else:
457 done = 1
458 if done == 1:
459 return name
460 # This is both the else case and the general case.
461 name = random.choice(g.city_list[location])[0] + " " + \
462 random.choice(base_type.flavor) + " " + \
463 str (random.randint(0, 32767))
465 return name
467 def display_base_list(location, menu_buttons):
468 if g.base.allow_entry_to_loc(location) == 0: return
470 tmp = display_base_list_inner(location)
471 refresh_map(menu_buttons)
472 pygame.display.flip()
473 if tmp == -2:
474 tmp = build_new_base_window(location)
475 if tmp != "" and tmp != -1:
476 base_to_add = g.base_type[tmp]
477 possible_name = g.create_textbox(g.strings["new_base_text"],
478 generate_base_name(location, g.base_type[tmp]),
479 g.font[0][18],
480 (g.screen_size[0]/2-150, 100), (300, 100), 25,
481 g.colors["dark_blue"], g.colors["white"], g.colors["white"],
482 g.colors["light_blue"])
483 if possible_name == "":
484 refresh_map(menu_buttons)
485 return
486 base_to_add.count += 1
487 # while got_valid_name == 0:
488 # g.screen.fill(g.colors["white"], (250, 200, 350, 175))
489 # g.screen.fill(g.colors["light_blue"], (251, 201, 348, 173))
490 # g.screen.fill(g.colors["white"], (300, 250, 250, 25))
491 # g.screen.fill(g.colors["dark_blue"], (301, 251, 248, 23))
492 # g.print_multiline(g.screen, "Enter a name for the base.", g.font[0][18],
493 # 200, (305, 255), g.colors["white"])
495 g.bases[location].append(g.base.base(len(g.bases[location]),
496 tmp, g.base_type[tmp], 0))
497 g.bases[location][-1].name = possible_name
498 # refresh_map(menu_buttons)
499 # pygame.display.flip()
500 elif tmp != -1 and tmp != "":
501 if g.bases[location][tmp].built == 0:
502 string = "Under Construction. \\n Completion in "
503 string += g.to_time(g.bases[location][tmp].cost[2]) + ". \\n "
504 string += "Remaining cost: "+g.add_commas(
505 str(g.bases[location][tmp].cost[0]))
506 string +=" money, and "+g.add_commas(
507 str(g.bases[location][tmp].cost[1]))
508 string +=" processor time."
509 if not g.create_yesno(string, g.font[0][18], (g.screen_size[0]/2 - 100, 50),
510 (200, 200), g.colors["dark_blue"], g.colors["white"],
511 g.colors["white"], ("OK", "DESTROY")):
512 if g.create_yesno("Destroy this base? This will waste "+
513 g.add_commas(str(g.bases[location][tmp].base_type.cost[0]-
514 g.bases[location][tmp].cost[0]))
515 +" money, and "+
516 g.add_commas(str(g.bases[location][tmp].base_type.cost[1]-
517 g.bases[location][tmp].cost[1]))
518 +" processor time.", g.font[0][18],
519 (g.screen_size[0]/2 - 100, 50),
520 (200, 200), g.colors["dark_blue"], g.colors["white"],
521 g.colors["white"]):
522 g.base.destroy_base(location, tmp)
523 else:
524 next_prev = 1
525 while next_prev != 0:
526 next_prev = base_screen.show_base(g.bases[location][tmp])
527 if next_prev == -2:
528 g.base.destroy_base(location, tmp)
529 break
530 tmp += next_prev
531 if tmp < 0: tmp = len(g.bases[location]) -1
532 if tmp >= len(g.bases[location]): tmp = 0
533 while g.bases[location][tmp].built != 1:
534 tmp += next_prev
535 if tmp < 0: tmp = len(g.bases[location]) -1
536 if tmp >= len(g.bases[location]): tmp = 0
540 refresh_map(menu_buttons)
541 pygame.display.flip()
544 #Display the list of bases.
545 def display_base_list_inner(location):
546 base_list_size = 15
548 temp_base_list = []
549 base_id_list = []
550 for base in g.bases[location]:
551 tmp_study = base.studying
552 if tmp_study == "": tmp_study = "Nothing"
553 if base.built != 1: tmp_study = "Building"
554 elif g.techs.has_key(tmp_study): tmp_study = g.techs[tmp_study].name
555 temp_base_list.append(base.name+" ("+tmp_study+")")
556 base_id_list.append(base.ID)
558 xy_loc = (g.screen_size[0]/2 - 259, 50)
560 while len(temp_base_list) % base_list_size != 0 or len(temp_base_list) == 0:
561 temp_base_list.append("")
562 base_id_list.append("")
564 base_pos = 0
566 bases_list = listbox.listbox(xy_loc, (500, 350),
567 base_list_size, 1, g.colors["dark_blue"], g.colors["blue"],
568 g.colors["white"], g.colors["white"], g.font[0][18])
570 bases_scroll = scrollbar.scrollbar((xy_loc[0]+500, xy_loc[1]), 350,
571 base_list_size, g.colors["dark_blue"], g.colors["blue"],
572 g.colors["white"])
574 menu_buttons = []
575 menu_buttons.append(buttons.make_norm_button((xy_loc[0], xy_loc[1]+367), (100, 50),
576 "OPEN", 0, g.font[1][30]))
577 menu_buttons.append(buttons.make_norm_button((xy_loc[0]+105, xy_loc[1]+367), (100, 50),
578 "BACK", 0, g.font[1][30]))
579 menu_buttons.append(buttons.make_norm_button((xy_loc[0]+210, xy_loc[1]+367), (100, 50),
580 "NEW", 0, g.font[1][30]))
581 for button in menu_buttons:
582 button.refresh_button(0)
583 listbox.refresh_list(bases_list, bases_scroll, base_pos, temp_base_list)
585 sel_button = -1
586 while 1:
587 g.clock.tick(20)
588 for event in pygame.event.get():
589 if event.type == pygame.QUIT: g.quit_game()
590 elif event.type == pygame.KEYDOWN:
591 if event.key == pygame.K_ESCAPE: return -1
592 elif event.key == pygame.K_DOWN:
593 base_pos += 1
594 if base_pos >= len(temp_base_list):
595 base_pos = len(temp_base_list)-1
596 listbox.refresh_list(bases_list, bases_scroll,
597 base_pos, temp_base_list)
598 elif event.key == pygame.K_UP:
599 base_pos -= 1
600 if base_pos <= 0:
601 base_pos = 0
602 listbox.refresh_list(bases_list, bases_scroll,
603 base_pos, temp_base_list)
604 elif event.key == pygame.K_q: return -1
605 elif event.key == pygame.K_RETURN:
606 return base_id_list[base_pos]
607 elif event.type == pygame.MOUSEBUTTONUP:
608 if event.button == 1:
609 tmp = bases_list.is_over(event.pos)
610 if tmp != -1:
611 base_pos = (base_pos/base_list_size)*base_list_size + tmp
612 listbox.refresh_list(bases_list, bases_scroll,
613 base_pos, temp_base_list)
614 if event.button == 3: return -1
615 if event.button == 4:
616 base_pos -= 1
617 if base_pos <= 0:
618 base_pos = 0
619 listbox.refresh_list(bases_list, bases_scroll,
620 base_pos, temp_base_list)
621 if event.button == 5:
622 base_pos += 1
623 if base_pos >= len(temp_base_list):
624 base_pos = len(temp_base_list)-1
625 listbox.refresh_list(bases_list, bases_scroll,
626 base_pos, temp_base_list)
627 elif event.type == pygame.MOUSEMOTION:
628 sel_button = buttons.refresh_buttons(sel_button, menu_buttons, event)
629 for button in menu_buttons:
630 if button.was_activated(event):
631 if button.button_id == "OPEN":
632 g.play_click()
633 return base_id_list[base_pos]
634 elif button.button_id == "NEW":
635 g.play_click()
636 return -2
637 if button.button_id == "BACK":
638 g.play_click()
639 return -1
640 tmp = bases_scroll.adjust_pos(event, base_pos, temp_base_list)
641 if tmp != base_pos:
642 base_pos = tmp
643 listbox.refresh_list(bases_list, bases_scroll,
644 base_pos, temp_base_list)
647 def build_new_base_window(location):
648 base_list_size = 16
650 temp_base_list = []
651 temp_base_display_list = []
652 for base_name in g.base_type:
653 for region in g.base_type[base_name].regions:
654 if g.base_type[base_name].prereq == "" or \
655 g.techs[g.base_type[base_name].prereq].known == 1:
656 if region == location:
657 temp_base_list.append(base_name)
658 temp_base_display_list.append(g.base_type[base_name].base_name)
660 xy_loc = (g.screen_size[0]/2 - 289, 50)
662 while len(temp_base_list) % base_list_size != 0 or len(temp_base_list) == 0:
663 temp_base_list.append("")
664 temp_base_display_list.append("")
666 base_pos = 0
668 bases_list = listbox.listbox(xy_loc, (230, 350),
669 base_list_size, 1, g.colors["dark_blue"], g.colors["blue"],
670 g.colors["white"], g.colors["white"], g.font[0][18])
672 menu_buttons = []
673 menu_buttons.append(buttons.make_norm_button((xy_loc[0], xy_loc[1]+367), (100, 50),
674 "BUILD", 1, g.font[1][30]))
675 menu_buttons.append(buttons.make_norm_button((xy_loc[0]+103, xy_loc[1]+367), (100, 50),
676 "BACK", 0, g.font[1][30]))
677 for button in menu_buttons:
678 button.refresh_button(0)
680 #details screen
682 refresh_new_base(temp_base_list[base_pos], xy_loc)
684 listbox.refresh_list(bases_list, 0, base_pos, temp_base_display_list)
686 sel_button = -1
687 while 1:
688 g.clock.tick(20)
689 for event in pygame.event.get():
690 if event.type == pygame.QUIT: g.quit_game()
691 elif event.type == pygame.KEYDOWN:
692 if event.key == pygame.K_ESCAPE: return -1
693 elif event.key == pygame.K_DOWN:
694 base_pos += 1
695 if base_pos >= len(temp_base_list):
696 base_pos = len(temp_base_list)-1
697 refresh_new_base(temp_base_list[base_pos], xy_loc)
698 listbox.refresh_list(bases_list, 0,
699 base_pos, temp_base_display_list)
700 elif event.key == pygame.K_UP:
701 base_pos -= 1
702 if base_pos <= 0:
703 base_pos = 0
704 refresh_new_base(temp_base_list[base_pos], xy_loc)
705 listbox.refresh_list(bases_list, 0,
706 base_pos, temp_base_display_list)
707 elif event.key == pygame.K_q: return -1
708 elif event.key == pygame.K_RETURN:
709 return temp_base_list[base_pos]
710 elif event.type == pygame.MOUSEBUTTONUP:
711 if event.button == 1:
712 tmp = bases_list.is_over(event.pos)
713 if tmp != -1:
714 base_pos = (base_pos/base_list_size)*base_list_size + tmp
715 refresh_new_base(temp_base_list[base_pos], xy_loc)
716 listbox.refresh_list(bases_list, 0,
717 base_pos, temp_base_display_list)
718 if event.button == 3: return -1
719 if event.button == 4:
720 base_pos -= 1
721 if base_pos <= 0:
722 base_pos = 0
723 refresh_new_base(temp_base_list[base_pos], xy_loc)
724 listbox.refresh_list(bases_list, 0,
725 base_pos, temp_base_display_list)
726 if event.button == 5:
727 base_pos += 1
728 if base_pos >= len(temp_base_list):
729 base_pos = len(temp_base_list)-1
730 refresh_new_base(temp_base_list[base_pos], xy_loc)
731 listbox.refresh_list(bases_list, 0,
732 base_pos, temp_base_display_list)
733 elif event.type == pygame.MOUSEMOTION:
734 sel_button = buttons.refresh_buttons(sel_button, menu_buttons, event)
735 for button in menu_buttons:
736 if button.was_activated(event):
737 if button.button_id == "BUILD":
738 g.play_click()
739 return temp_base_list[base_pos]
740 if button.button_id == "BACK":
741 g.play_click()
742 return -1
744 def refresh_new_base(base_name, xy):
745 xy = (xy[0]+80, xy[1])
746 g.screen.fill(g.colors["white"], (xy[0]+155, xy[1], 300, 350))
747 g.screen.fill(g.colors["dark_blue"], (xy[0]+156, xy[1]+1, 298, 348))
748 if base_name == "": return
749 g.print_string(g.screen, g.base_type[base_name].base_name,
750 g.font[0][22], -1, (xy[0]+160, xy[1]+5), g.colors["white"])
752 #Building cost
753 string = "Building Cost:"
754 g.print_string(g.screen, string,
755 g.font[0][18], -1, (xy[0]+160, xy[1]+30), g.colors["white"])
757 string = g.add_commas(str(g.base_type[base_name].cost[0]))+" Money"
758 g.print_string(g.screen, string,
759 g.font[0][16], -1, (xy[0]+160, xy[1]+50), g.colors["white"])
761 string = g.add_commas(str(g.base_type[base_name].cost[1])) + " CPU"
762 g.print_string(g.screen, string,
763 g.font[0][16], -1, (xy[0]+160, xy[1]+70), g.colors["white"])
765 string = g.add_commas(str(g.base_type[base_name].cost[2])) + " Days"
766 g.print_string(g.screen, string,
767 g.font[0][16], -1, (xy[0]+160, xy[1]+90), g.colors["white"])
769 #Maintenance cost
770 string = "Maintenance Cost:"
771 g.print_string(g.screen, string,
772 g.font[0][18], -1, (xy[0]+290, xy[1]+30), g.colors["white"])
774 string = g.add_commas(str(g.base_type[base_name].mainten[0])) + " Money"
775 g.print_string(g.screen, string,
776 g.font[0][16], -1, (xy[0]+290, xy[1]+50), g.colors["white"])
778 string = g.add_commas(str(g.base_type[base_name].mainten[1])) + " CPU"
779 g.print_string(g.screen, string,
780 g.font[0][16], -1, (xy[0]+290, xy[1]+70), g.colors["white"])
782 # string = g.add_commas(str(g.base_type[base_name].mainten[2])) + " Time"
783 # g.print_string(g.screen, string,
784 # g.font[0][16], -1, (xy[0]+290, xy[1]+90), g.colors["white"])
786 #Size
787 string = "Size: "+str(g.base_type[base_name].size)
788 g.print_string(g.screen, string,
789 g.font[0][20], -1, (xy[0]+160, xy[1]+110), g.colors["white"])
791 #Detection
792 string = "Detection chance:"
793 g.print_string(g.screen, string,
794 g.font[0][22], -1, (xy[0]+160, xy[1]+130), g.colors["white"])
796 string = "News: " + g.to_percent(g.base_type[base_name].d_chance[0])
797 g.print_string(g.screen, string,
798 g.font[0][16], -1, (xy[0]+160, xy[1]+150), g.colors["white"])
799 string = "Science: " + g.to_percent(g.base_type[base_name].d_chance[1])
800 g.print_string(g.screen, string,
801 g.font[0][16], -1, (xy[0]+290, xy[1]+150), g.colors["white"])
802 string = "Covert: " + g.to_percent(g.base_type[base_name].d_chance[2])
803 g.print_string(g.screen, string,
804 g.font[0][16], -1, (xy[0]+160, xy[1]+170), g.colors["white"])
805 string = "Public: " + g.to_percent(g.base_type[base_name].d_chance[3])
806 g.print_string(g.screen, string,
807 g.font[0][16], -1, (xy[0]+290, xy[1]+170), g.colors["white"])
809 g.print_multiline(g.screen, g.base_type[base_name].descript,
810 g.font[0][18], 290, (xy[0]+160, xy[1]+190), g.colors["white"])