Add better mission selection UI
This commit is contained in:
		
							parent
							
								
									50c4d06f19
								
							
						
					
					
						commit
						fe5d2fb12f
					
				| 
						 | 
					@ -2,6 +2,7 @@ using Godot;
 | 
				
			||||||
using KeepersCompound.LGS;
 | 
					using KeepersCompound.LGS;
 | 
				
			||||||
using KeepersCompound.LGS.Database;
 | 
					using KeepersCompound.LGS.Database;
 | 
				
			||||||
using KeepersCompound.LGS.Database.Chunks;
 | 
					using KeepersCompound.LGS.Database.Chunks;
 | 
				
			||||||
 | 
					using KeepersCompound.TMV.UI;
 | 
				
			||||||
using RectpackSharp;
 | 
					using RectpackSharp;
 | 
				
			||||||
using System;
 | 
					using System;
 | 
				
			||||||
using System.Collections.Generic;
 | 
					using System.Collections.Generic;
 | 
				
			||||||
| 
						 | 
					@ -22,11 +23,12 @@ public partial class Mission : Node3D
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public override void _Ready()
 | 
						public override void _Ready()
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		var fileNameLineEdit = GetNode<LineEdit>("%FileNameLineEdit");
 | 
							var missionSelector = GetNode<Control>("%MissionSelector") as MissionSelector;
 | 
				
			||||||
		fileNameLineEdit.Text = FileName;
 | 
							missionSelector.LoadMission += (string path) =>
 | 
				
			||||||
		fileNameLineEdit.TextSubmitted += (string text) => FileName = text;
 | 
							{
 | 
				
			||||||
		GetNode<Button>("%BuildButton").Pressed += () => RebuildMap();
 | 
								FileName = path;
 | 
				
			||||||
		GetNode<Button>("%ClearButton").Pressed += () => ClearMap();
 | 
								Build = true;
 | 
				
			||||||
 | 
							};
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public override void _Process(double delta)
 | 
						public override void _Process(double delta)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,74 @@
 | 
				
			||||||
 | 
					using System.IO;
 | 
				
			||||||
 | 
					using Godot;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace KeepersCompound.TMV.UI;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public partial class MissionSelector : Control
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						[Signal]
 | 
				
			||||||
 | 
						public delegate void LoadMissionEventHandler(string path);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						private FileDialog _FolderSelect;
 | 
				
			||||||
 | 
						private LineEdit _FolderPath;
 | 
				
			||||||
 | 
						private Button _BrowseButton;
 | 
				
			||||||
 | 
						private ItemList _Missions;
 | 
				
			||||||
 | 
						private Button _LoadButton;
 | 
				
			||||||
 | 
						private Button _CancelButton;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						public override void _Ready()
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							_FolderSelect = GetNode<FileDialog>("%FolderSelect");
 | 
				
			||||||
 | 
							_FolderPath = GetNode<LineEdit>("%FolderPath");
 | 
				
			||||||
 | 
							_BrowseButton = GetNode<Button>("%BrowseButton");
 | 
				
			||||||
 | 
							_Missions = GetNode<ItemList>("%Missions");
 | 
				
			||||||
 | 
							_LoadButton = GetNode<Button>("%LoadButton");
 | 
				
			||||||
 | 
							_CancelButton = GetNode<Button>("%CancelButton");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							_BrowseButton.Pressed += () => _FolderSelect.Visible = true;
 | 
				
			||||||
 | 
							_FolderSelect.DirSelected += (string dir) => { _FolderPath.Text = dir; BuildMissionList(dir); };
 | 
				
			||||||
 | 
							_FolderPath.TextSubmitted += BuildMissionList;
 | 
				
			||||||
 | 
							_Missions.ItemSelected += (long _) => _LoadButton.Disabled = false;
 | 
				
			||||||
 | 
							_LoadButton.Pressed += EmitLoadMission;
 | 
				
			||||||
 | 
							_CancelButton.Pressed += () => Visible = false;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						public override void _Input(InputEvent @event)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							if (@event is InputEventKey keyEvent && keyEvent.Pressed)
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								if (keyEvent.Keycode == Key.Escape)
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									Visible = !Visible;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						private void BuildMissionList(string path)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							_Missions.Clear();
 | 
				
			||||||
 | 
							_LoadButton.Disabled = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// TODO: Use install config to select paths better?
 | 
				
			||||||
 | 
							var mis = Directory.GetFiles(path, "*.mis", SearchOption.AllDirectories);
 | 
				
			||||||
 | 
							foreach (var m in mis)
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								_Missions.AddItem(m.TrimPrefix(path));
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						private void EmitLoadMission()
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							var selected = _Missions.GetSelectedItems();
 | 
				
			||||||
 | 
							if (selected.IsEmpty())
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								return;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							var item = _Missions.GetItemText(selected[0]);
 | 
				
			||||||
 | 
							var basePath = _FolderPath.Text;
 | 
				
			||||||
 | 
							var path = basePath + item;
 | 
				
			||||||
 | 
							EmitSignal(SignalName.LoadMission, path);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							Visible = false;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -1,7 +1,8 @@
 | 
				
			||||||
[gd_scene load_steps=4 format=3 uid="uid://boxi211q3kx6c"]
 | 
					[gd_scene load_steps=5 format=3 uid="uid://boxi211q3kx6c"]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[ext_resource type="Script" path="res://project/code/Mission.cs" id="1_xhqt7"]
 | 
					[ext_resource type="Script" path="res://project/code/Mission.cs" id="1_xhqt7"]
 | 
				
			||||||
[ext_resource type="Script" path="res://project/code/camera.gd" id="2_w5otl"]
 | 
					[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"]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[sub_resource type="Environment" id="Environment_oxkvl"]
 | 
					[sub_resource type="Environment" id="Environment_oxkvl"]
 | 
				
			||||||
ambient_light_source = 2
 | 
					ambient_light_source = 2
 | 
				
			||||||
| 
						 | 
					@ -13,7 +14,7 @@ ssao_enabled = true
 | 
				
			||||||
[node name="Mission" type="Node3D" parent="."]
 | 
					[node name="Mission" type="Node3D" parent="."]
 | 
				
			||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.110309, 0.187101, -0.461656)
 | 
					transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.110309, 0.187101, -0.461656)
 | 
				
			||||||
script = ExtResource("1_xhqt7")
 | 
					script = ExtResource("1_xhqt7")
 | 
				
			||||||
FileName = "/home/jarrod/Dev/thief/de-specs/test_data/lm-test.cow"
 | 
					FileName = "/home/jarrod/Dev/thief/de-specs/test_data/rose-garden.mis"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[node name="Camera3D" type="Camera3D" parent="."]
 | 
					[node name="Camera3D" type="Camera3D" parent="."]
 | 
				
			||||||
script = ExtResource("2_w5otl")
 | 
					script = ExtResource("2_w5otl")
 | 
				
			||||||
| 
						 | 
					@ -23,34 +24,5 @@ environment = SubResource("Environment_oxkvl")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[node name="UI" type="CanvasLayer" parent="."]
 | 
					[node name="UI" type="CanvasLayer" parent="."]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[node name="PanelContainer" type="PanelContainer" parent="UI"]
 | 
					[node name="MissionSelector" parent="UI" instance=ExtResource("3_hwfcj")]
 | 
				
			||||||
offset_right = 436.0
 | 
					 | 
				
			||||||
offset_bottom = 74.0
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
[node name="MarginContainer" type="MarginContainer" parent="UI/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="UI/PanelContainer/MarginContainer"]
 | 
					 | 
				
			||||||
layout_mode = 2
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
[node name="FileNameLineEdit" type="LineEdit" parent="UI/PanelContainer/MarginContainer/VBoxContainer"]
 | 
					 | 
				
			||||||
unique_name_in_owner = true
 | 
					unique_name_in_owner = true
 | 
				
			||||||
layout_mode = 2
 | 
					 | 
				
			||||||
text = "/home/jarrod/Dev/thief/de-specs/test_data/rose-garden.mis"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
[node name="HBoxContainer" type="HBoxContainer" parent="UI/PanelContainer/MarginContainer/VBoxContainer"]
 | 
					 | 
				
			||||||
layout_mode = 2
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
[node name="BuildButton" type="Button" parent="UI/PanelContainer/MarginContainer/VBoxContainer/HBoxContainer"]
 | 
					 | 
				
			||||||
unique_name_in_owner = true
 | 
					 | 
				
			||||||
layout_mode = 2
 | 
					 | 
				
			||||||
text = "Build"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
[node name="ClearButton" type="Button" parent="UI/PanelContainer/MarginContainer/VBoxContainer/HBoxContainer"]
 | 
					 | 
				
			||||||
unique_name_in_owner = true
 | 
					 | 
				
			||||||
layout_mode = 2
 | 
					 | 
				
			||||||
text = "Clear"
 | 
					 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,96 @@
 | 
				
			||||||
 | 
					[gd_scene load_steps=3 format=3 uid="uid://cekg1xb5f0ux1"]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[ext_resource type="Script" path="res://project/code/TMV/UI/MissionSelector.cs" id="1_kl8qm"]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[sub_resource type="LabelSettings" id="LabelSettings_4v24o"]
 | 
				
			||||||
 | 
					font_size = 20
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[node name="MissionSelector" type="Control"]
 | 
				
			||||||
 | 
					visible = false
 | 
				
			||||||
 | 
					layout_mode = 3
 | 
				
			||||||
 | 
					anchors_preset = 8
 | 
				
			||||||
 | 
					anchor_left = 0.5
 | 
				
			||||||
 | 
					anchor_top = 0.5
 | 
				
			||||||
 | 
					anchor_right = 0.5
 | 
				
			||||||
 | 
					anchor_bottom = 0.5
 | 
				
			||||||
 | 
					grow_horizontal = 2
 | 
				
			||||||
 | 
					grow_vertical = 2
 | 
				
			||||||
 | 
					script = ExtResource("1_kl8qm")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[node name="FolderSelect" type="FileDialog" parent="."]
 | 
				
			||||||
 | 
					unique_name_in_owner = true
 | 
				
			||||||
 | 
					title = "Open a Directory"
 | 
				
			||||||
 | 
					initial_position = 2
 | 
				
			||||||
 | 
					size = Vector2i(636, 159)
 | 
				
			||||||
 | 
					ok_button_text = "Select Current Folder"
 | 
				
			||||||
 | 
					file_mode = 2
 | 
				
			||||||
 | 
					access = 2
 | 
				
			||||||
 | 
					use_native_dialog = true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[node name="PanelContainer" type="PanelContainer" parent="."]
 | 
				
			||||||
 | 
					custom_minimum_size = Vector2(460, 0)
 | 
				
			||||||
 | 
					layout_mode = 1
 | 
				
			||||||
 | 
					anchors_preset = 8
 | 
				
			||||||
 | 
					anchor_left = 0.5
 | 
				
			||||||
 | 
					anchor_top = 0.5
 | 
				
			||||||
 | 
					anchor_right = 0.5
 | 
				
			||||||
 | 
					anchor_bottom = 0.5
 | 
				
			||||||
 | 
					offset_left = -144.0
 | 
				
			||||||
 | 
					offset_top = -37.0
 | 
				
			||||||
 | 
					offset_right = 144.0
 | 
				
			||||||
 | 
					offset_bottom = 37.0
 | 
				
			||||||
 | 
					grow_horizontal = 2
 | 
				
			||||||
 | 
					grow_vertical = 2
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[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="Title" type="Label" parent="PanelContainer/MarginContainer/VBoxContainer"]
 | 
				
			||||||
 | 
					layout_mode = 2
 | 
				
			||||||
 | 
					text = "Mission Selector"
 | 
				
			||||||
 | 
					label_settings = SubResource("LabelSettings_4v24o")
 | 
				
			||||||
 | 
					horizontal_alignment = 1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[node name="FolderSelect" type="HBoxContainer" parent="PanelContainer/MarginContainer/VBoxContainer"]
 | 
				
			||||||
 | 
					layout_mode = 2
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[node name="Label" type="Label" parent="PanelContainer/MarginContainer/VBoxContainer/FolderSelect"]
 | 
				
			||||||
 | 
					layout_mode = 2
 | 
				
			||||||
 | 
					text = "Folder"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[node name="FolderPath" type="LineEdit" parent="PanelContainer/MarginContainer/VBoxContainer/FolderSelect"]
 | 
				
			||||||
 | 
					unique_name_in_owner = true
 | 
				
			||||||
 | 
					layout_mode = 2
 | 
				
			||||||
 | 
					size_flags_horizontal = 3
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[node name="BrowseButton" type="Button" parent="PanelContainer/MarginContainer/VBoxContainer/FolderSelect"]
 | 
				
			||||||
 | 
					unique_name_in_owner = true
 | 
				
			||||||
 | 
					layout_mode = 2
 | 
				
			||||||
 | 
					text = "Browse"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[node name="Missions" type="ItemList" parent="PanelContainer/MarginContainer/VBoxContainer"]
 | 
				
			||||||
 | 
					unique_name_in_owner = true
 | 
				
			||||||
 | 
					custom_minimum_size = Vector2(0, 480)
 | 
				
			||||||
 | 
					layout_mode = 2
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[node name="Buttons" type="HBoxContainer" parent="PanelContainer/MarginContainer/VBoxContainer"]
 | 
				
			||||||
 | 
					layout_mode = 2
 | 
				
			||||||
 | 
					size_flags_horizontal = 8
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[node name="LoadButton" type="Button" parent="PanelContainer/MarginContainer/VBoxContainer/Buttons"]
 | 
				
			||||||
 | 
					unique_name_in_owner = true
 | 
				
			||||||
 | 
					layout_mode = 2
 | 
				
			||||||
 | 
					disabled = true
 | 
				
			||||||
 | 
					text = "Load"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[node name="CancelButton" type="Button" parent="PanelContainer/MarginContainer/VBoxContainer/Buttons"]
 | 
				
			||||||
 | 
					unique_name_in_owner = true
 | 
				
			||||||
 | 
					layout_mode = 2
 | 
				
			||||||
 | 
					text = "Cancel"
 | 
				
			||||||
		Loading…
	
		Reference in New Issue