Basics
This commit is contained in:
parent
c8956dc38b
commit
0e9e17cfdc
20 changed files with 267 additions and 1 deletions
18
addons/pvzadventure/scripts/AdventureEditor.cs
Normal file
18
addons/pvzadventure/scripts/AdventureEditor.cs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
using Godot;
|
||||
|
||||
[Tool]
|
||||
public partial class AdventureEditor : MarginContainer
|
||||
{
|
||||
public AdventureLevelResource editedResource;
|
||||
public string editedPath;
|
||||
|
||||
public void Reload()
|
||||
{
|
||||
editedResource = ResourceLoader.Load<AdventureLevelResource>(editedPath);
|
||||
}
|
||||
|
||||
public void Save()
|
||||
{
|
||||
ResourceSaver.Save(editedResource, editedPath);
|
||||
}
|
||||
}
|
||||
1
addons/pvzadventure/scripts/AdventureEditor.cs.uid
Normal file
1
addons/pvzadventure/scripts/AdventureEditor.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://dkgxtig5fwdgi
|
||||
53
addons/pvzadventure/scripts/FileButton.cs
Normal file
53
addons/pvzadventure/scripts/FileButton.cs
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
using Godot;
|
||||
|
||||
[Tool]
|
||||
public partial class FileButton : MenuButton
|
||||
{
|
||||
const int NEWFILE = 0;
|
||||
const int SAVEFILE = 1;
|
||||
const int OPENFILE = 2;
|
||||
private AdventureEditor editor;
|
||||
private FileDialog dialog;
|
||||
private int chosenOption = -1;
|
||||
public override void _Ready()
|
||||
{
|
||||
editor = (AdventureEditor)FindParent("AdventureEditor");
|
||||
dialog = GetNode<FileDialog>("FileDialog");
|
||||
|
||||
GetPopup().IndexPressed += OnIndexPressed;
|
||||
dialog.FileSelected += OnFileSelected;
|
||||
}
|
||||
|
||||
private void OnIndexPressed(long index)
|
||||
{
|
||||
chosenOption = (int)index;
|
||||
if (index == NEWFILE)
|
||||
{
|
||||
editor.editedResource = new AdventureLevelResource();
|
||||
dialog.PopupCentered();
|
||||
dialog.FileMode = FileDialog.FileModeEnum.SaveFile;
|
||||
}
|
||||
else if (index == SAVEFILE)
|
||||
{
|
||||
editor.Save();
|
||||
}
|
||||
else if (index == OPENFILE)
|
||||
{
|
||||
dialog.PopupCentered();
|
||||
dialog.FileMode = FileDialog.FileModeEnum.OpenFile;
|
||||
}
|
||||
}
|
||||
private void OnFileSelected(string path)
|
||||
{
|
||||
editor.editedPath = path;
|
||||
if (chosenOption == NEWFILE)
|
||||
{
|
||||
editor.Save();
|
||||
}
|
||||
else if (chosenOption == OPENFILE)
|
||||
{
|
||||
editor.Reload();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
1
addons/pvzadventure/scripts/FileButton.cs.uid
Normal file
1
addons/pvzadventure/scripts/FileButton.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://binuuattefn7d
|
||||
Loading…
Add table
Add a link
Reference in a new issue