Skip to content

Commit

Permalink
Add ability to toggle antenna on or off in Antenna Setup dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
KSP-TaxiService committed May 16, 2021
1 parent 83ac6ec commit 4122e2c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 2 additions & 0 deletions GameData/CommNetConstellation/Localization/en-us.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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>>'
Expand Down
2 changes: 2 additions & 0 deletions GameData/CommNetConstellation/Localization/zh-cn.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Localization
#CNC_Generic_CancelButton = 取消
#CNC_Generic_DropButton = 删除
#CNC_Generic_FrequencyLabel = 频段
#CNC_Generic_EnableLabel = Enable
#CNC_Generic_nameLabel = 名称
#CNC_Generic_PublicButton = 还原为公共频段

Expand Down Expand Up @@ -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>>"
Expand Down
16 changes: 15 additions & 1 deletion src/CommNetConstellation/UI/AntennaSetupDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -62,6 +63,11 @@ protected override List<DialogGUIBase> drawContentComponents()
DialogGUIHorizontalLayout freqGRoup = new DialogGUIHorizontalLayout(true, false, 4, new RectOffset(), TextAnchor.MiddleCenter, new DialogGUIBase[] { freqLabel, frequencyInput, publicButton });
listComponments.Add(freqGRoup);

DialogGUILabel enableLabel = new DialogGUILabel("<b>" + Localizer.Format("#CNC_Generic_EnableLabel") + "</b>", 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 });
Expand Down Expand Up @@ -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)
{
Expand Down

0 comments on commit 4122e2c

Please sign in to comment.