rimworld-blax-zones/Source/BlaxZones/Zone_Delivery.Tab.cs

67 lines
2.9 KiB
C#
Raw Permalink Normal View History

using System.Collections.Generic;
using RimWorld;
using UnityEngine;
using Verse;
using Verse.Sound;
namespace BlaxZones
{
/// <summary>Package Tab. Design: 1.0 "Delivery zone" > Tab. The delivery zone's tab and its copy/paste gizmos.</summary>
public partial class Zone_Delivery
{
/// <summary>Vanilla's copy and paste icons (StorageSettingsClipboard.cs:32, 43), loaded on first use on the main thread.</summary>
private static Texture2D copyIcon, pasteIcon;
private static Texture2D CopyIcon => copyIcon ??= ContentFinder<Texture2D>.Get("UI/Commands/CopySettings", reportFailure: false);
private static Texture2D PasteIcon => pasteIcon ??= ContentFinder<Texture2D>.Get("UI/Commands/PasteSettings", reportFailure: false);
/// <summary>The shared tab in an array, as Zone_Stockpile keeps its ITabs (Zone_Stockpile.cs:13-16, 70-73): the inspect pane asks every frame.</summary>
private static InspectTabBase[] inspectTabs;
/// <summary>ITab_Delivery, through InspectTabManager.GetSharedInstance.</summary>
public override IEnumerable<InspectTabBase> GetInspectTabs()
{
return inspectTabs ??= new[] { InspectTabManager.GetSharedInstance(typeof(ITab_Delivery)) };
}
/// <summary>The base zone gizmos plus copy and paste of the zone's settings (DeliveryClipboard).</summary>
public override IEnumerable<Gizmo> GetGizmos()
{
foreach (Gizmo g in base.GetGizmos())
yield return g;
yield return new Command_Action
{
icon = CopyIcon,
defaultLabel = "BlaxZones_CopySettings".Translate(),
defaultDesc = "BlaxZones_CopySettingsDesc".Translate(),
hotKey = KeyBindingDefOf.Misc4,
action = () =>
{
SoundDefOf.Tick_High.PlayOneShotOnCamera();
DeliveryClipboard.Copy(this);
Messages.Message("BlaxZones_SettingsCopied".Translate(), MessageTypeDefOf.NeutralEvent, historical: false);
},
};
var paste = new Command_Action
{
icon = PasteIcon,
defaultLabel = "BlaxZones_PasteSettings".Translate(),
defaultDesc = "BlaxZones_PasteSettingsDesc".Translate(),
hotKey = KeyBindingDefOf.Misc5,
action = () =>
{
SoundDefOf.Tick_High.PlayOneShotOnCamera();
DeliveryClipboard.PasteInto(this);
Messages.Message("BlaxZones_SettingsPasted".Translate(), MessageTypeDefOf.NeutralEvent, historical: false);
},
};
if (!DeliveryClipboard.HasCopy)
paste.Disable("BlaxZones_NothingCopied".Translate());
yield return paste;
}
}
}