private DialogGUIHorizontalLayout createFrequencyRow(short freq) { CNCCommNetVessel cncVessel = (CNCCommNetVessel)this.hostVessel.Connection; Color color = Constellation.getColor(freq); string name = Constellation.getName(freq); DialogGUIImage colorImage = new DialogGUIImage(new Vector2(32, 32), Vector2.one, color, colorTexture); DialogGUILabel nameLabel = new DialogGUILabel(name, 170, 12); DialogGUILabel eachFreqLabel = new DialogGUILabel(string.Format("(<color={0}>{1}</color>)", UIUtils.colorToHex(color), freq), 70, 12); DialogGUILabel freqPowerLabel = new DialogGUILabel(string.Format("Combined Comm Power: {0}", UIUtils.RoundToNearestMetricFactor(cncVessel.getMaxComPower(freq), 2)), 220, 12); return(new DialogGUIHorizontalLayout(true, false, 0, new RectOffset(), TextAnchor.MiddleLeft, new DialogGUIBase[] { colorImage, new DialogGUISpace(20), nameLabel, eachFreqLabel, freqPowerLabel })); }
public AbstractMgtTool(CommNetVessel thisVessel, string uniqueCodename, string toolName, List <Callback> actionCallbacks = null) { if (!(thisVessel is CNCCommNetVessel)) { CNCLog.Error("Vessel '{0}''s connection is not of type CNCCommNetVessel!", thisVessel.Vessel.vesselName); return; } this.cncVessel = (CNCCommNetVessel)thisVessel; this.codename = uniqueCodename + "_mgttool"; this.toolName = toolName; this.actionCallbacks = actionCallbacks; }
private DialogGUIHorizontalLayout createVesselRow(CNCCommNetVessel thisVessel) { //answer is from FlagBrowserGUIButton DialogGUIImage focusImage = new DialogGUIImage(new Vector2(32f, 32f), Vector2.zero, Color.white, focusTexture); DialogGUIHorizontalLayout imageBtnLayout = new DialogGUIHorizontalLayout(true, true, 0f, new RectOffset(1, 1, 1, 1), TextAnchor.MiddleCenter, new DialogGUIBase[] { focusImage }); DialogGUIButton focusButton = new DialogGUIButton("", delegate { vesselFocusClick(thisVessel.Vessel); }, 34, 34, false, new DialogGUIBase[] { imageBtnLayout }); DialogGUILabel vesselLabel = new DialogGUILabel(thisVessel.Vessel.GetDisplayName(), 160, 12); DialogGUILabel freqLabel = new DialogGUILabel(getFreqString(thisVessel.getFrequencyList(), thisVessel.getStrongestFrequency()), 160, 12); DialogGUILabel locationLabel = new DialogGUILabel(Localizer.Format("#CNC_ConstellationControl_locationLabel", thisVessel.Vessel.mainBody.GetDisplayName()), 100, 12); //Orbiting: <<1>> DialogGUIButton setupButton = new DialogGUIButton(Localizer.Format("#CNC_Generic_Setupbutton"), delegate { vesselSetupClick(thisVessel.Vessel); }, 70, 32, false); //"Setup" DialogGUIHorizontalLayout vesselGroup = new DialogGUIHorizontalLayout(true, false, 4, new RectOffset(), TextAnchor.MiddleCenter, new DialogGUIBase[] { focusButton, vesselLabel, freqLabel, locationLabel, setupButton }); vesselGroup.SetOptionText(thisVessel.Vessel.id.ToString()); return(vesselGroup); }
private void updateVesselGUIRow(Vessel updatedVessel) { if (this.currentContentType != ContentType.VESSELS) { return; } CNCCommNetVessel thisVessel = (CNCCommNetVessel)updatedVessel.Connection; List <DialogGUIBase> rows = contentLayout.children; for (int i = 0; i < rows.Count; i++) { DialogGUIBase thisRow = rows[i]; if (thisRow.OptionText.Equals(updatedVessel.id.ToString())) { DialogGUILabel freqLabel = thisRow.children[2] as DialogGUILabel; freqLabel.SetOptionText(getFreqString(thisVessel.getFrequencyList(), thisVessel.getStrongestFrequency())); return; } } }
private void refreshFrequencyRows() { deregisterLayoutComponents(frequencyRowLayout); CNCCommNetVessel cncVessel = (CNCCommNetVessel)this.hostVessel.Connection; List <short> vesselFrequencyList = cncVessel.getFrequencyList(); vesselFrequencyList.Sort(); for (int i = 0; i < vesselFrequencyList.Count; i++) { frequencyRowLayout.AddChild(createFrequencyRow(vesselFrequencyList[i])); } if (vesselFrequencyList.Count == 0) { frequencyRowLayout.AddChild(new DialogGUILabel(nofreqMessage, nofreqMessageStyle, true, false)); } registerLayoutComponents(frequencyRowLayout); scrollArea.Resize(); }
protected override List <DialogGUIBase> drawContentComponents() { List <DialogGUIBase> listComponments = new List <DialogGUIBase>(); CNCCommNetVessel cncVessel = (CNCCommNetVessel)this.hostVessel.Connection; List <short> vesselFrequencyList = cncVessel.getFrequencyList(); vesselFrequencyList.Sort(); listComponments.Add(new DialogGUIHorizontalLayout(true, false, 0, new RectOffset(), TextAnchor.UpperCenter, new DialogGUIBase[] { new DialogGUILabel(this.description + "\n\n", false, false) })); //frequency list listComponments.Add(new DialogGUILabel("<b>Active frequencies</b>", false, false)); DialogGUIBase[] frequencyRows; if (vesselFrequencyList.Count == 0) { frequencyRows = new DialogGUIBase[2]; frequencyRows[0] = new DialogGUIContentSizer(ContentSizeFitter.FitMode.Unconstrained, ContentSizeFitter.FitMode.PreferredSize, true); frequencyRows[1] = new DialogGUILabel(nofreqMessage, nofreqMessageStyle, true, false); } else { frequencyRows = new DialogGUIBase[vesselFrequencyList.Count + 1]; frequencyRows[0] = new DialogGUIContentSizer(ContentSizeFitter.FitMode.Unconstrained, ContentSizeFitter.FitMode.PreferredSize, true); for (int i = 0; i < vesselFrequencyList.Count; i++) { frequencyRows[i + 1] = createFrequencyRow(vesselFrequencyList[i]); } } frequencyRowLayout = new DialogGUIVerticalLayout(10, 100, 4, new RectOffset(5, 25, 5, 5), TextAnchor.UpperLeft, frequencyRows); scrollArea = new CustomDialogGUIScrollList(new Vector2(450, 100), false, true, frequencyRowLayout); listComponments.Add(scrollArea); //tools listComponments.AddRange(this.toolMgt.getLayoutContents()); return(listComponments); }
private List <DialogGUIHorizontalLayout> populateVesselRows(VesselTypeFilter filter) { List <DialogGUIHorizontalLayout> newRows = new List <DialogGUIHorizontalLayout>(); List <CNCCommNetVessel> allVessels = CNCCommNetScenario.Instance.getCommNetVessels(); switch (currentVesselSort) { case VesselListSort.RADIOFREQ: allVessels.Sort((x, y) => x.getStrongestFrequency() - y.getStrongestFrequency()); break; case VesselListSort.VESSELNAME: allVessels.Sort((x, y) => x.Vessel.GetName().CompareTo(y.Vessel.GetName())); break; case VesselListSort.CBODY: allVessels.Sort((x, y) => x.Vessel.mainBody.name.CompareTo(y.Vessel.mainBody.name)); break; default: allVessels.Sort((x, y) => x.Vessel.launchTime.CompareTo(y.Vessel.launchTime)); break; } var itr = allVessels.GetEnumerator(); while (itr.MoveNext()) { CNCCommNetVessel thisVessel = itr.Current; if (MapViewFiltering.CheckAgainstFilter(thisVessel.Vessel)) { newRows.Add(createVesselRow(thisVessel)); } } return(newRows); }
/// <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); } }