private void updateGroundStationGUIRow(string stationID) { if (this.currentContentType != ContentType.GROUNDSTATIONS) { return; } List <DialogGUIBase> rows = contentLayout.children; for (int i = 1; i < rows.Count; i++) { DialogGUIBase thisRow = rows[i]; if (thisRow.OptionText.Equals(stationID)) { DialogGUIImage colorImage = thisRow.children[0] as DialogGUIImage; DialogGUILabel nameLabel = thisRow.children[1] as DialogGUILabel; DialogGUILabel freqsLabel = thisRow.children[3] as DialogGUILabel; CNCCommNetHome station = CNCCommNetScenario.Instance.groundStations.Find(x => x.ID.Equals(stationID)); colorImage.uiItem.GetComponent <RawImage>().color = station.Color; nameLabel.SetOptionText(station.stationName); freqsLabel.SetOptionText(getFreqString(station.getFrequencyList())); break; } } }
public static Settings Load() { // Create a blank object of settings Settings settings = new Settings(); bool defaultSuccess = false; AssemblyLoader.LoadedAssembly assemblyDLL = null; for (int i = 0; i <= AssemblyLoader.loadedAssemblies.Count; i++) { if (AssemblyLoader.loadedAssemblies[i].assembly.GetName().Name.Equals("CommNetConstellation")) { assemblyDLL = AssemblyLoader.loadedAssemblies[i]; break; } } startingSettingCFGUrl = assemblyDLL.url.Replace("/Plugins", "") + "/cnc_settings/CommNetConstellationSettings"; settings.MajorVersion = assemblyDLL.versionMajor; settings.MinorVersion = assemblyDLL.versionMinor; // Exploit KSP's GameDatabase to find our MM-patched cfg of default settings UrlDir.UrlConfig[] cfgs = GameDatabase.Instance.GetConfigs("CommNetConstellationSettings"); for (var i = 0; i < cfgs.Length; i++) { if (cfgs[i].url.Equals(startingSettingCFGUrl)) { defaultSuccess = ConfigNode.LoadObjectFromConfig(settings, cfgs[i].config); //Workaround due to LoadObjectFromConfig not auto-populating ground stations for unknown reason settings.GroundStations = new List <CNCCommNetHome>(); ConfigNode[] stationNodes = cfgs[i].config.GetNode("GroundStations").GetNodes(); for (int j = 0; j < stationNodes.Length; j++) { CNCCommNetHome dummyGroundStation = new CNCCommNetHome(); ConfigNode.LoadObjectFromConfig(dummyGroundStation, stationNodes[j]); settings.GroundStations.Add(dummyGroundStation); } CNCLog.Verbose("Load starting settings into object with {0}: LOADED {1}", cfgs[i].config, defaultSuccess ? "OK" : "FAIL"); break; } } if (!defaultSuccess) // disable itself and write explanation to KSP's log { CNCLog.Error("The CommNet Constellation setting file '{0}' is not found!", startingSettingCFGUrl); return(null); // the main impact of returning null is the endless loop of invoking Load() in the KSP's loading screen } settings.SettingsLoaded = true; settings.postprocess(); return(settings); }
private DialogGUIHorizontalLayout createGroundStationRow(CNCCommNetHome thisStation) { DialogGUIImage colorImage = new DialogGUIImage(new Vector2(16, 16), Vector2.one, thisStation.Color, groundstationTexture); DialogGUILabel stationNameLabel = new DialogGUILabel(thisStation.stationName, 170, 12); DialogGUILabel locationLabel = new DialogGUILabel(Localizer.Format("#CNC_ConstellationControl_LatitudeAndLongitude", string.Format("{0:0.0}", thisStation.latitude), string.Format("{0:0.0}", thisStation.longitude)), 100, 24); //string.Format("LAT: \nLON: ", , ) DialogGUILabel freqsLabel = new DialogGUILabel(getFreqString(thisStation.getFrequencyList()), 210, 12); DialogGUIButton updateButton = new DialogGUIButton(Localizer.Format("#CNC_Generic_Editbutton"), delegate { groundstationEditClick(thisStation); }, 50, 32, false); //"Edit" DialogGUIBase[] rowGUIBase = new DialogGUIBase[] { colorImage, stationNameLabel, locationLabel, freqsLabel, updateButton }; DialogGUIHorizontalLayout groundStationGroup = new DialogGUIHorizontalLayout(true, false, 4, new RectOffset(), TextAnchor.MiddleCenter, rowGUIBase); groundStationGroup.SetOptionText(thisStation.ID); //for quick identification return(groundStationGroup); }
public GroundStationBuildDialog(string title, CNCCommNetHome thisStation, Callback <string> updateCallback) : base("gsBuild", title, 0.5f, //x 0.5f, //y 300, //width 330, //height new DialogOptions[] { DialogOptions.HideCloseButton }) { this.hostStation = thisStation; this.updateCallback = updateCallback; this.description = Localizer.Format("#CNC_GroundStationBuild_desc", thisStation.stationName);//"You are upgrading the ground station '{0}'." this.GetInputLocks(); }
public GroundStationEditDialog(string title, CNCCommNetHome thisStation, Callback <string> updateCallback) : base("gsEdit", title, 0.5f, //x 0.5f, //y 290, //width 300, //height new DialogOptions[] { DialogOptions.HideCloseButton }) { this.hostStation = thisStation; this.updateCallback = updateCallback; this.description = Localizer.Format("#CNC_GroundStationEdit_desc", thisStation.stationName);//string.Format("You are editing the ground station '{0}'.", ) this.freqListShown.AddRange(thisStation.getFrequencyList()); this.freqListShown.Sort(); this.constellColor = thisStation.Color; this.GetInputLocks(); }
protected override List <DialogGUIBase> drawContentComponents() { List <DialogGUIBase> listComponments = new List <DialogGUIBase>(); listComponments.Add(new DialogGUIHorizontalLayout(true, false, 0, new RectOffset(), TextAnchor.UpperCenter, new DialogGUIBase[] { new DialogGUILabel(this.description + "\n\n", false, false) })); DialogGUILabel nameLabel = new DialogGUILabel("<b>" + Localizer.Format("#CNC_Generic_nameLabel") + "</b>", 30, 12);//Name nameInput = new DialogGUITextInput(this.hostStation.stationName, false, CNCSettings.MaxLengthName, setNameInput, 145, 25); DialogGUIButton defaultButton = new DialogGUIButton(Localizer.Format("#CNC_Generic_Resetbutton"), defaultNameClick, 40, 25, false);//"Reset" DialogGUIHorizontalLayout nameGroup = new DialogGUIHorizontalLayout(true, false, 4, new RectOffset(), TextAnchor.MiddleCenter, new DialogGUIBase[] { nameLabel, nameInput, new DialogGUIFlexibleSpace(), defaultButton }); listComponments.Add(nameGroup); DialogGUILabel freqLabel = new DialogGUILabel("<b>" + Localizer.Format("#CNC_GroundStationEdit_freqLabel") + "</b>", 85, 12);//New frequency frequencyInput = new DialogGUITextInput("", false, CNCSettings.MaxDigits, setFreqInput, 60, 25); DialogGUIButton addButton = new DialogGUIButton(Localizer.Format("#CNC_Generic_Addbutton"), addClick, 40, 25, false);//"Add" stationColorImage = new DialogGUIImage(new Vector2(16f, 16f), Vector2.zero, this.hostStation.Color, CNCCommNetHome.getGroundStationTexture(this.hostStation.TechLevel)); DialogGUIHorizontalLayout imageBtnLayout = new DialogGUIHorizontalLayout(true, true, 0f, new RectOffset(5, 5, 5, 5), TextAnchor.MiddleCenter, new DialogGUIBase[] { stationColorImage }); DialogGUIButton colorButton = new DialogGUIButton("", colorEditClick, 26, 26, false, new DialogGUIBase[] { imageBtnLayout }); DialogGUIHorizontalLayout freqGRoup = new DialogGUIHorizontalLayout(true, false, 4, new RectOffset(), TextAnchor.MiddleCenter, new DialogGUIBase[] { freqLabel, frequencyInput, addButton, new DialogGUISpace(50), colorButton }); listComponments.Add(freqGRoup); //Prepare a list container for the GUILayout rows DialogGUIBase[] rows = new DialogGUIBase[this.hostStation.getFrequencyList().Count + 1]; rows[0] = new DialogGUIContentSizer(ContentSizeFitter.FitMode.Unconstrained, ContentSizeFitter.FitMode.PreferredSize, true); for (int i = 0; i < this.freqListShown.Count; i++) { rows[i + 1] = createConstellationRow(this.freqListShown[i]); } frequencyRowLayout = new DialogGUIVerticalLayout(10, 100, 0, new RectOffset(5, 25, 5, 5), TextAnchor.UpperLeft, rows); listComponments.Add(new CustomDialogGUIScrollList(new Vector2(240, 100), false, true, frequencyRowLayout)); DialogGUIButton updateButton = new DialogGUIButton(Localizer.Format("#CNC_Generic_UpdateButton"), updateAction, false); //"Update" DialogGUIButton cancelButton = new DialogGUIButton(Localizer.Format("#CNC_Generic_CancelButton"), delegate { this.dismiss(); }, false); //"Cancel" DialogGUIHorizontalLayout actionGroup = new DialogGUIHorizontalLayout(true, false, 4, new RectOffset(), TextAnchor.MiddleLeft, new DialogGUIBase[] { new DialogGUIFlexibleSpace(), updateButton, cancelButton, new DialogGUIFlexibleSpace() }); listComponments.Add(actionGroup); return(listComponments); }
///////////////////// // Actions private void groundstationEditClick(CNCCommNetHome thisStation) { new GroundStationEditDialog(Localizer.Format("#CNC_ConstellationControl_GroundStationEdit_title"), thisStation, updateGroundStationGUIRow).launch();//"Ground station - <color=#00ff00>Edit</color>" }
///////////////////// // Actions private void groundstationEditClick(CNCCommNetHome thisStation) { new GroundStationEditDialog("Ground station - <color=#00ff00>Edit</color>", thisStation, updateGroundStationGUIRow).launch(); }