private void updateClick() { try { try { short userFreq = short.Parse(frequencyInput.uiItem.GetComponent <TMP_InputField>().text); //Check frequency if (userFreq < 0) { throw new Exception(Localizer.Format("#CNC_CheckFrequency_negative"));//"Frequency cannot be negative" } else if (!Constellation.isFrequencyValid(userFreq)) { throw new Exception(Localizer.Format("#CNC_CheckFrequency_Valid", short.MaxValue));//"Frequency must be between 0 and " + } //ALL OK if (!this.cncVessel.isFreqListEditable()) { return; } //update all antennas to new freq for (int i = 0; i < this.antennas.Count; i++) { CNCAntennaPartInfo thisAntenna = this.antennas[i]; this.cncVessel.toggleAntenna(thisAntenna, true); if (thisAntenna.frequency != userFreq) // update each antenna to user freq { this.cncVessel.updateFrequency(thisAntenna, userFreq); } } this.cncVessel.rebuildFreqList(); //if membership option is not enabled, add public freq of same comm power if (!membershipOption && userFreq != CNCSettings.Instance.PublicRadioFrequency) { double commPower = this.cncVessel.getMaxComPower(userFreq); this.cncVessel.addToFreqList(CNCSettings.Instance.PublicRadioFrequency, commPower); } actionCallbacks[0](); } catch (FormatException e) { throw new FormatException(Localizer.Format("#CNC_CheckFrequency_Format"));//"Frequency must be numeric only" } catch (OverflowException e) { throw new OverflowException(Localizer.Format("#CNC_CheckFrequency_Overflow", short.MaxValue));//string.Format("Frequency must be equal to or less than {0}", ) } } catch (Exception e) { ScreenMessage msg = new ScreenMessage("<color=red>" + e.Message + "</color>", CNCSettings.ScreenMessageDuration, ScreenMessageStyle.UPPER_CENTER); ScreenMessages.PostScreenMessage(msg); } }
private void updateAntennaFreq(CNCAntennaPartInfo antennaInfo, string freqString) { try { try { short inputFreq = short.Parse(freqString); //Check frequency if (inputFreq < 0) { throw new Exception(Localizer.Format("#CNC_CheckFrequency_negative"));//"Frequency cannot be negative" } else if (!GameUtils.NonLinqAny(CNCCommNetScenario.Instance.constellations, inputFreq)) { throw new Exception(Localizer.Format("#CNC_CheckFrequency_Exist"));//"Please choose an existing constellation" } else if (!Constellation.isFrequencyValid(inputFreq)) { throw new Exception(Localizer.Format("#CNC_CheckFrequency_Valid", short.MaxValue));//"Frequency must be between 0 and " + } if (base.cncVessel != null && antennaInfo != null && inputFreq >= 0) { base.cncVessel.updateFrequency(antennaInfo, inputFreq); base.cncVessel.OnAntennaChange(); this.selfRefresh(); actionCallbacks[0](); } } catch (FormatException e) { throw new FormatException(Localizer.Format("#CNC_CheckFrequency_Format"));//"Frequency must be numeric only" } catch (OverflowException e) { throw new OverflowException(Localizer.Format("#CNC_CheckFrequency_Overflow", short.MaxValue));//string.Format("Frequency must be equal to or less than {0}", ) } } catch (Exception e) { ScreenMessage msg = new ScreenMessage("<color=red>" + e.Message + "</color>", CNCSettings.ScreenMessageDuration, ScreenMessageStyle.UPPER_CENTER); ScreenMessages.PostScreenMessage(msg); } }
public override List <DialogGUIBase> getContentComponents() { List <DialogGUIBase> layout = new List <DialogGUIBase>(); DialogGUILabel msgLbl = new DialogGUILabel(Localizer.Format("#CNC_getContentCompon_msgLabel2"), 100, 16);//"Change the frequency of each antenna." layout.Add(new DialogGUIHorizontalLayout(true, false, 0, new RectOffset(), TextAnchor.MiddleLeft, new DialogGUIBase[] { msgLbl })); freqInputArray = new DialogGUITextInput[antennas.Count]; DialogGUIVerticalLayout nameColumn = new DialogGUIVerticalLayout(false, false, 0, new RectOffset(), TextAnchor.MiddleLeft); DialogGUIVerticalLayout useColumn = new DialogGUIVerticalLayout(false, false, 0, new RectOffset(), TextAnchor.MiddleLeft); DialogGUIVerticalLayout freqColumn = new DialogGUIVerticalLayout(false, false, 0, new RectOffset(), TextAnchor.MiddleLeft); DialogGUIVerticalLayout freqInputColumn = new DialogGUIVerticalLayout(false, false, 0, new RectOffset(), TextAnchor.MiddleLeft); DialogGUIVerticalLayout updateColumn = new DialogGUIVerticalLayout(false, false, 0, new RectOffset(), TextAnchor.MiddleLeft); for (int i = 0; i < antennas.Count; i++) { int index = i;//convert to solid-reference variable for delegate block CNCAntennaPartInfo antennaInfo = antennas[i]; DialogGUILabel nameLabel = new DialogGUILabel(Localizer.Format("#CNC_getContentCompon_nameLabel", antennaInfo.name), style); nameLabel.size = new Vector2(200, 32); //string.Format("Name: {0}",) DialogGUILabel usageLabel = new DialogGUILabel(Localizer.Format("#CNC_getContentCompon_usageLabel") + ": " + (antennaInfo.inUse ? "<color=green>" + Localizer.Format("#CNC_Generic_Yes") + "</color>" : "<color=red>" + Localizer.Format("#CNC_Generic_No") + "</color>"), style); usageLabel.size = new Vector2(75, 32); //In UseYesNo DialogGUILabel freqLabel = new DialogGUILabel(Localizer.Format("#CNC_Generic_FrequencyLabel"), style); freqLabel.size = new Vector2(65, 32); //"Frequency" freqInputArray[i] = new DialogGUITextInput(antennaInfo.frequency.ToString(), false, CNCSettings.MaxDigits, setAntennaFreq, 65, 25); DialogGUIButton updateButton = new DialogGUIButton(Localizer.Format("#CNC_Generic_UpdateButton"), delegate { updateAntennaFreq(antennaInfo, freqInputArray[index].uiItem.GetComponent <TMP_InputField>().text); }, 70, 25, false); //"Update" nameColumn.AddChild(nameLabel); useColumn.AddChild(usageLabel); freqColumn.AddChild(freqLabel); freqInputColumn.AddChild(new DialogGUISpace(3)); freqInputColumn.AddChild(freqInputArray[index]); freqInputColumn.AddChild(new DialogGUISpace(4)); updateColumn.AddChild(new DialogGUISpace(3)); updateColumn.AddChild(updateButton); updateColumn.AddChild(new DialogGUISpace(4)); } layout.Add(new DialogGUIHorizontalLayout(true, false, 0, new RectOffset(), TextAnchor.MiddleLeft, new DialogGUIBase[] { nameColumn, useColumn, freqColumn, freqInputColumn, updateColumn })); return(layout); }
public override List <DialogGUIBase> getContentComponents() { List <DialogGUIBase> layout = new List <DialogGUIBase>(); DialogGUILabel msgLbl = new DialogGUILabel("Select one or more antennas to manually build the frequency list instead of the default list. Only deployed antennas can be chosen.", 100, 32); layout.Add(new DialogGUIHorizontalLayout(true, false, 0, new RectOffset(), TextAnchor.MiddleLeft, new DialogGUIBase[] { msgLbl })); toggleAntennaColumn = new DialogGUIVerticalLayout(false, false, 0, new RectOffset(), TextAnchor.MiddleLeft); DialogGUIVerticalLayout nameColumn = new DialogGUIVerticalLayout(false, false, 0, new RectOffset(), TextAnchor.MiddleLeft); DialogGUIVerticalLayout comPowerColumn = new DialogGUIVerticalLayout(false, false, 0, new RectOffset(), TextAnchor.MiddleLeft); DialogGUIVerticalLayout frequencyColumn = new DialogGUIVerticalLayout(false, false, 0, new RectOffset(), TextAnchor.MiddleLeft); DialogGUIVerticalLayout combinableColumn = new DialogGUIVerticalLayout(false, false, 0, new RectOffset(), TextAnchor.MiddleLeft); for (int i = 0; i < antennas.Count; i++) { CNCAntennaPartInfo antennaInfo = antennas[i]; DialogGUIToggle toggleBtn = new DialogGUIToggle(antennaInfo.inUse && antennaInfo.canComm, "", delegate(bool b) { vesselAntennaSelected(b, antennaInfo); actionCallbacks[0](); }, 20, 32); DialogGUILabel nameLabel = new DialogGUILabel(antennaInfo.name, style); nameLabel.size = new Vector2(150, 32); DialogGUILabel comPowerLabel = new DialogGUILabel(string.Format("Com power: {0}", UIUtils.RoundToNearestMetricFactor(antennaInfo.antennaPower * (double)HighLogic.CurrentGame.Parameters.CustomParams <CommNetParams>().rangeModifier, 2)), style); comPowerLabel.size = new Vector2(130, 32); DialogGUILabel frequencyLabel = new DialogGUILabel(string.Format("(<color={0}>{1}</color>)", UIUtils.colorToHex(Constellation.getColor(antennaInfo.frequency)), antennaInfo.frequency), style); frequencyLabel.size = new Vector2(60, 32); DialogGUILabel combinableLabel = new DialogGUILabel("Combinable: " + (antennaInfo.antennaCombinable ? "<color=green>Yes</color>" : "<color=red>No</color>") + "\nBroadcast: " + (antennaInfo.canComm ? "<color=green>Yes</color>" : "<color=red>No</color>"), style); combinableLabel.size = new Vector2(90, 32); toggleAntennaColumn.AddChild(toggleBtn); nameColumn.AddChild(nameLabel); frequencyColumn.AddChild(frequencyLabel); comPowerColumn.AddChild(comPowerLabel); combinableColumn.AddChild(combinableLabel); } layout.Add(new DialogGUIHorizontalLayout(true, false, 0, new RectOffset(), TextAnchor.MiddleLeft, new DialogGUIBase[] { toggleAntennaColumn, nameColumn, frequencyColumn, comPowerColumn, combinableColumn })); DialogGUIButton deselectButton = new DialogGUIButton("Deselect all", delegate { toggleAllAntennas(false); actionCallbacks[0](); }, false); DialogGUIButton selectButton = new DialogGUIButton("Select all", delegate { toggleAllAntennas(true); actionCallbacks[0](); }, false); layout.Add(new DialogGUIHorizontalLayout(true, false, 0, new RectOffset(), TextAnchor.MiddleLeft, new DialogGUIBase[] { selectButton, deselectButton })); return(layout); }
private void vesselAntennaSelected(bool useState, CNCAntennaPartInfo antenna) { cncVessel.toggleAntenna(antenna, useState); cncVessel.OnAntennaChange(); }