public void Start() { ConfigNode[] cfgs = GameDatabase.Instance.GetConfigNodes("RESEARCHBODIES"); foreach (ConfigNode node in cfgs) { if (node.GetValue("loadAs") == "locale") { Locale l = new Locale(node); locales.Add(l); RSTLogWriter.Log("Added locale \"{0}\"", l.LocaleId); } } if (locales.Count == 0) { RSTLogWriter.Log("No locale added !"); } else { RSTLogWriter.Log("Added {0} locales", locales.Count); } RSTLogWriter.Flush(); Locales.setLocale(""); Available = true; }
public void ApplySettings() { RSTLogWriter.Log("Database ApplySettings"); if (HighLogic.CurrentGame != null) { //if (RB_SettingsParms == null) RB_SettingsParms = HighLogic.CurrentGame.Parameters.CustomParams <ResearchBodies_SettingsParms>(); if (ResearchBodies.Instance != null) { ResearchBodies.Enabled = RB_SettingsParms.RBEnabled; } chances = RB_SettingsParms.DiscoverySeed; allowTSlevel1 = RB_SettingsParms.Enabledtslvl1; if (RB_SettingsParms.french) { if (Locales.currentLocale.LocaleFull != "Français") { Locales.setLocale("Français"); if (ResearchBodiesController.instance != null) { ResearchBodiesController.instance.French = true; } } } else { Locales.setLocale(""); } RSTLogWriter.debuggingOn = HighLogic.CurrentGame.Parameters.CustomParams <ResearchBodies_SettingsParms>().DebugLogging; } else { RSTLogWriter.Log("Database Failed to apply settings - Fatal Error"); } }
public static void LaunchResearchPlan(CelestialBody cb) { CelestialBody cbKey = Database.instance.ContainsBodiesKey(cb.bodyName); if (cbKey != null && Database.instance.CelestialBodies[cbKey].researchState == 0) { if (Funding.Instance != null) { //if (Funding.Instance.Funds >= Database.Instance.RB_SettingsParms.ResearchCost) if (Funding.Instance.Funds >= Database.instance.RB_SettingsParms.ResearchCost) { //Funding.Instance.AddFunds(-Database.Instance.RB_SettingsParms.ResearchCost, TransactionReasons.None); Funding.Instance.AddFunds(-Database.instance.RB_SettingsParms.ResearchCost, TransactionReasons.Progression); Research(cbKey, 10); } else { ScreenMessages.PostScreenMessage(Locales.FmtLocaleString("#autoLOC_RBodies_00014", cbKey.displayName), 3.0f, ScreenMessageStyle.UPPER_CENTER); } } else { if (HighLogic.CurrentGame.Mode != Game.Modes.CAREER) { Research(cbKey, 10); } } } else { RSTLogWriter.Log(Locales.FmtLocaleString("#autoLOC_RBodies_00015", cb.displayName)); } }
/// <summary> /// When a SOI change is triggered by GameEvents we check if the TO body Is Discovered or NOT. /// If it is not discovered we make it discovered. /// If it's researchState is less than 100 we set it to 100. /// Finally we set the discovery Level and ProgressiveCBMap. /// todo: change this dynamic to discover on SOI entry but gradually build up researchState over time as it remains in SOI. /// </summary> /// <param name="HostedfromtoAction"></param> private void onVesselSOIChanged(GameEvents.HostedFromToAction <Vessel, CelestialBody> HostedfromtoAction) { if (Database.instance.CelestialBodies.ContainsKey(HostedfromtoAction.to)) { if (!Database.instance.CelestialBodies[HostedfromtoAction.to].isResearched) { bool withparent; CelestialBody parentCB; FoundBody(0, HostedfromtoAction.to, out withparent, out parentCB); } if (Database.instance.CelestialBodies[HostedfromtoAction.to].researchState < 100) { Database.instance.CelestialBodies[HostedfromtoAction.to].researchState = 100; //ScreenMessages.PostScreenMessage(string.Format(Locales.currentLocale.Values["#autoLOC_RBodies_00012"],HostedfromtoAction.to.GetName(), Database.Instance.RB_SettingsParms.ScienceReward), 5f); //ResearchAndDevelopment.Instance.AddScience(Database.Instance.RB_SettingsParms.ScienceReward,TransactionReasons.None); ScreenMessages.PostScreenMessage(Locales.FmtLocaleString("#autoLOC_RBodies_00012", HostedfromtoAction.to.displayName, Database.instance.RB_SettingsParms.ScienceReward.ToString()), 5f); ResearchAndDevelopment.Instance.AddScience(Database.instance.RB_SettingsParms.ScienceReward, TransactionReasons.None); var keyvalue = Database.instance.CelestialBodies.FirstOrDefault(a => a.Key.bodyName == HostedfromtoAction.to.bodyName); if (keyvalue.Key != null) { SetIndividualBodyDiscoveryLevel(keyvalue); } } } }
private void DrawStartWindow(int id) { GUILayout.BeginVertical(); GUILayout.Box(Locales.currentLocale.Values["misc_lang"], Textures.sectionTitleStyle); for (int i = 0; i < Locales.locales.Count; i++) { if (GUILayout.Button(Locales.locales[i].LocaleFull)) { Locales.currentLocale = Locales.locales[i]; Locales.Save(Locales.locales[i]); Locales.LoadDiscoveryMessages(); OnLocaleChanged(Locales.currentLocale); } } difficulty = GUILayout.Toolbar(difficulty, Database.instance.difficultyStrings); GUILayout.Label(Database.instance.GetIgnoredBodies((Level)difficulty)); GUILayout.BeginHorizontal(); GUILayout.Label(new GUIContent("<size=11>" + Locales.currentLocale.Values["start_researchPlanCost"] + "</size>", Locales.currentLocale.Values["start_researchPlanCostTT"]), GUILayout.Width(152)); ResearchCost = (float)Math.Round(GUILayout.HorizontalSlider(ResearchCost, 10f, 50f, GUILayout.Width(270))); GUILayout.Label(Convert.ToInt32(ResearchCost + ProgressResearchCost).ToString(), GUILayout.Width(30)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label(new GUIContent("<size=11>" + Locales.currentLocale.Values["start_researchProgress"] + "</size>", Locales.currentLocale.Values["start_researchProgressTT"]), GUILayout.Width(152)); ProgressResearchCost = (float)Math.Round(GUILayout.HorizontalSlider(ProgressResearchCost, 5f, 15f, GUILayout.Width(270))); GUILayout.Label(Convert.ToInt32(ProgressResearchCost).ToString(), GUILayout.Width(30)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label(new GUIContent("<size=11>" + Locales.currentLocale.Values["start_scienceRewards"] + "</size>", Locales.currentLocale.Values["start_scienceRewardsTT"]), GUILayout.Width(152)); ScienceReward = (float)Math.Round(GUILayout.HorizontalSlider(ScienceReward, 5f, 60f, GUILayout.Width(270))); GUILayout.Label(Convert.ToInt32(ScienceReward).ToString(), GUILayout.Width(30)); GUILayout.EndHorizontal(); if (GUILayout.Button("OK")) { foreach (KeyValuePair <CelestialBody, CelestialBodyInfo> CB in Database.instance.CelestialBodies) { CB.Value.ignore = CB.Value.IgnoreData.GetLevel((Level)difficulty); if (CB.Value.ignore) { CB.Value.isResearched = true; CB.Value.researchState = 100; } } ResearchBodies.Instance.RBgameSettings.Difficulty = difficulty; ResearchBodies.Instance.RBgameSettings.ResearchCost = Convert.ToInt32(ResearchCost); ResearchBodies.Instance.RBgameSettings.ScienceReward = Convert.ToInt32(ScienceReward); SetBodyDiscoveryLevels(); showStartUI = false; } GUILayout.EndVertical(); Utilities.SetTooltipText(); GUI.DragWindow(); }
public void OnGUI() { if (!enable) { instructor_Werner.Instructor.enabled = false; instructor_Linus.Instructor.enabled = false; return; } instructor_Werner.Instructor.enabled = true; instructor_Linus.Instructor.enabled = true; try { if (!Textures.StylesSet) { Textures.SetupStyles(); } } catch (Exception ex) { RSTLogWriter.Log("Unable to set GUI Styles to draw the GUI"); RSTLogWriter.Log("Exception: {0}", ex); } GUI.skin = Textures.ObsSkin; #if DEBUGFACILITY if (showObsdebugUI) { observRect = GUILayout.Window(_RBwindowId + 1, observRect, DrawObservDebug, "Research Bodies"); } #endif if (!showGUI) { return; } if (PSystemSetup.Instance.GetSpaceCenterFacility("TrackingStation").GetFacilityDamage() > 0) { ScreenMessages.PostScreenMessage(Locales.FmtLocaleString("#autoLOC_RBodies_00018"), 3.0f, ScreenMessageStyle.UPPER_CENTER); return; } try { windowRect.ClampInsideScreen(); windowRect = GUILayout.Window(_RBwindowId, windowRect, DrawWindow, "Research Bodies"); Utilities.DrawToolTip(); } catch (Exception ex) { RSTLogWriter.Log("Unable to draw GUI"); RSTLogWriter.Log("Exception: {0}", ex); } }
public void ToggleGUI() { if (!this.vessel.Landed && this.vessel.atmDensity < 0.1 && this.vessel.altitude > minAltitude) { showGUI = !showGUI; } else { ScreenMessages.PostScreenMessage(Locales.FmtLocaleString("#autoLOC_RBodies_00019", minAltitude.ToString()), 3.0f, ScreenMessageStyle.UPPER_CENTER); } }
public static bool Research(CelestialBody body, int researchToAdd) { CelestialBody cbKey = Database.instance.ContainsBodiesKey(body.bodyName); if (cbKey != null && Database.instance.CelestialBodies[cbKey].researchState < 100) { if (Funding.Instance != null) { //if (Funding.Instance.Funds >= ResearchBodies.Instance.RBgameSettings.ProgressResearchCost) if (Funding.Instance.Funds >= Database.instance.RB_SettingsParms.ProgressResearchCost) { Database.instance.CelestialBodies[cbKey].researchState += researchToAdd; if (Database.instance.CelestialBodies[cbKey].researchState > 100) { Database.instance.CelestialBodies[cbKey].researchState = 100; } //Funding.Instance.AddFunds(-ResearchBodies.Instance.RBgameSettings.ProgressResearchCost, TransactionReasons.None); Funding.Instance.AddFunds(-Database.instance.RB_SettingsParms.ProgressResearchCost, TransactionReasons.Progression); } else { ScreenMessages.PostScreenMessage(Locales.FmtLocaleString("#autoLOC_RBodies_00047"), 3.0f, ScreenMessageStyle.UPPER_CENTER); } } else { if (HighLogic.CurrentGame.Mode != Game.Modes.CAREER) { Database.instance.CelestialBodies[cbKey].researchState += researchToAdd; } } KeyValuePair <CelestialBody, CelestialBodyInfo> cb = new KeyValuePair <CelestialBody, CelestialBodyInfo>(cbKey, Database.instance.CelestialBodies[cbKey]); ResearchBodiesController.instance.SetIndividualBodyDiscoveryLevel(cb); if (Database.instance.CelestialBodies[cbKey].researchState == 100 && ResearchAndDevelopment.Instance != null) { ScreenMessages.PostScreenMessage(Locales.FmtLocaleString("#autoLOC_RBodies_00012", cbKey.displayName, Database.instance.RB_SettingsParms.ScienceReward.ToString()), 5f); //ResearchAndDevelopment.Instance.AddScience(Database.Instance.RB_SettingsParms.ScienceReward, TransactionReasons.None); ResearchAndDevelopment.Instance.AddScience(Database.instance.RB_SettingsParms.ScienceReward, TransactionReasons.None); } return(true); } else { return(false); } }
public static void StopResearchPlan(CelestialBody cb) { CelestialBody cbKey = Database.instance.ContainsBodiesKey(cb.bodyName); if (cbKey != null && Database.instance.CelestialBodies[cbKey].researchState >= 10) { if (Funding.Instance != null) { Funding.Instance.AddFunds(Database.instance.RB_SettingsParms.ResearchCost, TransactionReasons.Progression); } Database.instance.CelestialBodies[cbKey].researchState = 0; KeyValuePair <CelestialBody, CelestialBodyInfo> cbd = new KeyValuePair <CelestialBody, CelestialBodyInfo>(cbKey, Database.instance.CelestialBodies[cbKey]); ResearchBodiesController.instance.SetIndividualBodyDiscoveryLevel(cbd); } else { RSTLogWriter.Log(Locales.FmtLocaleString("#autoLOC_RBodies_00016", cb.displayName)); } }
//This is only called by the Startup Menu GUI to show ignored bodies based on the level passed in. public string GetIgnoredBodies(Level l) { Locales.setLocale(""); string _bodies = Locales.FmtLocaleString("#autoLOC_RBodies_00030") + " : "; //string _bodies = ""; List <CelestialBody> TempBodiesList = new List <CelestialBody>(); for (int i = 0; i < BodyList.Count; i++) { if (CelestialBodies[BodyList[i]].IgnoreData.GetLevel(l) && (BodyList[i].Radius > 100 || BodyList[i].name.Contains("TSTGalaxies"))) { TempBodiesList.Add(BodyList[i]); } } for (int i = 0; i < TempBodiesList.Count; i++) { _bodies += BodyList[i].displayName.LocalizeRemoveGender(); if (i < TempBodiesList.Count - 1) { _bodies += ", "; } } return(_bodies); }
private void DrawWindow(int id) { GUIContent closeContent = new GUIContent(Textures.BtnRedCross, "Close Window"); Rect closeRect = new Rect(windowRect.width - 75, 4, 25, 25); if (GUI.Button(closeRect, closeContent, Textures.ClosebtnStyle)) { ResearchBodies_Observatory.SpaceCenterObservatory.DeActivateObservatory_SC_Facility(); return; } GUILayout.BeginVertical(); #region Top Half Screen //Screen Top Half Starts GUILayout.BeginHorizontal(); GUILayout.BeginArea(new Rect((Utilities.scaledScreenWidth / 2) - 380, 50, 760, 500)); GUILayout.BeginHorizontal(GUILayout.Width(750)); GUILayout.BeginVertical(); GUILayout.BeginVertical(); #region Wernher_Portrait Panel 1 InstructorscrollViewVector = GUILayout.BeginScrollView(InstructorscrollViewVector, GUILayout.Width(248), GUILayout.Height(186)); GUILayout.BeginVertical(); if ((IsTSlevel1 && Database.instance.allowTSlevel1) || !IsTSlevel1) { if (Event.current.type == EventType.Repaint) { GUILayout.Box(instructor_Werner.Portrait, GUILayout.Width(128), GUILayout.Height(128)); } else { GUILayout.Box(string.Empty, GUILayout.Width(128), GUILayout.Height(128)); } GUILayout.Label(instructor_Werner.InstructorName, GUILayout.Width(198)); } else { GUILayout.Label(Locales.FmtLocaleString("#autoLOC_RBodies_00017"), GUILayout.Width(198), GUILayout.Height(128)); } GUILayout.EndVertical(); GUILayout.EndScrollView(); #endregion GUILayout.EndVertical(); GUILayout.BeginVertical(); #region BodyList Panel 2 scrollViewVector = GUILayout.BeginScrollView(scrollViewVector, GUILayout.Width(248), GUILayout.Height(300)); GUILayout.BeginVertical(); haveTrackedBodies = false; foreach (KeyValuePair <CelestialBody, CelestialBodyInfo> cb in Database.instance.CelestialBodies) { //if (cb.Value.isResearched && !cb.Value.ignore) if (cb.Value.isResearched) { if (GUILayout.Button(cb.Key.bodyDisplayName.LocalizeRemoveGender(), GUILayout.Width(215))) { if (selectedBody == cb.Key) { selectedBody = null; } else { selectedBody = cb.Key; } instructor_Werner.PlayOKEmote(); } if (!cb.Value.ignore) { haveTrackedBodies = true; } } } GUILayout.EndVertical(); GUILayout.EndScrollView(); #endregion GUILayout.EndVertical(); GUILayout.EndVertical(); GUILayout.BeginVertical(); #region Research Panel 3 ResearchscrollViewVector = GUILayout.BeginScrollView(ResearchscrollViewVector, GUILayout.Width(500), GUILayout.Height(485)); GUILayout.BeginVertical(); if ((IsTSlevel1 && Database.instance.allowTSlevel1) || !IsTSlevel1) { if (selectedBody == null) { if (!haveTrackedBodies) { GUILayout.Label("<color=orange>" + Locales.FmtLocaleString("#autoLOC_RBodies_00001") + "</color>", GUILayout.Width(500)); } else { GUILayout.Label("<color=orange>" + Locales.FmtLocaleString("#autoLOC_RBodies_00001") + "</color>", GUILayout.Width(500)); //GUILayout } } else { GUILayout.BeginHorizontal(); GUILayout.Label("<b><size=24><color=orange>" + selectedBody.displayName.LocalizeRemoveGender() + "</color></size></b>", GUILayout.Width(150)); GUILayout.Label("<i>" + (French ? Database.instance.CelestialBodies[selectedBody].discoveryMessage : Localizer.Format("#autoLOC_RBodies_discovery_" + selectedBody.bodyName)) + "</i>", GUILayout.Width(300)); GUILayout.EndHorizontal(); if (selectedBody != Planetarium.fetch.Sun && selectedBody.referenceBody != null && selectedBody.bodyName != selectedBody.referenceBody.bodyName) { if (selectedBody.referenceBody != Planetarium.fetch.Sun) { GUILayout.Label(Locales.FmtLocaleString("#autoLOC_RBodies_00003", selectedBody.referenceBody.displayName.LocalizeRemoveGender()), GUILayout.Width(150)); } else { GUILayout.Label(Locales.FmtLocaleString("#autoLOC_RBodies_00004"), GUILayout.Width(150)); } } GUILayout.Label(Locales.FmtLocaleString("#autoLOC_RBodies_00005", Database.instance.CelestialBodies[selectedBody].researchState.ToString()), GUILayout.Width(480)); if (Database.instance.CelestialBodies[selectedBody].researchState == 0) { if ( GUILayout.Button("<color=#0ef907>" + Locales.FmtLocaleString("#autoLOC_RBodies_00006", selectedBody.displayName.LocalizeRemoveGender()) + "\n</color><size=10><i>(" + Locales.FmtLocaleString("#autoLOC_RBodies_00007", (Database.instance.RB_SettingsParms.ResearchCost + Database.instance.RB_SettingsParms.ProgressResearchCost).ToString() /* 10 */) + ")</i></size>", GUILayout.Width(480))) { LaunchResearchPlan(selectedBody); instructor_Werner.PlayNiceEmote(); } } else if (Database.instance.CelestialBodies[selectedBody].researchState >= 1) { if (!Database.instance.CelestialBodies[selectedBody].ignore) { if ( GUILayout.Button("<color=red>" + Locales.FmtLocaleString("#autoLOC_RBodies_00008", selectedBody.displayName.LocalizeRemoveGender()) + "\n</color><size=10><i>(" + Locales.FmtLocaleString("#autoLOC_RBodies_00009", Database.instance.RB_SettingsParms.ResearchCost.ToString() /* 5 */) + ")</i></size>", GUILayout.Width(480))) { StopResearchPlan(selectedBody); instructor_Werner.PlayBadEmote(); } } if (Database.instance.CelestialBodies[selectedBody].researchState < 40 && Database.instance.CelestialBodies[selectedBody].researchState >= 1) { if (HighLogic.CurrentGame.Mode == Game.Modes.SANDBOX || HighLogic.CurrentGame.Mode == Game.Modes.SCIENCE_SANDBOX) { if (GUILayout.Button(Locales.FmtLocaleString("#autoLOC_RBodies_00010"), GUILayout.Width(480))) { instructor_Werner.PlayNiceEmote(); Research(selectedBody, 10); } } } else if (Database.instance.CelestialBodies[selectedBody].researchState >= 40 && Database.instance.CelestialBodies[selectedBody].researchState < 100) { GUILayout.Label("<i><color=#0ef907>" + Locales.FmtLocaleString("#autoLOC_RBodies_00010") + " ✓</color></i>", GUILayout.Width(480)); if (HighLogic.CurrentGame.Mode == Game.Modes.SANDBOX || HighLogic.CurrentGame.Mode == Game.Modes.SCIENCE_SANDBOX) { if (GUILayout.Button(Locales.FmtLocaleString("#autoLOC_RBodies_00011"), GUILayout.Width(480))) { instructor_Werner.PlayNiceEmote(); Research(selectedBody, 10); } } } else if (Database.instance.CelestialBodies[selectedBody].researchState >= 100) { GUILayout.Label("<i><color=#0ef907>" + Locales.FmtLocaleString("#autoLOC_RBodies_00010") + " ✓</color></i>", GUILayout.Width(480)); //new Rect(188, 227, 502, 32), GUILayout.Label("<i><color=#0ef907>" + Locales.FmtLocaleString("#autoLOC_RBodies_00011") + " ✓</color></i>", GUILayout.Width(480)); //new Rect(188, 264, 502, 32), GUILayout.Label("<b>" + Locales.FmtLocaleString("#autoLOC_RBodies_00013", selectedBody.displayName.LocalizeRemoveGender()) + "</b>", GUILayout.Width(480)); } } } } GUILayout.EndVertical(); GUILayout.EndScrollView(); #endregion GUILayout.EndVertical(); GUILayout.EndHorizontal(); GUILayout.EndArea(); GUILayout.EndHorizontal(); //Screen Top Half Ends. #endregion #region Bottom Half Screen if (HighLogic.CurrentGame.Mode == Game.Modes.CAREER) { GUILayout.BeginHorizontal(); GUILayout.BeginArea(new Rect((Utilities.scaledScreenWidth / 2) - 380, 560, 760, 300)); GUILayout.BeginHorizontal(GUILayout.Width(700)); GUILayout.BeginVertical(); #region Linus_Portrait Panel 1 InstructorscrollViewVector = GUILayout.BeginScrollView(InstructorscrollViewVector, GUILayout.Width(248), GUILayout.Height(186)); GUILayout.BeginVertical(); if ((IsTSlevel1 && Database.instance.allowTSlevel1) || !IsTSlevel1) { if (Event.current.type == EventType.Repaint) { GUILayout.Box(instructor_Linus.Portrait, GUILayout.Width(128), GUILayout.Height(128)); } else { GUILayout.Box(string.Empty, GUILayout.Width(128), GUILayout.Height(128)); } GUILayout.Label(instructor_Linus.InstructorName, GUILayout.Width(178)); } else { GUILayout.Label(Locales.FmtLocaleString("#autoLOC_RBodies_00017"), GUILayout.Width(188), GUILayout.Height(128)); } GUILayout.EndVertical(); GUILayout.EndScrollView(); #endregion GUILayout.EndVertical(); #region ContractsSection ContractsscrollViewVector = GUILayout.BeginScrollView(ResearchscrollViewVector, GUILayout.Width(500), GUILayout.Height(186)); GUILayout.BeginVertical(); GUILayout.Label("<b><size=24><color=orange>" + Locales.FmtLocaleString("#autoLOC_RBodies_00103") + "</color></size></b>", GUILayout.Width(350)); GUILayout.Label("<b>" + Locales.FmtLocaleString("#autoLOC_RBodies_00104") + "</b>", GUILayout.Width(350)); for (int i = 0; i < Contracts.ContractSystem.Instance.Contracts.Count; ++i) { Contract contract = Contracts.ContractSystem.Instance.Contracts[i]; if (contract.ContractState == Contract.State.Active) { ContractConfigurator.ConfiguredContract configuredContract = contract as ContractConfigurator.ConfiguredContract; if (configuredContract != null) { switch (configuredContract.subType) { case "RB_TeleScopeSearchSkies": case "RB_TelescopeResearchBody": case "RB_SearchSkies": case "RB_ResearchBody": //Display Contract GUILayout.Label(configuredContract.Title, GUILayout.Width(400)); ContractParameter parameter = configuredContract.GetParameter("Duration"); if (parameter != null) { GUILayout.Label("<color=#0ef907>" + parameter.Title + "</color>", GUILayout.Width(400)); } break; } } } } GUILayout.EndVertical(); GUILayout.EndScrollView(); #endregion GUILayout.EndHorizontal(); GUILayout.EndArea(); GUILayout.EndHorizontal(); } #endregion GUILayout.EndVertical(); Utilities.SetTooltipText(); }
private void DrawSettings(int id) { GUIContent closeContent = new GUIContent(Textures.BtnRedCross, "Close Window"); Rect closeRect = new Rect(settingsRect.width - 21, 4, 16, 16); if (GUI.Button(closeRect, closeContent, Textures.ClosebtnStyle)) { showSettings = false; return; } GUILayout.BeginVertical(); langSettingsScroll = GUILayout.BeginScrollView(langSettingsScroll); GUILayout.BeginVertical(); GUILayout.Box(Locales.currentLocale.Values["misc_lang"], Textures.sectionTitleStyle); for (int i = 0; i < Locales.locales.Count; i++) { if (GUILayout.Button(Locales.locales[i].LocaleFull)) { Locales.currentLocale = Locales.locales[i]; Locales.Save(Locales.locales[i]); Locales.LoadDiscoveryMessages(); OnLocaleChanged(Locales.currentLocale); } } bool _inputAppL = Database.UseAppLauncher; if (!ToolbarManager.ToolbarAvailable) { GUI.enabled = false; tmpToolTip = Locales.currentLocale.Values["settings_useAppLTT_TBNA"]; } else { tmpToolTip = Locales.currentLocale.Values["settings_useAppLTT_TBA"]; } GUILayout.BeginHorizontal(); GUILayout.Box(new GUIContent(Locales.currentLocale.Values["settings_useAppL"], tmpToolTip), Textures.statusStyle, GUILayout.Width(250)); _inputAppL = GUILayout.Toggle(_inputAppL, "", GUILayout.MinWidth(30.0F)); //you can play with the width of the text box GUILayout.EndHorizontal(); if (Database.UseAppLauncher != _inputAppL) { Database.UseAppLauncher = _inputAppL; RBMenuAppLToolBar.chgAppIconStockToolBar(Database.UseAppLauncher); } GUI.enabled = true; GUILayout.EndVertical(); GUILayout.EndScrollView(); /* GUI.Label(new Rect(10, 195, 280, 32), Locales.currentLocale.Values["misc_instructor"]); * if (GUI.Button(new Rect(10, 232, 130, 32), "Wernher von Kerman")) * { * if (File.Exists("GameData/ResearchBodies/PluginData/cacheInstructor")) * { * StreamReader sr = new StreamReader("GameData/ResearchBodies/PluginData/cacheInstructor"); * string line = sr.ReadLine(); * * sr.Close(); * } * } * if (GUI.Button(new Rect(150, 232, 130, 32), "Gene Kerman")) * { } */ GUILayout.EndVertical(); Utilities.SetTooltipText(); GUI.DragWindow(); }
void DrawWindow(int windowID) { GUIContent closeContent = new GUIContent(Textures.BtnRedCross, Locales.FmtLocaleString("#autoLOC_RBodies_00050")); Rect closeRect = new Rect(windowRect.width - 21, 4, 16, 16); if (GUI.Button(closeRect, closeContent, Textures.ClosebtnStyle)) { showGUI = !showGUI; return; } GUILayout.BeginVertical(); scrollViewBodiesVector = GUILayout.BeginScrollView(scrollViewBodiesVector, GUILayout.MaxHeight(200f)); GUILayout.BeginVertical(); GUILayout.Label(Locales.FmtLocaleString("#autoLOC_RBodies_00024"), Textures.sectionTitleStyle); //#autoLOC_RBodies_00024 = Available Bodies foreach (var body in Database.instance.CelestialBodies) { if (body.Value.isResearched) { GUILayout.Label(body.Key.GetDisplayName().LocalizeRemoveGender() + " - " + body.Value.researchState.ToString("N0") + "%", Textures.PartListPartStyle); } } GUILayout.EndVertical(); GUILayout.EndScrollView(); scrollViewVector = GUILayout.BeginScrollView(scrollViewVector); GUILayout.BeginVertical(); GUILayout.Label(Locales.FmtLocaleString("#autoLOC_RBodies_00021", electricChargeRequest.ToString())); //#autoLOC_RBodies_00021 = Each use of the Telescope will use <<1>> Electric Charge if (GUILayout.Button(Locales.FmtLocaleString("#autoLOC_RBodies_00022"))) //#autoLOC_RBodies_00022 = Track Bodies { foundBody = false; withParent = false; foundBodyTooWeak = false; searchButtonDisplayTimer = Planetarium.GetUniversalTime(); searchButtonDisplay = true; nothing = Database.instance.NothingHere[random.Next(Database.instance.NothingHere.Count)]; BodiesInView.Clear(); //Check part dependency.. Unusual, But ok. if (requiresPart) { bool local = false; foreach (Part part in this.vessel.Parts) { if (part.name.Contains(requiredPart)) { local = true; } } if (!local) { canResearch = false; ScreenMessages.PostScreenMessage(Locales.FmtLocaleString("#autoLOC_RBodies_00020", requiredPart), 5.0f, ScreenMessageStyle.UPPER_CENTER); //#autoLOC_RBodies_00020 = The vessel must have a <<1>> part attached to it! } } if (canResearch) //Part check is OK { var totalElecreceived = Utilities.RequestResource(this.part, "ElectricCharge", electricChargeRequest); //get power if (totalElecreceived >= electricChargeRequest * 0.99) //If we got power { var randomMax = Database.instance.chances + difficulty; //Calculate the randomness (sic) and if we found something. This needs to be replaced with something better. var randomNum = random.Next(randomMax); if (randomNum == 1 || randomNum == 2) { //Scan the list of CB's and find anything in range? foreach (CelestialBody body in Database.instance.BodyList) { hostPos = this.part.transform.position; targetPos = body.transform.position; angle = Vector3.Angle(targetPos - hostPos, this.part.transform.up); distance = Vector3d.Distance(body.transform.position, this.vessel.transform.position); //Is it within the acceptable Angle? if (angle <= viewAngle) { //Is it within the maximum tracking distance of this part? if (distance <= maxTrackDistance) { if (!IsViewObstructed(this.part.transform, body.transform)) { BodiesInView.Add(body); //We got one! } } //Too far away. else { foundBodyTooWeak = true; } } } if (BodiesInView.Count > 0) //did we find anything? { //Remove any already researched. BodiesInViewResearched.Clear(); for (int i = BodiesInView.Count - 1; i >= 0; --i) { if (Database.instance.CelestialBodies[BodiesInView[i]].isResearched) { BodiesInViewResearched.Add(BodiesInView[i]); } } BodiesInViewResearched.ForEach(id => BodiesInView.Remove(id)); if (BodiesInView.Count > 0) //Do we still have any? If so: { bodyFound = BodiesInView[random.Next(BodiesInView.Count)]; //Randomly pick one. foundBody = true; ScreenMessages.PostScreenMessage(Localizer.Format("#autoLOC_RBodies_00051"), 15f); //#autoLOC_RBodies_00051 = Celestial Body Discovered! difficulty = startingdifficulty; //Reset the difficulty factor to the starting factor now that we found something. ResearchBodiesController.FoundBody(scienceReward, bodyFound, out withParent, out parentBody); } } } else { //We didn't find anything. Reduce the difficulty by one until we do. foundBody = false; if (randomMax > 2) { difficulty--; } } } else // There wasn't enough EC! { ScreenMessages.PostScreenMessage(Locales.FmtLocaleString("#autoLOC_RBodies_00048"), 5.0f, ScreenMessageStyle.UPPER_CENTER); //#autoLOC_RBodies_00048 = Not enough Electric Charge to operate the telescope. } } } //endif button //Populate RB GUI if found. if (searchButtonDisplay) { if (Planetarium.GetUniversalTime() - searchButtonDisplayTimer > 60) { searchButtonDisplayTimer = 0; searchButtonDisplay = false; } //Populate text box on discovery. if (foundBody) //Did we end up finding anything? { if (withParent) //And was a parent body also discovered? { GUILayout.Label(French ? Database.instance.CelestialBodies[bodyFound].discoveryMessage : Localizer.Format("#autoLOC_RBodies_discovery_" + bodyFound.bodyName)); GUILayout.Label(French ? Database.instance.CelestialBodies[parentBody].discoveryMessage : Localizer.Format("#autoLOC_RBodies_discovery_" + parentBody.bodyName)); } else { GUILayout.Label(French ? Database.instance.CelestialBodies[bodyFound].discoveryMessage : Localizer.Format("#autoLOC_RBodies_discovery_" + bodyFound.bodyName)); } } else //Nope, didn't find anything. { if (foundBodyTooWeak) //Was there something just out of telescope range? { GUILayout.Label(Locales.FmtLocaleString("#autoLOC_RBodies_00023"), HighLogic.Skin.label); //#autoLOC_RBodies_00023 = A faint signal has been detected but we need a more powerful Telescope. } else //Nope there was absolutely nothing to see here. { GUILayout.Label(Localizer.Format(nothing), HighLogic.Skin.label); } } } GUILayout.EndVertical(); GUILayout.EndScrollView(); GUILayout.EndVertical(); GUI.DragWindow(); }
public void OnGUI() { if (HighLogic.LoadedSceneIsFlight && !sceneChangeRequested) { if (showGUI && ResearchBodies.Enabled) { GUI.skin = HighLogic.Skin; windowRect.ClampToScreen(); windowRect = GUILayout.Window(_partwindowID, windowRect, DrawWindow, Locales.FmtLocaleString("#autoLOC_RBodies_00026")); } } }
public void LoadDatabase() { RSTLogWriter.Log("LoadDatabase"); //RB_SettingsParms = HighLogic.CurrentGame.Parameters.CustomParams<ResearchBodies_SettingsParms>(); Locales.setLocale(""); isTSTInstalled = Utilities.IsTSTInstalled; if (isTSTInstalled) //If TST assembly is present, initialise TST wrapper. { if (!TSTWrapper.InitTSTWrapper()) { isTSTInstalled = false; //If the initialise of wrapper failed set bool to false, we won't be interfacing to TST today. } } Textures.LoadIconAssets(); //Get a list of CBs BodyList = FlightGlobals.Bodies.ToList(); if (isTSTInstalled && TSTWrapper.APITSTReady) //If TST is installed add the TST Galaxies to the list. { BodyList = BodyList.Concat(TSTWrapper.actualTSTAPI.CBGalaxies).ToList(); } //Process Kopernicus Barycenter's. foreach (CelestialBody body in BodyList) { CelestialBodyInfo bodyinfo = new CelestialBodyInfo(body.GetName()); if (body.Radius < 100 && !body.name.Contains("TSTGalaxies")) //This body is a barycenter { bodyinfo.KOPbarycenter = true; } else { if (body.referenceBody.Radius < 100) // This Bodies Reference Body has a Radius < 100m. IE: It's Part of a Barycenter. { bodyinfo.KOPrelbarycenterBody = body.referenceBody; //Yeah so what... well we need it for pass 2 below. } } CelestialBodies.Add(body, bodyinfo); } //Now we look back through any CBs that were related to a barycenter body. foreach (var CB in CelestialBodies.Where(a => a.Value.KOPrelbarycenterBody != null)) { //So does this body have any orbitingBodies? //If it does we need to somehow find and link any related Orbit Body. foreach (CelestialBody orbitingBody in CB.Key.orbitingBodies) { CelestialBody findOrbitBody = FlightGlobals.Bodies.FirstOrDefault(a => a.name.Contains(CB.Key.name) && a.name.Contains(orbitingBody.name) && a.name.Contains("Orbit")); //so if we found the related Orbit body we store it into the CelestialBodies dictionary. if (findOrbitBody != null) { CelestialBodies[orbitingBody].KOPrelbarycenterBody = findOrbitBody; } } } //Load the database.cfg file. //=========================== ConfigNode cfg = ConfigNode.Load(Locales.PathDatabasePath); string[] sep = new string[] { " " }; Observatorylvl1Range = float.Parse(cfg.GetNode("RESEARCHBODIES").GetValue("observatorylvl1range")); Observatorylvl2Range = float.Parse(cfg.GetNode("RESEARCHBODIES").GetValue("observatorylvl2range")); AllowOldResearchinCareer = bool.Parse(cfg.GetNode("RESEARCHBODIES").GetValue("allowOldResearchinCareer")); //Get Costs string[] _startResearchCosts; _startResearchCosts = cfg.GetNode("RESEARCHBODIES").GetValue("StartResearchCosts").Split(sep, StringSplitOptions.RemoveEmptyEntries); StartResearchCosts = new int[] { int.Parse(_startResearchCosts[0]), int.Parse(_startResearchCosts[1]), int.Parse(_startResearchCosts[2]), int.Parse(_startResearchCosts[3]) }; string[] _progressResearchCosts; _progressResearchCosts = cfg.GetNode("RESEARCHBODIES").GetValue("ProgressResearchCosts").Split(sep, StringSplitOptions.RemoveEmptyEntries); ProgressResearchCosts = new int[] { int.Parse(_progressResearchCosts[0]), int.Parse(_progressResearchCosts[1]), int.Parse(_progressResearchCosts[2]), int.Parse(_progressResearchCosts[3]) }; string[] _scienceRewards; _scienceRewards = cfg.GetNode("RESEARCHBODIES").GetValue("ScienceRewards").Split(sep, StringSplitOptions.RemoveEmptyEntries); ScienceRewards = new int[] { int.Parse(_scienceRewards[0]), int.Parse(_scienceRewards[1]), int.Parse(_scienceRewards[2]), int.Parse(_scienceRewards[3]) }; RSTLogWriter.Log("Loading Priority database"); foreach (CelestialBody body in BodyList) { //Load the ondiscovery values - English only, which then get over-written in Locale.cs foreach (ConfigNode.Value value in cfg.GetNode("RESEARCHBODIES").GetNode("ONDISCOVERY").values) { if (value.name.Contains(body.bodyName)) { CelestialBodies[body].discoveryMessage = value.value; } } } //Load the IgnoreData dictionary. RSTLogWriter.Log("Loading ignore body list from database"); foreach (ConfigNode.Value value in cfg.GetNode("RESEARCHBODIES").GetNode("IGNORELEVELS").values) { foreach (CelestialBody body in BodyList) { if (body.GetName() == value.name) { string[] args; args = value.value.Split(sep, StringSplitOptions.RemoveEmptyEntries); BodyIgnoreData ignoredata = new BodyIgnoreData(bool.Parse(args[0]), bool.Parse(args[1]), bool.Parse(args[2]), bool.Parse(args[3])); CelestialBodies[body].IgnoreData = ignoredata; RSTLogWriter.Log("Body Ignore Data for {0} : {1}", body.GetName(), CelestialBodies[body].IgnoreData); } } } RSTLogWriter.Flush(); LoadModDatabaseNodes(); NothingHere.Add("#autoLOC_RBodies_00052"); NothingHere.Add("#autoLOC_RBodies_00053"); NothingHere.Add("#autoLOC_RBodies_00054"); NothingHere.Add("#autoLOC_RBodies_00055"); RSTLogWriter.Log("Chances to get a body is set to {0}", chances); RSTLogWriter.Log("Loaded gamemode-related information : enable mod in sandbox = {0}, allow tracking with Tracking station lvl 1 = {1}", enableInSandbox, allowTSlevel1); // Load locales for OnDiscovery - Locales are loaded Immediately gamescene. Before this is loaded in MainMenu. if (Locales.currentLocale.LocaleId != "en") { foreach (CelestialBody body in BodyList) { CelestialBody bodiesKey = ContainsBodiesKey(body.bodyName); if (Locales.currentLocale.Values.ContainsKey("#autoLOC_RBodies_discovery_" + body.bodyName) && bodiesKey != null) { CelestialBodies[bodiesKey].discoveryMessage = Locales.currentLocale.Values["#autoLOC_RBodies_discovery_" + body.bodyName]; } } } RSTLogWriter.Flush(); }