forked from oahassan/way-of-the-stick
/
stageselect.py
135 lines (104 loc) · 4.23 KB
/
stageselect.py
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
import os
from glob import glob
import pygame
import wotsuievents
import stage
import button
import gamestate
import versusmode
import splash
from stageselectui import StageSelector, StartMatchLabel, SelectStageBackground
loaded = False
exit_button = None
UI_objects = None
player_data = None
class StageSelectUI():
def __init__(self, stages):
self.background = None
self.stage_selector = StageSelector(stages, (250, 50))
self.title_label = button.Label((10,15), "Select Stage", (255,255,255), button.FONT_SIZES[7])
self.start_match_label = StartMatchLabel()
self.start_match_label_draw_timer = 0
self.start_match_label_draw_timeout = 500
def stage_selected(self):
return self.stage_selector.selected_thumbnail != None
def load(input_player_data):
global loaded
global exit_button
global UI_objects
global player_data
exit_button = button.ExitButton()
loaded = True
if UI_objects == None:
UI_objects = StageSelectUI(get_stage_data())
player_data = input_player_data
UI_objects.background = SelectStageBackground(player_data)
def unload():
global loaded
global exit_button
exit_button = None
loaded = False
def clear_data():
global UI_objects
UI_objects = None
def get_stage_data():
stage_list = []
for file_path in glob(os.path.join(".", stage.STAGE_DIR_NM, "*.stg")):
if os.path.isfile(file_path):
try:
loaded_stage = stage.load_from_JSON(file_path)
stage_list.append(loaded_stage)
except:
print("unable to load stage: " + file_path)
if len(stage_list) == 0:
stage_list.append(stage.load_default_stage())
return stage_list
def handle_events():
global UI_objects
global loaded
global exit_button
global player_data
if loaded == False:
load()
if pygame.MOUSEBUTTONDOWN in wotsuievents.event_types:
if exit_button.contains(wotsuievents.mouse_pos):
exit_button.handle_selected()
if pygame.MOUSEBUTTONUP in wotsuievents.event_types:
if exit_button.selected:
exit_button.handle_deselected()
if exit_button.contains(wotsuievents.mouse_pos):
gamestate.mode = gamestate.Modes.VERSUSMOVESETSELECT
unload()
clear_data()
if loaded:
gamestate.screen.blit(UI_objects.background.surface, (0,0))
exit_button.draw(gamestate.screen)
UI_objects.stage_selector.draw(gamestate.screen)
UI_objects.title_label.draw(gamestate.screen)
UI_objects.stage_selector.handle_events()
if UI_objects.stage_selected():
if UI_objects.start_match_label_draw_timer >= UI_objects.start_match_label_draw_timeout:
UI_objects.start_match_label.draw(gamestate.screen)
else:
UI_objects.start_match_label_draw_timer += gamestate.time_passed
if ((UI_objects.stage_selector.contains(wotsuievents.mouse_pos) and
pygame.MOUSEMOTION in wotsuievents.event_types) or
pygame.K_UP in wotsuievents.keys_pressed or
pygame.K_DOWN in wotsuievents.keys_pressed):
UI_objects.start_match_label_draw_timer = 0
UI_objects.start_match_label.hide()
if (pygame.K_KP_ENTER in wotsuievents.keys_pressed or
pygame.K_RETURN in wotsuievents.keys_pressed):
gamestate.screen.fill((0,0,0))
splash.draw_loading_splash()
gamestate.stage = UI_objects.stage_selector.selected_thumbnail.stage
versusmode.init(player_data)
#versusmode.local_state.init_recording(
# player1_moveset_select.selected_moveset.name,
# player2_moveset_select.selected_moveset.name
#)
unload()
gamestate.mode = gamestate.Modes.VERSUSMODE
else:
UI_objects.start_match_label_draw_timer = 0
UI_objects.start_match_label.hide()