//Associate a craft with a tag. Will create a Tag with the given name if it doesn't already exist public static void tag_craft(CraftData craft, string tag_name) { Tag tag = Tags.find_or_create_by(tag_name, craft.save_dir); tag.add(craft); }
//return the reference used to identify a craft; ie SPH_myRocket public static string craft_reference_key(CraftData craft) { return((craft.stock_craft ? "Stock_" : "") + craft.construction_type + "_" + craft.name); }
//listen to key press actions protected virtual void key_event_handler() { Event e = Event.current; //This is somewhat batshit, allow me to explain. Event.current.control only detects the key press, not a key hold, so we used Input.GetKey(..) //but if the focus is on the search text field Input.GetKey won't detect CTRL being held. so...this first bit detects CTRL down while focused on search field //also also sets check_ctrl_key to false so the regular check is skipped. check_ctrl_key is returned to true on key up if (GUI.GetNameOfFocusedControl() == "main_search_field" && e.type == EventType.KeyDown && e.control) { ctrl_key_down = true; check_ctrl_key = false; } if (e.type == EventType.KeyUp) { check_ctrl_key = true; } if (check_ctrl_key) { ctrl_key_down = (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl)); } shift_key_down = (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)); if (e.type == EventType.KeyDown) { //'esc' - close interface if (e.keyCode == KeyCode.Escape) { e.Use(); this.hide(); //'ctrl+f' - focus on main search field } else if ((ctrl_key_down || e.control) && e.keyCode == KeyCode.F) { GUI.FocusControl("main_search_field"); ctrl_key_down = false; e.Use(); //'ctrl+t' - create new tag } else if ((ctrl_key_down || e.control) && e.keyCode == KeyCode.T) { CraftManager.main_ui.create_tag_dialog(true); ctrl_key_down = false; e.Use(); } else if ((ctrl_key_down || e.control) && e.keyCode == KeyCode.A) { foreach (CraftData craft in CraftData.filtered) { CraftData.group_select(craft); } e.Use(); //'up arrow' move up in craft list } else if (e.keyCode == KeyCode.UpArrow && !upload_interface_ready) { jump_to_craft(CraftData.filtered.IndexOf(CraftData.selected_craft) - 1); e.Use(); //'down arrow' move down in craft list } else if (e.keyCode == KeyCode.DownArrow && !upload_interface_ready) { jump_to_craft(CraftData.filtered.IndexOf(CraftData.selected_craft) + 1); e.Use(); //'enter key' - load selected craft (if focus is not on search field) } else if ((e.keyCode == KeyCode.Return || e.keyCode == KeyCode.KeypadEnter) && GUI.GetNameOfFocusedControl() != "main_search_field" && CraftData.selected_craft != null) { load_craft(CraftData.selected_craft.construction_type == "Subassembly" ? "subload" : "load"); //'tab' - move focus from search field to craft list. } else if (GUI.GetNameOfFocusedControl() == "main_search_field" && e.keyCode == KeyCode.Tab) { jump_to_craft(0); e.Use(); } } }
protected void auto_focus_on(CraftData craft) { auto_focus_craft = craft; auto_focus_countdown = 10; //delay auto_focus by x passes, to give the list time to be drawn //(not happy with this but attempting to autofocus right away selects the craft, but doesn't scroll the list to it }
//load/reload craft from the active_save_dir and apply any active filters public void refresh() { CraftData.load_craft_from_files(active_save_dir == all_saves_ref ? null : active_save_dir); filter_craft(); }
protected void load_craft(string load_type, bool force = false) { if (CraftData.selected_craft != null) { CraftData craft = CraftData.selected_craft; if (craft.missing_parts && !load_type.Contains("ignore_missing") && (load_type == "load" || load_type == "merge" || load_type == "subload")) { CraftManager.main_ui.load_craft_with_missing_parts_dialog(craft, load_type); } else { if (load_type.Contains("ignore_missing")) { load_type = load_type.Replace("_ignore_missing", ""); } if (load_type == "load") { if (CraftData.loaded_craft_saved || force) { EditorLogic.LoadShipFromFile(craft.path); CraftManager.main_ui.hide(); } else { CraftManager.main_ui.load_craft_confirm_dialog(() => { load_craft(load_type, true); }); } } else if (load_type == "merge") { ShipConstruct ship = new ShipConstruct(); ship.LoadShip(ConfigNode.Load(craft.path)); EditorLogic.fetch.SpawnConstruct(ship); CraftManager.main_ui.hide(); } else if (load_type == "subload") { ShipTemplate subassembly = new ShipTemplate(); subassembly.LoadShip(ConfigNode.Load(craft.path)); EditorLogic.fetch.SpawnTemplate(subassembly); CraftManager.main_ui.hide(); } else if (load_type == "download") { download(true, false); } else if (load_type == "update") { download(true, true); } else if (load_type == "dl_load") { download(true, false, load_craft); } else if (load_type == "update_load") { download(true, true, load_craft); } else if (load_type == "dl_load_no_save") { if (CraftData.loaded_craft_saved || force) { download(false); CraftManager.main_ui.hide(); } else { CraftManager.main_ui.load_craft_confirm_dialog(() => { load_craft(load_type, true); }); } } else if (load_type == "upload") { craft.upload_data.post(); } } } }