add overlay cycling ui #6
This commit is contained in:
		
							parent
							
								
									4261d7762e
								
							
						
					
					
						commit
						156303ba99
					
				@ -1,4 +1,4 @@
 | 
			
		||||
[gd_scene load_steps=11 format=2]
 | 
			
		||||
[gd_scene load_steps=13 format=2]
 | 
			
		||||
 | 
			
		||||
[ext_resource path="res://nodes/grid.tscn" type="PackedScene" id=1]
 | 
			
		||||
[ext_resource path="res://nodes/grid_cursor.tscn" type="PackedScene" id=2]
 | 
			
		||||
@ -7,8 +7,10 @@
 | 
			
		||||
[ext_resource path="res://nodes/interaction_modes/interaction_mode.tscn" type="PackedScene" id=5]
 | 
			
		||||
[ext_resource path="res://nodes/ui/build_mode_ui.tscn" type="PackedScene" id=6]
 | 
			
		||||
[ext_resource path="res://nodes/interaction_modes/build_mode.tscn" type="PackedScene" id=7]
 | 
			
		||||
[ext_resource path="res://nodes/ui/overlays UI.tscn" type="PackedScene" id=8]
 | 
			
		||||
[ext_resource path="res://nodes/ui/mode_selection_ui.tscn" type="PackedScene" id=9]
 | 
			
		||||
[ext_resource path="res://nodes/overlays.tscn" type="PackedScene" id=10]
 | 
			
		||||
[ext_resource path="res://resources/overlays/overlays.tres" type="Resource" id=11]
 | 
			
		||||
 | 
			
		||||
[sub_resource type="Curve" id=1]
 | 
			
		||||
_data = [ Vector2( 0, 0 ), 0.0, 5.0, 0, 0, Vector2( 0.5, 1 ), 0.0, 0.0, 0, 0, Vector2( 1, 0 ), -4.0, 0.0, 0, 0 ]
 | 
			
		||||
@ -33,6 +35,7 @@ _gridPath = NodePath("../../World Grid")
 | 
			
		||||
_cursorPath = NodePath("../../Cursor")
 | 
			
		||||
 | 
			
		||||
[node name="Overlays" parent="." instance=ExtResource( 10 )]
 | 
			
		||||
_overlaysResource = ExtResource( 11 )
 | 
			
		||||
_worldGridPath = NodePath("../World Grid")
 | 
			
		||||
 | 
			
		||||
[node name="UI" type="Control" parent="."]
 | 
			
		||||
@ -47,6 +50,9 @@ _buildModePath = NodePath("../../Interaction Modes/Build Mode")
 | 
			
		||||
 | 
			
		||||
[node name="Mode Selection" parent="UI" instance=ExtResource( 9 )]
 | 
			
		||||
 | 
			
		||||
[node name="Overlays UI" parent="UI" instance=ExtResource( 8 )]
 | 
			
		||||
_overlaysPath = NodePath("../../Overlays")
 | 
			
		||||
 | 
			
		||||
[connection signal="OnPauseChanged" from="Clock" to="UI/Debug" method="_on_Clock_OnPauseChanged"]
 | 
			
		||||
[connection signal="OnTick" from="Clock" to="World Grid" method="_on_Clock_OnTick"]
 | 
			
		||||
[connection signal="OnTick" from="Clock" to="UI/Debug" method="_on_Clock_OnTick"]
 | 
			
		||||
@ -55,7 +61,8 @@ _buildModePath = NodePath("../../Interaction Modes/Build Mode")
 | 
			
		||||
[connection signal="OnModeEntered" from="Interaction Modes/Build Mode" to="Interaction Modes" method="_on_Build_Mode_OnModeEntered"]
 | 
			
		||||
[connection signal="OnModeEntered" from="Interaction Modes/Build Mode" to="UI/Mode Selection" method="EnableBuildMode"]
 | 
			
		||||
[connection signal="OnModeExited" from="Interaction Modes/Build Mode" to="Interaction Modes" method="_on_Build_Mode_OnModeExited"]
 | 
			
		||||
[connection signal="OnModeExited" from="Interaction Modes/Build Mode" to="UI/Mode Selection" method="Enable"]
 | 
			
		||||
[connection signal="SelectedTileTypeChanged" from="Interaction Modes/Build Mode" to="UI/Build Mode" method="UpdateButtonToggleState"]
 | 
			
		||||
[connection signal="OverlayCycled" from="Overlays" to="UI/Overlays UI" method="UpdateOverlayText"]
 | 
			
		||||
[connection signal="OnExit" from="UI/Build Mode" to="Interaction Modes" method="Reset"]
 | 
			
		||||
[connection signal="OnExit" from="UI/Build Mode" to="UI/Mode Selection" method="Enable"]
 | 
			
		||||
[connection signal="BuildModeEnabled" from="UI/Mode Selection" to="Interaction Modes/Build Mode" method="Enable"]
 | 
			
		||||
 | 
			
		||||
@ -14,6 +14,6 @@ margin_left = 2.0
 | 
			
		||||
margin_top = 562.0
 | 
			
		||||
margin_right = 38.0
 | 
			
		||||
margin_bottom = 598.0
 | 
			
		||||
text = "Build Mode"
 | 
			
		||||
text = "[B] Build Mode"
 | 
			
		||||
 | 
			
		||||
[connection signal="pressed" from="Build Mode" to="." method="EnableBuildMode"]
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										18
									
								
								half-earth/nodes/ui/overlays UI.tscn
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								half-earth/nodes/ui/overlays UI.tscn
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,18 @@
 | 
			
		||||
[gd_scene load_steps=2 format=2]
 | 
			
		||||
 | 
			
		||||
[ext_resource path="res://scripts/ui/OverlaysUI.cs" type="Script" id=1]
 | 
			
		||||
 | 
			
		||||
[node name="Overlays UI" type="Node"]
 | 
			
		||||
script = ExtResource( 1 )
 | 
			
		||||
_cycleOverlayButtonPath = NodePath("Button")
 | 
			
		||||
 | 
			
		||||
[node name="Button" type="Button" parent="."]
 | 
			
		||||
anchor_top = 1.0
 | 
			
		||||
anchor_bottom = 1.0
 | 
			
		||||
margin_top = -90.0
 | 
			
		||||
margin_right = 42.0
 | 
			
		||||
margin_bottom = -52.0
 | 
			
		||||
grow_vertical = 0
 | 
			
		||||
text = "[Tab] Cycle Overlay"
 | 
			
		||||
 | 
			
		||||
[connection signal="pressed" from="Button" to="." method="CycleOverlay"]
 | 
			
		||||
							
								
								
									
										9
									
								
								half-earth/resources/overlays/overlays.tres
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								half-earth/resources/overlays/overlays.tres
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,9 @@
 | 
			
		||||
[gd_resource type="Resource" load_steps=4 format=2]
 | 
			
		||||
 | 
			
		||||
[ext_resource path="res://scripts/overlays/OverlayCollection.cs" type="Script" id=1]
 | 
			
		||||
[ext_resource path="res://resources/overlays/no_overlay.tres" type="Resource" id=2]
 | 
			
		||||
[ext_resource path="res://resources/overlays/heat_overlay.tres" type="Resource" id=3]
 | 
			
		||||
 | 
			
		||||
[resource]
 | 
			
		||||
script = ExtResource( 1 )
 | 
			
		||||
_resources = [ ExtResource( 2 ), ExtResource( 3 ) ]
 | 
			
		||||
@ -5,7 +5,6 @@
 | 
			
		||||
[resource]
 | 
			
		||||
script = ExtResource( 1 )
 | 
			
		||||
Name = "Developed"
 | 
			
		||||
BuildLabel = "[D]eveloped"
 | 
			
		||||
Key = 68
 | 
			
		||||
Color = Color( 0.372549, 0.372549, 0.372549, 1 )
 | 
			
		||||
HeatGeneration = 0.4
 | 
			
		||||
 | 
			
		||||
@ -5,4 +5,4 @@
 | 
			
		||||
 | 
			
		||||
[resource]
 | 
			
		||||
script = ExtResource( 1 )
 | 
			
		||||
_tileTypeResources = [ ExtResource( 2 ) ]
 | 
			
		||||
_resources = [ ExtResource( 2 ) ]
 | 
			
		||||
 | 
			
		||||
@ -5,7 +5,6 @@
 | 
			
		||||
[resource]
 | 
			
		||||
script = ExtResource( 1 )
 | 
			
		||||
Name = "Wild"
 | 
			
		||||
BuildLabel = "[W]ild"
 | 
			
		||||
Key = 87
 | 
			
		||||
Color = Color( 0, 0.545098, 0.0196078, 1 )
 | 
			
		||||
HeatGeneration = -0.2
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										33
									
								
								half-earth/scripts/ReadOnlyResourceList.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								half-earth/scripts/ReadOnlyResourceList.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,33 @@
 | 
			
		||||
using Godot;
 | 
			
		||||
using System.Collections;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
 | 
			
		||||
public class ReadOnlyResourceList<T> : Resource, IReadOnlyList<T> where T : Resource
 | 
			
		||||
{
 | 
			
		||||
    [Export]
 | 
			
		||||
    private List<Resource> _resources = new List<Resource>();
 | 
			
		||||
    private List<T> Collection
 | 
			
		||||
    {
 | 
			
		||||
        get
 | 
			
		||||
        {
 | 
			
		||||
            if (_collection != null)
 | 
			
		||||
                return _collection;
 | 
			
		||||
 | 
			
		||||
            _collection = new List<T>();
 | 
			
		||||
            foreach (var resource in _resources)
 | 
			
		||||
            {
 | 
			
		||||
                _collection.Add((T)resource);
 | 
			
		||||
            }
 | 
			
		||||
            return _collection;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    private List<T> _collection = null;
 | 
			
		||||
 | 
			
		||||
    public T this[int index] => Collection[index];
 | 
			
		||||
 | 
			
		||||
    public int Count => Collection.Count;
 | 
			
		||||
 | 
			
		||||
    public IEnumerator<T> GetEnumerator() => Collection.GetEnumerator();
 | 
			
		||||
 | 
			
		||||
    IEnumerator IEnumerable.GetEnumerator() => Collection.GetEnumerator();
 | 
			
		||||
}
 | 
			
		||||
@ -2,5 +2,6 @@ using Godot;
 | 
			
		||||
 | 
			
		||||
public abstract class Overlay : Resource
 | 
			
		||||
{
 | 
			
		||||
    public string Name => GetType().ToString();
 | 
			
		||||
    public abstract void Apply(Tile tile, ShaderMaterial material);
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										3
									
								
								half-earth/scripts/overlays/OverlayCollection.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								half-earth/scripts/overlays/OverlayCollection.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,3 @@
 | 
			
		||||
public class OverlayCollection : ReadOnlyResourceList<Overlay>
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
@ -3,14 +3,16 @@ using System;
 | 
			
		||||
 | 
			
		||||
public class Overlays : Node
 | 
			
		||||
{
 | 
			
		||||
    [Signal]
 | 
			
		||||
    delegate void OverlayCycled(Overlay overlay);
 | 
			
		||||
 | 
			
		||||
    [Export]
 | 
			
		||||
    private KeyList _cycleOverlayKey;
 | 
			
		||||
 | 
			
		||||
    [Export]
 | 
			
		||||
    private Resource[] _overlayResources;
 | 
			
		||||
    private Overlay[] _overlays;
 | 
			
		||||
    [Export] private Resource _overlaysResource;
 | 
			
		||||
    public Overlay Current => _overlays[_overlayIdx];
 | 
			
		||||
    private OverlayCollection _overlays;
 | 
			
		||||
    private int _overlayIdx = 0;
 | 
			
		||||
    private Overlay Current => _overlays[_overlayIdx];
 | 
			
		||||
 | 
			
		||||
    [Export]
 | 
			
		||||
    private Resource _tileGridResource;
 | 
			
		||||
@ -22,12 +24,8 @@ public class Overlays : Node
 | 
			
		||||
 | 
			
		||||
    public override void _Ready()
 | 
			
		||||
    {
 | 
			
		||||
        _overlays = (OverlayCollection)_overlaysResource;
 | 
			
		||||
        _tileGrid = (TileGrid)_tileGridResource;
 | 
			
		||||
        _overlays = new Overlay[_overlayResources.Length];
 | 
			
		||||
        for (int i = 0; i < _overlayResources.Length; i++)
 | 
			
		||||
        {
 | 
			
		||||
            _overlays[i] = (Overlay)_overlayResources[i];
 | 
			
		||||
        }
 | 
			
		||||
        _worldGrid = GetNode<WorldGrid>(_worldGridPath);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -60,9 +58,10 @@ public class Overlays : Node
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void CycleOverlay()
 | 
			
		||||
    public void CycleOverlay()
 | 
			
		||||
    {
 | 
			
		||||
        _overlayIdx++;
 | 
			
		||||
        _overlayIdx %= _overlays.Length;
 | 
			
		||||
        _overlayIdx %= _overlays.Count;
 | 
			
		||||
        EmitSignal(nameof(OverlayCycled), Current);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -5,8 +5,7 @@ public class TileType : Resource
 | 
			
		||||
    [Export]
 | 
			
		||||
    public string Name { get; private set; }
 | 
			
		||||
 | 
			
		||||
    [Export]
 | 
			
		||||
    public string BuildLabel { get; private set; }
 | 
			
		||||
    public string BuildLabel => $"[{Key}] {Name}";
 | 
			
		||||
 | 
			
		||||
    [Export]
 | 
			
		||||
    public KeyList Key { get; private set; }
 | 
			
		||||
@ -17,8 +16,5 @@ public class TileType : Resource
 | 
			
		||||
    [Export]
 | 
			
		||||
    public float HeatGeneration { get; private set; }
 | 
			
		||||
 | 
			
		||||
    public override string ToString()
 | 
			
		||||
    {
 | 
			
		||||
        return Name;
 | 
			
		||||
    }
 | 
			
		||||
    public override string ToString() => Name;
 | 
			
		||||
}
 | 
			
		||||
@ -1,46 +1,3 @@
 | 
			
		||||
using Godot;
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
 | 
			
		||||
public class TileTypeCollection : Resource, IReadOnlyList<TileType>
 | 
			
		||||
public class TileTypeCollection : ReadOnlyResourceList<TileType>
 | 
			
		||||
{
 | 
			
		||||
    [Export]
 | 
			
		||||
    private List<Resource> _tileTypeResources = new List<Resource>();
 | 
			
		||||
 | 
			
		||||
    private List<TileType> TileTypes
 | 
			
		||||
    {
 | 
			
		||||
        get
 | 
			
		||||
        {
 | 
			
		||||
            if (_tileTypes != null)
 | 
			
		||||
                return _tileTypes;
 | 
			
		||||
 | 
			
		||||
            _tileTypes = new List<TileType>();
 | 
			
		||||
 | 
			
		||||
            foreach (var resource in _tileTypeResources)
 | 
			
		||||
            {
 | 
			
		||||
                if (!(resource is TileType))
 | 
			
		||||
                    throw new InvalidCastException($"{resource} must be a {typeof(TileType)}");
 | 
			
		||||
 | 
			
		||||
                _tileTypes.Add((TileType)resource);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return _tileTypes;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    private List<TileType> _tileTypes = null;
 | 
			
		||||
 | 
			
		||||
    public TileType this[int index] => TileTypes[index];
 | 
			
		||||
 | 
			
		||||
    public int Count => TileTypes.Count;
 | 
			
		||||
 | 
			
		||||
    public IEnumerator<TileType> GetEnumerator()
 | 
			
		||||
    {
 | 
			
		||||
        return TileTypes.GetEnumerator();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    IEnumerator IEnumerable.GetEnumerator()
 | 
			
		||||
    {
 | 
			
		||||
        return TileTypes.GetEnumerator();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										36
									
								
								half-earth/scripts/ui/OverlaysUI.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								half-earth/scripts/ui/OverlaysUI.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,36 @@
 | 
			
		||||
using Godot;
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
 | 
			
		||||
public class OverlaysUI : Node
 | 
			
		||||
{
 | 
			
		||||
    [Export]
 | 
			
		||||
    private NodePath _cycleOverlayButtonPath;
 | 
			
		||||
    private Button _cycleOverlayButton;
 | 
			
		||||
 | 
			
		||||
    [Export]
 | 
			
		||||
    private NodePath _overlaysPath;
 | 
			
		||||
    private Overlays _overlays;
 | 
			
		||||
 | 
			
		||||
    private string _mainText;
 | 
			
		||||
 | 
			
		||||
    public override void _Ready()
 | 
			
		||||
    {
 | 
			
		||||
        base._Ready();
 | 
			
		||||
 | 
			
		||||
        _cycleOverlayButton = GetNode<Button>(_cycleOverlayButtonPath);
 | 
			
		||||
        _mainText = _cycleOverlayButton.Text;
 | 
			
		||||
 | 
			
		||||
        _overlays = GetNode<Overlays>(_overlaysPath);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void CycleOverlay()
 | 
			
		||||
    {
 | 
			
		||||
        _overlays.CycleOverlay();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void UpdateOverlayText(Overlay overlay)
 | 
			
		||||
    {
 | 
			
		||||
        _cycleOverlayButton.Text = $"{_mainText} ({_overlays.Current.Name})";
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user