public bool TryApply(CompWirelessPower comp) { if (ChannelId == -1) { Core.Error("Tried to apply using an invalid CopyPasteData"); return(false); } if (comp == null) { Core.Error("Tried to apply CopyPasteData to a null wireless component."); return(false); } if (channel == null || channel.Destroyed) { Core.Error("Tried to apply CopyPasteData that has a null or invalid channel. Check data.IsValid() first."); return(false); } if (!comp.Props.canSendPower && Type == WirelessType.Transmitter) { Core.Warn($"Did not paste wireless settings on to {comp.parent?.LabelCap}, because it is not allowed to send power."); return(false); } if (comp.Props.fixedPowerLevel != null) { Core.Warn($"Pasting wireless settings, even though this {comp.parent?.LabelCap} has a fixed power level."); } // Already has these settings? if (comp.Type == Type && (comp.Channel?.Id ?? -1) == ChannelId && comp.TargetWatts == TargetPower) { return(true); } comp.SwitchToChannel(channel); comp.SwitchType(Type); if (comp.Props.fixedPowerLevel == null) { comp.TargetWatts = TargetPower; } return(true); }
public override void DoWindowContents(Rect inRect) { if (Comp == null || Comp.parent.DestroyedOrNull() || !Comp.parent.Spawned || Comp.Type == WirelessType.None) { Core.Warn("Pylon was destroyed or invalid, closing config window."); Close(); return; } Text.Font = GameFont.Medium; const float h = 28; const float p = 6; float x = inRect.x; float y = inRect.y; bool isSending = Comp.Type == WirelessType.Transmitter; string channelName = Comp.Channel?.Name ?? "None"; bool canChangeMode = Comp.Props.canSendPower; string txt = isSending ? "RF.Pylon.Sending".Translate() : "RF.Pylon.Requesting".Translate(); if (Widgets.ButtonText(new Rect(x, y, 150, h), txt, active: canChangeMode)) { Comp.SwitchType(isSending ? WirelessType.Receiver : WirelessType.Transmitter); } x += 150 + p; bool canChange = Comp.Props.fixedPowerLevel == null; int amount = Comp.TargetWatts; GUI.enabled = canChange; Widgets.IntEntry(new Rect(x, y, 290, h), ref amount, ref wattsBuffer, 10); GUI.enabled = true; Comp.TargetWatts = Mathf.Clamp(amount, 0, Comp.Props.maxPower); wattsBuffer = Comp.TargetWatts.ToString(); x += 290 + p; txt = "RF.Pylon.On".Translate(); var size = Text.CalcSize(txt); Widgets.Label(new Rect(x, y, size.x, h), txt); x += size.x + p; if (Widgets.ButtonText(new Rect(x, y, 200, h), channelName)) { var options = new List <FloatMenuOption>(); if (Comp.Manager != null) { foreach (var item in Comp.Manager.GetAvailableChannels(Comp)) { var op = new FloatMenuOption(item.Name, () => { Comp.SwitchToChannel(item); }); options.Add(op); } } if (Comp.Channel != null) { options.Add(new FloatMenuOption("RF.Pylon.EmptyChannel".Translate(), () => { Comp.SwitchToChannel(null); })); } options.Add(new FloatMenuOption("RF.Pylon.CreateNewChannel".Translate(), () => { if (tempWindow != null) { return; } Find.WindowStack.Add(tempWindow = new NewChannelWindow() { Manager = Comp.Manager, CreateNewChannel = name => { Core.Log($"User created new channel '{name}'"); int id = Comp.Manager.CreateNewChannel(name); var newChannel = Comp.Manager.TryGetChannel(id); if (newChannel == null) { Core.Error("Create new channel, but TryGetChannel returned null!? Why?"); } Comp.SwitchToChannel(newChannel); }, OnClose = () => { tempWindow = null; } }); })); Find.WindowStack.Add(new FloatMenu(options)); } var channel = Comp.Channel; if (channel == null || channel.Destroyed) { return; } Text.Font = GameFont.Small; x = 0; y += h + 10; int input = (int)channel.TotalInputWatts; int requested = (int)channel.TotalRequestedWatts; int balanceInt = input - requested; string balance = balanceInt > 0 ? $"<color=green>+{balanceInt}W</color>" : balanceInt < 0 ? $"<color=red>{balanceInt}W</color>" : "0W"; Widgets.Label(new Rect(x, y, inRect.width, inRect.height - y), $"{"RF.Pylon.ChannelInfoHeader".Translate(channel.Name)}\n" + $"{"RF.Pylon.ChannelInfoInput".Translate(channel.ActiveTransmitterCount, input)}\n" + $"{"RF.Pylon.ChannelInfoOutput".Translate(channel.ActiveReceiversCount, requested)}\n" + $"{"RF.Pylon.ChannelInfoBalance".Translate(balance)}" + (channel.UnsatisfiedReceivers > 0 ? "\n" + (string)"RF.Pylon.ChannelInfoUnsatisfied".Translate(channel.UnsatisfiedReceivers) : "")); }