From e00259cd31abd5aa4168c5afb72e3a59139ce60a Mon Sep 17 00:00:00 2001 From: Nicola Date: Sat, 9 May 2026 09:38:34 +0200 Subject: [PATCH] Added missing Symbol to the game, Improved move and explore logic, added map refresh for tiles. --- Assets/Images/Items/BronzeGearSymbol.png | Bin 0 -> 513 bytes .../Images/Items/BronzeGearSymbol.png.import | 40 +++++++++++++++++ Scenes/Game.tscn | 5 ++- Scripts/Crafting/ItemData.cs | 18 ++++++++ Scripts/DSL/Nodes/CraftNode.cs | 2 +- Scripts/DSL/Nodes/ExploreNode.cs | 5 +-- Scripts/DSL/Nodes/MoveNode.cs | 3 +- Scripts/Helpers/GameData.cs | 2 +- Scripts/Helpers/UIHandler.cs | 10 ++++- Scripts/Research/ResearchList.cs | 28 ++---------- Scripts/Robot/Robot.cs | 1 - Scripts/WorldGeneration/Map.cs | 41 ++++++++++++++++++ Scripts/WorldGeneration/Tile.cs | 7 +++ 13 files changed, 127 insertions(+), 35 deletions(-) create mode 100644 Assets/Images/Items/BronzeGearSymbol.png create mode 100644 Assets/Images/Items/BronzeGearSymbol.png.import diff --git a/Assets/Images/Items/BronzeGearSymbol.png b/Assets/Images/Items/BronzeGearSymbol.png new file mode 100644 index 0000000000000000000000000000000000000000..5027d3e6e3b3c6ff1915516b6ef8527e6b78f72f GIT binary patch literal 513 zcmV+c0{;DpP)Px$yGcYrR9J=WRy%6LKoEVal|a~}aN#?oGK4e+Um>J1xX%$xNNy0)7<>;Ck}J3| zAt`+g)iwglo-|%XTF>lmEOqg#v}oqd+xbbr1^*qYfiJbe6*UPypNue{i~s;yYgMz&S8kbH#~W1aTZ2^)7Otfk3+F^)6^lq3n;!IgSeNfiLK-ELX3IF3o02u@jPXx~1drfknx<*NCzJ>aRQ zt89w9so}Hx1`SqmYhW|rS~}fsmo}S?vjiMp6!CZU5()Jb{WyE26o`oRlS*KB`R@y* zVD0!C-)g>nl4D(lkY$=ZK;Rhr_`eBV-X70#y`6+0E_@(&lLa_5 0) { - options.AddItem(item.GetReadableName()); + options.AddItem(item.GetCraftingDisplay()); } } if (selectedItem != null) diff --git a/Scripts/DSL/Nodes/ExploreNode.cs b/Scripts/DSL/Nodes/ExploreNode.cs index 2b5f1da..b5320f0 100644 --- a/Scripts/DSL/Nodes/ExploreNode.cs +++ b/Scripts/DSL/Nodes/ExploreNode.cs @@ -41,15 +41,14 @@ public class ExploreNode : ProgramNode Vector3 target = pathPoints[0] - startPosition; float distance = target.Length(); - if (distance < 0.1f) + if (distance < 0.1f * Mathf.Sqrt(GameData.robotSpeed)) { robot.Position = pathPoints[0]; Vector3I mapIndex = Pathfinding.GetClosestStartPoint(robot.Position); Tile tile = GameData.map[mapIndex.Y].tiles[mapIndex.X, mapIndex.Z]; if (!tile.wasVisited) { - tile.wasVisited = true; - tile.ContentNode.Visible = true; + tile.VisitTile(); } pathPoints.Remove(pathPoints[0]); if (pathPoints.Count <= 0) diff --git a/Scripts/DSL/Nodes/MoveNode.cs b/Scripts/DSL/Nodes/MoveNode.cs index 97ab613..61bda06 100644 --- a/Scripts/DSL/Nodes/MoveNode.cs +++ b/Scripts/DSL/Nodes/MoveNode.cs @@ -30,8 +30,7 @@ public class MoveNode : ProgramNode Tile tile = GameData.map[mapIndex.Y].tiles[mapIndex.X, mapIndex.Z]; if (!tile.wasVisited) { - tile.wasVisited = true; - tile.ContentNode.Visible = true; + tile.VisitTile(); } pathPoints.Remove(pathPoints[0]); if (pathPoints.Count <= 0) diff --git a/Scripts/Helpers/GameData.cs b/Scripts/Helpers/GameData.cs index 58a68bc..1131dd0 100644 --- a/Scripts/Helpers/GameData.cs +++ b/Scripts/Helpers/GameData.cs @@ -4,7 +4,7 @@ using Godot; public partial class GameData { - public static bool DEBUGMODE = true; + public static bool DEBUGMODE = false; public static Random rand = new Random(seed); public static Layer[] map; //Current layer the player wants to see diff --git a/Scripts/Helpers/UIHandler.cs b/Scripts/Helpers/UIHandler.cs index 0508db1..46dec71 100644 --- a/Scripts/Helpers/UIHandler.cs +++ b/Scripts/Helpers/UIHandler.cs @@ -16,6 +16,7 @@ public partial class UIHandler : Control [Export] Control uiContent; [Export] PanelContainer menu; [Export] PanelContainer inventory; + [Export] ResearchList researchList; bool receivedRobotJumpSignal = false; public override void _Ready() @@ -46,6 +47,7 @@ public partial class UIHandler : Control if (Input.IsActionJustPressed("menu")) HandleMenuButton(); if (Input.IsActionJustPressed("robot_list")) HandleRobotListButton(); if (Input.IsActionJustPressed("inventory")) HandleInventoryButton(); + if (Input.IsActionJustPressed("research")) HandleResearchButton(); } @@ -57,7 +59,7 @@ public partial class UIHandler : Control public void HandleMapButton() { OpenUIElement(map); - map.ShowMap(); + if(map.Visible) map.ShowMap(); } public void HandleRobotListButton() @@ -71,6 +73,12 @@ public partial class UIHandler : Control OpenUIElement(inventory); } + public void HandleResearchButton() + { + OpenUIElement(researchList); + if(researchList.Visible) researchList.SetupGraph(); + } + public void DisplayStats() { FPS.Text = Engine.GetFramesPerSecond().ToString() + " FPS"; diff --git a/Scripts/Research/ResearchList.cs b/Scripts/Research/ResearchList.cs index e2ef7f1..e490af8 100644 --- a/Scripts/Research/ResearchList.cs +++ b/Scripts/Research/ResearchList.cs @@ -7,16 +7,12 @@ public partial class ResearchList : PanelContainer { [Export] private GraphEdit researchGraph; - private const float StartXDivisor = 32f; - private const float StartYDivisor = 4f; - private const float NodeSpacingMultiplier = 10f; - private List reloadKeys = new List(); public override void _Ready() { RecalculateResearchStates(); - SetupGraph(); + if(Visible) SetupGraph(); } public void SetupGraph() @@ -25,6 +21,7 @@ public partial class ResearchList : PanelContainer ClearGraph(); CreateResearchNodes(); CreateResearchConnections(); + researchGraph.ArrangeNodes(); } private void ClearGraph() @@ -111,7 +108,6 @@ public partial class ResearchList : PanelContainer { Name = id, Title = id, - PositionOffset = GetNodePosition(texture), SelfModulate = stateColor }; @@ -131,24 +127,6 @@ public partial class ResearchList : PanelContainer return node; } - private Vector2 GetNodePosition(Texture2D texture) - { - Vector2 viewportSize = GetViewport().GetVisibleRect().Size; - - float textureWidth = texture?.GetWidth() ?? 64f; - - Vector2 startPosition = new Vector2( - viewportSize.X / StartXDivisor, - viewportSize.Y / StartYDivisor - ); - - float xOffset = - GameData.availableResearch.Count * -textureWidth + - researchGraph.GetChildCount() * textureWidth * NodeSpacingMultiplier; - - return startPosition + new Vector2(xOffset, 0); - } - private void OnResearchPressed(string id) { GameData.availableResearch[id].state = ResearchState.RESEARCHED; @@ -208,4 +186,4 @@ public partial class ResearchList : PanelContainer _ => Colors.Red }; } -} \ No newline at end of file +} diff --git a/Scripts/Robot/Robot.cs b/Scripts/Robot/Robot.cs index bda6840..f735d86 100644 --- a/Scripts/Robot/Robot.cs +++ b/Scripts/Robot/Robot.cs @@ -49,5 +49,4 @@ public partial class Robot : Node3D isExecuting = true; currentNode = nodes[0]; } - } diff --git a/Scripts/WorldGeneration/Map.cs b/Scripts/WorldGeneration/Map.cs index a01ad51..db269ab 100644 --- a/Scripts/WorldGeneration/Map.cs +++ b/Scripts/WorldGeneration/Map.cs @@ -1,9 +1,12 @@ using Godot; using System; +using System.Collections.Generic; public partial class Map : PanelContainer { [Export] GridContainer grid; + private HashSet handledTiles = new HashSet(); + private Dictionary textureMap = new Dictionary(); // Called when the node enters the scene tree for the first time. public override void _Ready() { @@ -76,6 +79,15 @@ public partial class Map : PanelContainer texture.TooltipText = "Not explored"; } + + textureMap[tiles[x, z]] = texture; + + if (!handledTiles.Contains(tiles[x, z])) + { + tiles[x, z].OnTileVisited += OnTileVisited; + handledTiles.Add(tiles[x, z]); + } + texture.SizeFlagsHorizontal = SizeFlags.ExpandFill; texture.SizeFlagsVertical = SizeFlags.ExpandFill; texture.StretchMode = TextureRect.StretchModeEnum.Scale; @@ -86,6 +98,35 @@ public partial class Map : PanelContainer } } + private void OnTileVisited(object sender, EventArgs e) + { + Tile tile = sender as Tile; + + if (tile == null) + return; + + if (textureMap.TryGetValue(tile, out TextureRect texture)) + { + UpdateMap(tile, texture); + } + } + + public void UpdateMap(Tile tile, TextureRect texture) + { + if (!IsInstanceValid(texture)) return; + + if (tile.containsResource) + { + texture.Texture = ResourceDistributor.resources[tile.resource.name]; + texture.TooltipText = tile.resource.item.GetReadableName() + $"\r(X: {tile.GridPosition.X},Y: {GameData.currentLayer},Z: {tile.GridPosition.Y})"; + } + else + { + texture.Texture = GenerateTexture(32, new Color(0, 0, 0, 0)); + texture.TooltipText = ""; + } + } + public Texture2D GenerateTexture(int size, Color fillColor) { diff --git a/Scripts/WorldGeneration/Tile.cs b/Scripts/WorldGeneration/Tile.cs index 80fe4ad..43a3b5e 100644 --- a/Scripts/WorldGeneration/Tile.cs +++ b/Scripts/WorldGeneration/Tile.cs @@ -14,6 +14,7 @@ public partial class Tile public bool containsLight, containsDecoration, containsResource; public GameResource resource; public bool wasVisited; + public event EventHandler OnTileVisited; public void SetMeshes(Dictionary tileMeshes) @@ -138,4 +139,10 @@ public partial class Tile } } } + + public void VisitTile() + { + wasVisited = true; + OnTileVisited?.Invoke(this, EventArgs.Empty); + } }