indexing description: "[ Local High Score ]" date: "$Date$" revision: "$Revision$" class BB_LOCAL_HIGHSCORE inherit BB_HIGHSCORE create make, make_with_new_entry feature -- Initialization make is -- initialize menu local button: BB_MENU_BUTTON do init_menu highscore.set_local_file ("./", "highscore.hig") highscore.read_local highscore_list := highscore.local_highscore add_highscore_list create button.make ("Back") button.pressed_event.subscribe (agent back_button_pressed) button.set_position (100, 550) add_button (button) create button.make ("Online") button.pressed_event.subscribe (agent online_button_pressed) button.set_position (bb_window_width - 100 - button.width, 550) add_button (button) set_selected_menu_item (1) end make_with_new_entry (a_score: INTEGER) is -- initialize menu with name entry do init_menu score := a_score highscore.set_local_file ("./", "highscore.hig") highscore.read_local -- the player is entried in the local highscore if highscore.local_highscore.count < number_of_entries or highscore.local_highscore.last.score < score then create status_message.make_from_text ("Please enter your name") status_message.set_font (highscore_font) status_message.resize_to_optimal_dimension status_message.set_position (bb_window_width // 2 - status_message.width // 2, bb_window_height // 2 - 25) create nickname_textbox.make_from_size (Maximum_nickname_length + 3) nickname_textbox.set_position (bb_window_width // 2 - nickname_textbox.width // 2, bb_window_height // 2) nickname_textbox.set_text (bb_settings.nickname) nickname_textbox.set_changed nickname_textbox.text_changed_event.subscribe (agent on_nickname_changed) add_widget (nickname_textbox) create ok_button.make ("Ok") ok_button.set_font (highscore_font) ok_button.resize_to_optimal_dimension ok_button.set_position (bb_window_width // 2 - ok_button.width // 2, bb_window_height // 2 + 25) ok_button.pressed_event.subscribe (agent ok_button_pressed) add_button (ok_button) set_selected_menu_item (1) else highscore_list := highscore.local_highscore add_highscore_list set_next_scene (create {BB_LOCAL_HIGHSCORE}.make) start_next_scene end end feature -- Events ok_button_pressed is -- ok button was pressed local difficulty_array: ARRAY [STRING] button: BB_MENU_BUTTON do if nickname_textbox.text.count > 0 and nickname_textbox.text.count <= Maximum_nickname_length and ok_button.is_visible then ok_button.hide nickname_textbox.hide status_message.hide bb_settings.set_nickname (nickname_textbox.text.out) bb_settings.write_user_settings make_nickname_highscore_compatible create difficulty_array.make (1, 1) difficulty_array.put (bb_settings.difficulty.out, 1) highscore.add_entry_extended (nickname_textbox.text, score, difficulty_array) highscore.sort_local_by_score (False) highscore.crop_local (Number_of_entries) highscore.write_local highscore_list := highscore.local_highscore add_highscore_list create button.make ("Back") button.pressed_event.subscribe (agent back_button_pressed) button.set_position (100, 550) add_button (button) create button.make ("Online") button.pressed_event.subscribe (agent online_button_pressed) button.set_position (bb_window_width - 100 - button.width, 550) add_button (button) set_selected_menu_item (2) end end on_nickname_changed is -- nickname changed do if nickname_textbox.text.count > maximum_nickname_length then nickname_textbox.set_cursor_position (maximum_nickname_length) nickname_textbox.text.keep_head (maximum_nickname_length) nickname_textbox.set_changed end end online_button_pressed is -- online button was pressed do set_next_scene (create {BB_REMOTE_HIGHSCORE}.make) start_next_scene end feature {NONE} -- Implementation status_message: EM_LABEL -- status message nickname_textbox: EM_TEXTBOX -- textbox to enter the nickname ok_button: BB_MENU_BUTTON -- button to finish the name entry score: INTEGER -- score of entry to add feature {NONE} -- Implementation make_nickname_highscore_compatible is -- switch every ' ' into a '_' and delete every other non-alpha-numeric character local new_nickname: STRING i,j: INTEGER do nickname_textbox.set_cursor_position (0) create new_nickname.make_filled (' ', nickname_textbox.text.count) from i := 1 j := 1 until i > nickname_textbox.text.count loop if nickname_textbox.text.item (i) = ' ' then new_nickname.put ('_', j) j := j + 1 elseif nickname_textbox.text.item (i).is_alpha_numeric then new_nickname.put (nickname_textbox.text.item (i), j) j := j + 1 end i := i + 1 end new_nickname.keep_head (j - 1) nickname_textbox.set_text (new_nickname) nickname_textbox.set_changed end end