basically function but needs a lot of refinement

This commit is contained in:
2024-04-23 03:24:23 -05:00
parent 3ac7bf33c4
commit d3beca8014
26 changed files with 985 additions and 345 deletions

109
game.cs
View File

@@ -36,10 +36,9 @@ public partial class game : Control
public override void _Ready()
{
var rows = this.GetAllDescendents<row>().ToArray();
for (int i = 0; i < 50; i++)
for (int i = 0; i < 20; i++)
{
var c = card.MakeCard(GetTree());
GD.Print(c.CardId);
c.CardName = $"Card {c.CardId}";
if (GD.RandRange(0, 1) == 1)
{
@@ -56,31 +55,26 @@ public partial class game : Control
PropogateCardSize();
}
// public override void _UnhandledInput(InputEvent @event)
// {
// if (@event is InputEventMouseButton iemb)
// {
// if (iemb.ButtonIndex == MouseButton.Right)
// {
// }
// }
// else if (@event is InputEventKey iek)
// {
// }
// }
public override void _UnhandledInput(InputEvent @event)
{
if (@event.IsActionPressed("OpenMenu"))
{
GetNode<settings_popup>("%SettingsPopup").Visible = true;
GetViewport().SetInputAsHandled();
}
}
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta)
{
}
public void SetContainerMinima()
{
var node = GetNode<VBoxContainer>("%RowContainer");
node.CustomMinimumSize = new Vector2(0, _CardSize.Y * node.GetChildCount());
// var node = GetNode<VBoxContainer>("%RowContainer");
// node.CustomMinimumSize = new Vector2(0, _CardSize.Y * node.GetChildCount());
}
public row GetRowById(string id)
=> GetTree().GetNodesInGroup("RowGroup").OfType<row>().FirstOrDefault(r => r.RowId == id);
=> GetTree().GetNodesInGroup("RowGroup").OfType<row>()
.FirstOrDefault(r => r.RowId == id);
public void AddRow(row row, string after = null)
{
if (after is not null)
@@ -118,49 +112,10 @@ public partial class game : Control
}
return c;
}
/// <summary>
///
/// </summary>
/// <param name="id"></param>
/// <param name="target_row">null to unassign card</param>
/// <returns>false if something goes wrong</returns>
// public bool MoveCard(string id, row target_row, float horizontal)
// {
// foreach (row r in Rows)
// {
// if (r.TryRemoveCard(id) is card c)
// {
// //add to row
// if (target_row is not null)
// {
// target_row.AddCard(c);
// return true;
// }
// //unassign
// else
// {
// AddUnassignedCard(c);
// return true;
// }
// }
// }
// if (RemoveUnassignedCard(id) is card cc)
// {
// //add to row
// if (target_row is not null)
// {
// target_row.AddCard(cc);
// return true;
// }
// //unassign
// else
// {
// AddUnassignedCard(cc);
// return true;
// }
// }
// return false;
// }
public void EditCardInMenu(card c)
{
GetNode<card_edit_popup>("%CardEditPopup").ActivateForCard(c);
}
public card ClaimCard(string id)
{
foreach (row r in Rows)
@@ -221,15 +176,25 @@ public partial class game : Control
var r = FindRow(rowId);
if (r is null)
throw new Exception($"row {r.RowId} not found");
if (!deleteCards)
{
var unassigned = GetNode("%UnassignedCardContainer");
foreach (var c in r.Cards.ToArray())
c.Reparent(unassigned);
}
//GetNode("%RowContainer").RemoveChild(r);
r.QueueFree();
}
public void CreateCard(string title = null, Image image = null)
public void CreateCard(string title = null, ImageWithMetadata image = null)
{
var scn = GD.Load<PackedScene>("res://card.tscn");
var c = scn.Instantiate() as card;
var c = card.MakeCard(GetTree());
if (!string.IsNullOrWhiteSpace(title))
c.CardName = title;
if (image is not null)
c.SetTexture(ImageTexture.CreateFromImage(image));
{
c.SetTexture(ImageTexture.CreateFromImage(image.Image));
c.SetStretchMode(image.StretchMode);
}
AddUnassignedCard(c);
}
public void CreateRow(Color? color = null, string title = null)
@@ -240,25 +205,27 @@ public partial class game : Control
r.RowText = title;
if (color is Color color1)
r.RowColor = color1;
AddRow(r);
}
public void RenameCard(string cardId, string newName)
{
FindCard(cardId).CardName = newName;
}
public void RenameRow(string rowId, string newTitle)
{
GetRowById(rowId).RowText = newTitle;
}
public void RecolorRow(string rowId, Color color)
{
GetRowById(rowId).RowColor = color;
}
public void ChangeCardImage(string cardId, Image image)
public void ChangeCardImage(string cardId, ImageWithMetadata image)
{
var c = FindCard(cardId);
if (c is null)
throw new Exception($"card {c.CardId} not found");
c.SetTexture(ImageTexture.CreateFromImage(image));
c.SetTexture(ImageTexture.CreateFromImage(image.Image));
c.SetStretchMode(image.StretchMode);
}
#endregion //Commands
}