---------------------------------------------------------------------------------
-function gamemgr.dialog_new_game()
- local retval =
- "label[2,2;" .. fgettext("Game Name") .. "]"..
- "field[4.5,2.4;6,0.5;te_game_name;;]" ..
- "button[5,4.2;2.6,0.5;new_game_confirm;" .. fgettext("Create") .. "]" ..
- "button[7.5,4.2;2.8,0.5;new_game_cancel;" .. fgettext("Cancel") .. "]"
-
- return retval
-end
-
---------------------------------------------------------------------------------
-function gamemgr.handle_games_buttons(fields)
- if fields["gamelist"] ~= nil then
- local event = engine.explode_textlist_event(fields["gamelist"])
- gamemgr.selected_game = event.index
- end
-
- if fields["btn_game_mgr_edit_game"] ~= nil then
- return {
- is_dialog = true,
- show_buttons = false,
- current_tab = "dialog_edit_game"
- }
- end
-
- if fields["btn_game_mgr_new_game"] ~= nil then
- return {
- is_dialog = true,
- show_buttons = false,
- current_tab = "dialog_new_game"
- }
- end
-
- return nil
-end
-
---------------------------------------------------------------------------------
-function gamemgr.handle_new_game_buttons(fields)
-
- if fields["new_game_confirm"] and
- fields["te_game_name"] ~= nil and
- fields["te_game_name"] ~= "" then
- local gamepath = engine.get_gamepath()
-
- if gamepath ~= nil and
- gamepath ~= "" then
- local gamefolder = cleanup_path(fields["te_game_name"])
-
- --TODO check for already existing first
- engine.create_dir(gamepath .. DIR_DELIM .. gamefolder)
- engine.create_dir(gamepath .. DIR_DELIM .. gamefolder .. DIR_DELIM .. "mods")
- engine.create_dir(gamepath .. DIR_DELIM .. gamefolder .. DIR_DELIM .. "menu")
-
- local gameconf =
- io.open(gamepath .. DIR_DELIM .. gamefolder .. DIR_DELIM .. "game.conf","w")
-
- if gameconf then
- gameconf:write("name = " .. fields["te_game_name"])
- gameconf:close()
- end
- end
- end
-
- return {
- is_dialog = false,
- show_buttons = true,
- current_tab = engine.setting_get("main_menu_tab")
- }
-end
-
---------------------------------------------------------------------------------
-function gamemgr.handle_edit_game_buttons(fields)
- local current_game = gamemgr.get_game(gamemgr.selected_game)
-
- if fields["btn_close_edit_game"] ~= nil or
- current_game == nil then
- return {
- is_dialog = false,
- show_buttons = true,
- current_tab = engine.setting_get("main_menu_tab")
- }
- end
-
- if fields["btn_remove_mod_from_game"] ~= nil then
- gamemgr.delete_mod(current_game,engine.get_textlist_index("mods_current"))
- end
-
- if fields["btn_add_mod_to_game"] ~= nil then
- local modindex = engine.get_textlist_index("mods_available")
-
- local mod = modmgr.get_global_mod(modindex)
- if mod ~= nil then
-
- local sourcepath = mod.path
-
- if not gamemgr.add_mod(current_game,sourcepath) then
- gamedata.errormessage =
- fgettext("Gamemgr: Unable to copy mod \"$1\" to game \"$2\"", mod.name, current_game.id)
- end
- end
- end
-
- return nil
-end
-
---------------------------------------------------------------------------------
-function gamemgr.add_mod(gamespec,sourcepath)
- if gamespec.gamemods_path ~= nil and
- gamespec.gamemods_path ~= "" then
-
- local modname = get_last_folder(sourcepath)
-
- return engine.copy_dir(sourcepath,gamespec.gamemods_path .. DIR_DELIM .. modname);
- end
-
- return false
-end
-
---------------------------------------------------------------------------------
-function gamemgr.delete_mod(gamespec,modindex)
- if gamespec.gamemods_path ~= nil and
- gamespec.gamemods_path ~= "" then
- local game_mods = {}
- get_mods(gamespec.gamemods_path,game_mods)
-
- if modindex > 0 and
- #game_mods >= modindex then
-
- if game_mods[modindex].path:sub(0,gamespec.gamemods_path:len())
- == gamespec.gamemods_path then
- engine.delete_dir(game_mods[modindex].path)
- end
- end
- end
-end
-