ui stuffs

This commit is contained in:
Leinadix 2025-09-18 17:37:35 +02:00
parent fe06ed5f96
commit 65423358fd
5 changed files with 2444 additions and 1049 deletions

File diff suppressed because it is too large Load diff

View file

@ -10,6 +10,7 @@ using UnityEngine.UIElements;
using static UnityEngine.GraphicsBuffer; using static UnityEngine.GraphicsBuffer;
using static UnityEngine.UI.GridLayoutGroup; using static UnityEngine.UI.GridLayoutGroup;
[ExecuteAlways] [ExecuteAlways]
public class GameManager : MonoBehaviour public class GameManager : MonoBehaviour
{ {
@ -18,7 +19,7 @@ public class GameManager : MonoBehaviour
public Transform NodeParent; public Transform NodeParent;
public GameObject NodePrefab; public GameObject NodePrefab;
public Player players; public List<Player> players;
public int currentPlayer = -1; public int currentPlayer = -1;
public Node pressedNode = null; public Node pressedNode = null;
@ -42,6 +43,7 @@ public class GameManager : MonoBehaviour
public ActionType type; public ActionType type;
public int nodeFromId; public int nodeFromId;
public int nodeToId; public int nodeToId;
public int amount;
public int player; public int player;
} }
@ -115,7 +117,7 @@ public class GameManager : MonoBehaviour
} }
public List<Node> GetNodes() => NodeParent.GetComponentsInChildren<Node>().ToList(); public List<Node> GetNodes() => NodeParent.GetComponentsInChildren<Node>().ToList();
public List<Connection> GetConnections() => ConnectionParent?.GetComponentsInChildren<Connection>().ToList() ?? new(); public List<Connection> GetConnections() => ConnectionParent != null ? ConnectionParent.GetComponentsInChildren<Connection>()?.ToList() ?? new() : new();
public void ExecuteRoundEnd() public void ExecuteRoundEnd()
{ {
@ -133,16 +135,24 @@ public class GameManager : MonoBehaviour
Node nodeTo = GetNodes().Find(n => n.id == action.nodeToId); Node nodeTo = GetNodes().Find(n => n.id == action.nodeToId);
Node nodeFrom = GetNodes().Find(n => n.id == action.nodeFromId); Node nodeFrom = GetNodes().Find(n => n.id == action.nodeFromId);
Connection con = GetConnections().Find(c => (c.nodeA == nodeTo && c.nodeB == nodeFrom) || (c.nodeA == nodeFrom && c.nodeB == nodeTo)); Connection con = GetConnections().Find(c => (c.nodeA == nodeTo && c.nodeB == nodeFrom) || (c.nodeA == nodeFrom && c.nodeB == nodeTo));
Player p = players.Find(p => (p.id == action.player));
bool hostile = nodeTo.Owner != action.player; bool hostile = nodeTo.Owner != action.player;
switch (action.type) switch (action.type)
{ {
case ActionType.MOVE_UNITS: case ActionType.MOVE_UNITS:
if (p.energy < 1)
{
Debug.Log("Not enough energy");
return;
}
p.energy -= 1;
switch (con.state) switch (con.state)
{ {
case Connection.BuildState.EMPTY: case Connection.BuildState.EMPTY:
// Build Connection // Build Connection
con.state = Connection.BuildState.CONSTRUCTING; con.state = Connection.BuildState.CONSTRUCTING;
Debug.Log("Starting construction from " + nodeTo.id + " to " + nodeFrom.id); Debug.Log("Starting construction from " + nodeTo.id + " to " + nodeFrom.id);
return; return;
@ -173,10 +183,24 @@ public class GameManager : MonoBehaviour
if (hostile) if (hostile)
{ {
Debug.Log("Attacking hostile units at " + nodeFrom.id); Debug.Log("Attacking hostile units at " + nodeFrom.id);
int actualAmount = action.amount + Math.Min(0, nodeFrom.Units - action.amount);
nodeFrom.Units -= actualAmount;
var unitDiff = actualAmount - nodeFrom.Units;
nodeTo.Units -= actualAmount;
if (unitDiff == 0)
{
nodeTo.Owner = -1;
} else if (unitDiff > 0)
{
nodeTo.Owner = p.id;
}
} }
else else
{ {
Debug.Log("Moving units from " + nodeTo.id + " to " + nodeFrom.id); Debug.Log("Moving units from " + nodeTo.id + " to " + nodeFrom.id);
int actualAmount = action.amount + Math.Min(0, nodeFrom.Units - action.amount);
nodeFrom.Units -= actualAmount;
nodeTo.Units += actualAmount;
} }
return; return;
@ -187,6 +211,12 @@ public class GameManager : MonoBehaviour
case ActionType.DESTRUCT_CON: case ActionType.DESTRUCT_CON:
if (!hostile) if (!hostile)
{ {
if (p.energy < 1)
{
Debug.Log("Not enough energy");
return;
}
p.energy -= 1;
Debug.Log("Starten deconstruction from " + nodeTo.id + " to " + nodeFrom.id); Debug.Log("Starten deconstruction from " + nodeTo.id + " to " + nodeFrom.id);
con.state = Connection.BuildState.DECONSTRUCTING; con.state = Connection.BuildState.DECONSTRUCTING;
} }
@ -197,6 +227,12 @@ public class GameManager : MonoBehaviour
return; return;
case ActionType.EXPLODE_CON: case ActionType.EXPLODE_CON:
if (p.energy < 2)
{
Debug.Log("Not enough energy");
return;
}
p.energy -= 2;
Debug.Log("Exploding connection from " + nodeTo.id + " to " + nodeFrom.id); Debug.Log("Exploding connection from " + nodeTo.id + " to " + nodeFrom.id);
con.state = Connection.BuildState.EMPTY; con.state = Connection.BuildState.EMPTY;
return; return;

View file

@ -46,7 +46,7 @@ public class Node : MonoBehaviour
void Update() void Update()
{ {
unitText.enabled = hovered; unitText.enabled = hovered;
unitText.text = Nachos.ToString(); unitText.text = Units.ToString();
unitText.transform.forward = Camera.main.transform.forward; unitText.transform.forward = Camera.main.transform.forward;
UpdateColor(); UpdateColor();
UpdateTransform(); UpdateTransform();

View file

@ -1,32 +1,20 @@
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
public class Player : MonoBehaviour public class Player
{ {
/** Possible Moves: /** Possible Moves:
* - NodeA to NodeB (connection built): move Units (will attack if NodeB is hostile; cant traverse multiple unclaimed nodes) * - NodeA to NodeB (connection built): move Units (will attack if NodeB is hostile; cant traverse multiple unclaimed nodes)
* - NodeA to NodeB (connection empty): build connection (-1 energy, takes 1 round) * - NodeA to NodeB (connection empty): build connection (-1 energy, takes 1 round)
* - NodeA to NodeB (connection under de/-construction): intervene by attacking (will destroy connection if succesfull) * - NodeA to NodeB (connection under de/-construction): intervene by attacking (will destroy connection if succesfull)
* - Click connection: Option to Destruct (-1 energy, takes 1 round) or Blast (-2 energy, immediately) Connection * - Click connection: Option to Destruct (-1 energy, takes 1 round) or Blast (-2 energy, immediately) Connection <- blast ist schlecht weil problem
* *
* *
*/ */
public int id; public int id;
public int energyLeft; public int energy;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
}
// Update is called once per frame
void Update()
{
}
public List<Node> GetOwnedNodes() => GameManager.Instance.GetNodes().FindAll(n => n.Owner == this.id); public List<Node> GetOwnedNodes() => GameManager.Instance.GetNodes().FindAll(n => n.Owner == this.id);
} }

File diff suppressed because one or more lines are too long