functional card/row edit and drag

This commit is contained in:
2024-04-23 23:31:42 -05:00
parent 8e01e9cb9b
commit 56dcbb62af
29 changed files with 674 additions and 48 deletions

36
card.cs
View File

@@ -1,4 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using Godot;
using Microsoft.VisualBasic;
public partial class card : Panel
{
@@ -150,11 +155,40 @@ public partial class card : Panel
{
this.GetParentOfType<game>().EditCardInMenu(this);
}
//TODO need to completely rework this
public static card MakeCard(SceneTree tree)
{
var scene = GD.Load<PackedScene>("res://card.tscn");
var c = scene.Instantiate<card>();
c.CardId = tree.GetUnusedCardId();
string[] ids = {};
if (Context is CardMakerContext cme)
ids = cme.Ids.ToArray();
c.CardId = tree.GetUnusedCardId(ids);
if (Context is CardMakerContext cme2)
cme2.AddNewId(c.CardId);
return c;
}
public class CardMakerContext : IDisposable
{
private readonly SceneTree Tree;
private readonly List<string> NewCards = new();
public IEnumerable<string> Ids => NewCards;
public void AddNewId(string id) => NewCards.Add(id);
public CardMakerContext(SceneTree tree)
{
Tree = tree;
}
public void Dispose()
{
card.Context = null;
}
}
private static CardMakerContext Context = null;
public static CardMakerContext MakeContext(SceneTree tree)
{
if (Context is not null)
return null;
Context = new(tree);
return Context;
}
}