indexing description: "lets the user set an image and a number of parts and starts the game with these parameters" author: "Markus Neidhart and UC Team" date: "$Date$" revision: "$Revision$" class NEW_GAME inherit MENU redefine initialize_scene end EM_SHARED_BITMAP_FACTORY undefine copy, is_equal, default_create end feature -- Initialize save: UC_SAVE_PUZZLE initialize_scene is -- Initialize the scene local bitmap: EM_BITMAP title: EM_STRING do Precursor -- Build the menu entries create menu_entries.make (1, 1) menu_entries.put (create {EM_STRING}.make ("Back", normal_font), 1) menu_entries.item (1).set_x_y (512 - menu_entries.item (1).width // 2, 650) -- Build the background bitmap_factory.create_empty_bitmap (width, height) check todo_proper_error_handling: bitmap_factory.last_bitmap /= Void end bitmap := bitmap_factory.last_bitmap bitmap.fill (uc_background_color) bitmap.set_x_y (1, 1) scene.extend (bitmap) selected_nr := 1 menu_entries.item (selected_nr).set_font (select_font) add_menu_entries_to_scene -- Build the title create title.make ("Start your puzzle!", normal_font) scene.extend (title) title.set_x_y ((width - title.width) // 2, 10) -- Build the image input field create title.make ("Image:", normal_font) scene.extend (title) title.set_x_y (150, 250) create text_field.make (event_loop) --text_field.start_cursor_animation scene.extend (text_field) text_field.set_x_y (500, 262) -- Build the number input field create title.make ("Number:", normal_font) scene.extend (title) title.set_x_y (150, 350) create text_field2.make (event_loop) --text_field2.start_cursor_animation scene.extend (text_field2) text_field2.set_x_y (500, 362) -- Build the `start'-Button create start_button.make_with_name ("Start Puzzle", event_loop) scene.extend (start_button) start_button.set_x_y (150, 450) -- build the error message create error_string.make ("", uc_gui_elements_default_font) scene.extend(error_string) error_string.set_x_y (150, 200) -- subscribe the event for saving the puzzle -- text_field.return_key_pressed_event.subscribe (agent save_puzzle) start_button.button_clicked_event.subscribe (agent start_button_clicked) end feature {NONE} -- Implementation situation: PUZZLE_START_WINDOW -- actual situation, will be set in UC_INTERFACE, which have it as last_scene text_field: TEXT_FIELD text_field2:TEXT_FIELD start_button: BUTTON psw: PUZZLE_START_WINDOW feature {NONE} -- Event handler start_button_clicked is -- click on start button local error_code : INTEGER file_name : STRING do file_name := "image/" file_name.append (text_field.value) error_code := input_check if error_code = 0 then -- check wheter the user input is usable event_loop.stop create psw psw.set_image_file_name (file_name) psw.set_number_of_parts (text_field2.value.to_integer) next_scene := psw psw.set_initialized (False) else -- input was somehow wrong, reset and display information error_message(error_code) end end on_select is -- Set the `next_scene' according to `selected_nr' here local menu: MENU do if selected_nr = 1 then -- Back menu ?= last_scene menu.set_next_scene (Void) menu.restart_event_loop menu.empty_main_container next_scene := last_scene end end feature -- Input checking input_check : INTEGER is -- checks given input and returns error_code local file_name : STRING directory: DIRECTORY do if text_field.value.is_empty or text_field2.value.is_empty then result := 1 elseif not text_field2.value.is_integer then result := 2 else file_name := text_field.value create directory.make_open_read ("image/") if (directory.has_entry (file_name)) then file_name.prepend ("image/") directory.close bitmap_factory.create_bitmap_from_image (file_name) result := 0 else result := 3 end end end error_message(error_code: INTEGER) is -- put error message to given error_code on screen local a_message : STRING -- this is the error message do inspect error_code when 1 then a_message := "Please fill in all fields" when 2 then a_message := "Number must be an Integer" when 3 then a_message := "Image not found (must be in ./image) or corrupt" else a_message := "" end error_string.set_value (a_message) end error_string : EM_STRING -- this is the error message end -- class NEW_GAME