indexing description: "[ Scene that asks the user to enter a new name and score that will be added to the local highscore ]" date: "$Date$" revision: "$Revision$" class NEW_ENTRY_SCENE inherit EM_WIDGET_SCENE redefine initialize_scene end SHARED_HIGHSCORE create make_widget_scene feature -- Initialization initialize_scene is -- initialize the scene local do Precursor set_frame_counter_visibility (true) set_background_color (theme_colors.window_background) setup_widgets end feature -- Events on_ok is -- handle click on 'ok' button do if highscore.is_valid_string (name_box.text) and score_box.text.is_integer then highscore.add_or_update_entry (name_box.text, score_box.text.to_integer) highscore.sort_local_by_score (false) highscore.crop_local (highscore.num_of_local_entries) set_next_scene (create {LOCAL_HIGHSCORE_SCENE}.make_widget_scene) start_next_scene end end on_skip is -- handle click on 'skip' button do set_next_scene (create {LOCAL_HIGHSCORE_SCENE}.make_widget_scene) start_next_scene end on_name_box_changed is -- Check if the newly put character is valid. If not, remote if local new_char: CHARACTER do if name_box.cursor_position > 0 then new_char := name_box.text.item (name_box.cursor_position) if not highscore.is_valid_character (new_char) then name_box.delete_character_left_of_cursor end if name_box.text.count > 10 then name_box.delete_character_left_of_cursor end end end on_score_box_changed is -- Check if newly added character is a digit. If not, remove it local new_char: CHARACTER do if score_box.cursor_position > 0 then new_char := score_box.text.item (score_box.cursor_position) if not new_char.is_digit then score_box.delete_character_left_of_cursor end if score_box.text.count > 5 then score_box.delete_character_left_of_cursor end end end feature {NONE} -- Implementation setup_widgets is -- setup the widgets for the scene do create title.make_from_text ("Add new entry") title.set_position (100, 50) add_widget (title) create name_label.make_from_text ("Enter your name:") name_label.set_position (100, 180) create name_box.make_from_size (10) name_box.set_position (100, 200) name_box.text_changed_event.subscribe (agent on_name_box_changed) create score_label.make_from_text ("Enter your score:") score_label.set_position (100, 230) create score_box.make_from_size (5) score_box.set_position (100, 250) score_box.text_changed_event.subscribe (agent on_score_box_changed) create ok_button.make_from_dimension (180, 40) ok_button.set_position (100, 400) ok_button.set_text ("Ok") ok_button.clicked_event.subscribe (agent on_ok) create skip_button.make_from_dimension (180, 40) skip_button.set_position (300, 400) skip_button.set_text ("Skip") skip_button.clicked_event.subscribe (agent on_skip) add_widget (name_label) add_widget (name_box) add_widget (score_label) add_widget (score_box) add_widget (ok_button) add_widget (skip_button) end name_label: EM_LABEL name_box: EM_TEXTBOX score_label: EM_LABEL score_box: EM_TEXTBOX title: EM_LABEL ok_button: EM_BUTTON skip_button: EM_BUTTON end