Files
WulaFallenEmpireRW/Source/WulaFallenEmpire/WulaFallenEmpireMod.cs
2025-12-27 21:58:51 +08:00

129 lines
5.5 KiB
C#

using System;
using System.Reflection;
using HarmonyLib;
using UnityEngine;
using Verse;
using WulaFallenEmpire.Utils;
namespace WulaFallenEmpire
{
[StaticConstructorOnStartup]
public class WulaFallenEmpireMod : Mod
{
public static WulaFallenEmpireSettings settings;
public static bool _showApiKey = false;
public static bool _showVlmApiKey = false;
private string _maxContextTokensBuffer;
public WulaFallenEmpireMod(ModContentPack content) : base(content)
{
settings = GetSettings<WulaFallenEmpireSettings>();
// 初始化Harmony
var harmony = new Harmony("tourswen.wulafallenempire"); // 替换为您的唯一Mod ID
harmony.PatchAll(Assembly.GetExecutingAssembly());
WulaLog.Debug("[WulaFallenEmpire] Harmony patches applied.");
}
public override void DoSettingsWindowContents(Rect inRect)
{
Listing_Standard listingStandard = new Listing_Standard();
listingStandard.Begin(inRect);
listingStandard.Label("Wula_AISettings_Title".Translate());
listingStandard.Label("Wula_AISettings_ApiKey".Translate());
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);
listingStandard.Label("Wula_AISettings_Model".Translate());
settings.model = listingStandard.TextEntry(settings.model);
listingStandard.GapLine();
listingStandard.Label("Wula_AISettings_MaxContextTokens".Translate());
listingStandard.Label("Wula_AISettings_MaxContextTokensDesc".Translate());
Rect tokensRect = listingStandard.GetRect(Text.LineHeight);
Widgets.TextFieldNumeric(tokensRect, ref settings.maxContextTokens, ref _maxContextTokensBuffer, 1000, 200000);
listingStandard.GapLine();
listingStandard.CheckboxLabeled("Wula_EnableDebugLogs".Translate(), ref settings.enableDebugLogs, "Wula_EnableDebugLogsDesc".Translate());
// VLM 设置部分
listingStandard.GapLine();
listingStandard.Label("<color=cyan>VLM (视觉模型) 设置</color>");
listingStandard.CheckboxLabeled("启用 VLM 视觉功能", ref settings.enableVlmFeatures, "启用后 AI 可以「看到」游戏屏幕并分析");
if (settings.enableVlmFeatures)
{
listingStandard.Label("VLM API Key:");
Rect vlmKeyRect = listingStandard.GetRect(30f);
Rect vlmPasswordRect = new Rect(vlmKeyRect.x, vlmKeyRect.y, vlmKeyRect.width - toggleWidth - 5f, vlmKeyRect.height);
Rect vlmToggleRect = new Rect(vlmKeyRect.xMax - toggleWidth, vlmKeyRect.y, toggleWidth, vlmKeyRect.height);
if (_showVlmApiKey)
{
settings.vlmApiKey = Widgets.TextField(vlmPasswordRect, settings.vlmApiKey ?? "");
}
else
{
settings.vlmApiKey = GUI.PasswordField(vlmPasswordRect, settings.vlmApiKey ?? "", '•');
}
Widgets.CheckboxLabeled(vlmToggleRect, "Show", ref _showVlmApiKey);
listingStandard.Gap(listingStandard.verticalSpacing);
listingStandard.Label("VLM Base URL:");
settings.vlmBaseUrl = listingStandard.TextEntry(settings.vlmBaseUrl ?? "https://dashscope.aliyuncs.com/compatible-mode/v1");
listingStandard.Label("VLM Model:");
settings.vlmModel = listingStandard.TextEntry(settings.vlmModel ?? "qwen-vl-max");
}
listingStandard.GapLine();
listingStandard.Label("Translation tools");
Rect exportRect = listingStandard.GetRect(30f);
if (Widgets.ButtonText(exportRect, "Export DefInjected template (CN source)"))
{
DefInjectedExportUtility.ExportDefInjectedTemplateFromDefs(Content);
}
listingStandard.End();
base.DoSettingsWindowContents(inRect);
}
public override string SettingsCategory()
{
return "Wula Fallen Empire";
}
}
[StaticConstructorOnStartup]
public static class StartupLogger
{
static StartupLogger()
{
WulaLog.Debug("WulaFallenEmpire Mod DLL, version 1.0.2, has been loaded.");
}
}
}