This commit is contained in:
2025-12-27 20:34:59 +08:00
parent 6f945ab56b
commit efa6a27bb8
4 changed files with 89 additions and 42 deletions

View File

@@ -10,24 +10,47 @@ namespace WulaFallenEmpire.EventSystem.AI.UI
{
private string _message;
private int _tickCreated;
private const int DisplayTicks = 300; // 5 seconds
private const int DisplayTicks = 180; // 3 seconds
private Vector2 _size = new Vector2(320f, 65f);
public override Vector2 InitialSize => new Vector2(300f, 80f);
public override Vector2 InitialSize => _size;
public Overlay_WulaLink_Notification(string message)
{
_message = message;
_tickCreated = Find.TickManager.TicksGame;
// Transient properties
this.layer = WindowLayer.Super; // Topmost
// Calculate adaptive size (Instance-based)
Text.Font = GameFont.Small;
float textWidth = Text.CalcSize(message).x;
// Limit max width to 500f, wrapping for long text
if (textWidth > 450f)
{
float width = 550f; // Wider
float height = Text.CalcHeight(message, width - 65f) + 65f; // Extra buffer for bottom lines
_size = new Vector2(width, height);
}
else
{
_size = new Vector2(Mathf.Max(250f, textWidth + 85f), 85f); // Taller base
}
// Window properties
this.layer = WindowLayer.Super;
this.closeOnClickedOutside = false;
this.forcePause = false;
this.absorbInputAroundWindow = false;
this.doWindowBackground = false; // Custom bg
this.doWindowBackground = false;
this.drawShadow = false;
}
protected override void SetInitialSizeAndPosition()
{
// Position at top-left
this.windowRect = new Rect(20f, 20f, InitialSize.x, InitialSize.y);
}
public override void DoWindowContents(Rect inRect)
{
// Auto Close after time
@@ -37,59 +60,69 @@ namespace WulaFallenEmpire.EventSystem.AI.UI
return;
}
// Draw HUD Notification Style
Widgets.DrawBoxSolid(inRect, new Color(0.1f, 0.1f, 0.1f, 0.9f));
GUI.color = WulaLinkStyles.SystemAccentColor;
Widgets.DrawBox(inRect, 1);
// UI Styling (Legion Style)
Widgets.DrawBoxSolid(inRect, new Color(0.12f, 0.05f, 0.05f, 0.95f)); // Dark blood red background
GUI.color = WulaLinkStyles.HeaderColor;
Widgets.DrawBox(inRect, 2);
GUI.color = Color.white;
Rect iconRect = new Rect(10f, 10f, 30f, 30f);
Rect titleRect = new Rect(50f, 10f, 200f, 20f);
Rect textRect = new Rect(50f, 30f, 240f, 40f);
// 恢复刚才的视觉风格 (Content areas)
Rect iconRect = new Rect(10f, 12f, 25f, 25f);
Rect titleRect = new Rect(45f, 5f, inRect.width - 60f, 20f);
Rect textRect = new Rect(45f, 25f, inRect.width - 55f, inRect.height - 30f);
// Icon (Warning / Info)
Widgets.DrawBoxSolid(iconRect, WulaLinkStyles.SystemAccentColor);
GUI.color = Color.black;
// 绘制视觉装饰 (装饰性图标和标题)
Widgets.DrawBoxSolid(iconRect, WulaLinkStyles.HeaderColor);
GUI.color = Color.white;
Text.Anchor = TextAnchor.MiddleCenter;
Text.Font = GameFont.Medium;
Widgets.Label(iconRect, "!");
GUI.color = Color.white;
// Title
Text.Anchor = TextAnchor.UpperLeft;
Text.Font = GameFont.Tiny;
Widgets.Label(iconRect, "!");
Text.Anchor = TextAnchor.UpperLeft;
GUI.color = Color.yellow;
Widgets.Label(titleRect, "WULA LINK :: NEW ALERT");
Widgets.Label(titleRect, "WULA LINK :: MESSAGE");
GUI.color = Color.white;
// Text
// Body Text
Text.Font = GameFont.Small;
string truncated = _message.Length > 40 ? _message.Substring(0, 38) + "..." : _message;
Widgets.Label(textRect, truncated);
Widgets.Label(textRect, _message);
// Click to Open/Expand
if (Widgets.ButtonInvisible(inRect))
// Hover and Click Logic (全窗口交互,无需按钮)
if (Mouse.IsOver(inRect))
{
OpenWulaLink();
Close();
Widgets.DrawHighlight(inRect);
// 0 = Left Click, 1 = Right Click
if (Event.current.type == EventType.MouseDown)
{
if (Event.current.button == 0) // Left click: Open
{
OpenWulaLink();
Close();
Event.current.Use();
}
else if (Event.current.button == 1) // Right click: Close
{
Close();
Event.current.Use();
}
}
}
Text.Anchor = TextAnchor.UpperLeft;
Text.Font = GameFont.Small;
}
public void OpenWulaLink()
{
// Find existing or open new
var existing = Find.WindowStack.WindowOfType<Overlay_WulaLink>();
if (existing != null)
{
existing.Expand();
Find.WindowStack.Notify_ManuallySetFocus(existing);
}
else
{
// Create new if not exists
var core = AIIntelligenceCore.Instance;
// Without EventDef we can't easily open.
// Assuming notification implies active core state.
// Fallback: If no overlay exists, try to find EventDef or just show message
Messages.Message("Wula_AI_Notification_ClickTips".Translate(), MessageTypeDefOf.NeutralEvent);
}
}
}