add anthill ui and bying units

This commit is contained in:
Teatov 2024-10-06 15:56:04 +10:00
parent 0071d60fa1
commit 8096cd7046
17 changed files with 276 additions and 13 deletions

BIN
assets/textures/gui/window_large_bg.png (Stored with Git LFS) Normal file

Binary file not shown.

View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://dkg65b3si5dil"
path="res://.godot/imported/window_large_bg.png-7274770e6482f853250b0fe28f33e92f.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/textures/gui/window_large_bg.png"
dest_files=["res://.godot/imported/window_large_bg.png-7274770e6482f853250b0fe28f33e92f.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

BIN
assets/textures/gui/window_small_bg.png (Stored with Git LFS) Normal file

Binary file not shown.

View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://bu5r85adl8bd7"
path="res://.godot/imported/window_small_bg.png-5038a0713dd5c8760ea8a71fb50dfb97.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/textures/gui/window_small_bg.png"
dest_files=["res://.godot/imported/window_small_bg.png-5038a0713dd5c8760ea8a71fb50dfb97.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

View File

@ -24,6 +24,7 @@ CursorManager="*res://scripts/globals/cursor_manager.gd"
FullscreenManager="*res://scripts/globals/fullscreen_manager.gd"
QuittingManager="*res://scripts/globals/quitting_manager.gd"
DebugDraw="*res://scripts/globals/debug_draw.gd"
UiManager="*res://scripts/globals/ui_manager.gd"
[debug]

View File

@ -0,0 +1,15 @@
[gd_resource type="StyleBoxTexture" load_steps=2 format=3 uid="uid://cst1tevq2rlma"]
[ext_resource type="Texture2D" uid="uid://dkg65b3si5dil" path="res://assets/textures/gui/window_large_bg.png" id="1_mkn7d"]
[resource]
texture = ExtResource("1_mkn7d")
texture_margin_left = 35.0
texture_margin_top = 35.0
texture_margin_right = 35.0
texture_margin_bottom = 35.0
expand_margin_left = 35.0
expand_margin_top = 35.0
expand_margin_right = 35.0
expand_margin_bottom = 35.0
modulate_color = Color(0.796201, 0.670954, 0.477331, 1)

View File

@ -0,0 +1,15 @@
[gd_resource type="StyleBoxTexture" load_steps=2 format=3 uid="uid://do5c5v5kvgv0s"]
[ext_resource type="Texture2D" uid="uid://bu5r85adl8bd7" path="res://assets/textures/gui/window_small_bg.png" id="1_skd32"]
[resource]
texture = ExtResource("1_skd32")
texture_margin_left = 20.0
texture_margin_top = 20.0
texture_margin_right = 20.0
texture_margin_bottom = 20.0
expand_margin_left = 20.0
expand_margin_top = 20.0
expand_margin_right = 20.0
expand_margin_bottom = 20.0
modulate_color = Color(0.796201, 0.670954, 0.477331, 1)

View File

@ -22,3 +22,6 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.0021804, 0.00953716, -0.00
pixel_size = 0.0135
axis = 1
texture = ExtResource("1_bk5n4")
[node name="UiOrigin" type="Marker3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.15587, 0)

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=18 format=3 uid="uid://ceru75se7ifkb"]
[gd_scene load_steps=19 format=3 uid="uid://ceru75se7ifkb"]
[ext_resource type="Script" path="res://scripts/main_camera.gd" id="1_gnxhh"]
[ext_resource type="PackedScene" uid="uid://cfixshlmwhpmi" path="res://scenes/units/test_unit.tscn" id="2_4bgm6"]
@ -7,6 +7,7 @@
[ext_resource type="PackedScene" uid="uid://k11usj2shbtr" path="res://scenes/units/ant_nitwit.tscn" id="4_jcvdx"]
[ext_resource type="Texture2D" uid="uid://bgbe5l2woe5b2" path="res://assets/textures/gui/selection_box.png" id="5_g1xtt"]
[ext_resource type="PackedScene" uid="uid://clftjlaotf2g2" path="res://scenes/structures/Anthill.tscn" id="7_f30w3"]
[ext_resource type="PackedScene" uid="uid://d8ut24fit87x" path="res://scenes/ui/anthill_info.tscn" id="8_ohyy4"]
[sub_resource type="NavigationMesh" id="NavigationMesh_6jq54"]
vertices = PackedVector3Array(-2.95696, 0.5, 1.42491, -0.95696, 0.5, -0.0750852, -1.45696, 0.5, -0.325085, -3.20696, 0.5, 0.924915, -7.95696, 0.5, 5.42491, -4.70696, 0.5, 2.17491, -4.70696, 0.5, 1.42491, -7.95696, 0.5, -5.32509, -1.45696, 0.5, -1.07509, -3.70696, 0.5, 5.42491, -3.70696, 0.5, 2.67491, -4.20696, 0.5, 0.924915, -0.70696, 0.5, -5.32509, -0.70696, 0.5, -1.32509, -2.95696, 0.5, 2.42491, -0.20696, 0.5, -0.325085, 12.543, 0.5, -5.32509, -0.20696, 0.5, -1.07509, 12.543, 0.5, 5.42491)
@ -56,12 +57,6 @@ points = PackedVector3Array(-0.0778407, 1.54508, 4.75528, -31.3231, -5, -72.1516
[node name="World" type="Node3D"]
[node name="MainCamera" type="Camera3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 0.819152, 0.573576, 0, -0.573576, 0.819152, 0, 1, 2)
current = true
far = 200.0
script = ExtResource("1_gnxhh")
[node name="Static" type="Node" parent="."]
[node name="NavigationRegion3D" type="NavigationRegion3D" parent="Static"]
@ -155,3 +150,13 @@ shape = SubResource("ConvexPolygonShape3D_n34fh")
[node name="Anthill" parent="Structures" instance=ExtResource("7_f30w3")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -3.79455, 0, 1.78811)
[node name="UI" type="Node" parent="."]
[node name="AnthillInfo" parent="UI" instance=ExtResource("8_ohyy4")]
[node name="MainCamera" type="Camera3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 0.819152, 0.573576, 0, -0.573576, 0.819152, 0, 1, 2)
current = true
far = 200.0
script = ExtResource("1_gnxhh")

View File

@ -0,0 +1,44 @@
[gd_scene load_steps=3 format=3 uid="uid://d8ut24fit87x"]
[ext_resource type="StyleBox" uid="uid://do5c5v5kvgv0s" path="res://resources/styles/panel_small_style.tres" id="1_tod8w"]
[ext_resource type="Script" path="res://scripts/ui/anthill_info.gd" id="2_aj5vl"]
[node name="AnthillInfo" type="Control"]
layout_mode = 3
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -640.0
offset_top = -360.0
offset_right = -640.0
offset_bottom = -360.0
grow_horizontal = 2
grow_vertical = 2
mouse_filter = 2
script = ExtResource("2_aj5vl")
[node name="Panel" type="Panel" parent="."]
layout_mode = 0
offset_left = -112.0
offset_top = -107.0
offset_right = 111.0
offset_bottom = -26.0
theme_override_styles/panel = ExtResource("1_tod8w")
[node name="Label" type="Label" parent="Panel"]
layout_mode = 1
offset_right = 132.0
offset_bottom = 23.0
theme_override_colors/font_color = Color(0, 0, 0, 1)
theme_override_font_sizes/font_size = 16
text = "honeydew: 5"
[node name="NitwitButton" type="Button" parent="Panel"]
layout_mode = 0
offset_left = 1.0
offset_top = 34.0
offset_right = 119.0
offset_bottom = 65.0
text = "make nitwit: 5"

View File

@ -2,21 +2,53 @@ extends Interactable
class_name Anthill
const SPAWN_RADIUS: float = 1
const DEFAULT_MAX_HONEYDEW: int = 20
var honeydew: int = 0
var honeydew: int = 20
var max_honeydew: int = DEFAULT_MAX_HONEYDEW
var ant_nitwit := preload("res://scenes/units/ant_nitwit.tscn")
@onready var ui_origin: Node3D = $UiOrigin
@onready var nitwits_holder: Node = $/root/World/Units/Nitwits
## Returns amount of honeydew that did not fit
func put_honeydew(amount: int) -> int:
var new_honeydew_amount := honeydew + amount
var leftover: int = 0
if new_honeydew_amount > max_honeydew:
honeydew = max_honeydew
leftover = new_honeydew_amount - max_honeydew
else:
honeydew = new_honeydew_amount
return leftover
func spawn_nitwit() -> void:
var new_unit := _create_unit(ant_nitwit, AntNitwit.get_cost())
if new_unit == null:
return
nitwits_holder.add_child(new_unit)
func _click() -> void:
UiManager.anthill_info.open(self)
func _create_unit(unit_scene: PackedScene, cost: int) -> ControlledUnit:
var new_honeydew_amount := honeydew - cost
if new_honeydew_amount < 0:
return null
honeydew = new_honeydew_amount
var spawn_pos_angle := randf_range(0, 360)
var new_pos_offset := Vector3.BACK.rotated(Vector3.UP, spawn_pos_angle)
var new_pos := global_position + (new_pos_offset * SPAWN_RADIUS)
var new_unit := (
(ant_nitwit.instantiate() as AntNitwit).initialize(
(unit_scene.instantiate() as ControlledUnit).initialize(
self,
new_pos
)
)
nitwits_holder.add_child(new_unit)
return new_unit

View File

@ -116,12 +116,12 @@ func _draw_marker(pos: Vector3, radius: float, color: Color) -> void:
control.draw_line(y_start, y_end, color, LINE_WIDTH)
var z_start := _unproject(pos + (Vector3.FORWARD * radius))
var z_end := camera.unproject_position(pos + (Vector3.BACK * radius))
var z_end := _unproject(pos + (Vector3.BACK * radius))
control.draw_line(z_start, z_end, color, LINE_WIDTH)
func _draw_circle(pos: Vector3, color: Color) -> void:
var point := camera.unproject_position(pos)
var point := _unproject(pos)
control.draw_circle(point, CIRCLE_RADIUS, color)

View File

@ -0,0 +1,4 @@
extends Node
@onready var anthill_info: AnthillInfo = $/root/World/UI/AnthillInfo

View File

@ -0,0 +1,33 @@
extends FollowingUi
class_name AnthillInfo
var anthill: Anthill
@onready var label: Label = $Panel/Label
@onready var nitwit_button: Button = $Panel/NitwitButton
func _ready() -> void:
super._ready()
nitwit_button.pressed.connect(_on_nitwit_button_pressed)
func _process(delta: float) -> void:
super._process(delta)
if anthill == null:
return
label.text = 'honeydew: ' + str(anthill.honeydew)
func open(at: Anthill) -> void:
anthill = at
set_target(anthill.ui_origin)
func close() -> void:
super.close()
anthill = null
func _on_nitwit_button_pressed()->void:
anthill.spawn_nitwit()

View File

@ -0,0 +1,26 @@
extends Control
class_name FollowingUi
var target: Node3D
@onready var camera: Camera3D = get_viewport().get_camera_3d()
func _ready() -> void:
visible = false
func _process(_delta: float) -> void:
if not visible or target == null:
return
var pos := camera.unproject_position(target.global_position)
position = pos
func set_target(to: Node3D)->void:
visible = true
target = to
func close() -> void:
visible = true
target = null

View File

@ -23,6 +23,10 @@ func _process(delta: float) -> void:
_handle_wandering(delta)
static func get_cost() -> int:
return 5
func _handle_wandering(delta: float) -> void:
if state != AntNitwitState.WANDERING:
return

View File

@ -5,6 +5,7 @@ signal moving_started
signal moving_ended
var anthill: Anthill
var spawn_pos: Vector3
var selected: bool = false
var moving_to_target: bool = false
@ -26,6 +27,8 @@ func _ready() -> void:
set_selected(false)
super._ready()
if spawn_pos != null:
global_position = spawn_pos
func _physics_process(delta: float) -> void:
@ -52,10 +55,14 @@ func _input(event: InputEvent) -> void:
func initialize(from: Anthill, pos: Vector3) -> ControlledUnit:
anthill = from
global_position = pos
spawn_pos = pos
return self
static func get_cost() -> int:
return 5
func set_selected(on: bool) -> void:
selected = on