/// <summary> /// Action to add the input frequency to the temporary list to be committed /// </summary> private void addClick() { try { try // input checks { short newFreq = short.Parse(frequencyInput.uiItem.GetComponent <TMP_InputField>().text); if (newFreq < 0) { throw new Exception(Localizer.Format("#CNC_CheckFrequency_negative"));//"Frequency cannot be negative" } else if (this.freqListShown.Contains(newFreq)) { throw new Exception(Localizer.Format("#CNC_CheckFrequency_Contained"));//"Ground station has this frequency already" } else if (!GameUtils.NonLinqAny(CNCCommNetScenario.Instance.constellations, newFreq)) { throw new Exception(Localizer.Format("#CNC_CheckFrequency_Exist"));//"Please choose an existing constellation" } else if (!Constellation.isFrequencyValid(newFreq)) { throw new Exception(Localizer.Format("#CNC_CheckFrequency_Valid", short.MaxValue));//"Frequency must be between 0 and " + } //ALL OK this.freqListShown.Add(newFreq); this.freqListShown.Sort(); CNCLog.Debug("Added g-station freq: {0}", newFreq); refreshList(this.freqListShown); } 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); } }
/// <summary> /// Action to update the attributes of the antenna /// </summary> private void updateAction() { try { try { bool changesCommitted = false; short inputFreq = short.Parse(frequencyInput.uiItem.GetComponent <TMP_InputField>().text); string inputName = nameInput.uiItem.GetComponent <TMP_InputField>().text.Trim(); //Check name if (inputName.Length <= 0) { throw new Exception("Name cannot be empty"); } //Check frequency if (inputFreq < 0) { throw new Exception("Frequency cannot be negative"); } else if (!GameUtils.NonLinqAny(CNCCommNetScenario.Instance.constellations, inputFreq)) { throw new Exception("Please choose an existing constellation"); } else if (!Constellation.isFrequencyValid(inputFreq)) { throw new Exception("Frequency must be between 0 and " + short.MaxValue); } //ALL OK if (this.antennaModule.Frequency != inputFreq) // different frequency { this.antennaModule.Frequency = inputFreq; ScreenMessage msg = new ScreenMessage(string.Format("Frequency is updated to {0}", inputFreq), CNCSettings.ScreenMessageDuration, ScreenMessageStyle.UPPER_CENTER); ScreenMessages.PostScreenMessage(msg); changesCommitted = true; } if (!this.antennaModule.Name.Equals(inputName)) // different name { this.antennaModule.Name = inputName; ScreenMessage msg = new ScreenMessage(string.Format("Antenna is renamed to '{0}'", this.antennaModule.Name), CNCSettings.ScreenMessageDuration, ScreenMessageStyle.UPPER_CENTER); ScreenMessages.PostScreenMessage(msg); changesCommitted = true; } CNCLog.Debug("Updated antenna: {0}, {1}", inputName, inputFreq); if (changesCommitted) { if (this.hostVessel != null) { CNCCommNetVessel cncVessel = (CNCCommNetVessel)this.hostVessel.Connection; cncVessel.OnAntennaChange(); } this.dismiss(); } } catch (FormatException e) { throw new FormatException("Frequency must be numeric only"); } catch (OverflowException e) { throw new OverflowException(string.Format("Frequency must be equal to or less than {0}", short.MaxValue)); } } catch (Exception e) { ScreenMessage msg = new ScreenMessage("<color=red>" + e.Message + "</color>", CNCSettings.ScreenMessageDuration, ScreenMessageStyle.UPPER_CENTER); ScreenMessages.PostScreenMessage(msg); } }
/// <summary> /// Action to create or update the constellation /// </summary> private void actionClick() { try { try { short constellFreq = short.Parse(frequencyInput.uiItem.GetComponent <TMP_InputField>().text); string constellName = nameInput.uiItem.GetComponent <TMP_InputField>().text; //Check name if (constellName.Length <= 0) { throw new Exception(Localizer.Format("#CNC_CheckName_Empty"));//"Name cannot be empty" } //Check frequency if (constellFreq < 0) { throw new Exception(Localizer.Format("#CNC_CheckFrequency_negative"));//"Frequency cannot be negative" } else if (!Constellation.isFrequencyValid(constellFreq)) { throw new Exception(Localizer.Format("#CNC_CheckFrequency_Valid", short.MaxValue));//"Frequency must be between 0 and " + } else if (this.existingConstellation != null) { if (this.existingConstellation.frequency == CNCSettings.Instance.PublicRadioFrequency) //public one { if (constellFreq != CNCSettings.Instance.PublicRadioFrequency) { throw new Exception(Localizer.Format("#CNC_CheckFrequency_Locked", CNCSettings.Instance.PublicRadioFrequency));//"Public frequency " + + " is locked" } } /* * else if(constellFreq == CNCSettings.Instance.PublicRadioFrequency) // not public but new freq is public * { * throw new Exception("New frequency cannot be " + CNCSettings.Instance.PublicRadioFrequency); * } */ else if (GameUtils.NonLinqAny(CNCCommNetScenario.Instance.constellations, constellFreq) && this.existingConstellation.frequency != constellFreq) { throw new Exception(Localizer.Format("#CNC_CheckFrequency_InUse"));//"Frequency is in use already" } } else if (this.existingConstellation == null && GameUtils.NonLinqAny(CNCCommNetScenario.Instance.constellations, constellFreq)) { throw new Exception(Localizer.Format("#CNC_CheckFrequency_InUse"));//"Frequency is in use already" } //ALL OK if (this.existingConstellation == null && creationCallback != null) { Constellation newConstellation = new Constellation(constellFreq, constellName, this.constellColor); CNCCommNetScenario.Instance.constellations.Add(newConstellation); creationCallback(newConstellation); string message = Localizer.Format("#CNC_ScreenMsg_ConstellationCreated", constellName, constellFreq);//string.Format("New constellation '{0}' of frequency {1} is created", ) ScreenMessages.PostScreenMessage(new ScreenMessage(message, CNCSettings.ScreenMessageDuration, ScreenMessageStyle.UPPER_CENTER)); CNCLog.Debug("New constellation: {0}, {1}", constellName, constellFreq); this.dismiss(); } else if (this.existingConstellation != null && updateCallback != null) { bool changesCommitted = false; short prevFreq = this.existingConstellation.frequency; if (this.existingConstellation.frequency != constellFreq) // new frequency { this.existingConstellation.frequency = constellFreq; List <CNCCommNetVessel> affectedVessels = CNCCommNetScenario.Instance.getCommNetVessels().FindAll(x => x.getFrequencyList().Contains(prevFreq)); for (int i = 0; i < affectedVessels.Count; i++) { affectedVessels[i].replaceAllFrequencies(prevFreq, this.existingConstellation.frequency); affectedVessels[i].OnAntennaChange(); } List <CNCCommNetHome> affectedStations = CNCCommNetScenario.Instance.groundStations.FindAll(x => x.getFrequencyList().Contains(prevFreq)); for (int i = 0; i < affectedStations.Count; i++) { affectedStations[i].replaceFrequency(prevFreq, this.existingConstellation.frequency); } ScreenMessage msg = new ScreenMessage(Localizer.Format("#CNC_ScreenMsg_ConstellationFreqUpdate", constellFreq), CNCSettings.ScreenMessageDuration, ScreenMessageStyle.UPPER_CENTER);//string.Format("Constellation has the new frequency {0}", ) ScreenMessages.PostScreenMessage(msg); changesCommitted = true; } if (!this.existingConstellation.name.Equals(constellName)) // different name { this.existingConstellation.name = constellName; string message = Localizer.Format("#CNC_ScreenMsg_ConstellationNameUpdate", constellName);//string.Format("Constellation is renamed to '{0}'", ) ScreenMessages.PostScreenMessage(new ScreenMessage(message, CNCSettings.ScreenMessageDuration, ScreenMessageStyle.UPPER_CENTER)); changesCommitted = true; } if (!this.existingConstellation.color.Equals(this.constellColor)) // new color { this.existingConstellation.color = this.constellColor; string message = Localizer.Format("#CNC_ScreenMsg_ConstellationColorUpdate", UIUtils.colorToHex(this.constellColor));//string.Format("Constellation color becomes '{0}'", ) ScreenMessages.PostScreenMessage(new ScreenMessage(message, CNCSettings.ScreenMessageDuration, ScreenMessageStyle.UPPER_CENTER)); changesCommitted = true; } CNCLog.Debug("Updated constellation: {0}, {1}", constellName, constellFreq); if (changesCommitted) { updateCallback(this.existingConstellation, prevFreq); this.dismiss(); } } } 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); } }