换了背景和对话框

This commit is contained in:
2025-11-24 17:30:42 +08:00
parent bb1b8f8b66
commit f4e7f6c087
19 changed files with 621 additions and 165 deletions

View File

@@ -27,6 +27,190 @@ namespace WulaFallenEmpire
}
}
// 新增:自定义按钮样式设置
private static readonly Color CustomButtonNormalColor = new Color(0.5f, 0.2f, 0.2f, 1f);
private static readonly Color CustomButtonHoverColor = new Color(0.6f, 0.3f, 0.3f, 1f);
private static readonly Color CustomButtonDisabledColor = new Color(0.15f, 0.15f, 0.15f, 0.6f);
private static readonly Color CustomButtonTextNormalColor = new Color(0.9f, 0.9f, 0.9f, 1f);
private static readonly Color CustomButtonTextHoverColor = new Color(1f, 1f, 1f, 1f);
private static readonly Color CustomButtonTextDisabledColor = new Color(0.6f, 0.6f, 0.6f, 1f);
// 绘制单个选项 - 使用自定义样式
private void DrawSingleOption(Rect rect, EventOption option)
{
string reason;
bool conditionsMet = AreConditionsMet(option.conditions, out reason);
// 水平居中选项
float optionWidth = Mathf.Min(rect.width, Config.optionSize.x * (rect.width / Config.windowSize.x));
float optionX = rect.x + (rect.width - optionWidth) / 2;
Rect optionRect = new Rect(optionX, rect.y, optionWidth, rect.height);
// 保存原始状态
Color originalColor = GUI.color;
GameFont originalFont = Text.Font;
Color originalTextColor = GUI.contentColor;
TextAnchor originalAnchor = Text.Anchor;
try
{
// 设置文本居中
Text.Anchor = TextAnchor.MiddleCenter;
Text.Font = GameFont.Small;
if (conditionsMet)
{
// 启用状态的选项 - 使用自定义样式
if (option.useCustomColors)
{
// 使用选项自定义颜色
DrawCustomButtonWithColors(optionRect, option.label.Translate(), option);
}
else
{
// 使用默认自定义颜色
DrawCustomButton(optionRect, option.label.Translate(), isEnabled: true);
}
// 添加点击处理
if (Widgets.ButtonInvisible(optionRect))
{
HandleAction(option.optionEffects);
}
}
else
{
// 禁用状态的选项 - 使用自定义禁用样式
if (option.useCustomColors && option.disabledColor.HasValue)
{
// 使用选项自定义禁用颜色
DrawCustomButtonWithColors(optionRect, option.label.Translate(), option, isEnabled: false);
}
else
{
// 使用默认自定义禁用颜色
DrawCustomButton(optionRect, option.label.Translate(), isEnabled: false);
}
// 添加禁用提示
TooltipHandler.TipRegion(optionRect, GetDisabledReason(option, reason).Translate());
}
}
finally
{
// 恢复原始状态
GUI.color = originalColor;
Text.Font = originalFont;
GUI.contentColor = originalTextColor;
Text.Anchor = originalAnchor;
}
}
/// <summary>
/// 绘制自定义按钮(基础版本)
/// </summary>
private void DrawCustomButton(Rect rect, string label, bool isEnabled = true)
{
bool isMouseOver = Mouse.IsOver(rect);
// 确定按钮状态颜色
Color buttonColor, textColor;
if (!isEnabled)
{
// 禁用状态
buttonColor = CustomButtonDisabledColor;
textColor = CustomButtonTextDisabledColor;
}
else if (isMouseOver)
{
// 悬停状态
buttonColor = CustomButtonHoverColor;
textColor = CustomButtonTextHoverColor;
}
else
{
// 正常状态
buttonColor = CustomButtonNormalColor;
textColor = CustomButtonTextNormalColor;
}
// 绘制按钮背景
GUI.color = buttonColor;
Widgets.DrawBoxSolid(rect, buttonColor);
// 绘制边框
if (isEnabled)
{
Widgets.DrawBox(rect, 1);
}
else
{
// 禁用状态的边框更细更暗
Widgets.DrawBox(rect, 1);
}
// 绘制文本
GUI.color = textColor;
Text.Anchor = TextAnchor.MiddleCenter;
Widgets.Label(rect.ContractedBy(4f), label);
// 如果是禁用状态,添加删除线效果
if (!isEnabled)
{
GUI.color = new Color(0.6f, 0.6f, 0.6f, 0.8f);
Widgets.DrawLine(
new Vector2(rect.x + 10f, rect.center.y),
new Vector2(rect.xMax - 10f, rect.center.y),
GUI.color,
1f
);
}
}
/// <summary>
/// 绘制自定义按钮(使用选项自定义颜色)
/// </summary>
private void DrawCustomButtonWithColors(Rect rect, string label, EventOption option, bool isEnabled = true)
{
bool isMouseOver = Mouse.IsOver(rect);
// 确定按钮状态颜色
Color buttonColor, textColor;
if (!isEnabled)
{
// 禁用状态
buttonColor = option.disabledColor ?? CustomButtonDisabledColor;
textColor = option.textDisabledColor ?? CustomButtonTextDisabledColor;
}
else if (isMouseOver)
{
// 悬停状态
buttonColor = option.hoverColor ?? CustomButtonHoverColor;
textColor = option.textHoverColor ?? CustomButtonTextHoverColor;
}
else
{
// 正常状态
buttonColor = option.normalColor ?? CustomButtonNormalColor;
textColor = option.textColor ?? CustomButtonTextNormalColor;
}
// 绘制按钮背景
GUI.color = buttonColor;
Widgets.DrawBoxSolid(rect, buttonColor);
// 绘制边框
Widgets.DrawBox(rect);
// 绘制文本
GUI.color = textColor;
Text.Anchor = TextAnchor.MiddleCenter;
Widgets.Label(rect.ContractedBy(4f), label);
// 如果是禁用状态,添加删除线效果
if (!isEnabled)
{
GUI.color = new Color(0.6f, 0.6f, 0.6f, 0.8f);
Widgets.DrawLine(
new Vector2(rect.x + 10f, rect.center.y),
new Vector2(rect.xMax - 10f, rect.center.y),
GUI.color,
1f
);
}
}
// 使用配置的窗口尺寸
public override Vector2 InitialSize
{
@@ -342,90 +526,6 @@ namespace WulaFallenEmpire
}
}
}
// 绘制单个选项 - 增强版本(修复版本)
private void DrawSingleOption(Rect rect, EventOption option)
{
string reason;
bool conditionsMet = AreConditionsMet(option.conditions, out reason);
// 水平居中选项
float optionWidth = Mathf.Min(rect.width, Config.optionSize.x * (rect.width / Config.windowSize.x));
float optionX = rect.x + (rect.width - optionWidth) / 2;
Rect optionRect = new Rect(optionX, rect.y, optionWidth, rect.height);
if (conditionsMet)
{
// 保存原始状态
Color originalColor = GUI.color;
GameFont originalFont = Text.Font;
Color originalTextColor = GUI.contentColor;
TextAnchor originalAnchor = Text.Anchor;
try
{
// 应用自定义颜色
if (option.useCustomColors)
{
ApplyOptionColors(option, optionRect);
}
// 设置文本居中
Text.Anchor = TextAnchor.MiddleCenter;
if (Widgets.ButtonText(optionRect, option.label.Translate()))
{
HandleAction(option.optionEffects);
}
}
finally
{
// 恢复原始状态
GUI.color = originalColor;
Text.Font = originalFont;
GUI.contentColor = originalTextColor;
Text.Anchor = originalAnchor;
}
}
else
{
// 禁用状态的选项 - 修复版本
Color originalColor = GUI.color;
GameFont originalFont = Text.Font;
Color originalTextColor = GUI.contentColor;
TextAnchor originalAnchor = Text.Anchor;
try
{
// 设置禁用状态的颜色
GUI.color = new Color(0.85f, 0.85f, 0.85f, 1f);
GUI.contentColor = new Color(0.85f, 0.85f, 0.85f, 1f);
Text.Font = GameFont.Small;
// 修复:使用正确的 DrawBoxSolid 方法
Widgets.DrawBoxSolid(optionRect, new Color(0.2f, 0.2f, 0.2f, 0.3f));
Widgets.DrawBox(optionRect);
// 设置文本居中
Text.Anchor = TextAnchor.MiddleCenter;
// 绘制居中的文本
Rect textRect = optionRect.ContractedBy(4f);
Widgets.Label(textRect, option.label.Translate());
// 可选:在文本上添加删除线效果
if (Config.drawBorders)
{
// 修复:使用正确的 DrawLine 方法
Widgets.DrawLine(
new Vector2(textRect.x, textRect.center.y),
new Vector2(textRect.xMax, textRect.center.y),
Color.gray,
1f
);
}
TooltipHandler.TipRegion(optionRect, GetDisabledReason(option, reason).Translate());
}
finally
{
// 恢复原始状态
GUI.color = originalColor;
Text.Font = originalFont;
GUI.contentColor = originalTextColor;
Text.Anchor = originalAnchor;
}
}
}
// 应用选项颜色
private void ApplyOptionColors(EventOption option, Rect rect)
{

View File

@@ -0,0 +1,68 @@
using UnityEngine;
using Verse;
namespace WulaFallenEmpire
{
public class EventUIButtonConfigDef : Def
{
// ===== 基础按钮颜色设置 =====
public Color normalColor = new Color(0.5f, 0.2f, 0.2f, 1f);
public Color hoverColor = new Color(0.6f, 0.3f, 0.3f, 1f);
public Color activeColor = new Color(0.4f, 0.4f, 0.4f, 1f);
public Color disabledColor = new Color(0.15f, 0.15f, 0.15f, 0.6f);
// ===== 文本颜色设置 =====
public Color textNormalColor = new Color(0.9f, 0.9f, 0.9f, 1f);
public Color textHoverColor = new Color(1f, 1f, 1f, 1f);
public Color textActiveColor = new Color(1f, 1f, 1f, 1f);
public Color textDisabledColor = new Color(0.6f, 0.6f, 0.6f, 1f);
// ===== 边框设置 =====
public bool drawBorder = true;
public Color borderColor = new Color(0.6f, 0.2f, 0.2f, 1f);
public int borderWidth = 1;
// ===== 效果设置 =====
public bool showDisabledStrikethrough = true;
public Color strikethroughColor = new Color(0.6f, 0.6f, 0.6f, 0.8f);
public float strikethroughWidth = 1f;
// ===== 圆角设置 =====
public bool useRoundedCorners = true;
public float cornerRadius = 5f;
// ===== 阴影设置 =====
public bool drawShadow = false;
public Color shadowColor = new Color(0f, 0f, 0f, 0.5f);
public Vector2 shadowOffset = new Vector2(2f, 2f);
// ===== 动画设置 =====
public bool enableHoverAnimation = false;
public float hoverScaleFactor = 1.02f;
public float animationDuration = 0.1f;
// ===== 字体设置 =====
public GameFont buttonFont = GameFont.Small;
public bool useCustomFont = false;
public string customFontPath;
// ===== 获取配置实例 =====
private static EventUIButtonConfigDef config;
public static EventUIButtonConfigDef Config
{
get
{
if (config == null)
{
config = DefDatabase<EventUIButtonConfigDef>.GetNamed("Wula_EventUIButtonConfig");
if (config == null)
{
// 创建默认配置
config = new EventUIButtonConfigDef();
}
}
return config;
}
}
}
}

View File

@@ -125,6 +125,7 @@
<Compile Include="EventSystem\Effect\EffectBase.cs" />
<Compile Include="EventSystem\Effect\Effect_CallSkyfaller.cs" />
<Compile Include="EventSystem\EventDef.cs" />
<Compile Include="EventSystem\EventUIButtonConfigDef.cs" />
<Compile Include="EventSystem\EventUIConfigDef.cs" />
<Compile Include="EventSystem\EventVariableManager.cs" />
<Compile Include="EventSystem\QuestNode\QuestNode_EventLetter.cs" />