2026-11-29 18:27:08 +00:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using RimWorld;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using Verse;
|
|
|
|
|
|
|
|
|
|
namespace BlaxZones
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Package Tab. The delivery zone tab: priority dropdown (Low to Critical), source checkboxes
|
2026-11-30 21:33:40 +00:00
|
|
|
/// (orbital trade, quest rewards and caravan purchases), the "Caravans camp here" checkbox and
|
|
|
|
|
/// ThingFilterUI.DoThingFilterConfigWindow under DeliveryFilters.Parent.
|
2026-11-29 18:27:08 +00:00
|
|
|
///
|
2026-11-30 21:33:40 +00:00
|
|
|
/// Layout follows ITab_Storage (ITab_Storage.cs:104-151): the same window width contracted by 10, the
|
|
|
|
|
/// priority button top left, the filter below. Four checkbox rows sit between them, so the window is
|
|
|
|
|
/// two rows taller than the stockpile tab's 480.
|
2026-11-29 18:27:08 +00:00
|
|
|
/// </summary>
|
|
|
|
|
public class ITab_Delivery : ITab
|
|
|
|
|
{
|
2026-11-30 21:33:40 +00:00
|
|
|
private static readonly Vector2 WinSize = new Vector2(300f, 528f);
|
2026-11-29 18:27:08 +00:00
|
|
|
|
|
|
|
|
private const float PriorityButtonWidth = 160f;
|
|
|
|
|
private const float PriorityButtonHeight = 29f;
|
|
|
|
|
private const float RowHeight = 24f;
|
|
|
|
|
private const float Gap = 6f;
|
|
|
|
|
|
|
|
|
|
/// <summary>The filter tree's scroll position and search box. UI state of this shared tab, not game state.</summary>
|
|
|
|
|
private readonly ThingFilterUI.UIState thingFilterState = new ThingFilterUI.UIState();
|
|
|
|
|
|
|
|
|
|
public Zone_Delivery SelZone => SelObject as Zone_Delivery;
|
|
|
|
|
|
|
|
|
|
public ITab_Delivery()
|
|
|
|
|
{
|
|
|
|
|
size = WinSize;
|
|
|
|
|
labelKey = "BlaxZones_TabDelivery";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool IsVisible => SelZone != null;
|
|
|
|
|
|
|
|
|
|
public override void OnOpen()
|
|
|
|
|
{
|
|
|
|
|
base.OnOpen();
|
|
|
|
|
thingFilterState.quickSearch.Reset();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Notify_ClickOutsideWindow()
|
|
|
|
|
{
|
|
|
|
|
base.Notify_ClickOutsideWindow();
|
|
|
|
|
thingFilterState.quickSearch.Unfocus();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void FillTab()
|
|
|
|
|
{
|
|
|
|
|
Zone_Delivery zone = SelZone;
|
|
|
|
|
if (zone == null)
|
|
|
|
|
return;
|
|
|
|
|
zone.filter ??= DeliveryFilters.NewDefaultFilter();
|
|
|
|
|
|
|
|
|
|
Rect rect = new Rect(0f, 0f, WinSize.x, WinSize.y).ContractedBy(10f);
|
|
|
|
|
Widgets.BeginGroup(rect);
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Text.Font = GameFont.Small;
|
|
|
|
|
float y = 0f;
|
|
|
|
|
|
|
|
|
|
// Priority: a button that opens a float menu, as the stockpile tab does.
|
|
|
|
|
Rect priorityRect = new Rect(0f, y, PriorityButtonWidth, PriorityButtonHeight);
|
|
|
|
|
if (Widgets.ButtonText(priorityRect, PriorityButtonLabel(zone.priority)))
|
|
|
|
|
Find.WindowStack.Add(new FloatMenu(PriorityMenuOptions(zone)));
|
|
|
|
|
TooltipHandler.TipRegion(priorityRect, "BlaxZones_PriorityTip".Translate());
|
|
|
|
|
y += PriorityButtonHeight + Gap;
|
|
|
|
|
|
2026-11-30 21:33:40 +00:00
|
|
|
// Sources: orbital trade, quest rewards, caravan purchases.
|
2026-11-29 18:27:08 +00:00
|
|
|
Rect orbitalRect = new Rect(0f, y, rect.width, RowHeight);
|
|
|
|
|
Widgets.CheckboxLabeled(orbitalRect, "BlaxZones_AcceptOrbital".Translate(), ref zone.acceptOrbital);
|
|
|
|
|
TooltipHandler.TipRegion(orbitalRect, OrbitalTip());
|
|
|
|
|
y += RowHeight;
|
|
|
|
|
|
2026-11-30 21:33:40 +00:00
|
|
|
Rect rewardsRect = new Rect(0f, y, rect.width, RowHeight);
|
|
|
|
|
Widgets.CheckboxLabeled(rewardsRect, "BlaxZones_AcceptRewards".Translate(), ref zone.acceptRewards);
|
|
|
|
|
TooltipHandler.TipRegion(rewardsRect, RewardsTip());
|
|
|
|
|
y += RowHeight;
|
|
|
|
|
|
|
|
|
|
Rect caravanRect = new Rect(0f, y, rect.width, RowHeight);
|
|
|
|
|
Widgets.CheckboxLabeled(caravanRect, "BlaxZones_AcceptCaravan".Translate(), ref zone.acceptCaravan);
|
|
|
|
|
TooltipHandler.TipRegion(caravanRect, CaravanTip());
|
|
|
|
|
y += RowHeight;
|
|
|
|
|
|
2026-11-29 18:27:08 +00:00
|
|
|
Rect campRect = new Rect(0f, y, rect.width, RowHeight);
|
|
|
|
|
Widgets.CheckboxLabeled(campRect, "BlaxZones_CampHere".Translate(), ref zone.campHere);
|
|
|
|
|
TooltipHandler.TipRegion(campRect, CampTip());
|
|
|
|
|
y += RowHeight + Gap;
|
|
|
|
|
|
|
|
|
|
Rect filterRect = new Rect(0f, y, rect.width, rect.height - y);
|
|
|
|
|
ThingFilterUI.DoThingFilterConfigWindow(filterRect, thingFilterState, zone.filter, DeliveryFilters.Parent, 8,
|
|
|
|
|
HiddenDefs(), HiddenSpecialFilters());
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
Widgets.EndGroup();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>"Priority: Normal", the stockpile tab's button text (ITab_Storage.cs:114).</summary>
|
|
|
|
|
public static string PriorityButtonLabel(StoragePriority p) =>
|
|
|
|
|
"Priority".Translate() + ": " + p.Label().CapitalizeFirst();
|
|
|
|
|
|
|
|
|
|
/// <summary>The dropdown's entries: every StoragePriority from Low to Critical, never Unstored, each setting the zone's priority.</summary>
|
|
|
|
|
public static List<FloatMenuOption> PriorityMenuOptions(Zone_Delivery zone)
|
|
|
|
|
{
|
|
|
|
|
var list = new List<FloatMenuOption>();
|
|
|
|
|
foreach (StoragePriority p in Priorities())
|
|
|
|
|
{
|
|
|
|
|
StoragePriority local = p;
|
|
|
|
|
list.Add(new FloatMenuOption(local.Label().CapitalizeFirst(), () =>
|
|
|
|
|
{
|
|
|
|
|
if (zone != null)
|
|
|
|
|
zone.priority = local;
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>Low, Normal, Preferred, Important, Critical: the enum without Unstored, in enum order.</summary>
|
|
|
|
|
public static IEnumerable<StoragePriority> Priorities()
|
|
|
|
|
{
|
|
|
|
|
foreach (StoragePriority p in Enum.GetValues(typeof(StoragePriority)))
|
|
|
|
|
{
|
|
|
|
|
if (p != StoragePriority.Unstored)
|
|
|
|
|
yield return p;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The orbital checkbox's tooltip. Adds the Blax Slaves line while Slaves is active, and a note while
|
|
|
|
|
/// routing is off globally. "Route orbital trade" gates only DeliverFromOrbit; ZonesApi ignores it,
|
|
|
|
|
/// so with Slaves active the note says its payouts still land here.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static string OrbitalTip()
|
|
|
|
|
{
|
|
|
|
|
string tip = "BlaxZones_AcceptOrbitalTip".Translate();
|
|
|
|
|
if (!BlaxZonesMod.S.routeOrbital)
|
2026-11-29 19:49:47 +00:00
|
|
|
tip += "\n\n" + "BlaxZones_AcceptOrbitalOffTip".Translate();
|
2026-11-29 18:27:08 +00:00
|
|
|
return tip;
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-30 21:33:40 +00:00
|
|
|
/// <summary>The quest rewards checkbox's tooltip. Adds a note while "Route quest rewards" is off.</summary>
|
|
|
|
|
public static string RewardsTip()
|
|
|
|
|
{
|
|
|
|
|
string tip = "BlaxZones_AcceptRewardsTip".Translate();
|
|
|
|
|
if (!BlaxZonesMod.S.routeRewards)
|
|
|
|
|
tip += "\n\n" + "BlaxZones_AcceptRewardsOffTip".Translate();
|
|
|
|
|
return tip;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>The caravan checkbox's tooltip ("Trader caravans and guests"). Adds a note while "Route caravan purchases" is off.</summary>
|
|
|
|
|
public static string CaravanTip()
|
|
|
|
|
{
|
|
|
|
|
string tip = "BlaxZones_AcceptCaravanTip".Translate();
|
|
|
|
|
if (!BlaxZonesMod.S.routeCaravan)
|
|
|
|
|
tip += "\n\n" + "BlaxZones_AcceptCaravanOffTip".Translate();
|
|
|
|
|
return tip;
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-29 18:27:08 +00:00
|
|
|
/// <summary>The camp checkbox's tooltip. Adds a note while camping is off globally or stands down for a trading-spot mod.</summary>
|
|
|
|
|
public static string CampTip()
|
|
|
|
|
{
|
|
|
|
|
string tip = "BlaxZones_CampHereTip".Translate();
|
|
|
|
|
if (!BlaxZonesMod.S.campAtZones)
|
|
|
|
|
tip += "\n\n" + "BlaxZones_CampHereOffTip".Translate();
|
|
|
|
|
string spotMod = Compat.ActiveTradingSpotMod();
|
|
|
|
|
if (spotMod != null)
|
|
|
|
|
{
|
|
|
|
|
string name = ModLister.GetActiveModWithIdentifier(spotMod, ignorePostfix: true)?.Name ?? spotMod;
|
|
|
|
|
tip += "\n\n" + "BlaxZones_CampHereStandDownTip".Translate(name);
|
|
|
|
|
}
|
|
|
|
|
return tip;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static List<ThingDef> hiddenDefs;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Wastepack (Biotech, null-checked) and every corpse def. The parent filter already keeps them
|
|
|
|
|
/// out of the tree; passing them here also keeps "Clear all" and category checkboxes from
|
|
|
|
|
/// touching them (ThingFilter.SetAllow(ThingCategoryDef, ...) excepts these, ThingFilter.cs:718-730).
|
|
|
|
|
/// Built from defs once; no game state.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static List<ThingDef> HiddenDefs()
|
|
|
|
|
{
|
|
|
|
|
if (hiddenDefs == null)
|
|
|
|
|
{
|
|
|
|
|
var list = new List<ThingDef>();
|
|
|
|
|
ThingDef wastepack = ThingDefOf.Wastepack; // Biotech only; null without it
|
|
|
|
|
if (wastepack != null)
|
|
|
|
|
list.Add(wastepack);
|
|
|
|
|
if (ThingCategoryDefOf.Corpses != null)
|
|
|
|
|
list.AddRange(ThingCategoryDefOf.Corpses.DescendantThingDefs);
|
|
|
|
|
hiddenDefs = list;
|
|
|
|
|
}
|
|
|
|
|
return hiddenDefs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>The meat-source filters the stockpile tab hides with Ideology (ITab_Storage.cs:178-187), null-checked.</summary>
|
|
|
|
|
private static IEnumerable<SpecialThingFilterDef> HiddenSpecialFilters()
|
|
|
|
|
{
|
|
|
|
|
if (!ModsConfig.IdeologyActive)
|
|
|
|
|
yield break;
|
|
|
|
|
if (SpecialThingFilterDefOf.AllowVegetarian != null) yield return SpecialThingFilterDefOf.AllowVegetarian;
|
|
|
|
|
if (SpecialThingFilterDefOf.AllowCarnivore != null) yield return SpecialThingFilterDefOf.AllowCarnivore;
|
|
|
|
|
if (SpecialThingFilterDefOf.AllowCannibal != null) yield return SpecialThingFilterDefOf.AllowCannibal;
|
|
|
|
|
if (SpecialThingFilterDefOf.AllowInsectMeat != null) yield return SpecialThingFilterDefOf.AllowInsectMeat;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|