Basic functionality for the texture browser

This commit is contained in:
Jarrod Doyle 2024-09-08 14:45:52 +01:00
parent 63591c228b
commit b13d27c0b8
Signed by: Jayrude
GPG Key ID: 38B57B16E7C0ADF7
2 changed files with 152 additions and 35 deletions

View File

@ -0,0 +1,91 @@
using Godot;
namespace KeepersCompound.TMV.UI;
public partial class TextureBrowser : Node
{
private Tree _folderTree;
private LineEdit _searchBar;
private MenuButton _sortMenu;
private Button _openFolderButton;
private MenuButton _browserMenu;
private HFlowContainer _textureList;
private TextureRect _previewTexture;
private LineEdit _texturePath;
public override void _Ready()
{
// !HACK TEMP
Context.Instance.PathManager.Init("/stuff/Games/thief/drive_c/GOG Games/TG ND 1.27 (MAPPING)/");
Context.Instance.CampaignName = "TheBlackParade_1_0";
_folderTree = GetNode<Tree>("%FolderTree");
_searchBar = GetNode<LineEdit>("%SearchBar");
_sortMenu = GetNode<MenuButton>("%SortMenu");
_openFolderButton = GetNode<Button>("%OpenTextureFolderButton");
_browserMenu = GetNode<MenuButton>("%BrowserOverflowMenu");
_textureList = GetNode<HFlowContainer>("%TextureList");
_previewTexture = GetNode<TextureRect>("%PreviewTexture");
_texturePath = GetNode<LineEdit>("%PathBox");
BuildFolderTree();
BuildTextureList(); // TODO: This should be triggered on folder change
}
private void BuildFolderTree()
{
_folderTree.Clear();
_folderTree.SetColumnTitle(0, "Name");
_folderTree.SetColumnTitle(1, "Count");
// TODO: We need some way to get family names
// Maybe PathManager and CampaignResource should be expanded so that we
// can get the resource itself and query things
var pathManager = Context.Instance.PathManager;
}
private void BuildTextureList()
{
foreach (var child in _textureList.GetChildren())
{
child.QueueFree();
}
var pathManager = Context.Instance.PathManager;
var campaign = Context.Instance.CampaignName;
var resType = LGS.ResourceType.Texture;
var textureNames = pathManager.GetResourceNames(resType, campaign);
foreach (var name in textureNames)
{
var (_, path) = pathManager.GetResourcePath(resType, campaign, name);
var texture = TextureLoader.LoadTexture(path);
var textureRect = new TextureRect();
textureRect.Texture = texture;
textureRect.ExpandMode = TextureRect.ExpandModeEnum.IgnoreSize;
textureRect.StretchMode = TextureRect.StretchModeEnum.KeepAspectCentered;
textureRect.SetAnchorsPreset(Control.LayoutPreset.FullRect);
var slot = new Panel();
slot.CustomMinimumSize = new Vector2(128, 128);
slot.AddChild(textureRect);
slot.GuiInput += (input) =>
{
if (input is InputEventMouseButton mouseEvent &&
mouseEvent.Pressed &&
mouseEvent.ButtonIndex == MouseButton.Left)
{
SetPreviewTexture(name, texture);
}
};
_textureList.AddChild(slot);
}
}
private void SetPreviewTexture(string name, Texture2D texture)
{
_previewTexture.Texture = texture;
_texturePath.Text = name;
}
}

View File

@ -1,8 +1,8 @@
[gd_scene load_steps=8 format=3 uid="uid://byknmqac1a5vn"] [gd_scene load_steps=8 format=3 uid="uid://byknmqac1a5vn"]
[ext_resource type="Texture2D" uid="uid://b208ufsau5jhb" path="res://project/jorge.png" id="1_1vlw2"] [ext_resource type="Texture2D" uid="uid://b208ufsau5jhb" path="res://project/jorge.png" id="1_1vlw2"]
[ext_resource type="Script" path="res://project/code/TMV/UI/TextureBrowser.cs" id="1_72xft"]
[ext_resource type="Texture2D" uid="uid://beb4tj06ivjae" path="res://project/assets/icons/Search.svg" id="1_ityvd"] [ext_resource type="Texture2D" uid="uid://beb4tj06ivjae" path="res://project/assets/icons/Search.svg" id="1_ityvd"]
[ext_resource type="Texture2D" uid="uid://d1rqwnr7u0rq7" path="res://project/sky.png" id="2_dggh8"]
[ext_resource type="Texture2D" uid="uid://dx8paqeom7dtb" path="res://project/assets/icons/Sort.svg" id="3_0k1fm"] [ext_resource type="Texture2D" uid="uid://dx8paqeom7dtb" path="res://project/assets/icons/Sort.svg" id="3_0k1fm"]
[ext_resource type="Texture2D" uid="uid://dqefy830o4foj" path="res://project/assets/icons/Folder.svg" id="3_xdjfn"] [ext_resource type="Texture2D" uid="uid://dqefy830o4foj" path="res://project/assets/icons/Folder.svg" id="3_xdjfn"]
[ext_resource type="Texture2D" uid="uid://dm2jiwrvkjnaa" path="res://project/assets/icons/GuiTabMenuHl.svg" id="4_s4jwc"] [ext_resource type="Texture2D" uid="uid://dm2jiwrvkjnaa" path="res://project/assets/icons/GuiTabMenuHl.svg" id="4_s4jwc"]
@ -33,6 +33,7 @@ theme_override_constants/margin_left = 8
theme_override_constants/margin_top = 8 theme_override_constants/margin_top = 8
theme_override_constants/margin_right = 8 theme_override_constants/margin_right = 8
theme_override_constants/margin_bottom = 8 theme_override_constants/margin_bottom = 8
script = ExtResource("1_72xft")
metadata/_tab_index = 0 metadata/_tab_index = 0
[node name="VBoxContainer" type="VBoxContainer" parent="TabContainer/Textures"] [node name="VBoxContainer" type="VBoxContainer" parent="TabContainer/Textures"]
@ -43,8 +44,11 @@ layout_mode = 2
size_flags_vertical = 3 size_flags_vertical = 3
[node name="FolderTree" type="Tree" parent="TabContainer/Textures/VBoxContainer/HSplitContainer"] [node name="FolderTree" type="Tree" parent="TabContainer/Textures/VBoxContainer/HSplitContainer"]
unique_name_in_owner = true
custom_minimum_size = Vector2(256, 0) custom_minimum_size = Vector2(256, 0)
layout_mode = 2 layout_mode = 2
columns = 2
column_titles_visible = true
[node name="HSplitContainer" type="HSplitContainer" parent="TabContainer/Textures/VBoxContainer/HSplitContainer"] [node name="HSplitContainer" type="HSplitContainer" parent="TabContainer/Textures/VBoxContainer/HSplitContainer"]
layout_mode = 2 layout_mode = 2
@ -57,14 +61,16 @@ size_flags_horizontal = 3
[node name="Options" type="HBoxContainer" parent="TabContainer/Textures/VBoxContainer/HSplitContainer/HSplitContainer/Browser"] [node name="Options" type="HBoxContainer" parent="TabContainer/Textures/VBoxContainer/HSplitContainer/HSplitContainer/Browser"]
layout_mode = 2 layout_mode = 2
[node name="Search" type="LineEdit" parent="TabContainer/Textures/VBoxContainer/HSplitContainer/HSplitContainer/Browser/Options"] [node name="SearchBar" type="LineEdit" parent="TabContainer/Textures/VBoxContainer/HSplitContainer/HSplitContainer/Browser/Options"]
unique_name_in_owner = true
layout_mode = 2 layout_mode = 2
size_flags_horizontal = 3 size_flags_horizontal = 3
placeholder_text = "Search..." placeholder_text = "Search..."
clear_button_enabled = true clear_button_enabled = true
right_icon = ExtResource("1_ityvd") right_icon = ExtResource("1_ityvd")
[node name="Sort" type="MenuButton" parent="TabContainer/Textures/VBoxContainer/HSplitContainer/HSplitContainer/Browser/Options"] [node name="SortMenu" type="MenuButton" parent="TabContainer/Textures/VBoxContainer/HSplitContainer/HSplitContainer/Browser/Options"]
unique_name_in_owner = true
layout_mode = 2 layout_mode = 2
tooltip_text = "Sort Mode" tooltip_text = "Sort Mode"
icon = ExtResource("3_0k1fm") icon = ExtResource("3_0k1fm")
@ -84,14 +90,16 @@ popup/item_3/checkable = 2
popup/item_3/id = 3 popup/item_3/id = 3
popup/item_3/disabled = true popup/item_3/disabled = true
[node name="Button" type="Button" parent="TabContainer/Textures/VBoxContainer/HSplitContainer/HSplitContainer/Browser/Options"] [node name="OpenTextureFolderButton" type="Button" parent="TabContainer/Textures/VBoxContainer/HSplitContainer/HSplitContainer/Browser/Options"]
unique_name_in_owner = true
layout_mode = 2 layout_mode = 2
tooltip_text = "Open folder in File Explorer" tooltip_text = "Open folder in File Explorer"
icon = ExtResource("3_xdjfn") icon = ExtResource("3_xdjfn")
flat = true flat = true
icon_alignment = 1 icon_alignment = 1
[node name="MenuButton" type="MenuButton" parent="TabContainer/Textures/VBoxContainer/HSplitContainer/HSplitContainer/Browser/Options"] [node name="BrowserOverflowMenu" type="MenuButton" parent="TabContainer/Textures/VBoxContainer/HSplitContainer/HSplitContainer/Browser/Options"]
unique_name_in_owner = true
layout_mode = 2 layout_mode = 2
icon = ExtResource("4_s4jwc") icon = ExtResource("4_s4jwc")
item_count = 9 item_count = 9
@ -142,56 +150,73 @@ theme_override_constants/margin_bottom = 8
layout_mode = 2 layout_mode = 2
size_flags_vertical = 3 size_flags_vertical = 3
[node name="List" type="HFlowContainer" parent="TabContainer/Textures/VBoxContainer/HSplitContainer/HSplitContainer/Browser/PanelContainer/MarginContainer/Scroll"] [node name="TextureList" type="HFlowContainer" parent="TabContainer/Textures/VBoxContainer/HSplitContainer/HSplitContainer/Browser/PanelContainer/MarginContainer/Scroll"]
unique_name_in_owner = true
layout_mode = 2 layout_mode = 2
size_flags_horizontal = 3 size_flags_horizontal = 3
size_flags_vertical = 3 size_flags_vertical = 3
[node name="TextureRect" type="TextureRect" parent="TabContainer/Textures/VBoxContainer/HSplitContainer/HSplitContainer/Browser/PanelContainer/MarginContainer/Scroll/List"] [node name="Panel" type="Panel" parent="TabContainer/Textures/VBoxContainer/HSplitContainer/HSplitContainer/Browser/PanelContainer/MarginContainer/Scroll/TextureList"]
custom_minimum_size = Vector2(128, 128) custom_minimum_size = Vector2(128, 128)
layout_mode = 2 layout_mode = 2
[node name="TextureRect2" type="TextureRect" parent="TabContainer/Textures/VBoxContainer/HSplitContainer/HSplitContainer/Browser/PanelContainer/MarginContainer/Scroll/TextureList/Panel"]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
texture = ExtResource("1_1vlw2") texture = ExtResource("1_1vlw2")
expand_mode = 1
stretch_mode = 5
[node name="Preview" type="VBoxContainer" parent="TabContainer/Textures/VBoxContainer/HSplitContainer/HSplitContainer"] [node name="Preview" type="VBoxContainer" parent="TabContainer/Textures/VBoxContainer/HSplitContainer/HSplitContainer"]
custom_minimum_size = Vector2(384, 0) custom_minimum_size = Vector2(384, 0)
layout_mode = 2 layout_mode = 2
[node name="VSplitContainer" type="VSplitContainer" parent="TabContainer/Textures/VBoxContainer/HSplitContainer/HSplitContainer/Preview"] [node name="VBoxContainer" type="VBoxContainer" parent="TabContainer/Textures/VBoxContainer/HSplitContainer/HSplitContainer/Preview"]
layout_mode = 2 layout_mode = 2
size_flags_vertical = 3 size_flags_vertical = 3
[node name="TextureRect" type="TextureRect" parent="TabContainer/Textures/VBoxContainer/HSplitContainer/HSplitContainer/Preview/VSplitContainer"] [node name="Panel" type="Panel" parent="TabContainer/Textures/VBoxContainer/HSplitContainer/HSplitContainer/Preview/VBoxContainer"]
custom_minimum_size = Vector2(0, 384) custom_minimum_size = Vector2(384, 0)
layout_mode = 2 layout_mode = 2
texture = ExtResource("2_dggh8") size_flags_vertical = 3
[node name="PreviewTexture" type="TextureRect" parent="TabContainer/Textures/VBoxContainer/HSplitContainer/HSplitContainer/Preview/VBoxContainer/Panel"]
unique_name_in_owner = true
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
texture = ExtResource("1_1vlw2")
expand_mode = 1
stretch_mode = 5 stretch_mode = 5
[node name="PanelContainer2" type="PanelContainer" parent="TabContainer/Textures/VBoxContainer/HSplitContainer/HSplitContainer/Preview/VSplitContainer"] [node name="PanelContainer" type="PanelContainer" parent="TabContainer/Textures/VBoxContainer/HSplitContainer/HSplitContainer/Preview/VBoxContainer"]
layout_mode = 2 layout_mode = 2
size_flags_vertical = 3
[node name="MarginContainer" type="MarginContainer" parent="TabContainer/Textures/VBoxContainer/HSplitContainer/HSplitContainer/Preview/VSplitContainer/PanelContainer2"] [node name="MarginContainer" type="MarginContainer" parent="TabContainer/Textures/VBoxContainer/HSplitContainer/HSplitContainer/Preview/VBoxContainer/PanelContainer"]
layout_mode = 2 layout_mode = 2
theme_override_constants/margin_left = 8 theme_override_constants/margin_left = 8
theme_override_constants/margin_top = 8 theme_override_constants/margin_top = 8
theme_override_constants/margin_right = 8 theme_override_constants/margin_right = 8
theme_override_constants/margin_bottom = 8 theme_override_constants/margin_bottom = 8
[node name="Scroll" type="ScrollContainer" parent="TabContainer/Textures/VBoxContainer/HSplitContainer/HSplitContainer/Preview/VSplitContainer/PanelContainer2/MarginContainer"] [node name="Details" type="GridContainer" parent="TabContainer/Textures/VBoxContainer/HSplitContainer/HSplitContainer/Preview/VBoxContainer/PanelContainer/MarginContainer"]
layout_mode = 2
size_flags_vertical = 3
[node name="Details" type="GridContainer" parent="TabContainer/Textures/VBoxContainer/HSplitContainer/HSplitContainer/Preview/VSplitContainer/PanelContainer2/MarginContainer/Scroll"]
layout_mode = 2 layout_mode = 2
size_flags_horizontal = 3 size_flags_horizontal = 3
theme_override_constants/h_separation = 16 theme_override_constants/h_separation = 16
columns = 2 columns = 2
[node name="FilterLabel" type="Label" parent="TabContainer/Textures/VBoxContainer/HSplitContainer/HSplitContainer/Preview/VSplitContainer/PanelContainer2/MarginContainer/Scroll/Details"] [node name="FilterLabel" type="Label" parent="TabContainer/Textures/VBoxContainer/HSplitContainer/HSplitContainer/Preview/VBoxContainer/PanelContainer/MarginContainer/Details"]
layout_mode = 2 layout_mode = 2
text = "Texture Filter" text = "Texture Filter"
[node name="FilterOptions" type="OptionButton" parent="TabContainer/Textures/VBoxContainer/HSplitContainer/HSplitContainer/Preview/VSplitContainer/PanelContainer2/MarginContainer/Scroll/Details"] [node name="FilterOptions" type="OptionButton" parent="TabContainer/Textures/VBoxContainer/HSplitContainer/HSplitContainer/Preview/VBoxContainer/PanelContainer/MarginContainer/Details"]
layout_mode = 2 layout_mode = 2
size_flags_horizontal = 3 size_flags_horizontal = 3
selected = 0 selected = 0
@ -200,11 +225,11 @@ popup/item_0/text = "Linear"
popup/item_1/text = "Nearest" popup/item_1/text = "Nearest"
popup/item_1/id = 1 popup/item_1/id = 1
[node name="Position" type="Label" parent="TabContainer/Textures/VBoxContainer/HSplitContainer/HSplitContainer/Preview/VSplitContainer/PanelContainer2/MarginContainer/Scroll/Details"] [node name="Position" type="Label" parent="TabContainer/Textures/VBoxContainer/HSplitContainer/HSplitContainer/Preview/VBoxContainer/PanelContainer/MarginContainer/Details"]
layout_mode = 2 layout_mode = 2
text = "Position" text = "Position"
[node name="PositionOptions" type="OptionButton" parent="TabContainer/Textures/VBoxContainer/HSplitContainer/HSplitContainer/Preview/VSplitContainer/PanelContainer2/MarginContainer/Scroll/Details"] [node name="PositionOptions" type="OptionButton" parent="TabContainer/Textures/VBoxContainer/HSplitContainer/HSplitContainer/Preview/VBoxContainer/PanelContainer/MarginContainer/Details"]
layout_mode = 2 layout_mode = 2
size_flags_horizontal = 3 size_flags_horizontal = 3
selected = 0 selected = 0
@ -213,12 +238,12 @@ popup/item_0/text = "Scaled"
popup/item_1/text = "Tiled" popup/item_1/text = "Tiled"
popup/item_1/id = 1 popup/item_1/id = 1
[node name="ZoomLabel" type="Label" parent="TabContainer/Textures/VBoxContainer/HSplitContainer/HSplitContainer/Preview/VSplitContainer/PanelContainer2/MarginContainer/Scroll/Details"] [node name="ZoomLabel" type="Label" parent="TabContainer/Textures/VBoxContainer/HSplitContainer/HSplitContainer/Preview/VBoxContainer/PanelContainer/MarginContainer/Details"]
visible = false visible = false
layout_mode = 2 layout_mode = 2
text = "Zoom" text = "Zoom"
[node name="ZoomSlider" type="HSlider" parent="TabContainer/Textures/VBoxContainer/HSplitContainer/HSplitContainer/Preview/VSplitContainer/PanelContainer2/MarginContainer/Scroll/Details"] [node name="ZoomSlider" type="HSlider" parent="TabContainer/Textures/VBoxContainer/HSplitContainer/HSplitContainer/Preview/VBoxContainer/PanelContainer/MarginContainer/Details"]
visible = false visible = false
layout_mode = 2 layout_mode = 2
size_flags_horizontal = 3 size_flags_horizontal = 3
@ -227,46 +252,47 @@ min_value = 0.5
max_value = 8.0 max_value = 8.0
value = 0.5 value = 0.5
[node name="PathLabel" type="Label" parent="TabContainer/Textures/VBoxContainer/HSplitContainer/HSplitContainer/Preview/VSplitContainer/PanelContainer2/MarginContainer/Scroll/Details"] [node name="PathLabel" type="Label" parent="TabContainer/Textures/VBoxContainer/HSplitContainer/HSplitContainer/Preview/VBoxContainer/PanelContainer/MarginContainer/Details"]
layout_mode = 2 layout_mode = 2
text = "Path" text = "Path"
[node name="HBoxContainer" type="HBoxContainer" parent="TabContainer/Textures/VBoxContainer/HSplitContainer/HSplitContainer/Preview/VSplitContainer/PanelContainer2/MarginContainer/Scroll/Details"] [node name="HBoxContainer" type="HBoxContainer" parent="TabContainer/Textures/VBoxContainer/HSplitContainer/HSplitContainer/Preview/VBoxContainer/PanelContainer/MarginContainer/Details"]
layout_mode = 2 layout_mode = 2
[node name="PathBox" type="LineEdit" parent="TabContainer/Textures/VBoxContainer/HSplitContainer/HSplitContainer/Preview/VSplitContainer/PanelContainer2/MarginContainer/Scroll/Details/HBoxContainer"] [node name="PathBox" type="LineEdit" parent="TabContainer/Textures/VBoxContainer/HSplitContainer/HSplitContainer/Preview/VBoxContainer/PanelContainer/MarginContainer/Details/HBoxContainer"]
unique_name_in_owner = true
layout_mode = 2 layout_mode = 2
size_flags_horizontal = 3 size_flags_horizontal = 3
editable = false editable = false
[node name="PathCopyButton" type="Button" parent="TabContainer/Textures/VBoxContainer/HSplitContainer/HSplitContainer/Preview/VSplitContainer/PanelContainer2/MarginContainer/Scroll/Details/HBoxContainer"] [node name="PathCopyButton" type="Button" parent="TabContainer/Textures/VBoxContainer/HSplitContainer/HSplitContainer/Preview/VBoxContainer/PanelContainer/MarginContainer/Details/HBoxContainer"]
layout_mode = 2 layout_mode = 2
icon = ExtResource("7_2pq2g") icon = ExtResource("7_2pq2g")
flat = true flat = true
[node name="FileTypeLabel" type="Label" parent="TabContainer/Textures/VBoxContainer/HSplitContainer/HSplitContainer/Preview/VSplitContainer/PanelContainer2/MarginContainer/Scroll/Details"] [node name="FileTypeLabel" type="Label" parent="TabContainer/Textures/VBoxContainer/HSplitContainer/HSplitContainer/Preview/VBoxContainer/PanelContainer/MarginContainer/Details"]
layout_mode = 2 layout_mode = 2
text = "File Type" text = "File Type"
[node name="FileTypeBox" type="LineEdit" parent="TabContainer/Textures/VBoxContainer/HSplitContainer/HSplitContainer/Preview/VSplitContainer/PanelContainer2/MarginContainer/Scroll/Details"] [node name="FileTypeBox" type="LineEdit" parent="TabContainer/Textures/VBoxContainer/HSplitContainer/HSplitContainer/Preview/VBoxContainer/PanelContainer/MarginContainer/Details"]
layout_mode = 2 layout_mode = 2
size_flags_horizontal = 3 size_flags_horizontal = 3
editable = false editable = false
[node name="ResolutionLabel" type="Label" parent="TabContainer/Textures/VBoxContainer/HSplitContainer/HSplitContainer/Preview/VSplitContainer/PanelContainer2/MarginContainer/Scroll/Details"] [node name="ResolutionLabel" type="Label" parent="TabContainer/Textures/VBoxContainer/HSplitContainer/HSplitContainer/Preview/VBoxContainer/PanelContainer/MarginContainer/Details"]
layout_mode = 2 layout_mode = 2
text = "Resolution" text = "Resolution"
[node name="ResolutionBox" type="LineEdit" parent="TabContainer/Textures/VBoxContainer/HSplitContainer/HSplitContainer/Preview/VSplitContainer/PanelContainer2/MarginContainer/Scroll/Details"] [node name="ResolutionBox" type="LineEdit" parent="TabContainer/Textures/VBoxContainer/HSplitContainer/HSplitContainer/Preview/VBoxContainer/PanelContainer/MarginContainer/Details"]
layout_mode = 2 layout_mode = 2
size_flags_horizontal = 3 size_flags_horizontal = 3
editable = false editable = false
[node name="FileSizeLabel" type="Label" parent="TabContainer/Textures/VBoxContainer/HSplitContainer/HSplitContainer/Preview/VSplitContainer/PanelContainer2/MarginContainer/Scroll/Details"] [node name="FileSizeLabel" type="Label" parent="TabContainer/Textures/VBoxContainer/HSplitContainer/HSplitContainer/Preview/VBoxContainer/PanelContainer/MarginContainer/Details"]
layout_mode = 2 layout_mode = 2
text = "File Size" text = "File Size"
[node name="FileSizeBox" type="LineEdit" parent="TabContainer/Textures/VBoxContainer/HSplitContainer/HSplitContainer/Preview/VSplitContainer/PanelContainer2/MarginContainer/Scroll/Details"] [node name="FileSizeBox" type="LineEdit" parent="TabContainer/Textures/VBoxContainer/HSplitContainer/HSplitContainer/Preview/VBoxContainer/PanelContainer/MarginContainer/Details"]
layout_mode = 2 layout_mode = 2
size_flags_horizontal = 3 size_flags_horizontal = 3
editable = false editable = false