public bool on_kerbalx() { if (matching_remote_ids == null) { matching_remote_ids = new List <int>(); KerbalX.find_matching_remote_craft(this); } return(matching_remote_ids.Count > 0); }
internal static void bulk_download(Dictionary <int, Dictionary <string, string> > download_list, string save_dir, Callback callback) { string save_path = Paths.joined(CraftManager.ksp_root, "saves", save_dir); if (Directory.Exists(save_path)) { ensure_ship_folders_exist(save_dir); if (download_list.Count > 0) { CraftManager.status_info = "Downloading craft from KerbalX..."; List <int> keys = new List <int>(download_list.Keys); int id = keys[0]; Dictionary <string, string> craft_ref = download_list[id]; string type = craft_ref["type"]; string path = ""; if (type == "Subassembly") { path = Paths.joined(save_path, "Subassemblies", craft_ref["name"] + ".craft"); } else { path = Paths.joined(save_path, "Ships", type, craft_ref["name"] + ".craft"); } bulk_download_log += (String.IsNullOrEmpty(bulk_download_log) ? "" : "\n") + "downloading [" + (type == "Subassembly" ? "Sub" : type) + "]" + craft_ref["name"] + "..."; download_list.Remove(id); api.download_craft(id, (craft_file_string, code) => { if (code == 200) { ConfigNode craft = ConfigNode.Parse(craft_file_string); craft.Save(path); Thread.Sleep(1000); //This sleep is just to add a pause to reduce load on the site. bulk_download_log += "Done"; log_scroll.y = 10000; KerbalX.bulk_download(download_list, save_dir, callback); } }); } else { CraftManager.status_info = ""; callback(); } } }
protected void show_bulk_download_dialog() { string resp = ""; long time_completed = 0; long close_delay = 3000; long time_to_close = close_delay; Dictionary <int, Dictionary <string, string> > ids_to_download = new Dictionary <int, Dictionary <string, string> >(); foreach (CraftData craft in CraftData.selected_group) { if (!ids_to_download.ContainsKey(craft.remote_id)) { ids_to_download.Add(craft.remote_id, new Dictionary <string, string> { { "name", craft.name }, { "type", craft.construction_type } }); } } KerbalX.bulk_download_log = ""; KerbalX.bulk_download(ids_to_download, current_save_dir, () => { time_completed = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond; }); KerbalX.log_scroll = new Vector2(); show_dialog("Downloading from KerbalX...", "", d => { if (!String.IsNullOrEmpty(KerbalX.bulk_download_log)) { KerbalX.log_scroll = scroll(KerbalX.log_scroll, d.window_pos.width, 80f, (w) => { label(KerbalX.bulk_download_log); }); } if (time_completed != 0) { time_to_close = close_delay - ((DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) - time_completed); section(() => { fspace(); button("close (auto closing in " + ((time_to_close / (TimeSpan.TicksPerMillisecond / 10)) + 1).ToString() + ")", close_dialog); }); if (time_to_close <= 0) { resp = "200"; } } return(resp); }); }
internal void mod_lookup_dialog(CraftData craft) { string resp = ""; bool lookup_complete = false; List <string> required_mods = new List <string>(); if (KerbalX.enabled) { KerbalX.lookup_parts(craft.list_parts(), identified_parts => { foreach (string mod_name in identified_parts.Values) { if (mod_name != "Squad") { required_mods.AddUnique(mod_name); } } lookup_complete = true; }); } show_dialog("Mod Lookup", "", d => { section((w) => { if (lookup_complete) { if (required_mods.Count == 0) { label("This craft doesn't have any modded parts"); } else { label("This craft needs the following mods:\n" + required_mods.n_join("and")); } } else { label("Fetching Mod info from KerbalX", "h2"); } }); section(() => { button("close", close_dialog); }); return(resp); }); }
protected void change_craft_source(string save_name) { if (save_name == "kerbalx_remote") { KerbalX.load_remote_craft(); adjust_save_menu_width(); } else { if (kerbalx_mode) { KerbalX.load_local(); } if (active_save_dir != save_name) { active_save_dir = save_name; adjust_save_menu_width(); Tags.load(active_save_dir); stock_craft_loaded = false; refresh(); } } }
internal void download(bool save = true, bool force_overwrite = false, DialogAction action = null) { CraftData craft = CraftData.selected_craft; if (craft != null && craft.remote) { if (save) { KerbalX.ensure_ship_folders_exist(current_save_dir); if (!File.Exists(craft.path) || force_overwrite) { KerbalX.download(craft.remote_id, craft_file => { craft_file.Save(craft.path); craft.exists_locally = true; if (action != null) { action(); } }); } else { CraftManager.main_ui.download_confirm_dialog(action); } } else { KerbalX.download(craft.remote_id, craft_file => { string temp_path = Paths.joined(CraftManager.ksp_root, "GameData", "CraftManager", "temp.craft"); craft_file.Save(temp_path); EditorLogic.LoadShipFromFile(temp_path); File.Delete(temp_path); }); } } }
protected void populate_new_save_dialog() { KerbalX.get_craft_ids_by_version((craft_by_version, versions) => { string v1 = versions[0].ToString(); string v2 = versions[1].ToString(); string resp = ""; Version ksp_version = CraftManager.game_version; //new Version(Versioning.GetVersionString()); KerbalX.log_scroll = new Vector2(); KerbalX.bulk_download_log = ""; show_dialog("Import Craft From KerbalX", "", d => { label("You don't have any craft in this save yet.", "h2"); label("Do you want to fetch your craft from KerbalX?", "h2"); if (versions[0] == ksp_version) { button("download " + craft_by_version[v1].Count + " craft built in KSP " + ksp_version, () => { KerbalX.bulk_download(craft_by_version[v1], current_save_dir, () => {}); }); } else { label("You don't have any craft made in this version of KSP"); if (v1 != null || v2 != null) { label("get craft from previous versions:"); section(() => { if (v1 != null && craft_by_version[v1] != null) { button("download " + craft_by_version[v1].Count + " craft built in KSP " + v1, () => { KerbalX.bulk_download(craft_by_version[v1], current_save_dir, () => {}); }); } if (v2 != null && craft_by_version[v2] != null) { button("download " + craft_by_version[v2].Count + " craft built in KSP " + v2, () => { KerbalX.bulk_download(craft_by_version[v2], current_save_dir, () => {}); }); } }); } } if (!String.IsNullOrEmpty(KerbalX.bulk_download_log)) { KerbalX.log_scroll = scroll(KerbalX.log_scroll, d.window_pos.width, 80f, (w) => { label(KerbalX.bulk_download_log); }); } button("OR cherry pick the ones you want", () => { close_dialog(); exit_kerbalx_mode_after_close = true; CraftManager.main_ui.show(); KerbalX.load_remote_craft(); }); button("Close", close_dialog); return(resp); }); }); }
internal void load_craft_with_missing_parts_dialog(CraftData craft, string load_type) { string resp = ""; List <string> missing_parts_list = new List <string>(); Dictionary <string, string> identified_parts_list = new Dictionary <string, string>(); bool show_identified_parts = false; List <string> required_mods = new List <string>(); Vector2 part_list_scroll = new Vector2(); show_dialog("Missing Parts", "This Craft has missing parts", d => { section(() => { button("list missing parts", () => { show_identified_parts = false; missing_parts_list = craft.list_missing_parts(); }); if (KerbalX.enabled) { button("KerblaX Mod lookup", () => { KerbalX.lookup_parts(craft.list_missing_parts(), identified_parts => { identified_parts_list = identified_parts; missing_parts_list.Clear(); part_list_scroll = new Vector2(); required_mods.Clear(); foreach (string mod_name in identified_parts_list.Values) { if (mod_name != "Squad") { required_mods.AddUnique(mod_name); } } show_identified_parts = true; }); }); } }); if (KerbalX.enabled) { label("click \"KerbalX Mod Lookup\" and KerbalX will try to work out which mods you need for the missing parts"); } else { label("tip: if you enable KerbalX integration, Craft Manager can use KerbalX to try and work out which mods you need", "small"); } if (missing_parts_list.Count > 0) { part_list_scroll = scroll(part_list_scroll, d.window_pos.width, 200, (w) => { foreach (string part_name in missing_parts_list) { label(part_name); } }); } if (show_identified_parts) { if (identified_parts_list.Count > 0) { part_list_scroll = scroll(part_list_scroll, d.window_pos.width, 200, (w) => { foreach (KeyValuePair <string, string> pair in identified_parts_list) { section(() => { label(pair.Key, "Label", w * 0.3f); label(pair.Value, "Label", w * 0.6f); }); } }); if (identified_parts_list.ContainsValue("Squad")) { label("You seem to be missing some parts from the core game!", "alert"); } if (required_mods.Count > 0) { label("This craft needs the following mods:\n" + required_mods.n_join("and")); } } else { label("no part info found"); } } section(() => { button("Try to load anyway", () => { load_craft(load_type + "_ignore_missing", false); resp = "200"; }); button("Cancel", close_dialog); }); return(resp); }); }