Commit pending working-tree changes (local edits, line endings)
This commit is contained in:
1 parent
134cc686ec
commit
422802b12e
10 files changed
+317
-317
No files matched your search
+56
-56
@@ -1,56 +1,56 @@
|
||||
using System.Collections.Generic;
|
||||
using Cthangover.Core.Mods;
|
||||
using Cthangover.Core.Settings;
|
||||
|
||||
namespace Cthangover.Cooking
|
||||
{
|
||||
/// <summary>
|
||||
/// Exposes a user-configurable setting for the number of rations
|
||||
/// consumed per character per in-game day. Registered automatically
|
||||
/// via <see cref="ModSettingsRegistry"/> when the cooking mod
|
||||
/// assembly loads.
|
||||
///
|
||||
/// The static <see cref="RationsPerCharacter"/> property is the
|
||||
/// canonical source of truth shared with <c>RationStatisticsPanel</c>
|
||||
/// and any future consumption logic. It is updated by the core on
|
||||
/// boot (from persisted JSON) and on every UI change.
|
||||
/// </summary>
|
||||
public class CookingSettings : IModSettings
|
||||
{
|
||||
/// <summary>
|
||||
/// Current value for rations consumed per character per day.
|
||||
/// Default is 1. Updated by <see cref="ReadValues"/> on boot
|
||||
/// and whenever the player changes the setting in the menu.
|
||||
/// </summary>
|
||||
public static int RationsPerCharacter { get; private set; } = 1;
|
||||
|
||||
public IReadOnlyList<ModSettingDefinition> GetDefinitions()
|
||||
{
|
||||
return new List<ModSettingDefinition>
|
||||
{
|
||||
new()
|
||||
{
|
||||
Key = "rations_per_character",
|
||||
Name = "mod_cooking/rations_per_character",
|
||||
Type = SettingType.Slider,
|
||||
DefaultValue = "1",
|
||||
Min = 1f,
|
||||
Max = 10f,
|
||||
Step = 1f,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
public void WriteValues(DataBlob blob)
|
||||
{
|
||||
blob.SetInt("rations_per_character", RationsPerCharacter);
|
||||
}
|
||||
|
||||
public void ReadValues(DataBlob blob)
|
||||
{
|
||||
RationsPerCharacter = blob.GetInt("rations_per_character", 1);
|
||||
if (RationsPerCharacter < 1)
|
||||
RationsPerCharacter = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
using System.Collections.Generic;
|
||||
using Cthangover.Core.Mods;
|
||||
using Cthangover.Core.Settings;
|
||||
|
||||
namespace Cthangover.Cooking
|
||||
{
|
||||
/// <summary>
|
||||
/// Exposes a user-configurable setting for the number of rations
|
||||
/// consumed per character per in-game day. Registered automatically
|
||||
/// via <see cref="ModSettingsRegistry"/> when the cooking mod
|
||||
/// assembly loads.
|
||||
///
|
||||
/// The static <see cref="RationsPerCharacter"/> property is the
|
||||
/// canonical source of truth shared with <c>RationStatisticsPanel</c>
|
||||
/// and any future consumption logic. It is updated by the core on
|
||||
/// boot (from persisted JSON) and on every UI change.
|
||||
/// </summary>
|
||||
public class CookingSettings : IModSettings
|
||||
{
|
||||
/// <summary>
|
||||
/// Current value for rations consumed per character per day.
|
||||
/// Default is 1. Updated by <see cref="ReadValues"/> on boot
|
||||
/// and whenever the player changes the setting in the menu.
|
||||
/// </summary>
|
||||
public static int RationsPerCharacter { get; private set; } = 1;
|
||||
|
||||
public IReadOnlyList<ModSettingDefinition> GetDefinitions()
|
||||
{
|
||||
return new List<ModSettingDefinition>
|
||||
{
|
||||
new()
|
||||
{
|
||||
Key = "rations_per_character",
|
||||
Name = "mod_cooking/rations_per_character",
|
||||
Type = SettingType.Slider,
|
||||
DefaultValue = "1",
|
||||
Min = 1f,
|
||||
Max = 10f,
|
||||
Step = 1f,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
public void WriteValues(DataBlob blob)
|
||||
{
|
||||
blob.SetInt("rations_per_character", RationsPerCharacter);
|
||||
}
|
||||
|
||||
public void ReadValues(DataBlob blob)
|
||||
{
|
||||
RationsPerCharacter = blob.GetInt("rations_per_character", 1);
|
||||
if (RationsPerCharacter < 1)
|
||||
RationsPerCharacter = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,65 +1,65 @@
|
||||
using Cthangover.Cooking;
|
||||
|
||||
using System;
|
||||
using Cthangover.Core.Settings;
|
||||
using Cthangover.Core.UI;
|
||||
using Godot;
|
||||
|
||||
using Cthangover.Cooking;
|
||||
|
||||
using System;
|
||||
using Cthangover.Core.Settings;
|
||||
using Cthangover.Core.UI;
|
||||
using Godot;
|
||||
|
||||
using Cthangover.Mods.Interface.Base.Lists;
|
||||
namespace Mods.Cooking.Rations
|
||||
{
|
||||
/// <summary>
|
||||
/// Displays live ration statistics on the dinner/ration UI screen.
|
||||
/// Shows the player the current ration count, how many rations are
|
||||
/// consumed daily (one per character), and the maximum number of days
|
||||
/// the party can survive on available rations. Listens to
|
||||
/// <see cref="Core.Items.InventoryBag.Change"/> events to refresh
|
||||
/// automatically whenever the inventory is modified.
|
||||
/// </summary>
|
||||
public class RationStatisticsPanel : Widget
|
||||
{
|
||||
private RichTextLabel label;
|
||||
private Action<string, int> _onInventoryChange;
|
||||
|
||||
protected override void OnceConstruct()
|
||||
{
|
||||
label = GetNode<RichTextLabel>("RationMargin/RationLabel");
|
||||
|
||||
_onInventoryChange = (_, _) => UpdateInfo();
|
||||
GameData.Instance.Runtime.Inventory.Change += _onInventoryChange;
|
||||
}
|
||||
|
||||
protected override void ShowConstruct()
|
||||
{
|
||||
UpdateInfo();
|
||||
}
|
||||
|
||||
protected override void OnceDestruct()
|
||||
{
|
||||
GameData.Instance.Runtime.Inventory.Change -= _onInventoryChange;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Recomputes and refreshes the ration-statistics text.
|
||||
/// Reads current ration inventory via <see cref="Core.Items.InventoryBag.CheckCount"/>
|
||||
/// for <c>"food/ration"</c> and the total character count from
|
||||
/// <see cref="CharacterData"/>. Formats three localized lines:
|
||||
/// total rations, daily consumption, and remaining days
|
||||
/// (rations divided by character count, clamped to 1 minimum).
|
||||
/// </summary>
|
||||
public void UpdateInfo()
|
||||
{
|
||||
if (label == null)
|
||||
return;
|
||||
|
||||
var rationCount = GameData.Instance.Runtime.Inventory.CheckCount("food/ration");
|
||||
var characterCount = GameData.Instance.Runtime.CharacterData.Characters.Count;
|
||||
var perChar = CookingSettings.RationsPerCharacter;
|
||||
var dailyConsumption = characterCount * perChar;
|
||||
|
||||
label.Text = string.Format(TranslationServer.Translate("ui/diner/rationcount"), rationCount) +
|
||||
"\n" + string.Format(TranslationServer.Translate("ui/diner/rationday"), dailyConsumption) +
|
||||
"\n" + string.Format(TranslationServer.Translate("ui/diner/rationmax"), rationCount / Mathf.Max(1, dailyConsumption));
|
||||
}
|
||||
}
|
||||
}
|
||||
namespace Mods.Cooking.Rations
|
||||
{
|
||||
/// <summary>
|
||||
/// Displays live ration statistics on the dinner/ration UI screen.
|
||||
/// Shows the player the current ration count, how many rations are
|
||||
/// consumed daily (one per character), and the maximum number of days
|
||||
/// the party can survive on available rations. Listens to
|
||||
/// <see cref="Core.Items.InventoryBag.Change"/> events to refresh
|
||||
/// automatically whenever the inventory is modified.
|
||||
/// </summary>
|
||||
public class RationStatisticsPanel : Widget
|
||||
{
|
||||
private RichTextLabel label;
|
||||
private Action<string, int> _onInventoryChange;
|
||||
|
||||
protected override void OnceConstruct()
|
||||
{
|
||||
label = GetNode<RichTextLabel>("RationMargin/RationLabel");
|
||||
|
||||
_onInventoryChange = (_, _) => UpdateInfo();
|
||||
GameData.Instance.Runtime.Inventory.Change += _onInventoryChange;
|
||||
}
|
||||
|
||||
protected override void ShowConstruct()
|
||||
{
|
||||
UpdateInfo();
|
||||
}
|
||||
|
||||
protected override void OnceDestruct()
|
||||
{
|
||||
GameData.Instance.Runtime.Inventory.Change -= _onInventoryChange;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Recomputes and refreshes the ration-statistics text.
|
||||
/// Reads current ration inventory via <see cref="Core.Items.InventoryBag.CheckCount"/>
|
||||
/// for <c>"food/ration"</c> and the total character count from
|
||||
/// <see cref="CharacterData"/>. Formats three localized lines:
|
||||
/// total rations, daily consumption, and remaining days
|
||||
/// (rations divided by character count, clamped to 1 minimum).
|
||||
/// </summary>
|
||||
public void UpdateInfo()
|
||||
{
|
||||
if (label == null)
|
||||
return;
|
||||
|
||||
var rationCount = GameData.Instance.Runtime.Inventory.CheckCount("food/ration");
|
||||
var characterCount = GameData.Instance.Runtime.CharacterData.Characters.Count;
|
||||
var perChar = CookingSettings.RationsPerCharacter;
|
||||
var dailyConsumption = characterCount * perChar;
|
||||
|
||||
label.Text = string.Format(TranslationServer.Translate("ui/diner/rationcount"), rationCount) +
|
||||
"\n" + string.Format(TranslationServer.Translate("ui/diner/rationday"), dailyConsumption) +
|
||||
"\n" + string.Format(TranslationServer.Translate("ui/diner/rationmax"), rationCount / Mathf.Max(1, dailyConsumption));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,71 +1,71 @@
|
||||
using Cthangover.Core.Items;
|
||||
using Cthangover.Core.Settings;
|
||||
using Cthangover.Core.UI;
|
||||
using Cthangover.Core.UI.Theming;
|
||||
using Cthangover.Core.Utils;
|
||||
using Godot;
|
||||
|
||||
using Cthangover.Core.Items;
|
||||
using Cthangover.Core.Settings;
|
||||
using Cthangover.Core.UI;
|
||||
using Cthangover.Core.UI.Theming;
|
||||
using Cthangover.Core.Utils;
|
||||
using Godot;
|
||||
|
||||
using Cthangover.Mods.Interface.Base.Lists;
|
||||
namespace Mods.Cooking.Workbench
|
||||
{
|
||||
/// <summary>
|
||||
/// Renders a single ingredient row inside a <see cref="RecipeItemBehaviour"/>
|
||||
/// on the cooking workbench. Displays the ingredient's item icon and the
|
||||
/// required count. When <see cref="CheckAndUpdate"/> is called, compares
|
||||
/// inventory count against the recipe requirement and tints the icon and
|
||||
/// count text grey if the player lacks enough items.
|
||||
/// </summary>
|
||||
public class RecipeIconItemBehaviour : Widget
|
||||
{
|
||||
private static readonly Color NormalColor = UiTokens.InkBright;
|
||||
private static readonly Color NotItemsColor = UiTokens.Muted;
|
||||
|
||||
private TextureRect img;
|
||||
private Label txt;
|
||||
private IIngredient ingredient;
|
||||
|
||||
protected override void OnceConstruct()
|
||||
{
|
||||
img = GetNode<TextureRect>("Img");
|
||||
txt = GetNode<Label>("Txt");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Binds this icon widget to a recipe ingredient definition.
|
||||
/// Sets the icon texture from <c>ingredient.Item.Sprite</c> (logs an error
|
||||
/// if the item reference is null) and displays the required count as text.
|
||||
/// The <paramref name="hasItems"/> flag is currently unused but reserved
|
||||
/// for future visual pre-initialization.
|
||||
/// </summary>
|
||||
public void Init(IIngredient ingredient, bool hasItems)
|
||||
{
|
||||
EnsureConstructed();
|
||||
this.ingredient = ingredient;
|
||||
if (ingredient.Item != null)
|
||||
{
|
||||
img.Texture = ingredient.Item.Sprite;
|
||||
}
|
||||
else
|
||||
{
|
||||
GameLogger.Log("MOD_TEST", $"RecipeIconItemBehaviour::Init ingredient.Item is NULL", LogLevel.Error);
|
||||
}
|
||||
txt.Text = ingredient.Count.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Evaluates whether the player's inventory contains enough of the
|
||||
/// required ingredient. Tints the icon and count text to
|
||||
/// <c>NormalColor</c> (bright ink) when satisfied or <c>NotItemsColor</c>
|
||||
/// (muted) when insufficient. Called by the parent
|
||||
/// <see cref="RecipeItemBehaviour"/> during state refresh.
|
||||
/// </summary>
|
||||
/// <returns><c>true</c> if inventory meets or exceeds the required count.</returns>
|
||||
public bool CheckAndUpdate()
|
||||
{
|
||||
var result = GameData.Instance.Runtime.Inventory.CheckCount(ingredient.Item) >= ingredient.Count;
|
||||
txt.AddThemeColorOverride("font_color", result ? NormalColor : NotItemsColor);
|
||||
img.Modulate = result ? UiTokens.White : NotItemsColor;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
namespace Mods.Cooking.Workbench
|
||||
{
|
||||
/// <summary>
|
||||
/// Renders a single ingredient row inside a <see cref="RecipeItemBehaviour"/>
|
||||
/// on the cooking workbench. Displays the ingredient's item icon and the
|
||||
/// required count. When <see cref="CheckAndUpdate"/> is called, compares
|
||||
/// inventory count against the recipe requirement and tints the icon and
|
||||
/// count text grey if the player lacks enough items.
|
||||
/// </summary>
|
||||
public class RecipeIconItemBehaviour : Widget
|
||||
{
|
||||
private static readonly Color NormalColor = UiTokens.InkBright;
|
||||
private static readonly Color NotItemsColor = UiTokens.Muted;
|
||||
|
||||
private TextureRect img;
|
||||
private Label txt;
|
||||
private IIngredient ingredient;
|
||||
|
||||
protected override void OnceConstruct()
|
||||
{
|
||||
img = GetNode<TextureRect>("Img");
|
||||
txt = GetNode<Label>("Txt");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Binds this icon widget to a recipe ingredient definition.
|
||||
/// Sets the icon texture from <c>ingredient.Item.Sprite</c> (logs an error
|
||||
/// if the item reference is null) and displays the required count as text.
|
||||
/// The <paramref name="hasItems"/> flag is currently unused but reserved
|
||||
/// for future visual pre-initialization.
|
||||
/// </summary>
|
||||
public void Init(IIngredient ingredient, bool hasItems)
|
||||
{
|
||||
EnsureConstructed();
|
||||
this.ingredient = ingredient;
|
||||
if (ingredient.Item != null)
|
||||
{
|
||||
img.Texture = ingredient.Item.Sprite;
|
||||
}
|
||||
else
|
||||
{
|
||||
GameLogger.Log("MOD_TEST", $"RecipeIconItemBehaviour::Init ingredient.Item is NULL", LogLevel.Error);
|
||||
}
|
||||
txt.Text = ingredient.Count.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Evaluates whether the player's inventory contains enough of the
|
||||
/// required ingredient. Tints the icon and count text to
|
||||
/// <c>NormalColor</c> (bright ink) when satisfied or <c>NotItemsColor</c>
|
||||
/// (muted) when insufficient. Called by the parent
|
||||
/// <see cref="RecipeItemBehaviour"/> during state refresh.
|
||||
/// </summary>
|
||||
/// <returns><c>true</c> if inventory meets or exceeds the required count.</returns>
|
||||
public bool CheckAndUpdate()
|
||||
{
|
||||
var result = GameData.Instance.Runtime.Inventory.CheckCount(ingredient.Item) >= ingredient.Count;
|
||||
txt.AddThemeColorOverride("font_color", result ? NormalColor : NotItemsColor);
|
||||
img.Modulate = result ? UiTokens.White : NotItemsColor;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user