From 4122e2c20ff5d3d84105120089a214607e437314 Mon Sep 17 00:00:00 2001 From: KSP-TaxiService Date: Sun, 16 May 2021 21:33:01 +0800 Subject: [PATCH] Add ability to toggle antenna on or off in Antenna Setup dialog --- .../CommNetConstellation/Localization/en-us.cfg | 2 ++ .../CommNetConstellation/Localization/zh-cn.cfg | 2 ++ .../UI/AntennaSetupDialog.cs | 16 +++++++++++++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/GameData/CommNetConstellation/Localization/en-us.cfg b/GameData/CommNetConstellation/Localization/en-us.cfg index f87511b..818b28a 100644 --- a/GameData/CommNetConstellation/Localization/en-us.cfg +++ b/GameData/CommNetConstellation/Localization/en-us.cfg @@ -44,6 +44,7 @@ Localization #CNC_Generic_CancelButton = Cancel #CNC_Generic_DropButton = Drop #CNC_Generic_FrequencyLabel = Frequency + #CNC_Generic_EnableLabel = Enable #CNC_Generic_nameLabel = Name #CNC_Generic_PublicButton = Revert to public @@ -128,6 +129,7 @@ Localization #CNC_ScreenMsg_FreqUpdate = Frequency is updated to <<1>> #CNC_ScreenMsg_NameUpdate = Antenna is renamed to '<<1>>' #CNC_ScreenMsg_ConstellationCreated = New constellation '<<1>>' of frequency <<2>> is created + #CNC_ScreenMsg_EnableUpdate = Antenna is <<1>> #CNC_ScreenMsg_ConstellationFreqUpdate = Constellation has the new frequency <<1>> #CNC_ScreenMsg_ConstellationNameUpdate = Constellation is renamed to '<<1>>' #CNC_ScreenMsg_ConstellationColorUpdate = Constellation color becomes '<<1>>' diff --git a/GameData/CommNetConstellation/Localization/zh-cn.cfg b/GameData/CommNetConstellation/Localization/zh-cn.cfg index 9af21ee..eac1f3f 100644 --- a/GameData/CommNetConstellation/Localization/zh-cn.cfg +++ b/GameData/CommNetConstellation/Localization/zh-cn.cfg @@ -44,6 +44,7 @@ Localization #CNC_Generic_CancelButton = 取消 #CNC_Generic_DropButton = 删除 #CNC_Generic_FrequencyLabel = 频段 + #CNC_Generic_EnableLabel = Enable #CNC_Generic_nameLabel = 名称 #CNC_Generic_PublicButton = 还原为公共频段 @@ -127,6 +128,7 @@ Localization #CNC_ScreenMsg_toggleAntenna = 天线"<<1>>"未展开. #CNC_ScreenMsg_FreqUpdate = 频段已更改为<<1>> #CNC_ScreenMsg_NameUpdate = 天线重命名为'<<1>>' + #CNC_ScreenMsg_EnableUpdate = Antenna is <<1>> #CNC_ScreenMsg_ConstellationCreated = 频段为<<2>>的星座"<<1>>"已创建 #CNC_ScreenMsg_ConstellationFreqUpdate = 星座新增频段<<1>> #CNC_ScreenMsg_ConstellationNameUpdate = 星座重命名为"<<1>>" diff --git a/src/CommNetConstellation/UI/AntennaSetupDialog.cs b/src/CommNetConstellation/UI/AntennaSetupDialog.cs index 2e72ab4..096a507 100644 --- a/src/CommNetConstellation/UI/AntennaSetupDialog.cs +++ b/src/CommNetConstellation/UI/AntennaSetupDialog.cs @@ -20,6 +20,7 @@ public class AntennaSetupDialog : AbstractDialog private DialogGUITextInput frequencyInput; private DialogGUITextInput nameInput; + private DialogGUIToggle enableToggle; private DialogGUIImage constellationColorImage; private static readonly Texture2D colorTexture = UIUtils.loadImage("colorDisplay"); @@ -62,6 +63,11 @@ protected override List drawContentComponents() DialogGUIHorizontalLayout freqGRoup = new DialogGUIHorizontalLayout(true, false, 4, new RectOffset(), TextAnchor.MiddleCenter, new DialogGUIBase[] { freqLabel, frequencyInput, publicButton }); listComponments.Add(freqGRoup); + DialogGUILabel enableLabel = new DialogGUILabel("" + Localizer.Format("#CNC_Generic_EnableLabel") + "", 40, 12);//Enable + enableToggle = new DialogGUIToggle(this.antennaModule.InUse , "", delegate(bool a) { }, 20, 32); + DialogGUIHorizontalLayout enableGroup = new DialogGUIHorizontalLayout(true, false, 4, new RectOffset(), TextAnchor.MiddleCenter, new DialogGUIBase[] { enableLabel, enableToggle, new DialogGUISpace(160)}); + listComponments.Add(enableGroup); + constellationColorImage = new DialogGUIImage(new Vector2(32, 32), Vector2.one, Color.white, colorTexture); DialogGUILabel constNameLabel = new DialogGUILabel(getConstellationName, 200, 12); DialogGUIHorizontalLayout constellationGroup = new DialogGUIHorizontalLayout(true, false, 4, new RectOffset(5, 25, 5, 5), TextAnchor.MiddleCenter, new DialogGUIBase[] { constellationColorImage, constNameLabel }); @@ -153,7 +159,15 @@ private void updateAction() changesCommitted = true; } - CNCLog.Debug("Updated antenna: {0}, {1}", inputName, inputFreq); + if(this.antennaModule.InUse != enableToggle.toggle.isOn) // different enable state + { + this.antennaModule.InUse = enableToggle.toggle.isOn; + ScreenMessage msg = new ScreenMessage(Localizer.Format("#CNC_ScreenMsg_EnableUpdate", enableToggle.toggle.isOn ? "enabled" : "disabled"), CNCSettings.ScreenMessageDuration, ScreenMessageStyle.UPPER_CENTER);//Antenna is '<<1>>' now + ScreenMessages.PostScreenMessage(msg); + changesCommitted = true; + } + + CNCLog.Debug("Updated antenna: {0}, {1}, {2}", inputName, inputFreq, enableToggle.toggle.isOn); if (changesCommitted) {