mirror of
https://codeberg.org/Ikatono/TierMaker.git
synced 2025-10-28 20:45:35 -05:00
functional card/row edit and drag
This commit is contained in:
36
card.cs
36
card.cs
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user