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 main menu upon startup.
21 from os
import path
, listdir
31 #Displays the main menu. Returns 0 (new game), 1 (load game), or 2 (quit).
32 def display_main_menu():
33 g
.screen
.fill(g
.colors
["black"])
34 x_loc
= g
.screen_size
[0]/2 - 100
36 menu_buttons
.append(buttons
.make_norm_button((x_loc
, 150), (200, 50),
37 "NEW GAME", 0, g
.font
[1][30]))
38 menu_buttons
.append(buttons
.make_norm_button((x_loc
, 250), (200, 50),
39 "LOAD GAME", 0, g
.font
[1][30]))
40 menu_buttons
.append(buttons
.make_norm_button((x_loc
, 350), (200, 50),
41 "QUIT", 0, g
.font
[1][30]))
42 g
.print_string(g
.screen
, "ENDGAME: SINGULARITY", g
.font
[1][40], -1,
43 (x_loc
+100, 15), g
.colors
["dark_red"], 1)
45 for button
in menu_buttons
:
46 button
.refresh_button(0)
53 for event
in pygame
.event
.get():
54 if event
.type == pygame
.QUIT
: g
.quit_game()
55 elif event
.type == pygame
.KEYDOWN
:
56 if event
.key
== pygame
.K_ESCAPE
: return 2
57 elif event
.type == pygame
.MOUSEMOTION
:
58 sel_button
= buttons
.refresh_buttons(sel_button
, menu_buttons
, event
)
59 for button
in menu_buttons
:
60 if button
.was_activated(event
):
61 if button
.button_id
== "NEW GAME":
65 elif button
.button_id
== "LOAD GAME":
68 if button
.button_id
== "QUIT":
72 def display_load_menu():
74 xy_loc
= (g
.screen_size
[0]/2 - 109, 50)
76 save_dir
= g
.get_save_folder()
79 temp_saves_array
= listdir(save_dir
)
80 for save_name
in temp_saves_array
:
81 if save_name
[0] != "." and save_name
!= "CVS":
82 # If it's a new-style save, trim the .sav bit.
83 if len (save_name
) > 4 and save_name
[-4:] == ".sav":
84 save_name
= save_name
[:-4]
85 if save_name
not in saves_array
:
86 saves_array
.append(save_name
)
88 while len(saves_array
) % load_list_size
!= 0 or len(saves_array
) == 0:
89 saves_array
.append("")
95 saves_list
= listbox
.listbox(xy_loc
, (200, 350),
96 load_list_size
, 1, g
.colors
["dark_blue"], g
.colors
["blue"],
97 g
.colors
["white"], g
.colors
["white"], g
.font
[0][20])
99 saves_scroll
= scrollbar
.scrollbar((xy_loc
[0]+200, xy_loc
[1]), 350,
100 load_list_size
, g
.colors
["dark_blue"], g
.colors
["blue"],
104 menu_buttons
.append(buttons
.make_norm_button((xy_loc
[0], xy_loc
[1]+367), (100, 50),
105 "LOAD", 0, g
.font
[1][30]))
106 menu_buttons
.append(buttons
.make_norm_button((xy_loc
[0]+118, xy_loc
[1]+367),
107 (100, 50), "BACK", 0, g
.font
[1][30]))
108 for button
in menu_buttons
:
109 button
.refresh_button(0)
111 listbox
.refresh_list(saves_list
, saves_scroll
, saves_pos
, saves_array
)
116 for event
in pygame
.event
.get():
117 if event
.type == pygame
.QUIT
: g
.quit_game()
118 elif event
.type == pygame
.KEYDOWN
:
119 if event
.key
== pygame
.K_ESCAPE
: return -1
120 elif event
.key
== pygame
.K_DOWN
:
122 if saves_pos
>= len(saves_array
):
123 saves_pos
= len(saves_array
)-1
124 listbox
.refresh_list(saves_list
, saves_scroll
,
125 saves_pos
, saves_array
)
126 elif event
.key
== pygame
.K_UP
:
130 listbox
.refresh_list(saves_list
, saves_scroll
,
131 saves_pos
, saves_array
)
132 elif event
.key
== pygame
.K_q
: return -1
133 elif event
.key
== pygame
.K_RETURN
:
134 return saves_array
[saves_pos
]
135 elif event
.type == pygame
.MOUSEBUTTONUP
:
136 if event
.button
== 1:
137 tmp
= saves_scroll
.is_over(event
.pos
)
145 if saves_pos
>= len(saves_array
):
146 saves_pos
= len(saves_array
) - 1
148 saves_pos
-= load_list_size
152 saves_pos
+= load_list_size
153 if saves_pos
>= len(saves_array
) - 1:
154 saves_pos
= len(saves_array
) - 1
155 listbox
.refresh_list(saves_list
, saves_scroll
,
156 saves_pos
, saves_array
)
158 tmp
= saves_list
.is_over(event
.pos
)
160 saves_pos
= (saves_pos
/load_list_size
)*load_list_size \
162 listbox
.refresh_list(saves_list
, saves_scroll
,
163 saves_pos
, saves_array
)
165 if event
.button
== 4:
169 listbox
.refresh_list(saves_list
, saves_scroll
,
170 saves_pos
, saves_array
)
171 if event
.button
== 5:
173 if saves_pos
>= len(saves_array
):
174 saves_pos
= len(saves_array
)-1
175 listbox
.refresh_list(saves_list
, saves_scroll
,
176 saves_pos
, saves_array
)
177 elif event
.type == pygame
.MOUSEMOTION
:
178 sel_button
= buttons
.refresh_buttons(sel_button
, menu_buttons
, event
)
179 for button
in menu_buttons
:
180 if button
.was_activated(event
):
181 if button
.button_id
== "LOAD":
183 return saves_array
[saves_pos
]
184 elif button
.button_id
== "BACK":
187 tmp
= saves_scroll
.adjust_pos(event
, saves_pos
, saves_array
)
190 listbox
.refresh_list(saves_list
, saves_scroll
, saves_pos
,