Initial data
This commit is contained in:
parent
c18c7f4db7
commit
f65cb11474
12 changed files with 340 additions and 48 deletions
|
|
@ -11,6 +11,7 @@ public partial class AdventureResourceInspector : Node
|
|||
const string EVENTS_ITEM_NAME = "Events";
|
||||
const string HUGEWAVE_ITEM_NAME = "Is huge wave?";
|
||||
private PackedScene zombieEditorScene = ResourceLoader.Load<PackedScene>("uid://db5ah76l43ng2");
|
||||
private PackedScene initialEditorScene = ResourceLoader.Load<PackedScene>("uid://sqessjn0m4o3");
|
||||
|
||||
private Tree tree;
|
||||
private AdventureLevelResource heldResource;
|
||||
|
|
@ -99,7 +100,10 @@ public partial class AdventureResourceInspector : Node
|
|||
|
||||
break;
|
||||
case INITIAL_ITEM_NAME:
|
||||
|
||||
var initialEditor = initialEditorScene.Instantiate<InitialEditor>();
|
||||
editorContainer.AddChild(initialEditor);
|
||||
initialEditor.SetData(heldResource);
|
||||
initialEditor.SaveCallback += adventureEditor.Save;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
46
addons/pvzadventure/scripts/InitialEditor.cs
Normal file
46
addons/pvzadventure/scripts/InitialEditor.cs
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
using Godot;
|
||||
|
||||
[Tool]
|
||||
public partial class InitialEditor : Node
|
||||
{
|
||||
public AdventureLevelResource editedResource;
|
||||
[Signal] public delegate void SaveCallbackEventHandler();
|
||||
public override void _Ready()
|
||||
{
|
||||
foreach (var child in GetChild(0).GetChildren())
|
||||
{
|
||||
if (child is UNI_GridItem gridItem)
|
||||
{
|
||||
gridItem.ResourceChanged += OnResourceChanged;
|
||||
}
|
||||
}
|
||||
}
|
||||
public void SetData(AdventureLevelResource resource)
|
||||
{
|
||||
editedResource = resource;
|
||||
for (int i = 0; i < GetChild(0).GetChildCount(); i++)
|
||||
{
|
||||
if (GetChild(0).GetChild(i) is UNI_GridItem gridItem)
|
||||
{
|
||||
gridItem.index = i;
|
||||
if (editedResource.initialScenes[i] == null)
|
||||
gridItem.SetData("");
|
||||
else
|
||||
gridItem.SetData(editedResource.initialScenes[i].ResourcePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
public void OnResourceChanged(string to, int index)
|
||||
{
|
||||
if (ResourceLoader.Exists(to))
|
||||
{
|
||||
editedResource.initialScenes[index] = ResourceLoader.Load<PackedScene>(to);
|
||||
}
|
||||
else
|
||||
{
|
||||
editedResource.initialScenes[index] = null;
|
||||
}
|
||||
EmitSignal(SignalName.SaveCallback);
|
||||
}
|
||||
|
||||
}
|
||||
1
addons/pvzadventure/scripts/InitialEditor.cs.uid
Normal file
1
addons/pvzadventure/scripts/InitialEditor.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://cumeahjpjgagq
|
||||
|
|
@ -1,15 +1,46 @@
|
|||
using Godot;
|
||||
using System;
|
||||
|
||||
[Tool]
|
||||
public partial class UNI_GridItem : PanelContainer
|
||||
{
|
||||
// Called when the node enters the scene tree for the first time.
|
||||
public override void _Ready()
|
||||
private string path;
|
||||
public int index;
|
||||
[Signal] public delegate void ResourceChangedEventHandler(string path, int index);
|
||||
public void SetData(string data)
|
||||
{
|
||||
path = data;
|
||||
UpdateContent();
|
||||
}
|
||||
private void UpdateContent()
|
||||
{
|
||||
if (path == null || path == "")
|
||||
{
|
||||
GetNode<TextureRect>("Texture").Texture = null;
|
||||
return;
|
||||
}
|
||||
GetNode<TextureRect>("Texture").Call("set_path", path);
|
||||
}
|
||||
|
||||
// Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
public override void _Process(double delta)
|
||||
public override Variant _GetDragData(Vector2 atPosition)
|
||||
{
|
||||
return path;
|
||||
}
|
||||
public override bool _CanDropData(Vector2 atPosition, Variant data)
|
||||
{
|
||||
return data.AsGodotDictionary<string, string>().ContainsKey("files") && ResourceLoader.Exists(data.AsGodotDictionary<string, Variant>()["files"].AsStringArray()[0]);
|
||||
}
|
||||
public override void _DropData(Vector2 atPosition, Variant data)
|
||||
{
|
||||
SetData(data.AsGodotDictionary<string, Variant>()["files"].AsStringArray()[0]);
|
||||
EmitSignal(SignalName.ResourceChanged, path, index);
|
||||
|
||||
}
|
||||
public override void _GuiInput(InputEvent @event)
|
||||
{
|
||||
if (@event is InputEventMouseButton buttonEvent && buttonEvent.ButtonIndex == MouseButton.Right )
|
||||
{
|
||||
SetData(null);
|
||||
EmitSignal(SignalName.ResourceChanged, path, index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,42 @@
|
|||
@tool
|
||||
extends TextureRect
|
||||
|
||||
@onready var subview = $Viewport
|
||||
@onready var camera = $Viewport/Camera2D
|
||||
var scene : Node
|
||||
|
||||
func set_path(path):
|
||||
if scene:
|
||||
scene.queue_free()
|
||||
if ResourceLoader.exists(path) == false:
|
||||
return
|
||||
var packed_scene : PackedScene = load(path)
|
||||
render_scene(path, packed_scene)
|
||||
|
||||
|
||||
func render_scene(path: String,packed : PackedScene):
|
||||
scene = packed.instantiate()
|
||||
subview.add_child(scene)
|
||||
|
||||
var bb = get_bounding_box(scene)
|
||||
subview.size = Vector2(max(bb.size.x,bb.size.y),max(bb.size.x,bb.size.y))
|
||||
|
||||
camera.position = bb.position * Vector2(0.5,0.5)
|
||||
|
||||
var vtexture : ViewportTexture = subview.get_texture()
|
||||
texture = vtexture
|
||||
|
||||
|
||||
func get_bounding_box(root: Node2D) -> Rect2:
|
||||
var rect := Rect2();
|
||||
var children := root.get_children();
|
||||
while children:
|
||||
var child = children.pop_back();
|
||||
children.append_array(child.get_children());
|
||||
|
||||
if child.has_method('get_rect') and child.has_method('to_global'):
|
||||
var child_rect := child.get_rect() as Rect2;
|
||||
child_rect.position = child.to_global(child_rect.position);
|
||||
rect = rect.merge(child_rect);
|
||||
|
||||
return rect;
|
||||
|
|
@ -0,0 +1 @@
|
|||
uid://c3cgpwy1qaeww
|
||||
Loading…
Add table
Add a link
Reference in a new issue