indexing description: "Open script closeup, Save/Load game closeup" author: "Philipp Wolfensperger" date: "$2005/06/15$" revision: "$Revision$" class GUI_FILE_DIALOG inherit GUI_CLOSEUP export {NONE} make_from_game_closeup end create make_load, make_save, make_script feature -- Initialization make_load is -- create a loadgame dialog do create_frame create_image ("images/floppy.jpg") create_head ("Select a file to load") is_load_game := true check_savegame_folder -- CHANGES -> line here -- io.put_string ("line here") -- io.new_line load_entries_save end make_save is -- create a loadgame dialog do create_frame create_image ("images/floppy.jpg") create_head ("Select a file to save") check_savegame_folder load_entries_save end make_script is -- create a load script dialog do create_frame create_image ("images/floppy.jpg") create_head ("Select an XML script file to load") load_entries_xml end feature {NONE} -- Implementation load_entries_save is -- load savegame directory entries into clickable buttons local -- CHANGES -> directory -- directory: DIRECTORY directory: DIRECTORY file_name, file_path, file_description: STRING i, j: INTEGER exit: BOOLEAN game: GAME do create directory.make_open_read (savegame_folder) from until exit or i = 6 loop directory.readentry if directory.lastentry /= void then file_name := directory.lastentry.twin if file_name.substring (file_name.count - 4, file_name.count).is_equal(".save") then -- CHANGES -- file_path := savegame_folder + "\" + directory.lastentry file_path := savegame_folder + "/" + directory.lastentry game ?= (create {STORABLE}).retrieve_by_name (file_path) file_description := game.current_scene.description create_option (file_description, file_path) i := i + 1 end else exit := true end end if not is_load_game then from until j = 6 - i loop create_option ("[Empty Slot]", (i + 1).out) j := j + 1 end end end load_entries_xml is -- scan for subdirectories in "." local directory, subdirectory: DIRECTORY folder_name: STRING exit: BOOLEAN loop_defender: INTEGER do create directory.make_open_read (xml_folder) if directory.is_readable then scan_for_xml_file (directory) end -- loop_defender := 0 -- create directory.make_open_read (".") -- from -- until -- exit or entries_count = 6 or loop_defender > 10000 -- loop -- directory.readentry -- if directory.lastentry /= void then -- -- CHANGES -- -- folder_name := directory.lastentry.twin -- folder_name := "tomorrow" -- create subdirectory.make_open_read (folder_name) -- if subdirectory.is_readable then -- scan_for_xml_file (subdirectory) -- exit := true -- end -- else -- exit := true -- end -- loop_defender := loop_defender + 1 -- end end scan_for_xml_file (a_subdirectory: DIRECTORY) is -- scan a_directory for xml file, create entry for first -- xml file found local exit: BOOLEAN file_name, file_path: STRING string_list: ARRAY[STRING] do create string_list.make (0, 6) from until exit or entries_count = 6 loop a_subdirectory.readentry -- maximum of 6 entries if a_subdirectory.lastentry /= void then file_name := a_subdirectory.lastentry.twin if (not string_list.has (file_name)) then if file_name.substring (file_name.count -3, file_name.count).is_equal(".xml") then file_name.remove_tail (4) file_path := a_subdirectory.name + "/" + a_subdirectory.lastentry string_list.put (file_name, entries_count) file_name.replace_substring_all ("_", " ") create_option (file_name, file_path) entries_count := entries_count + 1 end else exit := true end else exit := true end end end entries_count: INTEGER -- variable counting how many menu entries have been displayed -- (used for 'load_entries_xml') check_savegame_folder is -- does the savegame folder exist? local folder, directory: DIRECTORY do create directory.make_open_read (".") if (not directory.has_entry (savegame_folder)) then create folder.make(savegame_folder) folder.create_dir end -- create folder.make_open_read (savegame_folder) -- if not folder.is_readable then -- create folder.make (savegame_folder) -- folder.create_dir -- end end feature {NONE} -- Constants and variables -- CHANGES -> save savegame_folder: STRING is "saved" xml_folder: STRING is "mission" is_load_game: BOOLEAN end -- class GUI_FILE_DIALOG