238 lines
11 KiB
C#
238 lines
11 KiB
C#
// File: ITabs/ITab_EquipmentOotheca_Incubation.cs
|
|
using UnityEngine;
|
|
using Verse;
|
|
using System.Collections.Generic;
|
|
using RimWorld;
|
|
using Verse.Sound;
|
|
|
|
namespace ArachnaeSwarm
|
|
{
|
|
public class ITab_EquipmentOotheca_Incubation : ITab
|
|
{
|
|
private const float BarHeight = 20f;
|
|
private const float Margin = 10f;
|
|
private const float LabelHeight = 30f;
|
|
private const float SmallLabelHeight = 20f;
|
|
private const float ButtonHeight = 25f;
|
|
private const float TabWidth = 320f;
|
|
private const float TabHeight = 420f;
|
|
|
|
private Vector2 scrollPosition = Vector2.zero;
|
|
private const float ViewHeight = 450f;
|
|
|
|
public override bool IsVisible
|
|
{
|
|
get
|
|
{
|
|
return SelThing.Faction == Faction.OfPlayer;
|
|
}
|
|
}
|
|
|
|
public ITab_EquipmentOotheca_Incubation()
|
|
{
|
|
size = new Vector2(TabWidth, TabHeight);
|
|
labelKey = "ARA_EquipmentIncubator.IncubationTab";
|
|
tutorTag = "EquipmentIncubation";
|
|
}
|
|
|
|
protected override void FillTab()
|
|
{
|
|
Rect rect = new Rect(0f, 0f, size.x, size.y).ContractedBy(Margin);
|
|
Widgets.DrawMenuSection(rect);
|
|
Building_EquipmentOotheca ootheca = SelThing as Building_EquipmentOotheca;
|
|
if (ootheca == null)
|
|
{
|
|
Widgets.Label(rect, "ARA_EquipmentIncubator.NotAnEquipmentOotheca".Translate());
|
|
return;
|
|
}
|
|
rect = rect.ContractedBy(5f);
|
|
|
|
Rect viewRect = new Rect(0f, 0f, rect.width - 16f, ViewHeight);
|
|
Rect scrollRect = new Rect(rect.x, rect.y, rect.width, rect.height);
|
|
|
|
Widgets.BeginScrollView(scrollRect, ref scrollPosition, viewRect);
|
|
|
|
float curY = 0f;
|
|
|
|
Rect titleRect = new Rect(0f, curY, viewRect.width, LabelHeight);
|
|
string title = "ARA_EquipmentIncubator.IncubationProgress".Translate();
|
|
Text.Font = GameFont.Medium;
|
|
Widgets.Label(titleRect, title);
|
|
Text.Font = GameFont.Small;
|
|
curY += LabelHeight + 15f;
|
|
|
|
float buttonWidth = (viewRect.width - 10f) / 2f;
|
|
|
|
Rect speedButtonRect = new Rect(0f, curY, buttonWidth, ButtonHeight);
|
|
string speedText = "ARA_EquipmentIncubator.Speed".Translate() + ": " + ootheca.SpeedMultiplier.ToStringPercent();
|
|
|
|
Color speedColor = Color.white;
|
|
if (ootheca.SpeedMultiplier != 1.0f)
|
|
{
|
|
speedColor = ootheca.SpeedMultiplier > 1.0f ?
|
|
new Color(0.2f, 0.8f, 0.2f) :
|
|
new Color(0.8f, 0.8f, 0.2f);
|
|
}
|
|
|
|
if (Widgets.ButtonText(speedButtonRect, speedText, true, true, speedColor))
|
|
{
|
|
// 可选:显示详细信息
|
|
}
|
|
|
|
TooltipHandler.TipRegion(speedButtonRect, () => ootheca.GetSpeedFactorsDescription(), 987654321);
|
|
|
|
Rect qualityButtonRect = new Rect(buttonWidth + 10f, curY, buttonWidth, ButtonHeight);
|
|
string qualityText = "ARA_EquipmentIncubator.Quality".Translate() + ": " + ootheca.QualityMultiplier.ToStringPercent();
|
|
|
|
Color qualityColor = Color.white;
|
|
float qualityMultiplier = ootheca.QualityMultiplier;
|
|
if (qualityMultiplier != 1.0f)
|
|
{
|
|
if (qualityMultiplier > 0.9f)
|
|
qualityColor = new Color(0.2f, 0.8f, 0.2f);
|
|
else if (qualityMultiplier > 0.7f)
|
|
qualityColor = new Color(0.8f, 0.8f, 0.2f);
|
|
else if (qualityMultiplier > 0.5f)
|
|
qualityColor = new Color(0.9f, 0.6f, 0.2f);
|
|
else
|
|
qualityColor = new Color(0.8f, 0.2f, 0.2f);
|
|
}
|
|
|
|
if (Widgets.ButtonText(qualityButtonRect, qualityText, true, true, qualityColor))
|
|
{
|
|
// 可选:显示详细信息
|
|
}
|
|
|
|
TooltipHandler.TipRegion(qualityButtonRect, () => ootheca.GetQualityFactorsDescription(), 987654322);
|
|
|
|
curY += ButtonHeight + 25f;
|
|
|
|
if (ootheca.isIncubating && ootheca.incubatingThingDef != null)
|
|
{
|
|
float progressPercent = ootheca.AdjustedProgressPercent;
|
|
float qualityPercent = ootheca.QualityPercent;
|
|
float daysRemaining = ootheca.GetRemainingDays();
|
|
float hoursRemaining = ootheca.GetRemainingHours();
|
|
|
|
Rect targetRect = new Rect(0f, curY, viewRect.width, SmallLabelHeight);
|
|
Widgets.Label(targetRect, "ARA_EquipmentIncubator.Target".Translate() + ": " + ootheca.incubatingThingDef.LabelCap);
|
|
curY += SmallLabelHeight + 20f;
|
|
|
|
Rect progressBarRect = new Rect(0f, curY, viewRect.width, BarHeight);
|
|
Rect progressLabelRect = new Rect(progressBarRect.x, progressBarRect.y - 20, progressBarRect.width, 18);
|
|
Text.Anchor = TextAnchor.MiddleCenter;
|
|
GUI.color = new Color(0.9f, 0.9f, 0.9f, 1f);
|
|
Widgets.Label(progressLabelRect, "ARA_EquipmentIncubator.IncubationProgressLabel".Translate());
|
|
Text.Anchor = TextAnchor.UpperLeft;
|
|
GUI.color = Color.white;
|
|
|
|
Widgets.FillableBar(progressBarRect, progressPercent, SolidColorMaterials.NewSolidColorTexture(new Color(0.2f, 0.8f, 0.2f, 0.5f)));
|
|
Widgets.FillableBarChangeArrows(progressBarRect, progressPercent);
|
|
|
|
string progressText = $"{progressPercent:P0}";
|
|
Text.Anchor = TextAnchor.MiddleCenter;
|
|
Widgets.Label(progressBarRect, progressText);
|
|
Text.Anchor = TextAnchor.UpperLeft;
|
|
|
|
curY += BarHeight + 30f;
|
|
|
|
Rect qualityBarRect = new Rect(0f, curY, viewRect.width, BarHeight);
|
|
Rect qualityLabelRect = new Rect(qualityBarRect.x, qualityBarRect.y - 20, qualityBarRect.width, 18);
|
|
Text.Anchor = TextAnchor.MiddleCenter;
|
|
GUI.color = new Color(0.9f, 0.9f, 0.9f, 1f);
|
|
Widgets.Label(qualityLabelRect, "ARA_EquipmentIncubator.QualityProgress".Translate());
|
|
Text.Anchor = TextAnchor.UpperLeft;
|
|
GUI.color = Color.white;
|
|
|
|
Widgets.FillableBar(qualityBarRect, qualityPercent, SolidColorMaterials.NewSolidColorTexture(new Color(0.1f, 0.4f, 0.8f, 0.5f)));
|
|
|
|
string qualityProgressText = $"{qualityPercent:P0}";
|
|
Text.Anchor = TextAnchor.MiddleCenter;
|
|
Widgets.Label(qualityBarRect, qualityProgressText);
|
|
Text.Anchor = TextAnchor.UpperLeft;
|
|
|
|
Rect targetQualityRect = new Rect(qualityBarRect.x + qualityBarRect.width - 40, qualityBarRect.y, 40, BarHeight);
|
|
GUI.color = new Color(0.8f, 0.8f, 0.8f, 0.7f);
|
|
Text.Anchor = TextAnchor.MiddleRight;
|
|
Widgets.Label(targetQualityRect, $"{ootheca.QualityMultiplier:P0}");
|
|
Text.Anchor = TextAnchor.UpperLeft;
|
|
GUI.color = Color.white;
|
|
|
|
curY += BarHeight + 25f;
|
|
|
|
Rect timeRect = new Rect(0f, curY, viewRect.width, SmallLabelHeight);
|
|
string timeText = "ARA_EquipmentIncubator.TimeRemaining".Translate() + ": " + daysRemaining.ToString("F1") + " " + "ARA_EquipmentIncubator.Days".Translate();
|
|
if (hoursRemaining > 0.1f && daysRemaining < 1f)
|
|
{
|
|
timeText += " (" + hoursRemaining.ToString("F1") + " " + "ARA_EquipmentIncubator.Hours".Translate() + ")";
|
|
}
|
|
Widgets.Label(timeRect, timeText);
|
|
}
|
|
else if (ootheca.assignedLarva != null)
|
|
{
|
|
Rect statusRect = new Rect(0f, curY, viewRect.width, SmallLabelHeight * 2);
|
|
if (ootheca.larvaOperateTicksRemaining > 0)
|
|
{
|
|
float secondsRemaining = ootheca.larvaOperateTicksRemaining / 60f;
|
|
Widgets.Label(statusRect, "ARA_EquipmentIncubator.LarvaIsActivatingOotheca".Translate() + "\n" +
|
|
secondsRemaining.ToString("F1") + " " + "ARA_EquipmentIncubator.SecondsRemaining".Translate());
|
|
}
|
|
else
|
|
{
|
|
Widgets.Label(statusRect, "ARA_EquipmentIncubator.LarvaIsOnTheWay".Translate());
|
|
}
|
|
|
|
curY += SmallLabelHeight * 2 + 15f;
|
|
|
|
var config = ootheca.EquipmentIncubatorData?.SelectedConfig;
|
|
if (config != null)
|
|
{
|
|
curY += 10f;
|
|
Rect targetRect = new Rect(0f, curY, viewRect.width, SmallLabelHeight * 3);
|
|
string targetText = "ARA_EquipmentIncubator.ReadyToIncubate".Translate() + "\n" + config.thingDef.LabelCap;
|
|
|
|
if (!config.IsResearchComplete && config.requiredResearch != null)
|
|
{
|
|
targetText += "\n" + "(" + "ARA_EquipmentIncubator.Requires".Translate() + ": " + config.requiredResearch.LabelCap + ")";
|
|
}
|
|
|
|
Widgets.Label(targetRect, targetText);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
var config = ootheca.EquipmentIncubatorData?.SelectedConfig;
|
|
if (config != null)
|
|
{
|
|
Rect targetRect = new Rect(0f, curY, viewRect.width, SmallLabelHeight * 3);
|
|
string targetText = "ARA_EquipmentIncubator.ReadyToIncubate".Translate() + "\n" + config.thingDef.LabelCap;
|
|
|
|
if (!config.IsResearchComplete && config.requiredResearch != null)
|
|
{
|
|
targetText += "\n" + "(" + "ARA_EquipmentIncubator.Requires".Translate() + ": " + config.requiredResearch.LabelCap + ")";
|
|
}
|
|
|
|
Widgets.Label(targetRect, targetText);
|
|
curY += SmallLabelHeight * 3 + 10f;
|
|
}
|
|
else
|
|
{
|
|
Rect noTargetRect = new Rect(0f, curY, viewRect.width, SmallLabelHeight);
|
|
Widgets.Label(noTargetRect, "ARA_EquipmentIncubator.NoIncubationTargetSelected".Translate());
|
|
curY += SmallLabelHeight + 10f;
|
|
}
|
|
}
|
|
|
|
curY += 20f;
|
|
viewRect.height = curY;
|
|
|
|
Widgets.EndScrollView();
|
|
}
|
|
|
|
protected override void UpdateSize()
|
|
{
|
|
size = new Vector2(TabWidth, TabHeight);
|
|
}
|
|
}
|
|
}
|