diff --git a/project/code/TMV/Mission.cs b/project/code/TMV/Mission.cs index 1e3802d..aa4e52e 100644 --- a/project/code/TMV/Mission.cs +++ b/project/code/TMV/Mission.cs @@ -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(); _lmLayerMask = new Vector2I(~0, ~0); + + var lightmapToggler = GetNode("%LightmapToggler") as LightmapLayerToggler; + lightmapToggler.Setup(this); + var missionSelector = GetNode("%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(); lmImages.Resize(lmLayerCount); for (var i = 0; i < lmLayerCount; i++) diff --git a/project/code/TMV/UI/LightmapLayerToggler.cs b/project/code/TMV/UI/LightmapLayerToggler.cs new file mode 100644 index 0000000..a6b74e2 --- /dev/null +++ b/project/code/TMV/UI/LightmapLayerToggler.cs @@ -0,0 +1,30 @@ +using Godot; + +namespace KeepersCompound.TMV.UI; + +public partial class LightmapLayerToggler : Control +{ + public void Setup(Mission mission) + { + var layersNode = GetNode("%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); + } + } +} diff --git a/project/scenes/main.tscn b/project/scenes/main.tscn index 7df2331..c483343 100644 --- a/project/scenes/main.tscn +++ b/project/scenes/main.tscn @@ -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="."] diff --git a/project/scenes/ui/lightmap_layer_toggler.tscn b/project/scenes/ui/lightmap_layer_toggler.tscn new file mode 100644 index 0000000..d3a8755 --- /dev/null +++ b/project/scenes/ui/lightmap_layer_toggler.tscn @@ -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