indexing description: "[ MENU contains functionalities used by all menus in the game. ]" author: "Benno Baumgartner, benno@student.ethz.ch, Mouse-Support by Stefan Hildenbrand and Team UC" date: "$Date$" revision: "$Revision$" deferred class MENU inherit EM_DRAWABLE_SCENE redefine handle_key_down_event, handle_mouse_motion_event, handle_mouse_button_up_event, initialize_scene end UC_SHARED_ITEMS undefine default_create end feature initialize_scene is -- Initialize the scene local bitmap: EM_BITMAP titel,titel2: EM_STRING do make_scene scene := main_container -- Build the fonts bitmap_factory.create_bitmap_from_image ("./image/comic_selected_s.png") check todo_proper_error_handling: bitmap_factory.last_bitmap /= Void end bitmap := bitmap_factory.last_bitmap create select_font.make (bitmap) bitmap_factory.create_bitmap_from_image ("./image/comic.png") check todo_proper_error_handling: bitmap_factory.last_bitmap /= Void end bitmap := bitmap_factory.last_bitmap create normal_font.make (bitmap) -- Build background number one 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) -- Build the title create titel.make ("Under", normal_font) titel.set_x_y ((width - titel.width) // 2,1) scene.extend (titel) create titel2.make ("Construction", normal_font) titel2.set_x_y ((width - titel2.width) // 2,45) scene.extend (titel2) create key_codes end feature {NONE} -- Event handler handle_key_down_event (a_keyboard_event: EM_KEYBOARD_EVENT) is -- Handle keyboard events. do if a_keyboard_event.key = key_codes.sdlk_down then selected_nr := selected_nr + 1 if selected_nr > menu_entries.count then selected_nr := 1 end update_menu_entries end if a_keyboard_event.key = key_codes.sdlk_up then selected_nr := selected_nr - 1 if selected_nr < 1 then selected_nr := menu_entries.count end update_menu_entries end if a_keyboard_event.key = key_codes.sdlk_return then event_loop.stop on_select end -- quit on escape if a_keyboard_event.key = key_codes.sdlk_escape then quit end end handle_mouse_motion_event (mme: EM_MOUSEMOTION_EVENT) is -- handle mouse motion local i : INTEGER -- local variable mouse_y : INTEGER do mouse_y := mme.y -- transform coords of mouse event for menue entries from i := menu_entries.count until i <= 1 or mouse_y > menu_entries.item(i).bounding_box.upper_bound -- loop as long as there are elements in the list. -- but stop when the mouse is below the upper bound of an menu_entry loop i := i-1 end -- now we are either at the first menu entry or at the one, where the mouse points to selected_nr := i update_menu_entries end handle_mouse_button_up_event (a_mouse_button_event: EM_MOUSEBUTTON_EVENT) is -- handle mouse click do if a_mouse_button_event.is_left_button and a_mouse_button_event.y < menu_entries.item(selected_nr).bounding_box.lower_bound and a_mouse_button_event.y > menu_entries.item(selected_nr).bounding_box.upper_bound then event_loop.stop on_select end end on_select is -- Set the `next_scene' according to `selected_nr' here deferred end feature {MENU,PUZZLE_START_WINDOW} -- Implementation scene: EM_DRAWABLE_CONTAINER [EM_DRAWABLE] -- The scene last_scene: EM_SCENE set_last_scene(ls: EM_SCENE) is -- create an instruction menu do last_scene := ls end key_codes: SDLKEY_ENUM_EXTERNAL -- key codes select_font: EM_BMP_FONT -- The font used to display a selected menu entry normal_font: EM_BMP_FONT -- The font used to display the not selected menu entries menu_entries: ARRAY [EM_STRING] -- The menu entries selected_nr: INTEGER -- The number of the selected entry update_menu_entries is -- Updates the `menu_entry' local i: INTEGER do from i:=1 until i > menu_entries.count loop if i = selected_nr then menu_entries.item (selected_nr).set_font (select_font) else menu_entries.item (i).set_font (normal_font) end i := i+1 end end add_menu_entries_to_scene is -- Add menu entries to `scene'. local i: INTEGER do from i:= menu_entries.lower until i > menu_entries.upper loop scene.extend (menu_entries.item (i)) i := i+1 end end restart_event_loop is -- restart the event loop do create event_loop.make_poll end empty_main_container is -- empty the main container do create main_container.make end end