/// <summary> /// Called by game when tool is disabled. /// Used to close the BOB info panel. /// </summary> protected override void OnDisable() { base.OnDisable(); // Is a BOB info panel already open? if (InfoPanelManager.Panel != null) { // Yes - close it. InfoPanelManager.Close(); } }
/// <summary> /// Save current configuration to the specified config file. /// </summary> /// <param name="config">Configuration file name; null for default file (default null)</param> /// <param name="clean">Set to true to generate a blank file (default false)</param> internal static void SaveConfig(string config = null, bool clean = false) { // Default file location is the general config file. string fileName = GeneralConfigFile; try { // Check if we've got an assigned custom config. if (config != null) { // Custom config assigned - use this filename in the configuration settings directory (creating directory if it doesn't already exist). if (!Directory.Exists(ConfigDirectory)) { Directory.CreateDirectory(ConfigDirectory); } fileName = FullConfigPath(config); } // Open specified file. using (StreamWriter textWriter = new StreamWriter(fileName, append: false)) { XmlSerializer xmlSerializer = new XmlSerializer(typeof(BOBConfigurationFile)); // Create new config if there isn't one. if (CurrentConfig == null) { CurrentConfig = new BOBConfigurationFile { // Version 1. version = 1 }; } // Don't populate file if we're doing a clean save. if (!clean) { // Serialise scales. try { CurrentConfig.propScales = Scaling.Instance.propScales.Values.ToList(); CurrentConfig.treeScales = Scaling.Instance.treeScales.Values.ToList(); } catch (Exception e) { // Don't let a single failure stop us. Logging.LogException(e, "exception serializing scaling elements"); } // Serialise active replacement packs. try { CurrentConfig.activePacks = NetworkPackReplacement.Instance.SerializeActivePacks(); } catch (Exception e) { // Don't let a single failure stop us. Logging.LogException(e, "exception serializing active replacement packs"); } } // Write to file. xmlSerializer.Serialize(textWriter, CurrentConfig); // Delete any old config. if (File.Exists(GeneralConfigName)) { File.Delete(GeneralConfigName); } } } catch (Exception e) { Logging.LogException(e, "exception saving XML configuration file ", fileName ?? "null"); } // Display any exception message that occured during save. InfoPanelManager.CheckException(); }
/// <summary> /// Called by the game when level loading is complete. /// </summary> /// <param name="mode">Loading mode (e.g. game, editor, scenario, etc.)</param> public override void OnLevelLoaded(LoadMode mode) { Logging.Message("commencing loading checks"); base.OnLevelLoaded(mode); // Don't do anything further if we're not operating. if (!isModEnabled) { Logging.Message("exiting"); return; } // Check to see that Harmony 2 was properly loaded. if (!Patcher.Patched) { // Harmony 2 wasn't loaded; abort. Logging.Error("Harmony patches not applied; aborting"); isModEnabled = false; // Display warning message. ListMessageBox harmonyBox = MessageBoxBase.ShowModal <ListMessageBox>(); // Key text items. harmonyBox.AddParas(Translations.Translate("ERR_HAR0"), Translations.Translate("BOB_ERR_HAR"), Translations.Translate("BOB_ERR_FAT"), Translations.Translate("ERR_HAR1")); // List of dot points. harmonyBox.AddList(Translations.Translate("ERR_HAR2"), Translations.Translate("ERR_HAR3")); // Closing para. harmonyBox.AddParas(Translations.Translate("MES_PAGE")); // Don't do anything further. return; } Logging.Message("loading checks passed"); // Build lists of loaded prefabs. PrefabLists.BuildLists(); // Load prop packs. new NetworkPackReplacement(); // Load configuration file. ConfigurationUtils.LoadConfig(); // Set up BOB tool. ToolsModifierControl.toolController.gameObject.AddComponent <BOBTool>(); // Display update notification. WhatsNew.ShowWhatsNew(); // Set up Network Skins 2 reflection. ModUtils.NS2Reflection(); // Enable thin wires, if applicable. if (ModSettings.ThinnerWires) { ElectricalWires.Instance.ApplyThinnerWires(); } // Force update of any dirty net or building prefabs from replacement process. Logging.Message("updating dirty prefabs"); BuildingData.Update(); NetData.Update(); // Set up options panel event handler. OptionsPanel.OptionsEventHook(); // Display any exception message that occured during load. InfoPanelManager.CheckException(); // Activate tool hotkey. UIThreading.Operating = true; Logging.Message("loading complete"); }
/// <summary> /// Tool GUI event processing. /// Called by game every GUI update. /// </summary> /// <param name="e">Event</param> protected override void OnToolGUI(Event e) { // Check for escape key. if (e.type == EventType.keyDown && e.keyCode == KeyCode.Escape) { // Escape key pressed - disable tool. e.Use(); ToolsModifierControl.SetTool <DefaultTool>(); } // Don't do anything if mouse is inside UI or if there are any errors other than failed raycast. if (m_toolController.IsInsideUI || (m_selectErrors != ToolErrors.None && m_selectErrors != ToolErrors.RaycastFailed)) { return; } // Try to get a hovered building instance. ushort building = m_hoverInstance.Building; if (building != 0) { // Check for mousedown events with button zero. if (e.type == EventType.MouseDown && e.button == 0) { // Got one; use the event. UIInput.MouseUsed(); // Restore the default tool and create the info panel with the hovered building prefab. ToolsModifierControl.SetTool <DefaultTool>(); InfoPanelManager.Create(Singleton <BuildingManager> .instance.m_buildings.m_buffer[building].Info); } } else { ushort segment = m_hoverInstance.NetSegment; // Try to get a hovered network instance. if (segment != 0) { // Check for mousedown events with button zero. if (e.type == EventType.MouseDown && e.button == 0) { // Got one; use the event. UIInput.MouseUsed(); // Restore the default tool and create the info panel with the hovered network prefab. ToolsModifierControl.SetTool <DefaultTool>(); InfoPanelManager.Create(Singleton <NetManager> .instance.m_segments.m_buffer[segment].Info); } } else { uint tree = m_hoverInstance.Tree; // Try to get a hovered tree instance. if (tree != 0) { // Check for mousedown events with button zero. if (e.type == EventType.MouseDown && e.button == 0) { // Got one; use the event. UIInput.MouseUsed(); // Restore the default tool and create the info panel with the hovered network prefab. ToolsModifierControl.SetTool <DefaultTool>(); InfoPanelManager.Create(Singleton <TreeManager> .instance.m_trees.m_buffer[tree].Info); } } else { ushort prop = m_hoverInstance.Prop; // Try to get a hovered prop instance. if (prop != 0) { // Check for mousedown events with button zero. if (e.type == EventType.MouseDown && e.button == 0) { // Got one; use the event. UIInput.MouseUsed(); // Restore the default tool and create the info panel with the hovered network prefab. ToolsModifierControl.SetTool <DefaultTool>(); InfoPanelManager.Create(Singleton <PropManager> .instance.m_props.m_buffer[prop].Info); } } } } } }
/// <summary> /// Checks for and displays any exception message. /// Called by the game every update cycle. /// </summary> public override void Update() { base.Update(); InfoPanelManager.CheckException(); }