indexing description: "[ Level Editor - Select order for custom levels ]" date: "$Date$" revision: "$Revision$" class BB_LEVELEDIT_CUSTOM inherit BB_CONSTANTS EM_WIDGET_SCENE create make feature {NONE} -- Initialization make is -- create level editor local color_background: EM_COLOR_BACKGROUND label: EM_LABEL do make_widget_scene create levels.make levels.set_equality_tester (create {UC_STRING_EQUALITY_TESTER}) create color_background.make_from_color (create {EM_COLOR}.make_with_rgb (255, 0, 0)) create level_list.make_empty level_list.selection_changed_event.subscribe (agent level_selection_changed) create level_box.make_from_widget (level_list) level_box.set_position (200, 100) level_box.set_dimension (170, 300) add_widget (level_box) create add_button.make_from_dimension (170, 20) add_button.set_text ("Add") add_button.set_position (200, 420) add_button.clicked_event.subscribe (agent add_click) add_widget (add_button) create remove_button.make_from_dimension (170, 20) remove_button.set_text ("Remove") remove_button.set_position (200, 450) remove_button.clicked_event.subscribe (agent remove_click) add_widget (remove_button) create save_button.make_from_dimension (130, 20) save_button.set_text ("Save") save_button.set_position (660, 520) save_button.clicked_event.subscribe (agent save_level_set) add_widget (save_button) create back_button.make_from_dimension (130, 20) back_button.set_text ("Back") back_button.set_position (660, 550) back_button.clicked_event.subscribe (agent back_click) add_widget (back_button) create move_up_button.make_from_dimension (30, 30) move_up_button.set_text ("/\") move_up_button.set_position (150, 200) move_up_button.clicked_event.subscribe (agent move_up_click) add_widget (move_up_button) create move_down_button.make_from_dimension (30, 30) move_down_button.set_text ("\/") move_down_button.set_position (150, 260) move_down_button.clicked_event.subscribe (agent move_down_click) add_widget (move_down_button) create label.make_from_text ("This list defines the order of your%Ncustom level files for singleplayer mode.") label.enable_multilined label.resize_to_optimal_dimension label.set_position (400, 200) add_widget (label) load_level_set end feature -- Miscellaneous load_level_set is -- load level set from file local level_file: PLAIN_TEXT_FILE do create level_file.make_open_read ("./levels/custom.ord") from level_file.start until level_file.end_of_file loop level_file.read_line levels.force_last (level_file.last_string.out) end level_file.close show_levels end show_levels is -- display levels in list do remove_widget (level_box) level_list.wipe_out from levels.start until levels.after loop level_list.put (levels.item_for_iteration.out) levels.forth end create level_box.make_from_widget (level_list) level_box.set_position (200, 100) level_box.set_dimension (170, 300) add_widget (level_box) level_list.set_selected_element (selected_level) end save_level_set is -- load level set from file local level_file: PLAIN_TEXT_FILE do create level_file.make_open_write ("./levels/custom.ord") from levels.start until levels.after loop level_file.put_string (levels.item_for_iteration.out) levels.forth if not levels.after then level_file.put_new_line end end level_file.close end feature -- Events move_up_click is -- move level up local level: STRING do if selected_level /= Void then levels.start levels.search_forth (selected_level) if not (levels.after or levels.index = 1) then level := levels.item_for_iteration levels.replace (levels.item (levels.index - 1), levels.index) levels.replace (level, levels.index - 1) end end show_levels end move_down_click is -- move level down local level: STRING do if selected_level /= Void then levels.start levels.search_forth (selected_level) if not (levels.after or levels.index = levels.count) then level := levels.item_for_iteration levels.replace (levels.item (levels.index + 1), levels.index) levels.replace (level, levels.index + 1) end end show_levels end level_selection_changed (a_level: STRING) is -- item list selection changed event do if a_level /= Void then selected_level := a_level.out end end add_click is -- handle add button click event local file_dialog: EM_FILE_DIALOG do create file_dialog.make file_dialog.show file_dialog.button_clicked_event.subscribe (agent handle_file_load_dialog_button_clicked (file_dialog)) file_dialog.set_directory ("./levels") file_dialog.set_title ("Add Level") end remove_click is -- handle remove button click event do if selected_level /= Void then levels.delete (selected_level) end show_levels end back_click is -- handle back button click event do Video_subsystem.default_cursor.show set_next_scene (create {BB_LEVELEDIT}.make) start_next_scene end handle_file_load_dialog_button_clicked (a_file_dialog: EM_FILE_DIALOG) is -- Handle click of a button on 'a_file_dialog'. do if a_file_dialog.was_ok_clicked then levels.force_last (a_file_dialog.filename) show_levels end end feature {NONE} -- Implementation menu_background: EM_BITMAP_BACKGROUND -- background bitmap level_list: EM_TEXTLIST [STRING] -- item list level_box: EM_SCROLLPANEL -- item selection box add_button: EM_BUTTON -- add button remove_button: EM_BUTTON -- remove button back_button: EM_BUTTON -- back button save_button: EM_BUTTON -- add button move_up_button: EM_BUTTON -- move up button move_down_button: EM_BUTTON -- move down button levels: DS_LINKED_LIST [STRING] -- level file list selected_level: STRING -- selected level end