临时提交
This commit is contained in:
@ -62,7 +62,12 @@ public partial class GameScene : Control
|
||||
productionProcessor.Name = "ProductionProcessor";
|
||||
AddChild(productionProcessor);
|
||||
|
||||
GD.Print("自动产线管理器初始化完成");
|
||||
// 创建PowerManager
|
||||
var powerManager = new PowerManager();
|
||||
powerManager.Name = "PowerManager";
|
||||
AddChild(powerManager);
|
||||
|
||||
GD.Print("自动产线管理器和电力管理器初始化完成");
|
||||
}
|
||||
|
||||
private void InitializeUI()
|
||||
@ -89,12 +94,12 @@ public partial class GameScene : Control
|
||||
}
|
||||
|
||||
// 获取UI引用
|
||||
powerGenerationLabel = GetNode<Label>("HSplitContainer/LeftPanel/VBoxContainer/PowerInfo/MarginContainer/VBoxContainer/PowerRow1/PowerGeneration");
|
||||
powerConsumptionLabel = GetNode<Label>("HSplitContainer/LeftPanel/VBoxContainer/PowerInfo/MarginContainer/VBoxContainer/PowerRow1/PowerConsumption");
|
||||
powerStorageLabel = GetNode<Label>("HSplitContainer/LeftPanel/VBoxContainer/PowerInfo/MarginContainer/VBoxContainer/PowerRow2/PowerStorage");
|
||||
powerDischargeLabel = GetNode<Label>("HSplitContainer/LeftPanel/VBoxContainer/PowerInfo/MarginContainer/VBoxContainer/PowerRow2/PowerDischarge");
|
||||
categoryTabs = GetNode<TabContainer>("HSplitContainer/RightPanel/VBoxContainer/CategoryTabs");
|
||||
craftingQueue = GetNode<CraftingQueueManager>("HSplitContainer/LeftPanel/VBoxContainer/CraftingQueue");
|
||||
powerGenerationLabel = GetNode<Label>("HBoxContainer/LeftPanel/VBoxContainer/PowerInfo/MarginContainer/VBoxContainer/PowerRow1/PowerGeneration");
|
||||
powerConsumptionLabel = GetNode<Label>("HBoxContainer/LeftPanel/VBoxContainer/PowerInfo/MarginContainer/VBoxContainer/PowerRow1/PowerConsumption");
|
||||
powerStorageLabel = GetNode<Label>("HBoxContainer/LeftPanel/VBoxContainer/PowerInfo/MarginContainer/VBoxContainer/PowerRow2/PowerStorage");
|
||||
powerDischargeLabel = GetNode<Label>("HBoxContainer/LeftPanel/VBoxContainer/PowerInfo/MarginContainer/VBoxContainer/PowerRow2/PowerDischarge");
|
||||
categoryTabs = GetNode<TabContainer>("HBoxContainer/RightPanel/VBoxContainer/CategoryTabs");
|
||||
craftingQueue = GetNode<CraftingQueueManager>("HBoxContainer/LeftPanel/VBoxContainer/CraftingQueue");
|
||||
|
||||
// 初始化库存(保留用于兼容性)
|
||||
InitializeInventory();
|
||||
@ -148,19 +153,53 @@ public partial class GameScene : Control
|
||||
|
||||
private void UpdatePowerInfo()
|
||||
{
|
||||
// 这里可以从电力管理器获取实际数据
|
||||
// 目前使用占位符数据
|
||||
if (powerGenerationLabel != null)
|
||||
powerGenerationLabel.Text = "发电: 0 KW";
|
||||
|
||||
if (powerConsumptionLabel != null)
|
||||
powerConsumptionLabel.Text = "耗电: 0 KW";
|
||||
|
||||
if (powerStorageLabel != null)
|
||||
powerStorageLabel.Text = "蓄电: 0 KWh";
|
||||
|
||||
if (powerDischargeLabel != null)
|
||||
powerDischargeLabel.Text = "放电: 0 KW";
|
||||
// 从PowerManager获取真实的电力数据
|
||||
var powerManager = PowerManager.Instance;
|
||||
if (powerManager != null)
|
||||
{
|
||||
var (generation, consumption, ratio) = powerManager.GetPowerStats();
|
||||
|
||||
if (powerGenerationLabel != null)
|
||||
powerGenerationLabel.Text = $"发电: {generation:F1} W";
|
||||
|
||||
if (powerConsumptionLabel != null)
|
||||
powerConsumptionLabel.Text = $"耗电: {consumption:F1} W";
|
||||
|
||||
if (powerStorageLabel != null)
|
||||
powerStorageLabel.Text = $"电力满足率: {ratio * 100:F1}%";
|
||||
|
||||
if (powerDischargeLabel != null)
|
||||
{
|
||||
float deficit = Mathf.Max(0, consumption - generation);
|
||||
powerDischargeLabel.Text = $"电力不足: {deficit:F1} W";
|
||||
|
||||
// 根据电力状态设置颜色
|
||||
if (deficit > 0)
|
||||
{
|
||||
powerDischargeLabel.Modulate = new Color(1.0f, 0.3f, 0.3f); // 红色表示不足
|
||||
}
|
||||
else
|
||||
{
|
||||
powerDischargeLabel.Modulate = new Color(0.3f, 1.0f, 0.3f); // 绿色表示充足
|
||||
powerDischargeLabel.Text = "电力充足";
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// PowerManager未初始化时的默认显示
|
||||
if (powerGenerationLabel != null)
|
||||
powerGenerationLabel.Text = "发电: 0 W";
|
||||
|
||||
if (powerConsumptionLabel != null)
|
||||
powerConsumptionLabel.Text = "耗电: 0 W";
|
||||
|
||||
if (powerStorageLabel != null)
|
||||
powerStorageLabel.Text = "电力满足率: 100%";
|
||||
|
||||
if (powerDischargeLabel != null)
|
||||
powerDischargeLabel.Text = "电力充足";
|
||||
}
|
||||
}
|
||||
|
||||
public override void _Input(InputEvent @event)
|
||||
@ -295,6 +334,7 @@ public partial class GameScene : Control
|
||||
inventoryManager.AddItem("miner", 6); // 添加6个采矿机
|
||||
inventoryManager.AddItem("assembler", 3); // 添加3个组装机
|
||||
inventoryManager.AddItem("chemical_plant", 2); // 添加2个化工厂
|
||||
inventoryManager.AddItem("wind_turbine", 5); // 添加5个风力发电机
|
||||
|
||||
// 原材料
|
||||
inventoryManager.AddItem("iron_ore", 50); // 添加50个铁矿
|
||||
@ -309,10 +349,12 @@ public partial class GameScene : Control
|
||||
inventoryManager.AddItem("copper_ingot", 20); // 添加20个铜块
|
||||
|
||||
GD.Print("已添加测试建筑设施和材料到库存:");
|
||||
GD.Print("建筑设施: 钻机x10, 熔炉x8, 冶炼厂x5, 采矿机x6, 组装机x3, 化工厂x2");
|
||||
GD.Print("建筑设施: 钻机x10, 熔炉x8, 冶炼厂x5, 采矿机x6, 组装机x3, 化工厂x2, 风力发电机x5");
|
||||
GD.Print("原材料: 铁矿x50, 铜矿x40, 煤矿x60, 石矿x80, 水x100, 原油x30");
|
||||
GD.Print("加工材料: 铁块x25, 铜块x20");
|
||||
GD.Print("现在可以在生产线和合成标签中测试各种功能了!");
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
190
scripts/production/PowerManager.cs
Normal file
190
scripts/production/PowerManager.cs
Normal file
@ -0,0 +1,190 @@
|
||||
using Godot;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
|
||||
public partial class PowerManager : Node
|
||||
{
|
||||
public static PowerManager Instance { get; private set; }
|
||||
|
||||
// 电力系统状态
|
||||
private float totalGeneration = 0.0f; // 总发电量 (W)
|
||||
private float totalConsumption = 0.0f; // 总耗电量 (W)
|
||||
private float currentPowerRatio = 1.0f; // 当前电力满足率 0-1
|
||||
|
||||
// 发电设备列表 - 记录每个发电设备的发电量
|
||||
private Dictionary<string, float> generators = new Dictionary<string, float>();
|
||||
|
||||
// 信号事件
|
||||
[Signal] public delegate void PowerRatioChangedEventHandler(float ratio);
|
||||
[Signal] public delegate void PowerStatsChangedEventHandler(float generation, float consumption);
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
if (Instance == null)
|
||||
{
|
||||
Instance = this;
|
||||
GD.Print("PowerManager 初始化完成");
|
||||
}
|
||||
else
|
||||
{
|
||||
QueueFree();
|
||||
}
|
||||
}
|
||||
|
||||
// 添加发电设备
|
||||
public void AddGenerator(string generatorId, float powerOutput)
|
||||
{
|
||||
if (powerOutput <= 0) return;
|
||||
|
||||
// 如果发电设备已存在,移除旧的再添加新的
|
||||
if (generators.ContainsKey(generatorId))
|
||||
{
|
||||
float oldPower = generators[generatorId];
|
||||
generators[generatorId] = powerOutput;
|
||||
GD.Print($"更新发电设备 {generatorId}: {oldPower}W -> {powerOutput}W");
|
||||
}
|
||||
else
|
||||
{
|
||||
generators[generatorId] = powerOutput;
|
||||
GD.Print($"添加发电设备 {generatorId}: +{powerOutput}W");
|
||||
}
|
||||
|
||||
UpdatePowerBalance();
|
||||
}
|
||||
|
||||
// 移除发电设备
|
||||
public void RemoveGenerator(string generatorId)
|
||||
{
|
||||
if (generators.ContainsKey(generatorId))
|
||||
{
|
||||
float removedPower = generators[generatorId];
|
||||
generators.Remove(generatorId);
|
||||
UpdatePowerBalance();
|
||||
|
||||
GD.Print($"移除发电设备 {generatorId}: -{removedPower}W");
|
||||
}
|
||||
}
|
||||
|
||||
// 更新发电设备状态(发电机异常或没有原料时调用)
|
||||
public void UpdateGeneratorStatus(string generatorId, bool isActive)
|
||||
{
|
||||
// 这里可以实现发电设备状态管理
|
||||
// 暂时简化,直接通过AddGenerator/RemoveGenerator来管理
|
||||
GD.Print($"发电设备 {generatorId} 状态更新: {(isActive ? "激活" : "停止")}");
|
||||
}
|
||||
|
||||
// 更新电力平衡
|
||||
private void UpdatePowerBalance()
|
||||
{
|
||||
// 计算总发电量
|
||||
totalGeneration = 0;
|
||||
foreach (var generator in generators.Values)
|
||||
{
|
||||
totalGeneration += generator;
|
||||
}
|
||||
|
||||
// 获取总耗电量(从生产线管理器获取)
|
||||
UpdateTotalConsumption();
|
||||
|
||||
// 计算电力满足率
|
||||
float newPowerRatio;
|
||||
if (totalConsumption > 0)
|
||||
{
|
||||
newPowerRatio = Mathf.Min(1.0f, totalGeneration / totalConsumption);
|
||||
}
|
||||
else
|
||||
{
|
||||
newPowerRatio = 1.0f; // 没有耗电设备时电力充足
|
||||
}
|
||||
|
||||
// 只有当电力状态发生显著变化时才打印日志和发送信号
|
||||
if (Math.Abs(newPowerRatio - currentPowerRatio) > 0.01f ||
|
||||
Math.Abs(totalGeneration - GetPreviousGeneration()) > 1.0f ||
|
||||
Math.Abs(totalConsumption - GetPreviousConsumption()) > 1.0f)
|
||||
{
|
||||
currentPowerRatio = newPowerRatio;
|
||||
|
||||
// 发送信号通知其他系统
|
||||
EmitSignal(SignalName.PowerRatioChanged, currentPowerRatio);
|
||||
EmitSignal(SignalName.PowerStatsChanged, totalGeneration, totalConsumption);
|
||||
|
||||
GD.Print($"电力平衡更新: 发电 {totalGeneration}W, 耗电 {totalConsumption}W, 满足率 {currentPowerRatio * 100:F1}%");
|
||||
}
|
||||
else
|
||||
{
|
||||
currentPowerRatio = newPowerRatio;
|
||||
}
|
||||
}
|
||||
|
||||
private float previousGeneration = 0;
|
||||
private float previousConsumption = 0;
|
||||
|
||||
private float GetPreviousGeneration()
|
||||
{
|
||||
float prev = previousGeneration;
|
||||
previousGeneration = totalGeneration;
|
||||
return prev;
|
||||
}
|
||||
|
||||
private float GetPreviousConsumption()
|
||||
{
|
||||
float prev = previousConsumption;
|
||||
previousConsumption = totalConsumption;
|
||||
return prev;
|
||||
}
|
||||
|
||||
// 更新总耗电量
|
||||
private void UpdateTotalConsumption()
|
||||
{
|
||||
totalConsumption = 0;
|
||||
|
||||
var productionLineManager = ProductionLineManager.Instance;
|
||||
if (productionLineManager != null)
|
||||
{
|
||||
var activeLines = productionLineManager.GetAllActiveProductionLines();
|
||||
foreach (var activeLine in activeLines.Values)
|
||||
{
|
||||
if (activeLine.IsActive)
|
||||
{
|
||||
totalConsumption += activeLine.TotalPowerConsumption;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 获取当前电力满足率
|
||||
public float GetPowerRatio()
|
||||
{
|
||||
return currentPowerRatio;
|
||||
}
|
||||
|
||||
// 获取电力统计信息
|
||||
public (float generation, float consumption, float ratio) GetPowerStats()
|
||||
{
|
||||
return (totalGeneration, totalConsumption, currentPowerRatio);
|
||||
}
|
||||
|
||||
// 定期更新电力系统(通过_Process调用)
|
||||
private float updateTimer = 0.0f;
|
||||
private const float UPDATE_INTERVAL = 0.5f; // 每0.5秒更新一次
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
updateTimer += (float)delta;
|
||||
|
||||
// 每0.5秒更新一次电力平衡,而不是每帧都更新
|
||||
if (updateTimer >= UPDATE_INTERVAL)
|
||||
{
|
||||
updateTimer = 0.0f;
|
||||
UpdatePowerBalance();
|
||||
}
|
||||
}
|
||||
|
||||
public override void _ExitTree()
|
||||
{
|
||||
if (Instance == this)
|
||||
{
|
||||
Instance = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -26,6 +26,7 @@ public partial class ProductionLineManager : Node
|
||||
public string Description { get; set; }
|
||||
public float ProductionTime { get; set; }
|
||||
public int PowerConsumption { get; set; }
|
||||
public int PowerGeneration { get; set; } = 0; // 新增:发电量
|
||||
public List<ProductionRecipeItem> BuildingRequirements { get; set; } = new List<ProductionRecipeItem>();
|
||||
public ProductionRecipe Recipe { get; set; } = new ProductionRecipe();
|
||||
}
|
||||
@ -44,6 +45,7 @@ public partial class ProductionLineManager : Node
|
||||
public bool IsActive { get; set; } = false; // 是否激活
|
||||
public float ProductionRate { get; set; } = 0; // 每秒产出率
|
||||
public int TotalPowerConsumption { get; set; } = 0; // 总功耗
|
||||
public int TotalPowerGeneration { get; set; } = 0; // 总发电量
|
||||
}
|
||||
|
||||
private ProductionLineData productionLineData;
|
||||
@ -191,19 +193,59 @@ public partial class ProductionLineManager : Node
|
||||
activeProductionLines[productionLineId] = new ActiveProductionLine
|
||||
{
|
||||
ProductionLineId = productionLineId,
|
||||
RemainingTime = productionLine.ProductionTime // 从完整的生产时间开始
|
||||
RemainingTime = productionLine.PowerGeneration > 0 && productionLine.ProductionTime <= 0
|
||||
? 0 // 发电设备不需要生产时间
|
||||
: productionLine.ProductionTime // 普通生产设备从完整的生产时间开始
|
||||
};
|
||||
GD.Print($"创建新产线 {productionLine.Name},初始剩余时间: {productionLine.ProductionTime}s");
|
||||
|
||||
if (productionLine.PowerGeneration > 0 && productionLine.ProductionTime <= 0)
|
||||
{
|
||||
GD.Print($"创建新发电设备 {productionLine.Name},无需生产周期");
|
||||
}
|
||||
else
|
||||
{
|
||||
GD.Print($"创建新产线 {productionLine.Name},初始剩余时间: {productionLine.ProductionTime}s");
|
||||
}
|
||||
}
|
||||
|
||||
var activeLine = activeProductionLines[productionLineId];
|
||||
activeLine.BuildingCount += count;
|
||||
activeLine.IsActive = true;
|
||||
activeLine.ProductionRate = activeLine.BuildingCount / productionLine.ProductionTime; // 每秒产出率
|
||||
|
||||
// 重新计算产出率:发电设备特殊处理
|
||||
if (productionLine.PowerGeneration > 0 && productionLine.ProductionTime <= 0)
|
||||
{
|
||||
// 发电设备不产出物品,产出率设为0
|
||||
activeLine.ProductionRate = 0;
|
||||
}
|
||||
else if (productionLine.ProductionTime > 0)
|
||||
{
|
||||
activeLine.ProductionRate = activeLine.BuildingCount / productionLine.ProductionTime;
|
||||
}
|
||||
else
|
||||
{
|
||||
activeLine.ProductionRate = 0; // 避免除零
|
||||
}
|
||||
|
||||
activeLine.TotalPowerConsumption = activeLine.BuildingCount * productionLine.PowerConsumption;
|
||||
activeLine.TotalPowerGeneration = activeLine.BuildingCount * productionLine.PowerGeneration;
|
||||
|
||||
// 如果是发电设备,通知PowerManager
|
||||
if (productionLine.PowerGeneration > 0)
|
||||
{
|
||||
var powerManager = PowerManager.Instance;
|
||||
if (powerManager != null)
|
||||
{
|
||||
// 使用更简单的generatorId,避免重复问题
|
||||
string generatorId = $"{productionLineId}";
|
||||
float totalGeneration = productionLine.PowerGeneration * activeLine.BuildingCount;
|
||||
powerManager.AddGenerator(generatorId, totalGeneration);
|
||||
GD.Print($"发电设备 {productionLine.Name} 已添加到电网: +{totalGeneration}W");
|
||||
}
|
||||
}
|
||||
|
||||
GD.Print($"成功添加 {count} 个设备到产线 {productionLine.Name}");
|
||||
GD.Print($"当前产线状态: {activeLine.BuildingCount} 个建筑, 产出率: {activeLine.ProductionRate:F2}/s, 功耗: {activeLine.TotalPowerConsumption}W");
|
||||
GD.Print($"当前产线状态: {activeLine.BuildingCount} 个建筑, 产出率: {activeLine.ProductionRate:F2}/s, 功耗: {activeLine.TotalPowerConsumption}W, 发电: {activeLine.TotalPowerGeneration}W");
|
||||
}
|
||||
|
||||
public void RemoveBuilding(string productionLineId, int count = 1)
|
||||
@ -220,6 +262,18 @@ public partial class ProductionLineManager : Node
|
||||
count = Mathf.Min(count, activeLine.BuildingCount);
|
||||
if (count <= 0) return;
|
||||
|
||||
// 如果是发电设备,先通知PowerManager移除发电量
|
||||
if (productionLine.PowerGeneration > 0)
|
||||
{
|
||||
var powerManager = PowerManager.Instance;
|
||||
if (powerManager != null)
|
||||
{
|
||||
string generatorId = $"{productionLineId}";
|
||||
float totalGeneration = productionLine.PowerGeneration * activeLine.BuildingCount;
|
||||
powerManager.RemoveGenerator(generatorId);
|
||||
}
|
||||
}
|
||||
|
||||
activeLine.BuildingCount -= count;
|
||||
|
||||
if (activeLine.BuildingCount <= 0)
|
||||
@ -227,11 +281,40 @@ public partial class ProductionLineManager : Node
|
||||
activeLine.IsActive = false;
|
||||
activeLine.ProductionRate = 0;
|
||||
activeLine.TotalPowerConsumption = 0;
|
||||
activeLine.TotalPowerGeneration = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
activeLine.ProductionRate = activeLine.BuildingCount / productionLine.ProductionTime;
|
||||
// 重新计算产出率:发电设备特殊处理
|
||||
if (productionLine.PowerGeneration > 0 && productionLine.ProductionTime <= 0)
|
||||
{
|
||||
// 发电设备不产出物品,产出率设为0
|
||||
activeLine.ProductionRate = 0;
|
||||
}
|
||||
else if (productionLine.ProductionTime > 0)
|
||||
{
|
||||
activeLine.ProductionRate = activeLine.BuildingCount / productionLine.ProductionTime;
|
||||
}
|
||||
else
|
||||
{
|
||||
activeLine.ProductionRate = 0; // 避免除零
|
||||
}
|
||||
|
||||
activeLine.TotalPowerConsumption = activeLine.BuildingCount * productionLine.PowerConsumption;
|
||||
activeLine.TotalPowerGeneration = activeLine.BuildingCount * productionLine.PowerGeneration;
|
||||
|
||||
// 如果是发电设备且还有剩余建筑,重新添加到PowerManager
|
||||
if (productionLine.PowerGeneration > 0)
|
||||
{
|
||||
var powerManager = PowerManager.Instance;
|
||||
if (powerManager != null)
|
||||
{
|
||||
string newGeneratorId = $"{productionLineId}";
|
||||
float totalGeneration = productionLine.PowerGeneration * activeLine.BuildingCount;
|
||||
powerManager.AddGenerator(newGeneratorId, totalGeneration);
|
||||
GD.Print($"发电设备 {productionLine.Name} 已添加到电网: +{totalGeneration}W");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 归还建筑材料到库存
|
||||
@ -246,7 +329,7 @@ public partial class ProductionLineManager : Node
|
||||
}
|
||||
|
||||
GD.Print($"移除 {count} 个设备从产线 {productionLine.Name}");
|
||||
GD.Print($"当前产线状态: {activeLine.BuildingCount} 个建筑, 产出率: {activeLine.ProductionRate:F2}/s, 功耗: {activeLine.TotalPowerConsumption}W");
|
||||
GD.Print($"当前产线状态: {activeLine.BuildingCount} 个建筑, 产出率: {activeLine.ProductionRate:F2}/s, 功耗: {activeLine.TotalPowerConsumption}W, 发电: {activeLine.TotalPowerGeneration}W");
|
||||
}
|
||||
|
||||
public ActiveProductionLine GetActiveProductionLine(string productionLineId)
|
||||
|
||||
@ -44,8 +44,33 @@ public partial class ProductionProcessor : Node
|
||||
var productionLine = ProductionLineManager.Instance?.GetProductionLine(activeLine.ProductionLineId);
|
||||
if (productionLine == null) return;
|
||||
|
||||
// 特殊处理:如果是发电设备(powerGeneration > 0 且 productionTime <= 0),跳过生产处理
|
||||
if (productionLine.PowerGeneration > 0 && productionLine.ProductionTime <= 0)
|
||||
{
|
||||
// 发电设备不需要生产周期,直接返回
|
||||
// 发电量已经在添加建筑时注册到PowerManager了
|
||||
return;
|
||||
}
|
||||
|
||||
// 获取电力满足率
|
||||
float powerRatio = 1.0f;
|
||||
var powerManager = PowerManager.Instance;
|
||||
if (powerManager != null)
|
||||
{
|
||||
powerRatio = powerManager.GetPowerRatio();
|
||||
}
|
||||
|
||||
// 根据电力满足率调整生产速度
|
||||
float adjustedDeltaTime = deltaTime * powerRatio;
|
||||
|
||||
// 如果电力不足,减慢生产速度
|
||||
if (powerRatio < 1.0f)
|
||||
{
|
||||
GD.Print($"产线 {productionLine.Name} 电力不足,生产速度调整为 {powerRatio * 100:F1}%");
|
||||
}
|
||||
|
||||
// 更新生产时间
|
||||
activeLine.RemainingTime -= deltaTime;
|
||||
activeLine.RemainingTime -= adjustedDeltaTime;
|
||||
|
||||
if (activeLine.RemainingTime <= 0)
|
||||
{
|
||||
@ -62,12 +87,32 @@ public partial class ProductionProcessor : Node
|
||||
activeLine.RemainingTime = productionLine.ProductionTime;
|
||||
|
||||
GD.Print($"产线 {productionLine.Name} 完成一轮生产,{activeLine.BuildingCount} 个建筑同时运行");
|
||||
|
||||
// 如果是发电设备,通知PowerManager(发电机运行)
|
||||
if (productionLine.PowerGeneration > 0)
|
||||
{
|
||||
if (powerManager != null)
|
||||
{
|
||||
string generatorId = $"{activeLine.ProductionLineId}_{activeLine.BuildingCount}";
|
||||
powerManager.UpdateGeneratorStatus(generatorId, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 原料不足,暂停生产
|
||||
activeLine.RemainingTime = 0.1f; // 短暂等待后再检查
|
||||
GD.Print($"产线 {productionLine.Name} 原料不足,暂停生产");
|
||||
|
||||
// 如果是发电设备,通知PowerManager(发电机异常)
|
||||
if (productionLine.PowerGeneration > 0)
|
||||
{
|
||||
if (powerManager != null)
|
||||
{
|
||||
string generatorId = $"{activeLine.ProductionLineId}_{activeLine.BuildingCount}";
|
||||
powerManager.UpdateGeneratorStatus(generatorId, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -77,6 +122,12 @@ public partial class ProductionProcessor : Node
|
||||
var inventoryManager = InventoryManager.Instance;
|
||||
if (inventoryManager == null) return false;
|
||||
|
||||
// 如果没有输入材料需求(如发电设备),直接返回true
|
||||
if (productionLine.Recipe.Inputs == null || productionLine.Recipe.Inputs.Count == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// 检查所有输入材料
|
||||
foreach (var input in productionLine.Recipe.Inputs)
|
||||
{
|
||||
@ -143,7 +194,12 @@ public partial class ProductionProcessor : Node
|
||||
}
|
||||
|
||||
float progress = 0;
|
||||
if (activeLine.IsActive && productionLine.ProductionTime > 0)
|
||||
// 发电设备的进度条始终显示100%
|
||||
if (productionLine.PowerGeneration > 0 && productionLine.ProductionTime <= 0)
|
||||
{
|
||||
progress = 1.0f; // 发电设备进度始终为100%
|
||||
}
|
||||
else if (activeLine.IsActive && productionLine.ProductionTime > 0)
|
||||
{
|
||||
progress = 1.0f - (activeLine.RemainingTime / productionLine.ProductionTime);
|
||||
}
|
||||
|
||||
@ -80,8 +80,30 @@ public partial class ProductionLineItem : Panel
|
||||
|
||||
// 设置基本信息
|
||||
nameLabel.Text = productionLine.Name;
|
||||
timeLabel.Text = $"{productionLine.ProductionTime:F1}s";
|
||||
powerLabel.Text = $"{productionLine.PowerConsumption}W";
|
||||
|
||||
// 设置时间显示:发电设备显示"持续",其他显示具体时间
|
||||
if (productionLine.PowerGeneration > 0 && productionLine.ProductionTime <= 0)
|
||||
{
|
||||
timeLabel.Text = "持续";
|
||||
timeLabel.Modulate = new Color(0.3f, 1.0f, 0.3f); // 绿色表示持续运行
|
||||
}
|
||||
else
|
||||
{
|
||||
timeLabel.Text = $"{productionLine.ProductionTime:F1}s";
|
||||
timeLabel.Modulate = new Color(1.0f, 1.0f, 1.0f); // 默认白色
|
||||
}
|
||||
|
||||
// 设置功耗或发电量显示
|
||||
if (productionLine.PowerGeneration > 0)
|
||||
{
|
||||
powerLabel.Text = $"+{productionLine.PowerGeneration}W";
|
||||
powerLabel.Modulate = new Color(0.3f, 1.0f, 0.3f); // 绿色表示发电
|
||||
}
|
||||
else
|
||||
{
|
||||
powerLabel.Text = $"{productionLine.PowerConsumption}W";
|
||||
powerLabel.Modulate = new Color(1.0f, 0.9f, 0.7f); // 原来的颜色表示耗电
|
||||
}
|
||||
|
||||
// 设置建筑需求信息
|
||||
if (productionLine.BuildingRequirements != null && productionLine.BuildingRequirements.Count > 0)
|
||||
@ -176,14 +198,24 @@ public partial class ProductionLineItem : Panel
|
||||
// 更新设备数量
|
||||
deviceLabel.Text = $"设备: {activeLine.BuildingCount}";
|
||||
|
||||
// 更新产出率
|
||||
if (activeLine.IsActive && activeLine.ProductionRate > 0)
|
||||
// 更新产出率或发电量显示
|
||||
if (productionLine.PowerGeneration > 0 && productionLine.ProductionTime <= 0)
|
||||
{
|
||||
// 发电设备显示发电量
|
||||
float totalGeneration = productionLine.PowerGeneration * activeLine.BuildingCount;
|
||||
productionLabel.Text = $"{totalGeneration}W";
|
||||
productionLabel.Modulate = new Color(0.3f, 1.0f, 0.3f); // 绿色表示发电
|
||||
}
|
||||
else if (activeLine.IsActive && activeLine.ProductionRate > 0)
|
||||
{
|
||||
// 普通生产设备显示产出率
|
||||
productionLabel.Text = $"{activeLine.ProductionRate:F1}/s";
|
||||
productionLabel.Modulate = new Color(1.0f, 1.0f, 1.0f); // 白色
|
||||
}
|
||||
else
|
||||
{
|
||||
productionLabel.Text = "0/s";
|
||||
productionLabel.Modulate = new Color(0.7f, 0.7f, 0.7f); // 灰色表示未激活
|
||||
}
|
||||
|
||||
// 更新进度条(添加边界检查,避免闪烁)
|
||||
|
||||
Reference in New Issue
Block a user