Add initial UI for lightmap layer toggling

This commit is contained in:
Jarrod Doyle 2024-08-28 08:07:01 +01:00
parent 4a80ef547b
commit 110c9b8a3c
Signed by: Jayrude
GPG Key ID: 38B57B16E7C0ADF7
4 changed files with 77 additions and 2 deletions

View File

@ -38,6 +38,7 @@ public partial class Mission : Node3D
public bool Clear = false;
[Export]
public bool Dump = false;
public int LightmapLayers = 33;
string _campaignName;
string _missionName;
@ -55,6 +56,10 @@ public partial class Mission : Node3D
_modelLoader = new ModelLoader(_installPaths);
_materials = new List<ShaderMaterial>();
_lmLayerMask = new Vector2I(~0, ~0);
var lightmapToggler = GetNode<Control>("%LightmapToggler") as LightmapLayerToggler;
lightmapToggler.Setup(this);
var missionSelector = GetNode<Control>("%MissionSelector") as MissionSelector;
missionSelector.pathManager = _installPaths;
missionSelector.MissionSelected += (string campaign, string mission) =>
@ -362,7 +367,7 @@ public partial class Mission : Node3D
GD.Print($"Creating lightmap with bounds: ({bounds.Width}, {bounds.Height})");
var lightmapFormat = Image.Format.Rgba8;
var lmLayerCount = 33;
var lmLayerCount = 33; // TODO: Use LightmapLayers
var lmImages = new Godot.Collections.Array<Image>();
lmImages.Resize(lmLayerCount);
for (var i = 0; i < lmLayerCount; i++)

View File

@ -0,0 +1,30 @@
using Godot;
namespace KeepersCompound.TMV.UI;
public partial class LightmapLayerToggler : Control
{
public void Setup(Mission mission)
{
var layersNode = GetNode<GridContainer>("%Layers");
foreach (var node in layersNode.GetChildren())
{
node.QueueFree();
}
var layerCount = mission.LightmapLayers;
for (var i = 0; i < layerCount; i++)
{
var button = new Button
{
Text = i.ToString(),
ToggleMode = true
};
button.Pressed += () =>
{
mission.ToggleLmLayer(uint.Parse(button.Text));
};
layersNode.AddChild(button);
}
}
}

View File

@ -1,8 +1,9 @@
[gd_scene load_steps=5 format=3 uid="uid://boxi211q3kx6c"]
[gd_scene load_steps=6 format=3 uid="uid://boxi211q3kx6c"]
[ext_resource type="Script" path="res://project/code/TMV/Mission.cs" id="1_3gnqe"]
[ext_resource type="Script" path="res://project/code/camera.gd" id="2_w5otl"]
[ext_resource type="PackedScene" uid="uid://cekg1xb5f0ux1" path="res://project/scenes/ui/mission_selector.tscn" id="3_hwfcj"]
[ext_resource type="PackedScene" uid="uid://0h2w7w84vbea" path="res://project/scenes/ui/lightmap_layer_toggler.tscn" id="4_naip8"]
[sub_resource type="Environment" id="Environment_cckyk"]
ambient_light_source = 2
@ -23,5 +24,10 @@ script = ExtResource("2_w5otl")
[node name="MissionSelector" parent="UI" instance=ExtResource("3_hwfcj")]
unique_name_in_owner = true
[node name="LightmapToggler" parent="UI" instance=ExtResource("4_naip8")]
unique_name_in_owner = true
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
environment = SubResource("Environment_cckyk")
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]

View File

@ -0,0 +1,34 @@
[gd_scene load_steps=2 format=3 uid="uid://0h2w7w84vbea"]
[ext_resource type="Script" path="res://project/code/TMV/UI/LightmapLayerToggler.cs" id="1_xwjtg"]
[node name="LightmapToggler" type="Control"]
layout_mode = 3
anchors_preset = 0
offset_right = 40.0
offset_bottom = 40.0
script = ExtResource("1_xwjtg")
[node name="PanelContainer" type="PanelContainer" parent="."]
layout_mode = 0
offset_right = 40.0
offset_bottom = 40.0
[node name="MarginContainer" type="MarginContainer" parent="PanelContainer"]
layout_mode = 2
theme_override_constants/margin_left = 8
theme_override_constants/margin_top = 8
theme_override_constants/margin_right = 8
theme_override_constants/margin_bottom = 8
[node name="VBoxContainer" type="VBoxContainer" parent="PanelContainer/MarginContainer"]
layout_mode = 2
[node name="Label" type="Label" parent="PanelContainer/MarginContainer/VBoxContainer"]
layout_mode = 2
text = "Lightmap Layers"
[node name="Layers" type="GridContainer" parent="PanelContainer/MarginContainer/VBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
columns = 8