@@ -175,9 +175,99 @@ function add_score(player)
175175 Log .info (" Added score to player! ID:" .. pc .id .. " NewScore: " .. new_score )
176176end
177177
178+ local main_menu_doc
179+ local p1_status
180+ local p2_status
181+ local main_menu
182+ local lobby
183+ local btn_start
184+
185+ function load_rmlui (scene )
186+ local ui_document_path = vfs :resolve_physical_dir (WORKING_DIR , " UI/main_menu.rml" )
187+ local rml_main_context = rmlui .contexts [' main' ]
188+ main_menu_doc = rml_main_context :LoadDocument (ui_document_path )
189+ main_menu_doc :Show ()
190+
191+ main_menu = main_menu_doc :GetElementById (" main_menu" )
192+ lobby = main_menu_doc :GetElementById (" lobby" )
193+ p1_status = main_menu_doc :GetElementById (" p1_status" )
194+ p2_status = main_menu_doc :GetElementById (" p2_status" )
195+ btn_start = main_menu_doc :GetElementById (" btn_start" )
196+
197+ main_menu_doc :GetElementById (" btn_local_coop" ):AddEventListener (" click" , function ()
198+ main_menu .style .display = ' none'
199+ lobby .style .display = ' flex'
200+ current_state = GameState .Lobby
201+ end )
202+
203+ main_menu_doc :GetElementById (" btn_back" ):AddEventListener (" click" , function ()
204+ p1_ready = false
205+ p2_ready = false
206+
207+ -- Reset UI text and colors
208+ p1_status .inner_rml = " Player 1: Press Up/Down to Ready"
209+ p1_status :SetClass (" ready" , false )
210+ p1_status :SetClass (" not-ready" , true )
211+
212+ p2_status .inner_rml = " Player 2: Press W/S to Ready"
213+ p2_status :SetClass (" ready" , false )
214+ p2_status :SetClass (" not-ready" , true )
215+
216+ btn_start .style .display = ' none'
217+
218+ lobby .style .display = ' none'
219+ main_menu .style .display = ' flex'
220+ current_state = GameState .MainMenu
221+ end )
222+
223+ main_menu_doc :GetElementById (" btn_exit" ):AddEventListener (" click" , function ()
224+ App :get ():should_stop ()
225+ end )
226+
227+ main_menu_doc :GetElementById (" btn_start" ):AddEventListener (" click" , function ()
228+ start_match (scene )
229+ end )
230+ end
231+
232+ function on_scene_update (scene )
233+ local input = App .mod .Input
234+ if input :get_key_pressed (KeyCode .R ) then
235+ main_menu_doc :Close ()
236+ load_rmlui (scene )
237+ end
238+
239+
240+ if current_state == GameState .Lobby then
241+ local state_changed = false
242+
243+ if not p1_ready and (input :get_key_pressed (KeyCode .Up ) or input :get_key_pressed (KeyCode .Down )) then
244+ p1_ready = true
245+ p1_status .inner_rml = " Player 1: READY"
246+ p1_status :SetClass (" not-ready" , false )
247+ p1_status :SetClass (" ready" , true )
248+ state_changed = true
249+ end
250+
251+ if not p2_ready and (input :get_key_pressed (KeyCode .W ) or input :get_key_pressed (KeyCode .S )) then
252+ p2_ready = true
253+ p2_status .inner_rml = " Player 2: READY"
254+ p2_status :SetClass (" not-ready" , false )
255+ p2_status :SetClass (" ready" , true )
256+ state_changed = true
257+ end
258+
259+ -- If someone just readied up, check if we should show the Start button
260+ if state_changed and p1_ready and p2_ready then
261+ btn_start .style .display = ' block'
262+ end
263+ end
264+ end
265+
178266function on_scene_start (scene )
179267 Assets .load_assets (WORKING_DIR )
180268
269+ load_rmlui (scene )
270+
181271 scene
182272 :world ()
183273 :system (" ball_system" , { Core .TransformComponent , Components .BallComponent }, { flecs .OnUpdate }, function (it )
@@ -238,78 +328,6 @@ function on_scene_start(scene)
238328 end )
239329end
240330
241- function on_scene_render (scene , extent , format )
242- ImGui .PushFont (30 )
243-
244- if current_state == GameState .MainMenu then
245- -- MAIN MENU UI
246- UI .center_next_window (ImGuiCond .Always )
247- if ImGui .Begin (" Main Menu" , true , ImGuiWindowFlags .AlwaysAutoResize + ImGuiWindowFlags .NoDecoration ) then
248- ImGui .TextUnformatted (" Welcome to Pong!" )
249- ImGui .Separator ()
250-
251- if ImGui .Button (" Local Co-Op" ) then
252- current_state = GameState .Lobby
253- end
254- if ImGui .Button (" Quit Game" ) then
255- App :get ():should_stop ()
256- end
257- end
258- ImGui .End ()
259- elseif current_state == GameState .Lobby then
260- -- LOBBY UI
261- UI .center_next_window (ImGuiCond .Always )
262- if ImGui .Begin (" Local Co-Op Lobby" , true , ImGuiWindowFlags .AlwaysAutoResize + ImGuiWindowFlags .NoDecoration ) then
263- -- Check for inputs to ready up
264- local input = App .mod .Input
265- if input :get_key_pressed (KeyCode .Up ) or input :get_key_pressed (KeyCode .Down ) then
266- p1_ready = true
267- end
268- if input :get_key_pressed (KeyCode .W ) or input :get_key_pressed (KeyCode .S ) then
269- p2_ready = true
270- end
271-
272- -- Display status
273- if p1_ready then
274- ImGui .TextColored (0 , 1 , 0 , 1 , " Player 1: READY" )
275- else
276- ImGui .TextColored (1 , 0 , 0 , 1 , " Player 1: Press Up/Down to Ready" )
277- end
278-
279- if p2_ready then
280- ImGui .TextColored (0 , 1 , 0 , 1 , " Player 2: READY" )
281- else
282- ImGui .TextColored (1 , 0 , 0 , 1 , " Player 2: Press W/S to Ready" )
283- end
284-
285- ImGui .Separator ()
286-
287- if p1_ready and p2_ready then
288- if ImGui .Button (" Start Match!" ) then
289- start_match (scene )
290- end
291- end
292-
293- if ImGui .Button (" Back" ) then
294- p1_ready = false
295- p2_ready = false
296- current_state = GameState .MainMenu
297- end
298- end
299- ImGui .End ()
300-
301- elseif current_state == GameState .Playing then
302- -- PLAYING UI
303- if ImGui .Begin (" Player Score Debug View" , true , ImGuiWindowFlags .NoDecoration ) then
304- ImGui .TextUnformatted (" Player 1: " .. player1 :get_mut (Components .PlayerComponent ).score )
305- ImGui .TextUnformatted (" Player 2: " .. player2 :get_mut (Components .PlayerComponent ).score )
306- end
307- ImGui .End ()
308- end
309-
310- ImGui .PopFont ()
311- end
312-
313331function on_contact_added (scene , body1 , body2 )
314332 local ball_body = nil
315333 local paddle_body = nil
0 commit comments