-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathui_game_menu_pulldown_item.py
More file actions
345 lines (296 loc) · 11.2 KB
/
ui_game_menu_pulldown_item.py
File metadata and controls
345 lines (296 loc) · 11.2 KB
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
# coding=utf-8
from ui_menu_pulldown_item import PulldownMenuItem, SeparatorItem, PulldownMenuData, FileQuitItem, ViewToggleCRTItem, ViewToggleCameraTiltItem, ViewSetZoomItem, ViewToggleGridItem
class GameModePulldownMenuItem(PulldownMenuItem):
# unless overridden, game mode items not allowed in art mode
art_mode_allowed = False
#
# game menu
#
class HideEditUIItem(GameModePulldownMenuItem):
label = 'Hide edit UI'
command = 'toggle_game_edit_ui'
close_on_select = True
always_active = True
class NewGameDirItem(GameModePulldownMenuItem):
label = 'New game…'
command = 'new_game_dir'
always_active = True
class SetGameDirItem(GameModePulldownMenuItem):
label = 'Open game…'
command = 'set_game_dir'
close_on_select = True
always_active = True
class PauseGameItem(GameModePulldownMenuItem):
label = 'blah'
command = 'toggle_anim_playback'
always_active = True
def get_label(app):
return ['Pause game', 'Unpause game'][app.gw.paused]
class OpenConsoleItem(GameModePulldownMenuItem):
label = 'Open dev console'
command = 'toggle_console'
close_on_select = True
always_active = True
art_mode_allowed = True
#
# state menu
#
class ResetStateItem(GameModePulldownMenuItem):
label = 'Reset to last state'
command = 'reset_game'
close_on_select = True
def should_dim(app):
return not app.gw.game_dir
class LoadStateItem(GameModePulldownMenuItem):
label = 'Load state…'
command = 'load_game_state'
close_on_select = True
def should_dim(app):
return not app.gw.game_dir
class SaveStateItem(GameModePulldownMenuItem):
label = 'Save current state'
command = 'save_current'
close_on_select = True
def should_dim(app):
return not app.gw.game_dir
class SaveNewStateItem(GameModePulldownMenuItem):
label = 'Save new state…'
command = 'save_game_state'
def should_dim(app):
return not app.gw.game_dir
#
# view menu
#
class ObjectsToCameraItem(GameModePulldownMenuItem):
label = 'Move selected object(s) to camera'
command = 'objects_to_camera'
close_on_select = True
def should_dim(app):
return len(app.gw.selected_objects) == 0
class CameraToObjectsItem(GameModePulldownMenuItem):
label = 'Move camera to selected object'
command = 'camera_to_objects'
close_on_select = True
def should_dim(app):
return len(app.gw.selected_objects) != 1
class ToggleDebugObjectsItem(GameModePulldownMenuItem):
label = ' Draw debug objects'
command = 'toggle_debug_objects'
def should_dim(app):
return not app.gw.game_dir
def should_mark(ui):
return ui.app.gw.properties and ui.app.gw.properties.draw_debug_objects
class ToggleOriginVizItem(GameModePulldownMenuItem):
label = ' Show all object origins'
command = 'toggle_all_origin_viz'
def should_dim(app):
return not app.gw.game_dir
def should_mark(ui):
return ui.app.gw.show_origin_all
class ToggleBoundsVizItem(GameModePulldownMenuItem):
label = ' Show all object bounds'
command = 'toggle_all_bounds_viz'
def should_dim(app):
return not app.gw.game_dir
def should_mark(ui):
return ui.app.gw.show_bounds_all
class ToggleCollisionVizItem(GameModePulldownMenuItem):
label = ' Show all object collision'
command = 'toggle_all_collision_viz'
def should_dim(app):
return not app.gw.game_dir
def should_mark(ui):
return ui.app.gw.show_collision_all
#
# world menu
#
class EditWorldPropertiesItem(GameModePulldownMenuItem):
label = 'Edit world properties…'
command = 'edit_world_properties'
close_on_select = True
def should_dim(app):
return not app.gw.game_dir
#
# room menu
#
class ChangeRoomItem(GameModePulldownMenuItem):
label = 'Change current room…'
command = 'change_current_room'
close_on_select = True
def should_dim(app):
return len(app.gw.rooms) == 0
class AddRoomItem(GameModePulldownMenuItem):
label = 'Add room…'
command = 'add_room'
def should_dim(app):
return not app.gw.game_dir
class SetRoomObjectsItem(GameModePulldownMenuItem):
label = 'Add/remove objects from room…'
command = 'set_room_objects'
close_on_select = True
def should_dim(app):
return app.gw.current_room is None
class RemoveRoomItem(GameModePulldownMenuItem):
label = 'Remove this room'
command = 'remove_current_room'
close_on_select = True
def should_dim(app):
return app.gw.current_room is None
class RenameRoomItem(GameModePulldownMenuItem):
label = 'Rename this room…'
command = 'rename_current_room'
def should_dim(app):
return app.gw.current_room is None
class ToggleAllRoomsVizItem(GameModePulldownMenuItem):
label = 'blah'
command = 'toggle_all_rooms_visible'
def should_dim(app):
return len(app.gw.rooms) == 0
def get_label(app):
return ['Show all rooms', 'Show only current room'][app.gw.show_all_rooms]
class ToggleListOnlyRoomObjectItem(GameModePulldownMenuItem):
label = ' List only objects in this room'
command = 'toggle_list_only_room_objects'
def should_dim(app):
return len(app.gw.rooms) == 0
def should_mark(ui):
return ui.app.gw.list_only_current_room_objects
class ToggleRoomCamerasItem(GameModePulldownMenuItem):
label = ' Camera changes with room'
command = 'toggle_room_camera_changes'
def should_dim(app):
return len(app.gw.rooms) == 0
def should_mark(ui):
return ui.app.gw.room_camera_changes_enabled
class SetRoomCameraItem(GameModePulldownMenuItem):
label = "Set this room's camera marker…"
command = 'set_room_camera_marker'
def should_dim(app):
return app.gw.current_room is None
class SetRoomEdgeDestinationsItem(GameModePulldownMenuItem):
label = "Set this room's edge warps…"
command = 'set_room_edge_warps'
def should_dim(app):
return app.gw.current_room is None
class SetRoomBoundsObject(GameModePulldownMenuItem):
label = "Set this room's edge object…"
command = 'set_room_bounds_obj'
def should_dim(app):
return app.gw.current_room is None
class AddSelectedToCurrentRoomItem(GameModePulldownMenuItem):
label = 'Add selected objects to this room'
command = 'add_selected_to_room'
def should_dim(app):
return app.gw.current_room is None or len(app.gw.selected_objects) == 0
class RemoveSelectedFromCurrentRoomItem(GameModePulldownMenuItem):
label = 'Remove selected objects from this room'
command = 'remove_selected_from_room'
def should_dim(app):
return app.gw.current_room is None or len(app.gw.selected_objects) == 0
#
# object menu
#
class SpawnObjectItem(GameModePulldownMenuItem):
label = 'Spawn object…'
command = 'choose_spawn_object_class'
close_on_select = True
def should_dim(app):
return not app.gw.game_dir
class DuplicateObjectsItem(GameModePulldownMenuItem):
label = 'Duplicate selected objects'
command = 'duplicate_selected_objects'
close_on_select = True
def should_dim(app):
return len(app.gw.selected_objects) == 0
class SelectObjectsItem(GameModePulldownMenuItem):
label = 'Select objects…'
command = 'select_objects'
close_on_select = True
def should_dim(app):
return not app.gw.game_dir
class EditArtForObjectsItem(GameModePulldownMenuItem):
label = 'Edit art for selected…'
command = 'edit_art_for_selected_objects'
close_on_select = True
def should_dim(app):
return len(app.gw.selected_objects) == 0
class SetObjectRoomsItem(GameModePulldownMenuItem):
label = 'Add/remove this object from rooms…'
command = 'set_object_rooms'
close_on_select = True
def should_dim(app):
return len(app.gw.selected_objects) != 1
class DeleteSelectedObjectsItem(GameModePulldownMenuItem):
label = 'Delete selected object(s)'
command = 'erase_selection_or_art'
close_on_select = True
def should_dim(app):
return len(app.gw.selected_objects) == 0
class GameMenuData(PulldownMenuData):
items = [HideEditUIItem, OpenConsoleItem, SeparatorItem,
NewGameDirItem, SetGameDirItem, PauseGameItem, SeparatorItem,
FileQuitItem]
class GameStateMenuData(PulldownMenuData):
items = [ResetStateItem, LoadStateItem, SaveStateItem, SaveNewStateItem]
class GameViewMenuData(PulldownMenuData):
items = [ViewToggleCRTItem, ViewToggleGridItem, SeparatorItem,
ViewSetZoomItem, ViewToggleCameraTiltItem, SeparatorItem,
ObjectsToCameraItem, CameraToObjectsItem, ToggleDebugObjectsItem,
ToggleOriginVizItem, ToggleBoundsVizItem, ToggleCollisionVizItem]
def should_mark_item(item, ui):
if hasattr(item, 'should_mark'):
return item.should_mark(ui)
return False
class GameWorldMenuData(PulldownMenuData):
items = [EditWorldPropertiesItem]
class GameRoomMenuData(PulldownMenuData):
items = [ChangeRoomItem, AddRoomItem, RemoveRoomItem, RenameRoomItem,
ToggleAllRoomsVizItem, ToggleListOnlyRoomObjectItem, ToggleRoomCamerasItem, SeparatorItem,
AddSelectedToCurrentRoomItem, RemoveSelectedFromCurrentRoomItem,
SetRoomObjectsItem, SeparatorItem,
SetRoomCameraItem, SetRoomEdgeDestinationsItem, SetRoomBoundsObject,
SeparatorItem
]
def should_mark_item(item, ui):
"show checkmark for current room"
if not ui.app.gw.current_room:
return False
if hasattr(item, 'should_mark'):
return item.should_mark(ui)
return ui.app.gw.current_room.name == item.cb_arg
def get_items(app):
items = []
if len(app.gw.rooms) == 0:
return items
# TODO: this is almost c+p'd from LayerMenuData, generalize it
# first determine longest line to set width of items
longest_line = 0
for room_name in app.gw.rooms:
if len(room_name) > longest_line:
longest_line = len(room_name)
# check non-generated menu items too
for item in GameRoomMenuData.items:
if len(item.label) + 1 > longest_line:
longest_line = len(item.label) + 1
# cap at max allowed line length
for room_name,room in app.gw.rooms.items():
class TempMenuItemClass(GameModePulldownMenuItem): pass
item = TempMenuItemClass
# leave spaces for mark
item.label = ' %s' % room_name
# pad, put Z depth on far right
item.label = item.label.ljust(longest_line)
# trim to keep below a max length
item.label = item.label[:longest_line]
# tell PulldownMenu's button creation process not to auto-pad
item.no_pad = True
item.command = 'change_current_room_to'
item.cb_arg = room_name
items.append(item)
# sort room list alphabetically so it's stable, if arbitrary
items.sort(key=lambda item: item.label, reverse=False)
return items
class GameObjectMenuData(PulldownMenuData):
items = [SpawnObjectItem, DuplicateObjectsItem, SeparatorItem,
SelectObjectsItem, EditArtForObjectsItem, SetObjectRoomsItem,
DeleteSelectedObjectsItem]