添加基础的生产线内容-不少bug
This commit is contained in:
@ -5,6 +5,7 @@ public partial class DynamicTabManager : TabContainer
|
||||
{
|
||||
private PackedScene itemPanelScene;
|
||||
private PackedScene craftingItemScene;
|
||||
private PackedScene productionLineItemScene;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
@ -29,7 +30,22 @@ public partial class DynamicTabManager : TabContainer
|
||||
return;
|
||||
}
|
||||
|
||||
// 加载ProductionLineItem场景(用于生产线)
|
||||
productionLineItemScene = GD.Load<PackedScene>("res://scenes/ProductionLineItem.tscn");
|
||||
if (productionLineItemScene == null)
|
||||
{
|
||||
GD.PrintErr("无法加载ProductionLineItem场景");
|
||||
return;
|
||||
}
|
||||
|
||||
GD.Print("开始初始化标签页");
|
||||
// 延迟初始化以确保所有管理器都已初始化
|
||||
CallDeferred(nameof(InitializeTabs));
|
||||
}
|
||||
|
||||
public void RefreshTabs()
|
||||
{
|
||||
GD.Print("刷新标签页");
|
||||
InitializeTabs();
|
||||
}
|
||||
|
||||
@ -113,29 +129,146 @@ public partial class DynamicTabManager : TabContainer
|
||||
vboxContainer.SizeFlagsVertical = Control.SizeFlags.ExpandFill;
|
||||
scrollContainer.AddChild(vboxContainer);
|
||||
|
||||
// 获取所有分类
|
||||
var categoryManager = ResourceCategoryManager.Instance;
|
||||
if (categoryManager == null)
|
||||
// 获取生产线管理器
|
||||
var productionLineManager = ProductionLineManager.Instance;
|
||||
if (productionLineManager == null)
|
||||
{
|
||||
GD.PrintErr("ResourceCategoryManager 实例为null");
|
||||
GD.PrintErr("ProductionLineManager 实例为null,创建空的生产线标签");
|
||||
|
||||
// 创建一个提示标签
|
||||
var noDataLabel = new Label();
|
||||
noDataLabel.Text = "生产线管理器未初始化";
|
||||
noDataLabel.HorizontalAlignment = HorizontalAlignment.Center;
|
||||
noDataLabel.VerticalAlignment = VerticalAlignment.Center;
|
||||
vboxContainer.AddChild(noDataLabel);
|
||||
|
||||
// 添加到TabContainer
|
||||
AddChild(scrollContainer);
|
||||
SetTabTitle(GetTabCount() - 1, "生产线");
|
||||
return;
|
||||
}
|
||||
|
||||
var allCategories = categoryManager.GetAllCategories();
|
||||
// 获取所有生产线分类
|
||||
var categories = productionLineManager.GetAllCategories();
|
||||
GD.Print($"获取到 {categories.Count} 个生产线分类");
|
||||
|
||||
// 为生产线相关的分类创建块
|
||||
foreach (var category in allCategories)
|
||||
if (categories.Count == 0)
|
||||
{
|
||||
// 生产线标签包含:生产设备
|
||||
if (category.CategoryName == "生产设备")
|
||||
GD.Print("没有找到生产线分类,创建提示标签");
|
||||
|
||||
// 创建一个提示标签
|
||||
var noDataLabel = new Label();
|
||||
noDataLabel.Text = "暂无生产线配置";
|
||||
noDataLabel.HorizontalAlignment = HorizontalAlignment.Center;
|
||||
noDataLabel.VerticalAlignment = VerticalAlignment.Center;
|
||||
vboxContainer.AddChild(noDataLabel);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 为每个分类创建块
|
||||
foreach (var category in categories)
|
||||
{
|
||||
CreateCategoryBlock(vboxContainer, category, "生产线");
|
||||
GD.Print($"处理生产线分类: {category}");
|
||||
CreateProductionCategoryBlock(vboxContainer, category);
|
||||
}
|
||||
}
|
||||
|
||||
// 添加到TabContainer
|
||||
AddChild(scrollContainer);
|
||||
SetTabTitle(GetTabCount() - 1, "生产线");
|
||||
|
||||
GD.Print("生产线标签创建完成");
|
||||
}
|
||||
|
||||
private void CreateProductionCategoryBlock(VBoxContainer parentContainer, string category)
|
||||
{
|
||||
GD.Print($"创建生产线分类块: {category}");
|
||||
|
||||
// 创建分类块的容器
|
||||
var categoryContainer = new VBoxContainer();
|
||||
categoryContainer.Name = $"{category}Block";
|
||||
|
||||
// 添加间距
|
||||
var topSpacer = new Control();
|
||||
topSpacer.CustomMinimumSize = new Vector2(0, 10);
|
||||
categoryContainer.AddChild(topSpacer);
|
||||
|
||||
// 创建标题行(分类名称 + 横线)
|
||||
var titleContainer = new HBoxContainer();
|
||||
|
||||
// 分类名称标签
|
||||
var titleLabel = new Label();
|
||||
titleLabel.Text = category;
|
||||
titleLabel.HorizontalAlignment = HorizontalAlignment.Left;
|
||||
titleContainer.AddChild(titleLabel);
|
||||
|
||||
// 添加小间距
|
||||
var labelSpacer = new Control();
|
||||
labelSpacer.CustomMinimumSize = new Vector2(10, 0);
|
||||
titleContainer.AddChild(labelSpacer);
|
||||
|
||||
// HSeparator 横线分隔符
|
||||
var separator = new HSeparator();
|
||||
separator.SizeFlagsHorizontal = Control.SizeFlags.ExpandFill;
|
||||
separator.SizeFlagsVertical = Control.SizeFlags.ShrinkCenter;
|
||||
titleContainer.AddChild(separator);
|
||||
|
||||
categoryContainer.AddChild(titleContainer);
|
||||
|
||||
// 添加小间距
|
||||
var spacer = new Control();
|
||||
spacer.CustomMinimumSize = new Vector2(0, 5);
|
||||
categoryContainer.AddChild(spacer);
|
||||
|
||||
// 创建生产线网格 - 使用VBoxContainer实现垂直堆叠
|
||||
var productionContainer = new VBoxContainer();
|
||||
productionContainer.Name = $"{category}ProductionLines";
|
||||
productionContainer.SizeFlagsHorizontal = Control.SizeFlags.ExpandFill;
|
||||
productionContainer.AddThemeConstantOverride("separation", 8); // 垂直间距
|
||||
|
||||
// 添加该分类的所有生产线
|
||||
AddProductionLinesToContainer(productionContainer, category);
|
||||
|
||||
categoryContainer.AddChild(productionContainer);
|
||||
|
||||
// 添加到父容器
|
||||
parentContainer.AddChild(categoryContainer);
|
||||
}
|
||||
|
||||
private void AddProductionLinesToContainer(VBoxContainer container, string category)
|
||||
{
|
||||
GD.Print($"为分类 '{category}' 添加生产线");
|
||||
|
||||
var productionLineManager = ProductionLineManager.Instance;
|
||||
if (productionLineManager == null)
|
||||
{
|
||||
GD.PrintErr("ProductionLineManager 实例为null");
|
||||
return;
|
||||
}
|
||||
|
||||
// 获取该分类的所有生产线
|
||||
var productionLines = productionLineManager.GetProductionLinesByCategory(category);
|
||||
|
||||
GD.Print($"获取到 {productionLines.Count} 条生产线");
|
||||
|
||||
foreach (var productionLine in productionLines)
|
||||
{
|
||||
// 创建ProductionLineItem实例
|
||||
var productionLineItem = productionLineItemScene.Instantiate<ProductionLineItem>();
|
||||
if (productionLineItem == null)
|
||||
{
|
||||
GD.PrintErr($"无法创建ProductionLineItem实例: {productionLine.Name}");
|
||||
continue;
|
||||
}
|
||||
|
||||
// 设置生产线数据
|
||||
productionLineItem.SetupProductionLine(productionLine);
|
||||
|
||||
// 添加到容器
|
||||
container.AddChild(productionLineItem);
|
||||
|
||||
GD.Print($"成功添加生产线: {productionLine.Name}");
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateCategoryBlock(VBoxContainer parentContainer, ResourceCategoryManager.ResourceCategory category, string tabType)
|
||||
|
||||
Reference in New Issue
Block a user