Extremely simple building (placement of workbenches).

main
Martin Felis 2024-01-04 16:41:26 +01:00
parent 60000a8570
commit 7bdda54112
8 changed files with 1203 additions and 20 deletions

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

14
entities/Workbench.cs Normal file
View File

@ -0,0 +1,14 @@
public class Workbench : Entity {
// Declare member variables here. Examples:
// private int a = 2;
// private string b = "text";
// Called when the node enters the scene tree for the first time.
public override void _Ready() { }
// // Called every frame. 'delta' is the elapsed time since the previous frame.
// public override void _Process(float delta)
// {
//
// }
}

28
entities/Workbench.tscn Normal file
View File

@ -0,0 +1,28 @@
[gd_scene load_steps=6 format=2]
[ext_resource path="res://assets/KenneySurvivalKit/Models/workbench.glb" type="PackedScene" id=1]
[ext_resource path="res://entities/Workbench.cs" type="Script" id=2]
[sub_resource type="BoxShape" id=1]
extents = Vector3( 0.19, 0.19, 0.33 )
[sub_resource type="CubeMesh" id=2]
size = Vector3( 0.38, 0.38, 0.66 )
[sub_resource type="SpatialMaterial" id=3]
flags_transparent = true
albedo_color = Color( 0.380392, 0.145098, 0.145098, 0.501961 )
[node name="Workbench" type="KinematicBody"]
script = ExtResource( 2 )
[node name="Geometry" parent="." instance=ExtResource( 1 )]
transform = Transform( 2.26249, 0, -1.06354, 0, 2.5, 0, 1.06354, 0, 2.26249, 0, 0, 0 )
[node name="CollisionShape" type="CollisionShape" parent="."]
transform = Transform( -1.29904, 0, 0.5, 0, 1.5, 0, -0.749999, 0, -0.866026, 0, 0.240716, 0 )
shape = SubResource( 1 )
[node name="MeshInstance" type="MeshInstance" parent="CollisionShape" groups=["PhysicsGeometry"]]
mesh = SubResource( 2 )
material/0 = SubResource( 3 )

View File

@ -2,6 +2,13 @@ using System.Diagnostics;
using Godot; using Godot;
public class Game : Spatial { public class Game : Spatial {
private enum ActionMode {
Default,
Building
}
private ActionMode _actionMode = ActionMode.Default;
private ImageTexture _blackWhitePatternTexture; private ImageTexture _blackWhitePatternTexture;
private Camera _camera; private Camera _camera;
private Vector3 _cameraOffset; private Vector3 _cameraOffset;
@ -15,6 +22,8 @@ public class Game : Spatial {
private Label _woodCountLabel; private Label _woodCountLabel;
private Label _goldCountLabel; private Label _goldCountLabel;
private TextureRect _heightTextureRect; private TextureRect _heightTextureRect;
private Button _walkActionButton;
private Button _buildActionButton;
// other members // other members
private HexGrid _hexGrid; private HexGrid _hexGrid;
@ -34,6 +43,7 @@ public class Game : Spatial {
private Label _tileOffsetLabel; private Label _tileOffsetLabel;
private World _world; private World _world;
private TextureRect _worldTextureRect; private TextureRect _worldTextureRect;
private readonly PackedScene _workbenchScene = GD.Load<PackedScene>("res://entities/Workbench.tscn");
// Called when the node enters the scene tree for the first time. // Called when the node enters the scene tree for the first time.
public override void _Ready() { public override void _Ready() {
@ -53,10 +63,14 @@ public class Game : Spatial {
_worldTextureRect = worldGeneratorWidget.GetNode<TextureRect>("WorldTextureRect"); _worldTextureRect = worldGeneratorWidget.GetNode<TextureRect>("WorldTextureRect");
_heightTextureRect = worldGeneratorWidget.GetNode<TextureRect>("HeightTextureRect"); _heightTextureRect = worldGeneratorWidget.GetNode<TextureRect>("HeightTextureRect");
_gameUi = (Control)FindNode("GameUI"); _gameUi = (Control)FindNode("GameUI");
_woodCountLabel = _gameUi.GetNode<Label>("WoodCount"); _woodCountLabel = _gameUi.GetNode<Label>("TopRight/WoodCount");
Debug.Assert(_woodCountLabel != null); Debug.Assert(_woodCountLabel != null);
_goldCountLabel = _gameUi.GetNode<Label>("GoldCount"); _goldCountLabel = _gameUi.GetNode<Label>("TopRight/GoldCount");
Debug.Assert(_goldCountLabel != null); Debug.Assert(_goldCountLabel != null);
_walkActionButton = _gameUi.GetNode<Button>("BottomCenter/WalkActionButton");
Debug.Assert(_walkActionButton != null);
_buildActionButton = _gameUi.GetNode<Button>("BottomCenter/BuildActionButton");
Debug.Assert(_buildActionButton != null);
// scene nodes // scene nodes
_tileHighlight = GetNode<Spatial>("TileHighlight"); _tileHighlight = GetNode<Spatial>("TileHighlight");
@ -92,6 +106,8 @@ public class Game : Spatial {
_world.Connect("TileHovered", this, nameof(OnTileHovered)); _world.Connect("TileHovered", this, nameof(OnTileHovered));
_world.Connect("OnWorldViewTileTypeImageChanged", this, nameof(OnWorldViewTileTypeImageChanged)); _world.Connect("OnWorldViewTileTypeImageChanged", this, nameof(OnWorldViewTileTypeImageChanged));
_world.Connect("OnHeightmapImageChanged", this, nameof(OnHeightmapImageChanged)); _world.Connect("OnHeightmapImageChanged", this, nameof(OnHeightmapImageChanged));
_walkActionButton.Connect("pressed", this, nameof(OnWalkActionPressed));
_buildActionButton.Connect("pressed", this, nameof(OnBuildActionPressed));
// register entity events // register entity events
foreach (Node node in GetNode("Entities").GetChildren()) { foreach (Node node in GetNode("Entities").GetChildren()) {
@ -197,6 +213,16 @@ public class Game : Spatial {
return; return;
} }
if (_actionMode == ActionMode.Building) {
Workbench workbench = (Workbench)_workbenchScene.Instance();
workbench.Transform = tile.GlobalTransform;
AddChild(workbench);
_world.MarkCellUnwalkable(tile.Cell);
return;
}
if (_player.InteractionComponent != null) { if (_player.InteractionComponent != null) {
_player.InteractionComponent.EmitSignal("InteractionEnd"); _player.InteractionComponent.EmitSignal("InteractionEnd");
} }
@ -239,6 +265,7 @@ public class Game : Spatial {
_woodCountLabel.Text = "0"; _woodCountLabel.Text = "0";
_goldCountLabel.Text = "0"; _goldCountLabel.Text = "0";
_actionMode = ActionMode.Default;
foreach (Spatial entity in GetNode("Entities").GetChildren()) { foreach (Spatial entity in GetNode("Entities").GetChildren()) {
Transform entityTransform = entity.Transform; Transform entityTransform = entity.Transform;
@ -285,4 +312,12 @@ public class Game : Spatial {
animationPlayer.Seek(0); animationPlayer.Seek(0);
animationPlayer.Play(); animationPlayer.Play();
} }
public void OnWalkActionPressed() {
_actionMode = ActionMode.Default;
}
public void OnBuildActionPressed() {
_actionMode = ActionMode.Building;
}
} }

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=19 format=2] [gd_scene load_steps=20 format=2]
[ext_resource path="res://ui/WorldGeneratorWidget.gd" type="Script" id=1] [ext_resource path="res://ui/WorldGeneratorWidget.gd" type="Script" id=1]
[ext_resource path="res://entities/Player.tscn" type="PackedScene" id=2] [ext_resource path="res://entities/Player.tscn" type="PackedScene" id=2]
@ -12,6 +12,7 @@
[ext_resource path="res://entities/Wood.tscn" type="PackedScene" id=10] [ext_resource path="res://entities/Wood.tscn" type="PackedScene" id=10]
[ext_resource path="res://entities/Chest.tscn" type="PackedScene" id=11] [ext_resource path="res://entities/Chest.tscn" type="PackedScene" id=11]
[ext_resource path="res://ui/game_theme.tres" type="Theme" id=12] [ext_resource path="res://ui/game_theme.tres" type="Theme" id=12]
[ext_resource path="res://ui/action_buttongroup.tres" type="ButtonGroup" id=13]
[ext_resource path="res://entities/Axe.tscn" type="PackedScene" id=14] [ext_resource path="res://entities/Axe.tscn" type="PackedScene" id=14]
[ext_resource path="res://systems/InteractionSystem.cs" type="Script" id=15] [ext_resource path="res://systems/InteractionSystem.cs" type="Script" id=15]
@ -66,6 +67,9 @@ tracks/0/keys = {
[node name="Game" type="Spatial"] [node name="Game" type="Spatial"]
script = ExtResource( 9 ) script = ExtResource( 9 )
__meta__ = {
"_edit_horizontal_guides_": [ -333.0 ]
}
[node name="TileHighlight" parent="." instance=ExtResource( 5 )] [node name="TileHighlight" parent="." instance=ExtResource( 5 )]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.1, 0 ) transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.1, 0 )
@ -73,59 +77,91 @@ visible = false
[node name="MouseTileHighlight" parent="." instance=ExtResource( 5 )] [node name="MouseTileHighlight" parent="." instance=ExtResource( 5 )]
[node name="GameUI" type="HBoxContainer" parent="."] [node name="GameUI" type="Control" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
mouse_filter = 2
theme = ExtResource( 12 )
[node name="TopRight" type="HBoxContainer" parent="GameUI"]
anchor_left = 1.0 anchor_left = 1.0
anchor_right = 1.0 anchor_right = 1.0
margin_left = -40.0 margin_left = -206.0
margin_right = -10.0
margin_bottom = 40.0 margin_bottom = 40.0
grow_horizontal = 0 grow_horizontal = 0
mouse_filter = 2 mouse_filter = 2
theme = ExtResource( 12 )
alignment = 2 alignment = 2
[node name="WoodLabel" type="Label" parent="GameUI"] [node name="WoodLabel" type="Label" parent="GameUI/TopRight"]
margin_left = 4.0
margin_top = 10.0 margin_top = 10.0
margin_right = 49.0 margin_right = 53.0
margin_bottom = 29.0 margin_bottom = 29.0
text = "Wood" text = "Wood"
[node name="WoodCount" type="Label" parent="GameUI"] [node name="WoodCount" type="Label" parent="GameUI/TopRight"]
margin_left = 53.0 margin_left = 57.0
margin_top = 10.0 margin_top = 10.0
margin_right = 103.0 margin_right = 107.0
margin_bottom = 29.0 margin_bottom = 29.0
rect_min_size = Vector2( 50, 0 ) rect_min_size = Vector2( 50, 0 )
rect_pivot_offset = Vector2( 25, 8 ) rect_pivot_offset = Vector2( 25, 8 )
text = "0" text = "0"
align = 1 align = 1
[node name="AnimationPlayer" type="AnimationPlayer" parent="GameUI/WoodCount"] [node name="AnimationPlayer" type="AnimationPlayer" parent="GameUI/TopRight/WoodCount"]
root_node = NodePath("../..") root_node = NodePath("../..")
anims/FlashLabel = SubResource( 27 ) anims/FlashLabel = SubResource( 27 )
anims/RESET = SubResource( 28 ) anims/RESET = SubResource( 28 )
[node name="GoldLabel" type="Label" parent="GameUI"] [node name="GoldLabel" type="Label" parent="GameUI/TopRight"]
margin_left = 107.0 margin_left = 111.0
margin_top = 10.0 margin_top = 10.0
margin_right = 148.0 margin_right = 152.0
margin_bottom = 29.0 margin_bottom = 29.0
text = "Gold" text = "Gold"
[node name="GoldCount" type="Label" parent="GameUI"] [node name="GoldCount" type="Label" parent="GameUI/TopRight"]
margin_left = 152.0 margin_left = 156.0
margin_top = 10.0 margin_top = 10.0
margin_right = 202.0 margin_right = 206.0
margin_bottom = 29.0 margin_bottom = 29.0
rect_min_size = Vector2( 50, 0 ) rect_min_size = Vector2( 50, 0 )
rect_pivot_offset = Vector2( 25, 8 ) rect_pivot_offset = Vector2( 25, 8 )
text = "0" text = "0"
align = 1 align = 1
[node name="AnimationPlayer" type="AnimationPlayer" parent="GameUI/GoldCount"] [node name="AnimationPlayer" type="AnimationPlayer" parent="GameUI/TopRight/GoldCount"]
root_node = NodePath("../..") root_node = NodePath("../..")
anims/FlashLabel = SubResource( 25 ) anims/FlashLabel = SubResource( 25 )
[node name="BottomCenter" type="HBoxContainer" parent="GameUI"]
anchor_left = 0.5
anchor_top = 1.0
anchor_right = 0.5
anchor_bottom = 1.0
margin_left = -61.0
margin_top = -46.0
margin_right = 59.0
margin_bottom = -6.0
[node name="WalkActionButton" type="Button" parent="GameUI/BottomCenter"]
margin_right = 58.0
margin_bottom = 40.0
rect_min_size = Vector2( 40, 40 )
toggle_mode = true
pressed = true
group = ExtResource( 13 )
text = "Walk"
[node name="BuildActionButton" type="Button" parent="GameUI/BottomCenter"]
margin_left = 62.0
margin_right = 120.0
margin_bottom = 40.0
toggle_mode = true
group = ExtResource( 13 )
text = "Build"
[node name="DebugContainer" type="PanelContainer" parent="."] [node name="DebugContainer" type="PanelContainer" parent="."]
self_modulate = Color( 1, 1, 1, 0.443137 ) self_modulate = Color( 1, 1, 1, 0.443137 )
anchor_left = 1.0 anchor_left = 1.0

View File

@ -0,0 +1,5 @@
[gd_resource type="ButtonGroup" format=2]
[resource]
resource_local_to_scene = false
resource_name = "ActionButtonGroup"