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

@@ -188,7 +188,7 @@ namespace WulaFallenEmpire.EventSystem.AI.UI
Rect avatarRect = new Rect(8f, 8f, avaSize, avaSize);
int expId = _core?.ExpressionId ?? 1;
string portraitPath = _def.portraitPath ?? $"Wula/Events/Portraits/WULA_Legion_{expId}";
string portraitPath = "Wula/Storyteller/WULA_Legion_TINY";
Texture2D portrait = ContentFinder<Texture2D>.Get(portraitPath, false);
if (portrait != null)
{
@@ -510,11 +510,7 @@ namespace WulaFallenEmpire.EventSystem.AI.UI
// 绘制方形头像
int expId = _core?.ExpressionId ?? 1;
string portraitPath = _def.portraitPath ?? $"Wula/Events/Portraits/WULA_Legion_{expId}";
if (expId > 1 && _def.portraitPath == null)
{
portraitPath = $"Wula/Events/Portraits/WULA_Legion_{expId}";
}
string portraitPath = "Wula/Storyteller/WULA_Legion_TINY";
Texture2D portrait = ContentFinder<Texture2D>.Get(portraitPath, false);
if (portrait != null)

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);
}
}
}

View File

@@ -11,6 +11,7 @@ namespace WulaFallenEmpire
public class WulaFallenEmpireMod : Mod
{
public static WulaFallenEmpireSettings settings;
public static bool _showApiKey = false;
private string _maxContextTokensBuffer;
public WulaFallenEmpireMod(ModContentPack content) : base(content)
@@ -32,7 +33,24 @@ namespace WulaFallenEmpire
listingStandard.Label("Wula_AISettings_Title".Translate());
listingStandard.Label("Wula_AISettings_ApiKey".Translate());
settings.apiKey = listingStandard.TextEntry(settings.apiKey);
Rect apiKeyRect = listingStandard.GetRect(30f);
// 这里我们手动实现一个带切换功能的密码输入框
float toggleWidth = 60f;
Rect passwordRect = new Rect(apiKeyRect.x, apiKeyRect.y, apiKeyRect.width - toggleWidth - 5f, apiKeyRect.height);
Rect toggleRect = new Rect(apiKeyRect.xMax - toggleWidth, apiKeyRect.y, toggleWidth, apiKeyRect.height);
// 使用静态布尔值或类成员来记住显示状态
if (WulaFallenEmpireMod._showApiKey)
{
settings.apiKey = Widgets.TextField(passwordRect, settings.apiKey);
}
else
{
settings.apiKey = GUI.PasswordField(passwordRect, settings.apiKey, '•');
}
Widgets.CheckboxLabeled(toggleRect, "Show", ref WulaFallenEmpireMod._showApiKey);
listingStandard.Gap(listingStandard.verticalSpacing);
listingStandard.Label("Wula_AISettings_BaseUrl".Translate());
settings.baseUrl = listingStandard.TextEntry(settings.baseUrl);