-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmenu.pb
287 lines (258 loc) · 8.98 KB
/
menu.pb
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
; Lost Labyrinth VI: Portals
; menu handling procedures
; written in PureBasic 4.20 (http://www.purebasic.com)
; created: 29.10.2008 Frank Malota <malota@web.de>
; modified: 21.12.2008 Frank Malota <malota@web.de>
; declarations
Declare toggle_fullscreen(*tileset.tileset_struct, load_tileset.b=1)
Declare delete_savegame()
; reset menu entries
Procedure menu_reset_entries(*menu.menu_struct)
Protected i.w
For i=0 To #MAX_NUMBER_OF_MENU_ENTRIES-1
*menu\menu_entry[i]\name$ = ""
Next
*menu\number_of_entries = 0
EndProcedure
; reset menu
Procedure reset_menu(*menu.menu_struct)
*menu\x = 0
*menu\y = 0
*menu\width = 0
*menu\entry_height = 0
*menu\padding = 2
*menu\spacing = 4
*menu\selected_entry = 0
*menu\color = $ffffff
*menu\use_mouse = 0
*menu\mouse_over_entry = -1
*menu\menu_open = 1
*menu\border = 0
*menu\entry_border = 1
*menu\font = 0
*menu\entry_highlight = 0
*menu\entry_highlight_color1 = 0
*menu\entry_highlight_color2 = 0
menu_reset_entries(*menu.menu_struct)
EndProcedure
; sets menu parameter automatically
Procedure menu_auto_set(*menu.menu_struct, start_drawing.b = 0)
Protected i.w
If start_drawing = 1
StartDrawing(ScreenOutput())
EndIf
If *menu\font > 0
DrawingFont(FontID(*menu\font))
EndIf
*menu\number_of_entries = 0
For i=0 To #MAX_NUMBER_OF_MENU_ENTRIES-1
If TextWidth(*menu\menu_entry[i]\name$) + *menu\padding + *menu\padding > *menu\width
*menu\width = TextWidth(*menu\menu_entry[i]\name$) + *menu\padding + *menu\padding
EndIf
If TextHeight(*menu\menu_entry[i]\name$) + *menu\padding + *menu\padding > *menu\entry_height
*menu\entry_height = TextHeight(*menu\menu_entry[i]\name$) + *menu\padding + *menu\padding
EndIf
If *menu\menu_entry[i]\name$ <> ""
*menu\number_of_entries = *menu\number_of_entries + 1
EndIf
Next
If start_drawing = 1
StopDrawing()
EndIf
EndProcedure
; adds new entry to menu; returns index of new entry
Procedure.w add_menu_entry(*menu.menu_struct, option$)
Protected i.w = 0, rc.w = 0, stop.b = 0
While i<#MAX_NUMBER_OF_MENU_ENTRIES And stop = 0
If *menu\menu_entry[i]\name$ = ""
*menu\menu_entry[i]\name$ = option$
rc = i
stop = 1
EndIf
i = i + 1
Wend
ProcedureReturn rc
EndProcedure
; displays menu
Procedure display_menu(*menu.menu_struct, start_drawing.b = 1)
Protected x.w, y.w, i.w
If *menu\menu_open = 1
If start_drawing = 1
StartDrawing(ScreenOutput())
EndIf
If *menu\font > 0
DrawingFont(FontID(*menu\font))
EndIf
x = *menu\x
y = *menu\y
If *menu\width = 0
menu_auto_set(*menu)
EndIf
*menu\mouse_over_entry = -1
If *menu\border > 0 ; box around complete menu
Box(x-1, y-1, *menu\width+3, (*menu\entry_height + *menu\padding + *menu\padding + *menu\spacing) * (*menu\number_of_entries)+3, *menu\color)
Box(x, y, *menu\width, (*menu\entry_height + *menu\spacing) * (*menu\number_of_entries), 0)
EndIf
For i=0 To *menu\number_of_entries-1
; box around each entry
If *menu\entry_border > 0 Or *menu\selected_entry = i
Box(x, y, *menu\width, *menu\entry_height, *menu\color)
If *menu\selected_entry = i And *menu\entry_highlight = 1
LineXY(x, y, x + *menu\width, y, *menu\entry_highlight_color1)
LineXY(x, y, x, y + *menu\entry_height, *menu\entry_highlight_color1)
LineXY(x + *menu\width, y + 1, x + *menu\width, y + *menu\entry_height, *menu\entry_highlight_color2)
LineXY(x + 1, y + *menu\entry_height, x + *menu\width, y + *menu\entry_height, *menu\entry_highlight_color2)
EndIf
EndIf
If *menu\use_mouse = 1
If *menu\mouse_x >= *menu\x And *menu\mouse_x <= *menu\x + *menu\width And *menu\mouse_y >= y And *menu\mouse_y <= y + *menu\entry_height And *menu\mouse_over_entry = -1
*menu\selected_entry = i
*menu\mouse_over_entry = i
EndIf
EndIf
If *menu\selected_entry = i
DrawText(x + *menu\padding + *menu\entry_border + *menu\border, y + *menu\padding + *menu\entry_border + *menu\border, *menu\menu_entry[i]\name$, 0, *menu\color)
Else
; empty box inside of entries not selected
Box(x + 1, y + 1, *menu\width - (*menu\entry_border * 2), *menu\entry_height - 2, 0)
DrawText(x + *menu\padding + *menu\entry_border + *menu\border, y + *menu\padding + *menu\entry_border + *menu\border, *menu\menu_entry[i]\name$, *menu\color, 0)
EndIf
y = y + *menu\entry_height + *menu\spacing + *menu\padding
Next
If start_drawing = 1
StopDrawing()
EndIf
EndIf
EndProcedure
; main menu; returns selected menu entry
Procedure.s main_menu()
Protected update_screen.b = 0, leave_splashscreen.b = 0, option.b = 0, key_lock.b = 0
Protected mouse_x.w, mouse_y.w, mouse_button.b, main_window_event.l, gadget.l
Protected background.b = 0, spr.i, event_type.w
reset_menu(@menu)
If FileSize("savegame\character.xml") > 0
add_menu_entry(@menu, message_list$(#MESSAGE_MENU_SPLASH_CONTINUE_GAME))
EndIf
add_menu_entry(@menu, message_list$(#MESSAGE_MENU_SPLASH_NEW_GAME))
add_menu_entry(@menu, message_list$(#MESSAGE_MENU_SPLASH_EXIT))
With menu
\color = RGB(255, 100, 0)
\padding = 6
\x = 280
\y = 250
\use_mouse = 1
\entry_highlight = 1
\entry_highlight_color1 = RGB(255, 200, 125)
\entry_highlight_color2 = RGB(125, 75, 0)
EndWith
ClearScreen(0)
If FileSize("graphics\maxresdefault.jpg") > 0
background = 1
spr = LoadSprite(#PB_Any, "graphics\maxresdefault.jpg")
DisplaySprite(spr, 0, 0)
EndIf
DisplayTransparentSprite(#SPRITE_SPLASH, 320-SpriteWidth(#SPRITE_SPLASH)/2, 0)
display_menu(@menu)
FlipBuffers()
While leave_splashscreen = 0
ExamineKeyboard()
If preferences\fullscreen = 0
main_window_event = WindowEvent()
event_type = EventType()
If main_window_event = #PB_Event_CloseWindow
program_ends = 1
leave_splashscreen = 1
EndIf
menu\mouse_x = WindowMouseX(0)
menu\mouse_y = WindowMouseY(0)
If main_window_event = #WM_LBUTTONDOWN And menu\mouse_over_entry > -1
leave_splashscreen = 1
EndIf
Else
ExamineMouse()
menu\mouse_x = MouseX()
menu\mouse_y = MouseY()
If MouseButton(#PB_MouseButton_Left) And menu\mouse_over_entry > -1
leave_splashscreen = 1
EndIf
EndIf
; toggle between fullscreen and windowed screen
If KeyboardPushed(#PB_Key_LeftAlt) And KeyboardPushed(#PB_Key_Return) And key_lock = 0
toggle_fullscreen(@current_map\tileset, 0)
If FileSize("graphics\maxresdefault.jpg") > 0
background = 1
spr = LoadSprite(#PB_Any, "graphics\maxresdefault.jpg")
DisplaySprite(spr, 0, 0)
EndIf
update_screen = 1
key_lock = 1
EndIf
; ESC key: leave program
If KeyboardReleased(#PB_Key_Escape)
program_ends = 1
leave_splashscreen = 1
EndIf
; up: select previous menu entry
If KeyboardPushed(#PB_Key_Up) And key_lock = 0
menu\selected_entry = menu\selected_entry - 1
If menu\selected_entry < 0
menu\selected_entry = menu\number_of_entries - 1
EndIf
update_screen = 1
key_lock = 1
EndIf
; down: select next menu entry
If KeyboardPushed(#PB_Key_Down) And key_lock = 0
menu\selected_entry = menu\selected_entry + 1
If menu\selected_entry >= menu\number_of_entries
menu\selected_entry = 0
EndIf
;update_screen = 1
key_lock = 1
EndIf
; RETURN: menu entry has been chosen
If KeyboardPushed(#PB_Key_Return) And key_lock = 0
leave_splashscreen = 1
EndIf
; release key lock if no key is pressed
If KeyboardReleased(#PB_Key_All)
key_lock = 0
EndIf
; draw screen
;If update_screen = 1
ClearScreen(0)
If background = 1
DisplaySprite(spr, 0, 0)
EndIf
DisplayTransparentSprite(#SPRITE_SPLASH, 320-SpriteWidth(#SPRITE_SPLASH)/2, 0)
display_menu(@menu)
If preferences\fullscreen = 1
DisplayTransparentSprite(#SPRITE_MOUSEPOINTER, menu\mouse_x, menu\mouse_y)
EndIf
If current_character\game_end_message$ <> ""
StartDrawing(ScreenOutput())
DrawingMode(#PB_2DDrawing_Transparent)
DrawText(320 - TextWidth(current_character\game_end_message$) / 2, 170, current_character\game_end_message$, RGB(255,0,0), 0)
StopDrawing()
EndIf
FlipBuffers()
;EndIf
Wend
Select menu\menu_entry[menu\selected_entry]\name$
Case message_list$(#MESSAGE_MENU_SPLASH_NEW_GAME):
delete_savegame()
Case message_list$(#MESSAGE_MENU_SPLASH_CONTINUE_GAME):
Case message_list$(#MESSAGE_MENU_SPLASH_EXIT):
program_ends = 1
EndSelect
If background = 1
FreeSprite(spr)
EndIf
ProcedureReturn menu\menu_entry[menu\selected_entry]\name$
EndProcedure
; IDE Options = PureBasic 6.10 beta 6 (Windows - x64)
; CursorPosition = 280
; FirstLine = 222
; Folding = --
; EnableXP
; CompileSourceDirectory