diff --git a/addons/pvzadventure/scenes/seedpack-editor/foribidden_editor_seedpacket.tscn b/addons/pvzadventure/scenes/seedpack-editor/foribidden_editor_seedpacket.tscn index 1997f9f..8258894 100644 --- a/addons/pvzadventure/scenes/seedpack-editor/foribidden_editor_seedpacket.tscn +++ b/addons/pvzadventure/scenes/seedpack-editor/foribidden_editor_seedpacket.tscn @@ -1,10 +1,11 @@ -[gd_scene load_steps=4 format=3 uid="uid://dymyownbt688c"] +[gd_scene load_steps=5 format=3 uid="uid://dymyownbt688c"] [ext_resource type="Texture2D" uid="uid://dxyf557m4mq1p" path="res://assets/sprites/gui/EmptyPlantCard.png" id="1_x27jk"] [ext_resource type="Texture2D" uid="uid://cabpf23ndlvx0" path="res://assets/sprites/gui/Selection.tres" id="2_m8071"] [ext_resource type="Texture2D" uid="uid://cjkwy3u0wuax3" path="res://assets/sprites/gui/ForbiddenPacket.tres" id="3_ji8qd"] +[ext_resource type="Script" uid="uid://cy5t2lk5g75x7" path="res://addons/pvzadventure/scripts/seedpacket-editor/ForbiddableSeedpacket.cs" id="3_m8071"] -[node name="EditorSeedpacket" type="TextureButton"] +[node name="EditorSeedpacket" type="TextureButton" node_paths=PackedStringArray("preview", "forrbidTexture")] anchors_preset = -1 anchor_right = 0.137 anchor_bottom = 0.28 @@ -13,6 +14,9 @@ mouse_default_cursor_shape = 2 texture_normal = ExtResource("1_x27jk") texture_focused = ExtResource("2_m8071") stretch_mode = 0 +script = ExtResource("3_m8071") +preview = NodePath("PlantPreviewContainer/Preview") +forrbidTexture = NodePath("ForbiddenTexture") metadata/_edit_use_anchors_ = true [node name="PlantPreviewContainer" type="Control" parent="."] diff --git a/addons/pvzadventure/scenes/seedpack-editor/seedpacket_editor.tscn b/addons/pvzadventure/scenes/seedpack-editor/seedpacket_editor.tscn index d50b7fa..2ab8ecc 100644 --- a/addons/pvzadventure/scenes/seedpack-editor/seedpacket_editor.tscn +++ b/addons/pvzadventure/scenes/seedpack-editor/seedpacket_editor.tscn @@ -112,6 +112,7 @@ layout_mode = 2 visible = false layout_mode = 2 size_flags_vertical = 3 +alignment = 1 [node name="Label" type="Label" parent="VBoxContainer/ForbiddenTags"] layout_mode = 2 @@ -128,6 +129,7 @@ columns = 9 [node name="ForbiddenPlants" type="VBoxContainer" parent="VBoxContainer"] layout_mode = 2 size_flags_vertical = 3 +alignment = 1 [node name="Label" type="Label" parent="VBoxContainer/ForbiddenPlants"] layout_mode = 2 @@ -138,6 +140,7 @@ vertical_alignment = 1 [node name="FPlantsContainer" type="GridContainer" parent="VBoxContainer/ForbiddenPlants"] unique_name_in_owner = true layout_mode = 2 +size_flags_horizontal = 4 size_flags_vertical = 3 columns = 9 diff --git a/addons/pvzadventure/scripts/seedpacket-editor/ForbiddableSeedpacket.cs b/addons/pvzadventure/scripts/seedpacket-editor/ForbiddableSeedpacket.cs new file mode 100644 index 0000000..5d2c9e0 --- /dev/null +++ b/addons/pvzadventure/scripts/seedpacket-editor/ForbiddableSeedpacket.cs @@ -0,0 +1,28 @@ +using Godot; +using Newlon.Resources; + +[Tool] +public partial class ForbiddableSeedpacket : TextureButton +{ + [Signal] public delegate void SaveCallbackEventHandler(); + [Export] private TextureRect preview; + [Export] private TextureRect forrbidTexture; + public PlantResource HeldResource; + public bool forbidden = false; + public override void _Pressed() + { + forbidden = !forbidden; + Update(); + } + + private void Update() + { + RefreshTexture(); + EmitSignal(SignalName.SaveCallback); + } + public void RefreshTexture() + { + preview.Texture = HeldResource.Preview; + forrbidTexture.Visible = forbidden; + } +} diff --git a/addons/pvzadventure/scripts/seedpacket-editor/ForbiddableSeedpacket.cs.uid b/addons/pvzadventure/scripts/seedpacket-editor/ForbiddableSeedpacket.cs.uid new file mode 100644 index 0000000..957fc62 --- /dev/null +++ b/addons/pvzadventure/scripts/seedpacket-editor/ForbiddableSeedpacket.cs.uid @@ -0,0 +1 @@ +uid://cy5t2lk5g75x7 diff --git a/addons/pvzadventure/scripts/seedpacket-editor/SeedpacketEditor.cs b/addons/pvzadventure/scripts/seedpacket-editor/SeedpacketEditor.cs index 637f6b4..1265a70 100644 --- a/addons/pvzadventure/scripts/seedpacket-editor/SeedpacketEditor.cs +++ b/addons/pvzadventure/scripts/seedpacket-editor/SeedpacketEditor.cs @@ -1,5 +1,7 @@ +using System.Collections.Generic; using Godot; using Godot.Collections; +using Newlon.Components.GUI; using Newlon.Resources; [Tool] @@ -9,15 +11,17 @@ public partial class SeedpacketEditor : BaseEditor public override void SetEditedData(AdventureLevelResource data) { base.SetEditedData(data); - SetPrepickedPlants(); + SetupPrepickedPlants(); + SetupForbiddablePlants(); } public override void Save() { CalculatePrepickedPlants(); + CalculateForbiddenPlants(); base.Save(); } - private void SetPrepickedPlants() + private void SetupPrepickedPlants() { for (int i = 0; i < editedResource.prepickedPlants.Count; i++) { @@ -28,6 +32,21 @@ public partial class SeedpacketEditor : BaseEditor } } } + private void SetupForbiddablePlants() + { + var plants = GetPlants(); + var packed = ResourceLoader.Load("uid://dymyownbt688c"); + for (int i = 0; i < plants.Count; i++) + { + var seedpacket = packed.Instantiate(); + seedpacket.HeldResource = plants[i]; + seedpacket.forbidden = editedResource.forbiddenPlants.Contains(plants[i].GetInternalID()); + seedpacket.RefreshTexture(); + seedpacket.SaveCallback += Save; + + GetNode("%FPlantsContainer").AddChild(seedpacket); + } + } private void CalculatePrepickedPlants() { Array prepicked = new(); @@ -40,6 +59,20 @@ public partial class SeedpacketEditor : BaseEditor } editedResource.prepickedPlants = prepicked; } + private void CalculateForbiddenPlants() + { + Array forbidden = new(); + + foreach (var child in GetNode("%FPlantsContainer").GetChildren()) + { + if (child is ForbiddableSeedpacket packet && packet.forbidden) + { + forbidden.Add(packet.HeldResource.GetInternalID()); + } + } + + editedResource.forbiddenPlants = forbidden; + } private PlantResource TryGetPlant(string plantName) { foreach (var file in ResourceLoader.ListDirectory(PLANTS_DIRECTORY)) @@ -49,5 +82,20 @@ public partial class SeedpacketEditor : BaseEditor } return null; } + private List GetPlants() + { + var result = new List(); + + foreach (var file in ResourceLoader.ListDirectory(PLANTS_DIRECTORY)) + { + result.Add(ResourceLoader.Load(PLANTS_DIRECTORY + file)); + } + result.Sort((a, b) => + { + return a.Order - b.Order; + }); + + return result; + } } diff --git a/addons/pvzadventure/scripts/seedpacket-editor/editor_seedpacket.gd b/addons/pvzadventure/scripts/seedpacket-editor/editor_seedpacket.gd deleted file mode 100644 index 535771f..0000000 --- a/addons/pvzadventure/scripts/seedpacket-editor/editor_seedpacket.gd +++ /dev/null @@ -1,28 +0,0 @@ -@tool -extends TextureButton - -signal save_callback - -var held_data : PlantResource = null -@export var preview : TextureRect - -func _can_drop_data(at_position: Vector2, data: Variant) -> bool: - if typeof(data) == TYPE_DICTIONARY: - if data.type == "files": - return load(data.files[0]) is PlantResource - return false - -func _drop_data(at_position: Vector2, data: Variant) -> void: - held_data = load(data.files[0]) as PlantResource - update() - -func update(): - if held_data: - preview.texture = held_data.Preview - else: - preview.texture = null - save_callback.emit() - -func _pressed() -> void: - held_data = null - update() diff --git a/addons/pvzadventure/scripts/seedpacket-editor/editor_seedpacket.gd.uid b/addons/pvzadventure/scripts/seedpacket-editor/editor_seedpacket.gd.uid deleted file mode 100644 index 089de69..0000000 --- a/addons/pvzadventure/scripts/seedpacket-editor/editor_seedpacket.gd.uid +++ /dev/null @@ -1 +0,0 @@ -uid://donugf6vnchij diff --git a/assets/levels/video_level.tres b/assets/levels/video_level.tres index e2e7c8d..9cfc2fc 100644 --- a/assets/levels/video_level.tres +++ b/assets/levels/video_level.tres @@ -281,9 +281,9 @@ wavePercentage = 0.5 standardWaveDelay = 30.0 initialWaveDelay = 20.0 reward = ExtResource("1_eqa0o") -forbiddenPlants = Array[String](["aloe", "spikeweed", "peashooter", "wallnut"]) +forbiddenPlants = Array[String]([]) forbiddenTags = Array[String]([]) -prepickedPlants = Array[String](["snipach", "potatomine", "sunflower", "garlic", "cucumber"]) +prepickedPlants = Array[String]([]) waves = Array[ExtResource("4_kc7t2")]([SubResource("Resource_c21si"), SubResource("Resource_icaa5"), SubResource("Resource_kc7t2"), SubResource("Resource_66y5q"), SubResource("Resource_tuvrx"), SubResource("Resource_t4nit"), SubResource("Resource_qx8xe"), SubResource("Resource_hyvhe"), SubResource("Resource_8syff"), SubResource("Resource_jfmww"), SubResource("Resource_vrqir"), SubResource("Resource_2seob"), SubResource("Resource_geil0"), SubResource("Resource_lxb1x"), SubResource("Resource_o5y12"), SubResource("Resource_diw66"), SubResource("Resource_pwwqn")]) initialScenes = Array[PackedScene]([null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null]) metadata/_custom_type_script = "uid://bximdujbkj2n4" diff --git a/scripts/gui/seedpackets/PrepickedDummyHandler.cs b/scripts/gui/seedpackets/PrepickedDummyHandler.cs index 8a71cda..5c11a1e 100644 --- a/scripts/gui/seedpackets/PrepickedDummyHandler.cs +++ b/scripts/gui/seedpackets/PrepickedDummyHandler.cs @@ -10,6 +10,7 @@ public class PrepickedDummyHandler : SeedpacketHandler LevelGUIElements.Instance.SeedpacketsHotbar.AddChild(hotbarSeedpacket); hotbarSeedpacket.SetResource(_owner.GetResource()); - hotbarSeedpacket.SetHandler(new PrepickedHandler(_owner)); + hotbarSeedpacket.SetHandler(new PrepickedHandler(hotbarSeedpacket)); + hotbarSeedpacket.disablePacket = true; } } \ No newline at end of file