Added debug option, fixed #1, visual tweaks

This commit is contained in:
jepsu 2026-06-26 21:45:23 +03:00
parent 05df588aa7
commit bb80a4b2d9
6 changed files with 51 additions and 10 deletions

View file

@ -31,6 +31,7 @@ func _ready() -> void:
give_money.connect(_on_give_money) give_money.connect(_on_give_money)
func _on_give_experience(amount: float) -> void: func _on_give_experience(amount: float) -> void:
print('Gave: %.0f xp' % amount)
xp += amount xp += amount
if xp >= 100: if xp >= 100:
while xp >= 100: while xp >= 100:

View file

@ -6,6 +6,7 @@ extends PanelContainer
@onready var select_job: OptionButton = $MarginContainer/MainArea/SelectJob @onready var select_job: OptionButton = $MarginContainer/MainArea/SelectJob
@onready var status_label: Label = $MarginContainer/MainArea/TopInfo/StatusLabel @onready var status_label: Label = $MarginContainer/MainArea/TopInfo/StatusLabel
@onready var time_left_label: Label = $MarginContainer/MainArea/PrintInfo/TimeLeftLabel @onready var time_left_label: Label = $MarginContainer/MainArea/PrintInfo/TimeLeftLabel
@onready var start_button: Button = $MarginContainer/MainArea/Buttons/StartButton
var printer_data: PrinterData var printer_data: PrinterData
var selected_job: JobData var selected_job: JobData
@ -31,9 +32,6 @@ func _process(delta) -> void:
set_status() set_status()
var total_time = selected_job.job_time var total_time = selected_job.job_time
var progress = (total_time - time_left) / total_time var progress = (total_time - time_left) / total_time
#print('Job time: %.2f' % total_time)
#print('Time left: %.2f' % time_left)
#print('Progress: %.2f' % progress)
time_left -= delta time_left -= delta
progress_bar.value = progress progress_bar.value = progress
time_left_label.text = 'Time left: %s' % calculate_time_left(time_left) time_left_label.text = 'Time left: %s' % calculate_time_left(time_left)
@ -82,13 +80,17 @@ func _on_select_job_pressed() -> void:
if PlayerData.jobs.is_empty(): if PlayerData.jobs.is_empty():
select_job.add_item("No jobs accepted") select_job.add_item("No jobs accepted")
start_button.disabled = true
else: else:
start_button.disabled = false
for job in PlayerData.jobs: for job in PlayerData.jobs:
var item_text = '%s (XP: %d | %d)' % [job.job_name, job.job_experience, job.job_reward] var item_text = '%s (XP: %d | %d | %s)' % [job.job_name, job.job_experience, job.job_reward, calculate_time_left(job.job_time)]
select_job.add_item(item_text) select_job.add_item(item_text)
var current_index = select_job.item_count - 1 var current_index = select_job.item_count - 1
select_job.set_item_metadata(current_index, job) select_job.set_item_metadata(current_index, job)
selected_job = select_job.get_item_metadata(0)
selected_job_index = 0
func _on_start_button_pressed() -> void: func _on_start_button_pressed() -> void:
if select_job.get_item_text(0) == "No jobs accepted": if select_job.get_item_text(0) == "No jobs accepted":
@ -96,12 +98,7 @@ func _on_start_button_pressed() -> void:
else: else:
time_left = selected_job.job_time time_left = selected_job.job_time
is_printing = true is_printing = true
#PlayerData.give_money.emit(selected_job.job_reward)
#if PlayerData.jobs.size() == 1:
# PlayerData.jobs.clear()
#else:
# PlayerData.jobs.remove_at(selected_job_index)
_on_select_job_pressed() _on_select_job_pressed()
func _on_select_job_item_selected(index: int) -> void: func _on_select_job_item_selected(index: int) -> void:

View file

@ -2,6 +2,7 @@
[ext_resource type="Script" uid="uid://dj7pngpg53qdb" path="res://printer.gd" id="1_jhpce"] [ext_resource type="Script" uid="uid://dj7pngpg53qdb" path="res://printer.gd" id="1_jhpce"]
[ext_resource type="StyleBox" uid="uid://csahw36txnewl" path="res://Styles/btn_style_box_green_hover.tres" id="2_tnxmo"] [ext_resource type="StyleBox" uid="uid://csahw36txnewl" path="res://Styles/btn_style_box_green_hover.tres" id="2_tnxmo"]
[ext_resource type="StyleBox" uid="uid://b0kxbbhtsbhcr" path="res://Styles/btn_style_box_red_hover.tres" id="3_vtisp"]
[node name="Printer" type="PanelContainer" unique_id=1372437203] [node name="Printer" type="PanelContainer" unique_id=1372437203]
custom_minimum_size = Vector2(0, 150) custom_minimum_size = Vector2(0, 150)
@ -72,6 +73,7 @@ text = "Upgrade"
[node name="SellButton" type="Button" parent="MarginContainer/MainArea/Buttons" unique_id=929234066] [node name="SellButton" type="Button" parent="MarginContainer/MainArea/Buttons" unique_id=929234066]
layout_mode = 2 layout_mode = 2
size_flags_horizontal = 3 size_flags_horizontal = 3
theme_override_styles/hover = ExtResource("3_vtisp")
text = "Sell printer" text = "Sell printer"
[node name="SelectJob" type="OptionButton" parent="MarginContainer/MainArea" unique_id=1500040832] [node name="SelectJob" type="OptionButton" parent="MarginContainer/MainArea" unique_id=1500040832]

View file

@ -10,6 +10,9 @@ var printer_data: PrinterData
@onready var printer_price: Label = $MarginContainer/VBoxContainer/HBoxContainer/Price @onready var printer_price: Label = $MarginContainer/VBoxContainer/HBoxContainer/Price
@onready var buy_button: Button = $MarginContainer/VBoxContainer/HBoxContainer/BuyButton @onready var buy_button: Button = $MarginContainer/VBoxContainer/HBoxContainer/BuyButton
func _ready() -> void:
PlayerData.money_changed.connect(_on_toggle_button)
func initialize_printer(data: PrinterData) -> void: func initialize_printer(data: PrinterData) -> void:
printer_data = data printer_data = data
printer_name.text = printer_data.printer_manufacturer printer_name.text = printer_data.printer_manufacturer
@ -26,3 +29,9 @@ func initialize_printer(data: PrinterData) -> void:
func _on_buy_button_pressed() -> void: func _on_buy_button_pressed() -> void:
buy_printer.emit(self) buy_printer.emit(self)
print("Shop tab printer clicked: " + self.printer_data.printer_manufacturer) print("Shop tab printer clicked: " + self.printer_data.printer_manufacturer)
func _on_toggle_button(money) -> void:
if PlayerData.money > printer_data.printer_price:
buy_button.disabled = false
else:
buy_button.disabled = true

21
ui.gd
View file

@ -2,11 +2,18 @@ extends Control
@export var jobs_array: Array[JobData] @export var jobs_array: Array[JobData]
@export var job_limit: int = 5 @export var job_limit: int = 5
@export var debug: bool = false
var jobs_tab_button: Button var jobs_tab_button: Button
@onready var debug_xp: Button = $VBoxContainer/TopBar/VBoxContainer/MarginContainer/HBoxContainer/DebugXP
@onready var debug_money: Button = $VBoxContainer/TopBar/VBoxContainer/MarginContainer/HBoxContainer/DebugMoney
const JOB_SCENE = preload("uid://dvfcie8hqcb0") const JOB_SCENE = preload("uid://dvfcie8hqcb0")
const PRINTER = preload("uid://33ctlyrpibs3") const PRINTER = preload("uid://33ctlyrpibs3")
func _ready() -> void: func _ready() -> void:
check_debug()
%Money.text = "Money: " + str(PlayerData.money) + "" %Money.text = "Money: " + str(PlayerData.money) + ""
%Experience.value = PlayerData.xp %Experience.value = PlayerData.xp
%Level.text = "Level: " + str(PlayerData.level) %Level.text = "Level: " + str(PlayerData.level)
@ -54,3 +61,17 @@ func _on_printers_printer_purchase_requested(printer_data: PrinterData) -> void:
var new_printer = PRINTER.instantiate() var new_printer = PRINTER.instantiate()
%PrinterContainer.add_child(new_printer) %PrinterContainer.add_child(new_printer)
new_printer.initialize_printer(printer_data) new_printer.initialize_printer(printer_data)
func check_debug() -> void:
debug_xp.visible = false
debug_money.visible = false
if debug:
debug_xp.visible = true
debug_money.visible = true
func _on_debug_money_pressed() -> void:
PlayerData.give_money.emit(100)
func _on_debug_xp_pressed() -> void:
var xp = randf() * 100
PlayerData.give_experience.emit(xp)

11
ui.tscn
View file

@ -70,6 +70,14 @@ layout_mode = 2
size_flags_horizontal = 3 size_flags_horizontal = 3
text = "Money: 0 €" text = "Money: 0 €"
[node name="DebugMoney" type="Button" parent="VBoxContainer/TopBar/VBoxContainer/MarginContainer/HBoxContainer" unique_id=601739475]
layout_mode = 2
text = "Give 100€"
[node name="DebugXP" type="Button" parent="VBoxContainer/TopBar/VBoxContainer/MarginContainer/HBoxContainer" unique_id=535993224]
layout_mode = 2
text = "Give xp"
[node name="Time" type="Label" parent="VBoxContainer/TopBar/VBoxContainer/MarginContainer/HBoxContainer" unique_id=1503956629] [node name="Time" type="Label" parent="VBoxContainer/TopBar/VBoxContainer/MarginContainer/HBoxContainer" unique_id=1503956629]
visible = false visible = false
layout_mode = 2 layout_mode = 2
@ -100,6 +108,7 @@ layout_mode = 2
size_flags_horizontal = 3 size_flags_horizontal = 3
[node name="Header" type="MarginContainer" parent="VBoxContainer/MainArea/LeftColumn" unique_id=674103883] [node name="Header" type="MarginContainer" parent="VBoxContainer/MainArea/LeftColumn" unique_id=674103883]
visible = false
layout_mode = 2 layout_mode = 2
theme_override_constants/margin_left = 10 theme_override_constants/margin_left = 10
theme_override_constants/margin_top = 10 theme_override_constants/margin_top = 10
@ -204,6 +213,8 @@ layout_mode = 2
[node name="JobSpawner" type="Timer" parent="." unique_id=1696213535] [node name="JobSpawner" type="Timer" parent="." unique_id=1696213535]
autostart = true autostart = true
[connection signal="pressed" from="VBoxContainer/TopBar/VBoxContainer/MarginContainer/HBoxContainer/DebugMoney" to="." method="_on_debug_money_pressed"]
[connection signal="pressed" from="VBoxContainer/TopBar/VBoxContainer/MarginContainer/HBoxContainer/DebugXP" to="." method="_on_debug_xp_pressed"]
[connection signal="pressed" from="VBoxContainer/MainArea/RightColumn/TabSwitcher/TabButtons/JobsTabButton" to="VBoxContainer/MainArea/RightColumn/TabSwitcher" method="_on_jobs_tab_button_pressed"] [connection signal="pressed" from="VBoxContainer/MainArea/RightColumn/TabSwitcher/TabButtons/JobsTabButton" to="VBoxContainer/MainArea/RightColumn/TabSwitcher" method="_on_jobs_tab_button_pressed"]
[connection signal="pressed" from="VBoxContainer/MainArea/RightColumn/TabSwitcher/TabButtons/ShopTabButton" to="VBoxContainer/MainArea/RightColumn/TabSwitcher" method="_on_shop_tab_button_pressed"] [connection signal="pressed" from="VBoxContainer/MainArea/RightColumn/TabSwitcher/TabButtons/ShopTabButton" to="VBoxContainer/MainArea/RightColumn/TabSwitcher" method="_on_shop_tab_button_pressed"]
[connection signal="pressed" from="VBoxContainer/MainArea/RightColumn/TabSwitcher/TabButtons/MenuTabButton" to="VBoxContainer/MainArea/RightColumn/TabSwitcher" method="_on_menu_tab_button_pressed"] [connection signal="pressed" from="VBoxContainer/MainArea/RightColumn/TabSwitcher/TabButtons/MenuTabButton" to="VBoxContainer/MainArea/RightColumn/TabSwitcher" method="_on_menu_tab_button_pressed"]