private void stringContractParse(string s, string type) { contractTypeContainer c; string[] a = s.Split(','); try { if (cTypeList.ContainsKey(type)) { c = cTypeList[type]; } else { DMC_MBE.LogFormatted("Contract Type Not Found; Removing Type From List"); return; } } catch (Exception e) { DMC_MBE.LogFormatted("Contract Type List Not Responding: {0}", e); return; } c.RewardFund = stringFloatParse(a[0], true); c.AdvanceFund = stringFloatParse(a[1], true); c.PenaltyFund = stringFloatParse(a[2], true); c.RewardRep = stringFloatParse(a[3], true); c.PenaltyRep = stringFloatParse(a[4], true); c.RewardScience = stringFloatParse(a[5], true); c.DurationTime = stringFloatParse(a[6], true); c.MaxOffer = stringFloatParse(a[7], false); c.MaxActive = stringFloatParse(a[8], false); }
private void stringParamParse(string s, string type) { paramTypeContainer p; string[] a = s.Split(','); try { if (pTypeList.ContainsKey(type)) { p = pTypeList[type]; } else { DMC_MBE.LogFormatted("Parameter Type Not Found; Removing Type From List"); return; } } catch (Exception e) { DMC_MBE.LogFormatted("Parameter Type List Not Responding: {0}", e); return; } p.RewardFund = stringFloatParse(a[0], true); p.PenaltyFund = stringFloatParse(a[1], true); p.RewardRep = stringFloatParse(a[2], true); p.PenaltyRep = stringFloatParse(a[3], true); p.RewardScience = stringFloatParse(a[4], true); }
internal void addContract(Guid id, contractContainer c) { if (!masterList.ContainsKey(id)) { masterList.Add(id, c); } else { DMC_MBE.LogFormatted_DebugOnly("Contract Already Present In List"); } }
/// <summary> /// Copies a skin so you can make a new custom skin from an already defined one /// </summary> /// <param name="SkinID">The string ID of the custom skin</param> /// <returns>The new copy of the skin</returns> internal static GUISkin CopySkin(String SkinID) { if (List.ContainsKey(SkinID)) { return((GUISkin)DMC_MBE.Instantiate(List[SkinID])); } else { DMC_MBE.LogFormatted("Unable to copy GUISkin to {0}, GUISkin not found", SkinID); throw new SystemException(String.Format("Unable to copy GUISkin to {0}, GUISkin not found", SkinID)); } }
/// <summary> /// Copies a skin so you can make a new custom skin from an already defined one /// </summary> /// <param name="DefaultSkin">Which predefined skin to use</param> /// <returns>The new copy of the skin</returns> internal static GUISkin CopySkin(DefSkinType DefaultSkin) { switch (DefaultSkin) { case DefSkinType.Unity: return((GUISkin)DMC_MBE.Instantiate(DefUnitySkin)); case DefSkinType.KSP: return((GUISkin)DMC_MBE.Instantiate(DefKSPSkin)); //case DefSkinType.None: return new GUISkin(); default: return((GUISkin)DMC_MBE.Instantiate(DefKSPSkin)); } }
private void Start() { //if (stockIcon == null) // stockIcon = contractLoader.Images.LoadAsset<Texture>("toolbar_icon"); Assembly assembly = AssemblyLoader.loadedAssemblies.GetByAssembly(Assembly.GetExecutingAssembly()).assembly; var ainfoV = Attribute.GetCustomAttribute(assembly, typeof(AssemblyInformationalVersionAttribute)) as AssemblyInformationalVersionAttribute; switch (ainfoV == null) { case true: infoVersion = ""; break; default: infoVersion = ainfoV.InformationalVersion; break; } try { _cWin = gameObject.AddComponent <contractWindow>(); } catch (Exception e) { DMC_MBE.LogFormatted("Contracts Windows Cannot Be Started: {0}", e); } bool stockToolbar = true; if (contractLoader.Settings != null) { stockToolbar = contractLoader.Settings.useStockToolbar; } if (stockToolbar || !ToolbarManager.ToolbarAvailable || contractLoader.Settings.replaceStockApp) { appLauncherButton = gameObject.AddComponent <contractStockToolbar>(); if (blizzyToolbarButton != null) { Destroy(blizzyToolbarButton); blizzyToolbarButton = null; } } else if (ToolbarManager.ToolbarAvailable && !stockToolbar) { blizzyToolbarButton = gameObject.AddComponent <contractToolbar>(); if (appLauncherButton != null) { Destroy(appLauncherButton); appLauncherButton = null; } } contractParser.onParameterAdded.Add(onParameterAdded); }
internal contractMission getMissionList(string name, bool warn = false) { if (missionList.Contains(name)) { return(missionList[name]); } else if (warn) { DMC_MBE.LogFormatted("No Mission Of Name [{0}] Found In Primary Mission List", name); } return(null); }
internal bool addMissionList(contractMission mission) { if (!missionList.Contains(mission.MissionTitle)) { missionList.Add(mission.MissionTitle, mission); return(true); } else { DMC_MBE.LogFormatted("Missions List Already Contains Mission Of Name: [{0}]; Please Rename", name); } return(false); }
private static bool DMAsteroidAvailable() { if (_DMAst != null) { return(true); } if (DMAstRun) { return(false); } DMAstRun = true; try { Type DMAstType = AssemblyLoader.loadedAssemblies.SelectMany(a => a.assembly.GetExportedTypes()) .SingleOrDefault(t => t.FullName == DMAsteroidTypeName); if (DMAstType == null) { DMC_MBE.LogFormatted_DebugOnly("DMagic Asteroid Type Not Found"); return(false); } _DMAstType = DMAstType; MethodInfo DMastMethod = DMAstType.GetMethod("PartName"); if (DMastMethod == null) { DMC_MBE.LogFormatted_DebugOnly("DMagic Asteroid String Method Not Found"); return(false); } else { _DMAst = (DMAstSci)Delegate.CreateDelegate(typeof(DMAstSci), DMastMethod); DMC_MBE.LogFormatted("DMagic Asteroid Reflection Method Assigned"); } return(_DMAst != null); } catch (Exception e) { DMC_MBE.LogFormatted("Exception While Loading DMagic Asteroid Accessor: {0}", e); } return(false); }
private ConfigNode AsConfigNode() { try { ConfigNode node = new ConfigNode(GetType().Name); node = ConfigNode.CreateConfigFromObject(this, node); return(node); } catch (Exception e) { DMC_MBE.LogFormatted("Failed to generate settings file node...\n{0}", e); return(new ConfigNode(GetType().Name)); } }
internal bool addMissionList(string name) { if (!missionList.Contains(name)) { contractMission mission = new contractMission(name); missionList.Add(name, mission); return(true); } else { DMC_MBE.LogFormatted("Missions List Already Contains Mission Of Name: [{0}]; Please Rename", name); } return(false); }
public bool Save() { try { ConfigNode node = AsConfigNode(); ConfigNode wrapper = new ConfigNode(GetType().Name); wrapper.AddNode(node); wrapper.Save(fullPath); return(true); } catch (Exception e) { DMC_MBE.LogFormatted("Error while saving settings file at [{0}]\n{1}", fullPath, e); return(false); } }
internal void removeMissionList(string name, bool delete = true) { if (missionList.Contains(name)) { if (delete) { contractMission c = missionList[name]; c = null; } missionList.Remove(name); } else { DMC_MBE.LogFormatted("No Mission List Of Name: [{0}] Found", name); } }
internal paramTypeContainer(Type PType) { paramType = PType; try { param = (ContractParameter)Activator.CreateInstance(PType); } catch (Exception e) { DMC_MBE.LogFormatted("This Parameter Type: {0} Does Not Have An Empty Constructor And Will Be Skipped: {1]", PType.Name, e); return; } name = PType.Name; name = Regex.Replace(name, "([a-z](?=[A-Z])|[A-Z](?=[A-Z][a-z]))", "$1 "); rewardFund = penaltyFund = rewardRep = penaltyRep = rewardScience = 1f; }
public contractSettings() { fullPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), fileName).Replace("\\", "/"); if (Load()) { DMC_MBE.LogFormatted("Settings File Loaded"); } else { if (Save()) { DMC_MBE.LogFormatted("New Contracts Window + Settings file saved to:\n{0}", fullPath); } } }
internal contractTypeContainer(Type CType) { contractType = CType; try { contractC = (Contract)Activator.CreateInstance(CType); } catch (Exception e) { DMC_MBE.LogFormatted("This Contract Type: {0} Does Not Have An Empty Constructor And Will Be Skipped: {1]", CType.Name, e); } name = CType.Name; name = Regex.Replace(name, "([a-z](?=[A-Z])|[A-Z](?=[A-Z][a-z]))", "$1 "); rewardFund = penaltyFund = advanceFund = rewardRep = penaltyRep = rewardScience = durationTime = expirationTime = 1f; maxOffer = maxActive = 10f; }
private static bool MCEAvailable() { if (_MCE != null) { return(true); } if (MCERun) { return(false); } MCERun = true; try { Type MCEType = AssemblyLoader.loadedAssemblies.SelectMany(a => a.assembly.GetExportedTypes()) .SingleOrDefault(t => t.FullName == MCETypeName); if (MCEType == null) { DMC_MBE.LogFormatted_DebugOnly("Mision Controller Type Not Found"); return(false); } _MCEType = MCEType; MethodInfo MCEMethod = MCEType.GetMethod("iPartName", new Type[] { typeof(ContractParameter) }); if (MCEMethod == null) { DMC_MBE.LogFormatted_DebugOnly("Mission Controller String Method Not Found"); return(false); } _MCE = (MCESci)Delegate.CreateDelegate(typeof(MCESci), MCEMethod); DMC_MBE.LogFormatted("Mission Control Reflection Method Assigned"); return(_MCE != null); } catch (Exception e) { DMC_MBE.LogFormatted("Exception While Loading Mission Controller Accessor: {0}", e); } return(false); }
private static bool FPAssemblyLoaded() { if (_FP != null) { return(true); } if (FPRun) { return(false); } FPRun = true; try { Type FPType = AssemblyLoader.loadedAssemblies.SelectMany(a => a.assembly.GetExportedTypes()) .SingleOrDefault(t => t.FullName == FPContractTypeName); if (FPType == null) { DMC_MBE.LogFormatted_DebugOnly("Fine Print Type Not Found"); return(false); } _FPType = FPType; MethodInfo FPMethod = FPType.GetMethod("PartName", new Type[] { typeof(ContractParameter) }); if (FPMethod == null) { DMC_MBE.LogFormatted_DebugOnly("Fine Print String Method Not Found"); return(false); } _FP = (FPSci)Delegate.CreateDelegate(typeof(FPSci), FPMethod); DMC_MBE.LogFormatted("Fine Print Reflection Method Assigned"); return(_FP != null); } catch (Exception e) { DMC_MBE.LogFormatted("Exception While Loading Fine Print Accessor: {0}", e); } return(false); }
public override void OnSave(ConfigNode node) { try { if (contractLoader.Settings != null) { contractLoader.Settings.Save(); } saveWindow(windowRects[currentScene(HighLogic.LoadedScene)]); ConfigNode scenes = new ConfigNode("Contracts_Window_Parameters"); //Scene settings scenes.AddValue("WindowPosition", stringConcat(windowPos, windowPos.Length)); scenes.AddValue("WindowVisible", stringConcat(windowVisible, windowVisible.Length)); for (int i = missionList.Count - 1; i >= 0; i--) { contractMission m = missionList.At(i); if (m == null) { continue; } ConfigNode missionNode = new ConfigNode("Contracts_Window_Mission"); missionNode.AddValue("MissionName", m.InternalName); missionNode.AddValue("ActiveListID", m.stringConcat(m.ActiveMissionList)); missionNode.AddValue("HiddenListID", m.stringConcat(m.HiddenMissionList)); missionNode.AddValue("VesselIDs", m.vesselConcat(currentMission)); missionNode.AddValue("AscendingSort", m.AscendingOrder); missionNode.AddValue("ShowActiveList", m.ShowActiveMissions); missionNode.AddValue("SortMode", (int)m.OrderMode); scenes.AddNode(missionNode); } node.AddNode(scenes); } catch (Exception e) { DMC_MBE.LogFormatted("Contracts Window Settings Cannot Be Saved: {0}", e); } }
private void contractChanged(float[] originals, contractTypeContainer c) { DMC_MBE.LogFormatted_DebugOnly("Contract Value Event Fired; Type: {0}", c.Name); var cList = ContractSystem.Instance.Contracts; for (int i = 0; i < cList.Count; i++) { if (cList[i].ContractState == Contract.State.Active || cList[i].ContractState == Contract.State.Offered) { updateContractValues(c, cList[i], originals); } } for (int j = 0; j < masterList.Count; j++) { masterList.ElementAt(j).Value.updateContractInfo(); } }
private void updateContractValues(contractTypeContainer cC, Contract c, float[] O) { if (cTypeList.ContainsValue(cC)) { if (c.GetType() == cC.ContractType) { DMC_MBE.LogFormatted_DebugOnly("Contract Values Updating; Type: {0}", cC.Name); DMC_MBE.LogFormatted_DebugOnly("Original Contract Values: {0}; New Values: {1}", printArray(O), printArray(cC.ContractValues)); c.FundsCompletion = (c.FundsCompletion / O[0]) * cC.RewardFund; c.FundsAdvance = (c.FundsAdvance / O[1]) * cC.AdvanceFund; c.FundsFailure = (c.FundsFailure / O[2]) * cC.PenaltyFund; c.ReputationCompletion = (c.ReputationCompletion / O[3]) * cC.RewardRep; c.ReputationFailure = (c.ReputationFailure / O[4]) * cC.PenaltyRep; c.ScienceCompletion = (c.ScienceCompletion / O[5]) * cC.RewardScience; c.TimeDeadline = (c.TimeDeadline / O[6]) * cC.DurationTime; } } }
private void updateParameterValues(paramTypeContainer pC, List <ContractParameter> pL, float[] O) { foreach (ContractParameter p in pL) { if (pTypeList.ContainsValue(pC)) { if (p.GetType() == pC.ParamType) { DMC_MBE.LogFormatted_DebugOnly("Updating Param Values; Type: {0}", pC.Name); DMC_MBE.LogFormatted_DebugOnly("Original Param Values: {0}; New Values: {1}", printArray(O), printArray(pC.ParamValues)); p.FundsCompletion = (p.FundsCompletion / O[0]) * pC.RewardFund; p.FundsFailure = (p.FundsFailure / O[1]) * pC.PenaltyFund; p.ReputationCompletion = (p.ReputationCompletion / O[2]) * pC.RewardRep; p.ReputationFailure = (p.ReputationFailure / O[3]) * pC.PenaltyRep; p.ScienceCompletion = (p.ScienceCompletion / O[4]) * pC.RewardScience; } } } }
private void updateParameterValues(paramTypeContainer pC, Contract c, float[] originals) { List <ContractParameter> modifyList = new List <ContractParameter>(); var cParams = c.AllParameters; for (int i = 0; i < cParams.Count(); i++) { if (cParams.ElementAt(i).GetType() == pC.ParamType) { DMC_MBE.LogFormatted_DebugOnly("Found Parameter Of Type: {0}; Updating Values", pC.Name); modifyList.Add(cParams.ElementAt(i)); } } if (modifyList.Count > 0) { DMC_MBE.LogFormatted_DebugOnly("Found {0} Parameters Of Type: {1}", modifyList.Count, pC.Name); updateParameterValues(pC, modifyList, originals); } }
private void LoadPrefabs() { prefabs = AssetBundle.LoadFromFile(path + prefabAssetName); if (prefabs != null) { loadedPrefabs = prefabs.LoadAllAssets <GameObject>(); } if (loadedPrefabs == null) { return; } if (!tmpProcessed) { processTMPPrefabs(); } if (!tooltipsProcessed && _tooltipPrefab != null) { processTooltips(); } if (!prefabsProcessed) { processUIPrefabs(); } if (tmpProcessed && tooltipsProcessed && prefabsProcessed) { DMC_MBE.LogFormatted("UI prefab bundle loaded and processed"); } else { DMC_MBE.LogFormatted("Error in processing UI prefab bundle\nSome UI elements may be affected or non-functional"); } prefabsLoaded = true; }
/// <summary> /// Sets the current Skin to one of the Pre-Defined types /// </summary> /// <param name="DefaultSkin">Which predefined skin to use</param> internal static void SetCurrent(DefSkinType DefaultSkin) { DMC_MBE.LogFormatted_DebugOnly("Setting GUISkin to {0}", DefaultSkin); GUISkin OldSkin = _CurrentSkin; switch (DefaultSkin) { case DefSkinType.Unity: _CurrentSkin = DefUnitySkin; break; case DefSkinType.KSP: _CurrentSkin = DefKSPSkin; break; //case DefSkinType.None: _CurrentSkin = new GUISkin(); break; default: _CurrentSkin = DefKSPSkin; break; } //Now set the tooltip style as well SetCurrentTooltip(); if (OldSkin != CurrentSkin && OnSkinChanged != null) { OnSkinChanged(); } }
/// <summary> /// Sets the current skin to one of the custom skins /// </summary> /// <param name="SkinID">The string ID of the custom skin</param> internal static void SetCurrent(String SkinID) { DMC_MBE.LogFormatted_DebugOnly("Setting GUISkin to {0}", SkinID); GUISkin OldSkin = _CurrentSkin; //check the skin exists, and throw a log line if it doesnt if (List.ContainsKey(SkinID)) { _CurrentSkin = List[SkinID]; } else { DMC_MBE.LogFormatted("Unable to change GUISkin to {0}, GUISkin not found", SkinID); } //Now set the tooltip style as well SetCurrentTooltip(); if (OldSkin != CurrentSkin && OnSkinChanged != null) { OnSkinChanged(); } }
public bool Load() { try { if (File.Exists(fullPath)) { ConfigNode node = ConfigNode.Load(fullPath); ConfigNode unwrapped = node.GetNode(GetType().Name); ConfigNode.LoadObjectFromConfig(this, unwrapped); return(true); } else { DMC_MBE.LogFormatted("Settings file could not be found [{0}]", fullPath); return(false); } } catch (Exception e) { DMC_MBE.LogFormatted("Error while loading settings file from [{0}]\n{1}", fullPath, e); return(false); } }
/// <summary> /// Add a style to a skin, if the styleID already exists it will update the style /// </summary> /// <param name="SkinToAction">The GUISkin we are going to adjust. The name of the Style is its ID</param> /// <param name="NewStyle">The GUIStyle to add or update</param> internal static void AddStyle(ref GUISkin SkinToAction, GUIStyle NewStyle) { if (NewStyle.name == null || NewStyle.name == "") { DMC_MBE.LogFormatted("No Name Provided in the Style to add to {0}. Cannot add this.", SkinToAction.name); return; } //Convert to a list List <GUIStyle> lstTemp = SkinToAction.customStyles.ToList <GUIStyle>(); //Add or edit the customstyle if (lstTemp.Any(x => x.name == NewStyle.name)) { //if itexists then remove it first GUIStyle styleTemp = lstTemp.First(x => x.name == NewStyle.name); lstTemp.Remove(styleTemp); } //add the new style lstTemp.Add(NewStyle); //Write the list back to the array SkinToAction.customStyles = lstTemp.ToArray <GUIStyle>(); }
private void updateParameterValues(Contract c) { if (ContractSystem.Instance.Contracts.Contains(c)) { DMC_MBE.LogFormatted_DebugOnly("Updating Parameters For Newly Offered Contract"); var cParams = c.AllParameters; if (cParams.Count() > 0) { for (int i = 0; i < cParams.Count(); i++) { string name = cParams.ElementAt(i).GetType().Name; if (pTypeList.ContainsKey(name)) { updateParameterValues(pTypeList[name], new List <ContractParameter>() { cParams.ElementAt(i) }, new float[5] { 1, 1, 1, 1, 1 }); } } } } }
//Convert all of our saved strings into the appropriate arrays for each game scene public override void OnLoad(ConfigNode node) { instance = this; try { //The first step is manually checking for active contracts from the Game ConfigNode (ie persistent.sfs file); the count of active contracts will be used later when the window is loading ConfigNode gameNode = HighLogic.CurrentGame.config; if (gameNode != null) { ConfigNode contractSystemNode = gameNode.GetNodes("SCENARIO").FirstOrDefault(c => c.GetValue("name") == "ContractSystem"); if (contractSystemNode != null) { ConfigNode cNode = contractSystemNode.GetNode("CONTRACTS"); if (cNode != null) { foreach (ConfigNode C in cNode.GetNodes("CONTRACT")) { if (C == null) { continue; } if (C.HasValue("autoAccept")) { if (C.GetValue("autoAccept") == "True") { continue; } } if (C.HasValue("state")) { if (C.GetValue("state") == "Active") { contractCount++; } } } } else { DMC_MBE.LogFormatted("Contract System Can't Be Checked... Node Invalid"); } } } ConfigNode scenes = node.GetNode("Contracts_Window_Parameters"); if (scenes != null) { windowPos = stringSplit(scenes.GetValue("WindowPosition")); windowVisible = stringSplitBool(scenes.GetValue("WindowVisible")); int[] winPos = new int[4] { windowPos[4 * currentScene(HighLogic.LoadedScene)], windowPos[(4 * currentScene(HighLogic.LoadedScene)) + 1], windowPos[(4 * currentScene(HighLogic.LoadedScene)) + 2], windowPos[(4 * currentScene(HighLogic.LoadedScene)) + 3] }; //All saved contract missions are loaded here //Each mission has a separate contract list foreach (ConfigNode m in scenes.GetNodes("Contracts_Window_Mission")) { if (m == null) { continue; } string name; string activeString = ""; string hiddenString = ""; string vesselString = ""; bool ascending, showActive; int sortMode; bool master = false; if (m.HasValue("MissionName")) { name = m.GetValue("MissionName"); } else { continue; } if (name == "MasterMission") { master = true; } if (m.HasValue("ActiveListID")) { activeString = m.GetValue("ActiveListID"); } if (m.HasValue("HiddenListID")) { hiddenString = m.GetValue("HiddenListID"); } if (m.HasValue("VesselIDs")) { vesselString = m.GetValue("VesselIDs"); } if (!bool.TryParse(m.GetValue("AscendingSort"), out ascending)) { ascending = true; } if (!bool.TryParse(m.GetValue("ShowActiveList"), out showActive)) { showActive = true; } if (!int.TryParse(m.GetValue("SortMode"), out sortMode)) { sortMode = 0; } contractMission mission = new contractMission(name, activeString, hiddenString, vesselString, ascending, showActive, sortMode, master); if (master) { masterMission = mission; DMC_MBE.LogFormatted_DebugOnly("Setting Master Mission During Load"); } if (!missionList.Contains(name)) { missionList.Add(name, mission); } } loadWindow(winPos); } } catch (Exception e) { DMC_MBE.LogFormatted("Contracts Window Settings Cannot Be Loaded: {0}", e); } }