add ant bying and pause menu

This commit is contained in:
Teatov 2024-10-07 02:36:19 +10:00
parent 76ccd210ec
commit 705e861e3f
17 changed files with 487 additions and 24 deletions

2
.gitattributes vendored
View File

@ -3,3 +3,5 @@
*.png filter=lfs diff=lfs merge=lfs -text
*.glb filter=lfs diff=lfs merge=lfs -text
*.ogg filter=lfs diff=lfs merge=lfs -text
*.wav filter=lfs diff=lfs merge=lfs -text

BIN
assets/textures/gui/pictograms.png (Stored with Git LFS)

Binary file not shown.

View File

@ -22,7 +22,6 @@ config/icon="res://icon.svg"
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"
HoveringManager="*res://scripts/globals/hovering_manager.gd"

View File

@ -1,7 +1,9 @@
[gd_scene load_steps=13 format=3 uid="uid://ceru75se7ifkb"]
[gd_scene load_steps=15 format=3 uid="uid://ceru75se7ifkb"]
[ext_resource type="Script" path="res://scripts/main_camera.gd" id="1_gnxhh"]
[ext_resource type="PackedScene" uid="uid://d4c6ujs1ra1ob" path="res://scenes/units/aphid.tscn" id="3_eh22j"]
[ext_resource type="PackedScene" uid="uid://c70rhvk2okkcu" path="res://scenes/ui/buy_ants.tscn" id="4_irvxk"]
[ext_resource type="PackedScene" uid="uid://davys5ol18oyo" path="res://scenes/ui/pause_menu.tscn" id="5_ljrsn"]
[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"]
@ -96,6 +98,10 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -3.79455, 0, 1.78811)
[node name="AnthillInfo" parent="UI" instance=ExtResource("8_ohyy4")]
[node name="BuyAnts" parent="UI" instance=ExtResource("4_irvxk")]
[node name="PauseMenu" parent="UI" instance=ExtResource("5_ljrsn")]
[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

View File

@ -22,18 +22,18 @@ script = ExtResource("2_aj5vl")
[node name="AddOneButton" type="Button" parent="."]
layout_mode = 0
offset_left = 239.0
offset_top = -10.0
offset_right = 266.0
offset_bottom = 21.0
offset_left = 166.0
offset_top = 44.0
offset_right = 193.0
offset_bottom = 75.0
text = "+1"
[node name="AddFiveButton" type="Button" parent="."]
layout_mode = 0
offset_left = 270.0
offset_top = -10.0
offset_right = 297.0
offset_bottom = 21.0
offset_left = 197.0
offset_top = 44.0
offset_right = 224.0
offset_bottom = 75.0
text = "+5"
[node name="HoneydewCounter" parent="." instance=ExtResource("3_8onrx")]

210
scenes/ui/buy_ants.tscn Normal file
View File

@ -0,0 +1,210 @@
[gd_scene load_steps=13 format=3 uid="uid://c70rhvk2okkcu"]
[ext_resource type="StyleBox" uid="uid://do5c5v5kvgv0s" path="res://resources/styles/panel_small_style.tres" id="1_wcf51"]
[ext_resource type="Script" path="res://scripts/ui/buy_ants.gd" id="2_sf7hb"]
[ext_resource type="Texture2D" uid="uid://bh01xbmjanku0" path="res://assets/textures/gui/button_bg.png" id="2_shpjn"]
[ext_resource type="Texture2D" uid="uid://jv8twhntt6x3" path="res://assets/textures/gui/button_hover_bg.png" id="3_bwnfl"]
[ext_resource type="Texture2D" uid="uid://slraulfmk8c0" path="res://assets/textures/gui/pictograms.png" id="4_s7jbe"]
[ext_resource type="PackedScene" uid="uid://w3ydggdgvyqn" path="res://scenes/ui/honeydew_counter.tscn" id="5_5hx6c"]
[sub_resource type="AtlasTexture" id="AtlasTexture_t7i0n"]
atlas = ExtResource("4_s7jbe")
region = Rect2(37.1788, 80.4158, 27.2037, 25.0274)
[sub_resource type="AtlasTexture" id="AtlasTexture_du04k"]
atlas = ExtResource("4_s7jbe")
region = Rect2(28.6998, 105.07, 81.3694, 45.293)
[sub_resource type="AtlasTexture" id="AtlasTexture_eg31t"]
atlas = ExtResource("4_s7jbe")
region = Rect2(35.3161, 150.756, 77.1561, 46.083)
[sub_resource type="AtlasTexture" id="AtlasTexture_spu7x"]
atlas = ExtResource("4_s7jbe")
region = Rect2(134.461, 11.7237, 236.668, 108.79)
[sub_resource type="AtlasTexture" id="AtlasTexture_gdhp3"]
atlas = ExtResource("4_s7jbe")
region = Rect2(593.488, 12.3042, 44.8981, 33.8908)
[sub_resource type="AtlasTexture" id="AtlasTexture_nknr8"]
atlas = ExtResource("4_s7jbe")
region = Rect2(142.097, 122.771, 180.55, 96.3861)
[node name="BuyAnts" type="Panel"]
offset_left = 21.0
offset_top = 12.0
offset_right = 271.0
offset_bottom = 215.0
pivot_offset = Vector2(121, 256)
theme_override_styles/panel = ExtResource("1_wcf51")
script = ExtResource("2_sf7hb")
[node name="Equals1" type="TextureRect" parent="."]
layout_mode = 1
offset_left = 110.0
offset_top = 95.0
offset_right = 137.0
offset_bottom = 120.0
texture = SubResource("AtlasTexture_t7i0n")
[node name="Equals2" type="TextureRect" parent="."]
layout_mode = 1
offset_left = 111.0
offset_top = 33.0
offset_right = 138.0
offset_bottom = 58.0
texture = SubResource("AtlasTexture_t7i0n")
[node name="BuyNitwitButton" type="TextureButton" parent="."]
modulate = Color(0.81, 0.748035, 0.5913, 1)
layout_mode = 0
offset_left = 13.0
offset_top = 16.0
offset_right = 112.0
offset_bottom = 72.0
texture_normal = ExtResource("2_shpjn")
texture_pressed = ExtResource("2_shpjn")
texture_hover = ExtResource("3_bwnfl")
ignore_texture_size = true
stretch_mode = 0
[node name="ButtonTexture" type="TextureRect" parent="BuyNitwitButton"]
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -39.5
offset_top = -24.0
offset_right = 41.5
offset_bottom = 21.0
grow_horizontal = 2
grow_vertical = 2
texture = SubResource("AtlasTexture_du04k")
[node name="NitwitPriceCounter" parent="." instance=ExtResource("5_5hx6c")]
layout_mode = 0
offset_left = 136.0
offset_top = 27.0
offset_right = 220.0
offset_bottom = 71.0
[node name="BuyGathererButton" type="TextureButton" parent="."]
modulate = Color(0.81, 0.748035, 0.5913, 1)
layout_mode = 0
offset_left = 15.0
offset_top = 77.0
offset_right = 114.0
offset_bottom = 133.0
texture_normal = ExtResource("2_shpjn")
texture_pressed = ExtResource("2_shpjn")
texture_hover = ExtResource("3_bwnfl")
ignore_texture_size = true
stretch_mode = 0
[node name="ButtonTexture" type="TextureRect" parent="BuyGathererButton"]
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -36.5
offset_top = -25.0
offset_right = 40.5
offset_bottom = 21.0
grow_horizontal = 2
grow_vertical = 2
texture = SubResource("AtlasTexture_eg31t")
[node name="GathererPriceCounter" parent="." instance=ExtResource("5_5hx6c")]
layout_mode = 0
offset_left = 135.0
offset_top = 87.0
offset_right = 219.0
offset_bottom = 131.0
[node name="HoneydewCounter" parent="." instance=ExtResource("5_5hx6c")]
layout_mode = 0
offset_left = 16.0
offset_top = 150.0
offset_right = 235.0
offset_bottom = 183.0
[node name="NitwitPanel" type="Panel" parent="."]
layout_mode = 0
offset_left = 249.0
offset_top = -11.0
offset_right = 506.0
offset_bottom = 124.0
theme_override_styles/panel = ExtResource("1_wcf51")
[node name="InfoTexture" type="TextureRect" parent="NitwitPanel"]
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -124.0
offset_top = -54.0
offset_right = 124.0
offset_bottom = 54.0
grow_horizontal = 2
grow_vertical = 2
texture = SubResource("AtlasTexture_spu7x")
[node name="Arrow" type="TextureRect" parent="NitwitPanel"]
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -147.5
offset_top = -24.5
offset_right = -103.5
offset_bottom = 8.5
grow_horizontal = 2
grow_vertical = 2
texture = SubResource("AtlasTexture_gdhp3")
[node name="GathererPanel" type="Panel" parent="."]
layout_mode = 0
offset_left = 262.0
offset_top = 43.0
offset_right = 458.0
offset_bottom = 174.0
theme_override_styles/panel = ExtResource("1_wcf51")
[node name="InfoTexture" type="TextureRect" parent="GathererPanel"]
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -90.0
offset_top = -48.0
offset_right = 90.0
offset_bottom = 48.0
grow_horizontal = 2
grow_vertical = 2
texture = SubResource("AtlasTexture_nknr8")
[node name="Arrow" type="TextureRect" parent="GathererPanel"]
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -125.0
offset_top = -13.5
offset_right = -81.0
offset_bottom = 19.5
grow_horizontal = 2
grow_vertical = 2
texture = SubResource("AtlasTexture_gdhp3")

View File

@ -5,4 +5,5 @@
[node name="HoneydewCounter" type="ReferenceRect"]
offset_right = 77.0
offset_bottom = 33.0
mouse_filter = 2
script = ExtResource("1_en213")

128
scenes/ui/pause_menu.tscn Normal file
View File

@ -0,0 +1,128 @@
[gd_scene load_steps=10 format=3 uid="uid://davys5ol18oyo"]
[ext_resource type="StyleBox" uid="uid://do5c5v5kvgv0s" path="res://resources/styles/panel_small_style.tres" id="1_06xpe"]
[ext_resource type="Script" path="res://scripts/ui/pause_menu.gd" id="1_kcif0"]
[ext_resource type="Texture2D" uid="uid://bh01xbmjanku0" path="res://assets/textures/gui/button_bg.png" id="2_e7opb"]
[ext_resource type="Texture2D" uid="uid://jv8twhntt6x3" path="res://assets/textures/gui/button_hover_bg.png" id="3_fx7y7"]
[ext_resource type="Texture2D" uid="uid://slraulfmk8c0" path="res://assets/textures/gui/pictograms.png" id="4_dmywd"]
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_4k086"]
bg_color = Color(0, 0, 0, 0.25098)
[sub_resource type="AtlasTexture" id="AtlasTexture_td4xc"]
atlas = ExtResource("4_dmywd")
region = Rect2(376.638, 15.8875, 58.3096, 53.2115)
[sub_resource type="AtlasTexture" id="AtlasTexture_wh53g"]
atlas = ExtResource("4_dmywd")
region = Rect2(532.01, 2.29694, 48.3741, 55.326)
[sub_resource type="AtlasTexture" id="AtlasTexture_wimn7"]
atlas = ExtResource("4_dmywd")
region = Rect2(9.61571, 881, 845.387, 129)
[node name="PauseMenu" type="Panel"]
process_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
theme_override_styles/panel = SubResource("StyleBoxFlat_4k086")
script = ExtResource("1_kcif0")
[node name="Panel" type="Panel" parent="."]
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -80.0
offset_top = -55.5
offset_right = 80.0
offset_bottom = 55.5
grow_horizontal = 2
grow_vertical = 2
theme_override_styles/panel = ExtResource("1_06xpe")
[node name="QuitButton" type="TextureButton" parent="Panel"]
modulate = Color(0.843007, 0.282913, 0.299802, 1)
offset_left = 38.0
offset_top = 24.0
offset_right = 117.0
offset_bottom = 97.0
texture_normal = ExtResource("2_e7opb")
texture_pressed = ExtResource("2_e7opb")
texture_hover = ExtResource("3_fx7y7")
ignore_texture_size = true
stretch_mode = 0
[node name="TextureRect" type="TextureRect" parent="Panel/QuitButton"]
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -29.0
offset_top = -26.5
offset_right = 29.0
offset_bottom = 26.5
grow_horizontal = 2
grow_vertical = 2
texture = SubResource("AtlasTexture_td4xc")
[node name="CancelButton" type="TextureButton" parent="Panel"]
modulate = Color(0.81, 0.748035, 0.5913, 1)
offset_left = 117.0
offset_top = -25.0
offset_right = 182.0
offset_bottom = 35.0
texture_normal = ExtResource("2_e7opb")
texture_pressed = ExtResource("2_e7opb")
texture_hover = ExtResource("3_fx7y7")
ignore_texture_size = true
stretch_mode = 0
[node name="TextureRect" type="TextureRect" parent="Panel/CancelButton"]
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -24.0
offset_top = -27.5
offset_right = 24.0
offset_bottom = 27.5
grow_horizontal = 2
grow_vertical = 2
texture = SubResource("AtlasTexture_wh53g")
[node name="ControlsInfo" type="Panel" parent="."]
layout_mode = 1
anchors_preset = 2
anchor_top = 1.0
anchor_bottom = 1.0
offset_left = 15.0
offset_top = -169.0
offset_right = 895.0
offset_bottom = -21.0
grow_vertical = 0
theme_override_styles/panel = ExtResource("1_06xpe")
[node name="TextureRect" type="TextureRect" parent="ControlsInfo"]
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -422.5
offset_top = -64.5
offset_right = 422.5
offset_bottom = 64.5
grow_horizontal = 2
grow_vertical = 2
texture = SubResource("AtlasTexture_wimn7")

View File

@ -10,6 +10,7 @@ var disable_confinement: bool = false
func _ready() -> void:
Input.mouse_mode = Input.MOUSE_MODE_CONFINED
process_mode = Node.PROCESS_MODE_ALWAYS
func _input(event: InputEvent) -> void:

View File

@ -3,6 +3,10 @@ extends Node
var is_fullscreen: bool = false
func _ready() -> void:
process_mode = Node.PROCESS_MODE_ALWAYS
func _input(event: InputEvent) -> void:
if event.is_action_pressed("toggle_fullscreen"):
_toggle_fullscreen()

View File

@ -1,5 +0,0 @@
extends Node
func _input(event: InputEvent) -> void:
if event.is_action_pressed("menu"):
get_tree().quit()

View File

@ -1,7 +1,9 @@
extends Node
@onready var anthill_info: AnthillInfo = $/root/World/UI/AnthillInfo
@onready var buy_ants: BuyAnts = $/root/World/UI/BuyAnts
func _ready() -> void:
assert(anthill_info != null, "anthill_info missing!")
assert(buy_ants != null, "buy_ants missing!")

View File

@ -25,9 +25,14 @@ func _process(delta: float) -> void:
if anthill == null or not visible:
return
counter.update_counter(anthill.honeydew)
add_one_button.disabled = not DebugDraw.enabled
add_one_button.visible = DebugDraw.enabled
add_five_button.disabled = not DebugDraw.enabled
add_five_button.visible = DebugDraw.enabled
func open(at: Anthill) -> void:
visible = true
anthill = at
set_target(anthill.ui_origin)
counter.initialize(anthill.honeydew, anthill.max_honeydew)
@ -39,7 +44,8 @@ func close() -> void:
func _on_ant_buy_button_pressed() -> void:
print('AAAAAA')
UiManager.buy_ants.open(anthill)
close()
func _on_add_one_button_pressed() -> void:

67
scripts/ui/buy_ants.gd Normal file
View File

@ -0,0 +1,67 @@
extends FollowingUI
class_name BuyAnts
const COUNTER_SIZE:float = 32
var anthill: Anthill
@onready var buy_nitwit_button: BaseButton = $BuyNitwitButton
@onready var nitwit_price_counter: HoneydewCounter = $NitwitPriceCounter
@onready var nitwit_info: Control = $NitwitPanel
@onready var buy_gatherer_button: BaseButton = $BuyGathererButton
@onready var gatherer_price_counter: HoneydewCounter = $GathererPriceCounter
@onready var gatherer_info: Control = $GathererPanel
@onready var counter: HoneydewCounter = $HoneydewCounter
func _ready() -> void:
assert(buy_nitwit_button != null, "buy_nitwit_button missing!")
assert(nitwit_price_counter != null, "nitwit_price_counter missing!")
assert(nitwit_info != null, "nitwit_info missing!")
assert(buy_gatherer_button != null, "buy_gatherer_button missing!")
assert(gatherer_price_counter != null, "gatherer_price_counter missing!")
assert(gatherer_info != null, "gatherer_info missing!")
super._ready()
buy_nitwit_button.pressed.connect(_on_buy_nitwit_button_pressed)
nitwit_info.visible = false
buy_gatherer_button.pressed.connect(_on_buy_gatherer_button_pressed)
gatherer_info.visible = false
func _process(delta: float) -> void:
super._process(delta)
if anthill == null or not visible:
return
counter.update_counter(anthill.honeydew)
nitwit_info.visible = buy_nitwit_button.is_hovered()
gatherer_info.visible = buy_gatherer_button.is_hovered()
func open(at: Anthill) -> void:
visible = true
anthill = at
nitwit_price_counter.initialize(
AntNitwit.get_cost(),
AntNitwit.get_cost(),
COUNTER_SIZE,
)
gatherer_price_counter.initialize(
AntGatherer.get_cost(),
AntGatherer.get_cost(),
COUNTER_SIZE,
)
set_target(anthill.ui_origin)
counter.initialize(anthill.honeydew, anthill.max_honeydew)
func close() -> void:
super.close()
anthill = null
func _on_buy_nitwit_button_pressed() -> void:
anthill.spawn_nitwit()
func _on_buy_gatherer_button_pressed() -> void:
anthill.spawn_gatherer()

View File

@ -27,7 +27,6 @@ func _process(_delta: float) -> void:
func set_target(to: Node3D) -> void:
visible = true
target = to

View File

@ -10,6 +10,7 @@ var rects: Array[TextureRect] = []
var max_count: int = 0
var count_per_row: int = 0
var rect_size: float = RECT_SIZE
var counter_1 := preload("res://assets/textures/gui/honeydew_1.png")
var counter_2 := preload("res://assets/textures/gui/honeydew_2.png")
@ -19,11 +20,16 @@ var counter_5 := preload("res://assets/textures/gui/honeydew_5.png")
func _ready() -> void:
count_per_row = floor(size.x / (RECT_SIZE + GAP))
count_per_row = floor(size.x / (rect_size + GAP))
func initialize(init_count: int, init_max_count: int) -> void:
func initialize(
init_count: int,
init_max_count: int,
r_size: float = RECT_SIZE,
) -> void:
max_count = init_max_count
rect_size = r_size
rects.clear()
for rect in get_children():
remove_child(rect)
@ -75,13 +81,13 @@ func _create_rect(col: int, row: int) -> TextureRect:
rect.expand_mode = TextureRect.EXPAND_IGNORE_SIZE
rect.position.x = (
col
* (RECT_SIZE + GAP)
* (rect_size + GAP)
+ randf_range(-RANDOM_OFFSET, RANDOM_OFFSET)
)
rect.position.y = (
row
* (RECT_SIZE + GAP)
* (rect_size + GAP)
+ randf_range(-RANDOM_OFFSET, RANDOM_OFFSET)
)
rect.size = Vector2(RECT_SIZE, RECT_SIZE)
rect.size = Vector2(rect_size, rect_size)
return rect

37
scripts/ui/pause_menu.gd Normal file
View File

@ -0,0 +1,37 @@
extends Panel
class_name PauseMenu
@onready var cancel_button: BaseButton = $Panel/CancelButton
@onready var quit_button: BaseButton = $Panel/QuitButton
func _ready() -> void:
assert(cancel_button != null, "cancel_button missing!")
assert(quit_button != null, "quit_button missing!")
cancel_button.pressed.connect(_on_cancel_button_pressed)
quit_button.pressed.connect(_on_quit_button_pressed)
visible = false
func _input(event: InputEvent) -> void:
if event.is_action_pressed("menu"):
if visible:
_close()
else:
visible = true
get_tree().paused = true
func _close() -> void:
visible = false
get_tree().paused = false
func _on_cancel_button_pressed() -> void:
print('cancel')
_close()
func _on_quit_button_pressed() -> void:
print('quit')
get_tree().quit()