private string getFreqString(List <short> frequencies, short strongestFreq = -1)
        {
            frequencies.Sort();
            string freqString = Localizer.Format("#CNC_ConstellationControl_getFreqString") + " "; //"Frequencies: "

            if (frequencies.Count == 0)                                                            // nothing
            {
                return(Localizer.Format("#CNC_ConstellationControl_getFreqString_nothing"));       //"No frequency assigned"
            }
            for (int i = 0; i < frequencies.Count; i++)
            {
                Color color = Constellation.getColor(frequencies[i]);
                freqString += string.Format("<color={0}>{1}</color>", UIUtils.colorToHex(color), (strongestFreq == frequencies[i])? "<b>" + frequencies[i] + "</b>": frequencies[i] + "");//
                if (i <= frequencies.Count - 2)
                {
                    freqString += ", ";
                }
            }

            return(freqString);
        }
Example #2
0
        /// <summary>
        /// Action to update the ground station
        /// </summary>
        private void updateAction()
        {
            bool   changesCommitted = false;
            string newName          = nameInput.uiItem.GetComponent <TMP_InputField>().text.Trim();

            if (!this.hostStation.stationName.Equals(newName)) // different name
            {
                if (newName.Equals(this.hostStation.displaynodeName))
                {
                    this.hostStation.stationName = "";
                }
                else
                {
                    this.hostStation.stationName = newName;
                }

                ScreenMessage msg = new ScreenMessage(Localizer.Format("#CNC_ScreenMsg_GroundStationNameUpdate", this.hostStation.stationName), CNCSettings.ScreenMessageDuration, ScreenMessageStyle.UPPER_CENTER);//string.Format("Ground station is renamed to '{0}'", )
                ScreenMessages.PostScreenMessage(msg);
                changesCommitted = true;
            }

            if (this.hostStation.Color != this.constellColor)
            {
                this.hostStation.Color = this.constellColor;
                ScreenMessage msg = new ScreenMessage(Localizer.Format("#CNC_ScreenMsg_GroundStationColorUpdate", UIUtils.colorToHex(this.hostStation.Color)), CNCSettings.ScreenMessageDuration, ScreenMessageStyle.UPPER_CENTER);//string.Format("Ground station is '{0}' now", )
                ScreenMessages.PostScreenMessage(msg);
                changesCommitted = true;
            }

            int commonFreq = GameUtils.NonLinqIntersect(this.freqListShown.ToArray(), this.hostStation.getFrequencyArray()).Length;

            if (!(commonFreq == this.hostStation.getFrequencyList().Count&& commonFreq == this.freqListShown.Count))
            {
                this.hostStation.replaceFrequencies(this.freqListShown);
                ScreenMessage msg = new ScreenMessage(Localizer.Format("#CNC_ScreenMsg_GroundStationFreqUpdate"), CNCSettings.ScreenMessageDuration, ScreenMessageStyle.UPPER_CENTER);//"Ground station's frequency list is updated"
                ScreenMessages.PostScreenMessage(msg);
                changesCommitted = true;
            }

            string strFreqs = ""; for (int i = 0; i < this.freqListShown.Count; i++)

            {
                strFreqs += this.freqListShown[i] + " ";
            }

            CNCLog.Debug("Updated g-station: {0}, {1}", newName, strFreqs);

            if (changesCommitted)
            {
                this.dismiss();
            }
        }
Example #3
0
        private DialogGUIHorizontalLayout createConstellationRow(short freq)
        {
            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, 140, 12);
            DialogGUILabel  eachFreqLabel = new DialogGUILabel(string.Format("(<color={0}>{1}</color>)", UIUtils.colorToHex(color), freq), 40, 12);
            DialogGUIButton removeButton  = new DialogGUIButton(Localizer.Format("#CNC_Generic_DropButton"), delegate { deleteFreqClick(freq); }, 40, 25, false);//"Drop"

            return(new DialogGUIHorizontalLayout(true, false, 0, new RectOffset(), TextAnchor.MiddleLeft, new DialogGUIBase[] { colorImage, nameLabel, eachFreqLabel, removeButton }));
        }
        private void resetPublicConstClick()
        {
            string            message       = Localizer.Format("#CNC_ConstellationControl_resetPublicMsg", CNCSettings.Instance.DefaultPublicName, UIUtils.colorToHex(CNCSettings.Instance.DefaultPublicColor)); //string.Format("Revert to the default name '{0}' and color {1}?",
            MultiOptionDialog warningDialog = new MultiOptionDialog("cncResetConstWindow", message, Localizer.Format("#CNC_ConstellationControl_Dialog_title"), HighLogic.UISkin, new DialogGUIBase[]            //"Constellation"
            {
                new DialogGUIButton(Localizer.Format("#CNC_Generic_Resetbutton"), resetPublicConstellation, true),                                                                                               //"Reset"
                new DialogGUIButton(Localizer.Format("#CNC_Generic_CancelButton"), delegate { }, true)                                                                                                           //"Cancel"
            });

            PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), warningDialog, false, HighLogic.UISkin, true, string.Empty);
        }
        private void updateConstellationGUIRow(short updatedfrequency, short previousFrequency)
        {
            if (this.currentContentType != ContentType.CONSTELLATIONS)
            {
                return;
            }

            List <DialogGUIBase> rows = contentLayout.children;

            for (int i = 2; i < rows.Count; i++)
            {
                DialogGUIBase thisRow = rows[i];
                if (thisRow.OptionText.Equals(updatedfrequency.ToString()) || thisRow.OptionText.Equals(previousFrequency.ToString()))
                {
                    DialogGUIImage colorImage  = thisRow.children[0] as DialogGUIImage;
                    DialogGUILabel nameLabel   = thisRow.children[1] as DialogGUILabel;
                    DialogGUILabel freqLabel   = thisRow.children[2] as DialogGUILabel;
                    DialogGUILabel vesselLabel = thisRow.children[3] as DialogGUILabel;

                    Constellation updatedConstellation = CNCCommNetScenario.Instance.constellations.Find(x => x.frequency == updatedfrequency);
                    colorImage.uiItem.GetComponent <RawImage>().color = updatedConstellation.color;
                    nameLabel.SetOptionText(updatedConstellation.name);
                    freqLabel.SetOptionText(Localizer.Format("#CNC_Generic_FrequencyLabel") + string.Format(": <color={0}>{1}</color>", UIUtils.colorToHex(updatedConstellation.color), updatedConstellation.frequency)); //Frequency
                    vesselLabel.SetOptionText(Localizer.Format("#CNC_ConstellationControl_numSatsLabel", Constellation.countVessels(updatedConstellation)));                                                              // + " vessels"

                    thisRow.SetOptionText(updatedConstellation.frequency.ToString());
                    break;
                }
            }
        }
        private DialogGUIHorizontalLayout createConstellationRow(Constellation thisConstellation)
        {
            Color color = Constellation.getColor(thisConstellation.frequency);

            DialogGUIImage        colorImage     = new DialogGUIImage(new Vector2(32, 32), Vector2.zero, thisConstellation.color, colorTexture);
            DialogGUILabel        constNameLabel = new DialogGUILabel(thisConstellation.name, 170, 12);
            DialogGUILabel        freqLabel      = new DialogGUILabel(Localizer.Format("#CNC_Generic_FrequencyLabel") + string.Format(": <color={0}>{1}</color>", UIUtils.colorToHex(color), thisConstellation.frequency), 100, 12); //Frequency
            DialogGUILabel        numSatsLabel   = new DialogGUILabel(Localizer.Format("#CNC_ConstellationControl_numSatsLabel", Constellation.countVessels(thisConstellation)), 75, 12);                                            //string.Format("{0} vessels", )
            DialogGUIButton       updateButton   = new DialogGUIButton(Localizer.Format("#CNC_Generic_Editbutton"), delegate { editConstellationClick(thisConstellation); }, 50, 32, false);                                         //"Edit"
            DialogGUIToggleButton toggleButton   = new DialogGUIToggleButton(thisConstellation.visibility, Localizer.Format("#CNC_Generic_Mapbutton"), delegate { toggleConstellationVisibility(thisConstellation); }, 45, 32);      //"Map"

            DialogGUIBase[] rowGUIBase = new DialogGUIBase[] { colorImage, constNameLabel, freqLabel, numSatsLabel, toggleButton, updateButton, null };
            if (thisConstellation.frequency == CNCSettings.Instance.PublicRadioFrequency)
            {
                rowGUIBase[rowGUIBase.Length - 1] = new DialogGUIButton(Localizer.Format("#CNC_Generic_Resetbutton"), resetPublicConstClick, 60, 32, false);//"Reset"
            }
            else
            {
                rowGUIBase[rowGUIBase.Length - 1] = new DialogGUIButton(Localizer.Format("#CNC_Generic_DeleteButton"), delegate { deleteConstellationClick(thisConstellation); }, 60, 32, false);//"Delete"
            }
            DialogGUIHorizontalLayout constellationGroup = new DialogGUIHorizontalLayout(true, false, 4, new RectOffset(), TextAnchor.MiddleCenter, rowGUIBase);

            constellationGroup.SetOptionText(thisConstellation.frequency.ToString()); //for quick identification
            return(constellationGroup);
        }
Example #7
0
        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 }));
        }
        private void resetPublicConstClick()
        {
            string            message       = string.Format("Revert to the default name '{0}' and color {1}?", CNCSettings.Instance.DefaultPublicName, UIUtils.colorToHex(CNCSettings.Instance.DefaultPublicColor));
            MultiOptionDialog warningDialog = new MultiOptionDialog("cncResetConstWindow", message, "Constellation", HighLogic.UISkin, new DialogGUIBase[]
            {
                new DialogGUIButton("Reset", resetPublicConstellation, true),
                new DialogGUIButton("Cancel", delegate { }, true)
            });

            PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), warningDialog, false, HighLogic.UISkin, true, string.Empty);
        }
Example #9
0
        /// <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);
            }
        }