From 793938857ea395aaeda683c0eec9967bbf61fb87 Mon Sep 17 00:00:00 2001 From: gotfishmakesticks <80163046+gotfishmakesticks@users.noreply.github.com> Date: Sun, 14 Jan 2024 14:00:42 +0300 Subject: [PATCH] Bugged trading inventory --- scenes/menus/BaseMenu.tscn | 151 ++++++++++++++++++++++++--------- scripts/menu/BaseMenu.gd | 28 +++++- scripts/menu/OpenMenuButton.gd | 2 - 3 files changed, 136 insertions(+), 45 deletions(-) diff --git a/scenes/menus/BaseMenu.tscn b/scenes/menus/BaseMenu.tscn index 33473d6..8dc3c17 100644 --- a/scenes/menus/BaseMenu.tscn +++ b/scenes/menus/BaseMenu.tscn @@ -1,9 +1,20 @@ -[gd_scene load_steps=5 format=3 uid="uid://bdwk0dqcx0xhp"] +[gd_scene load_steps=10 format=3 uid="uid://bdwk0dqcx0xhp"] [ext_resource type="Script" path="res://scripts/menu/BaseMenu.gd" id="1_0wv8j"] [ext_resource type="Texture2D" uid="uid://db4euprxhape0" path="res://sprites/9s.png" id="1_vb0tn"] [ext_resource type="Script" path="res://scripts/menu/CloseMenuButton.gd" id="2_ld3o5"] [ext_resource type="Script" path="res://scripts/menu/OpenMenuButton.gd" id="3_63o1s"] +[ext_resource type="Texture2D" uid="uid://daojdy0tpvsoh" path="res://sprites/items_icons/energy.png" id="5_a74tb"] +[ext_resource type="Texture2D" uid="uid://w3aft10s2hxd" path="res://sprites/items_icons/food.png" id="6_36d3e"] +[ext_resource type="Texture2D" uid="uid://dlh6eyywjrsk4" path="res://sprites/items_icons/raw_materials.png" id="7_41v33"] +[ext_resource type="Texture2D" uid="uid://cova10yh1rlk1" path="res://sprites/items_icons/water.png" id="8_815di"] + +[sub_resource type="GDScript" id="GDScript_ovke4"] +script/source = "extends Button + +func _on_button_up(): + get_parent().visible = false +" [node name="BaseMenu" type="Control"] process_mode = 1 @@ -39,51 +50,40 @@ vertical_alignment = 1 [node name="TradingMenuGoto" type="Button" parent="MainMenu"] layout_mode = 0 offset_left = 1.0 -offset_top = 64.0 +offset_top = 160.0 offset_right = 639.0 -offset_bottom = 192.0 -text = "Buy / Sell goods" +offset_bottom = 224.0 +text = "Trading" script = ExtResource("3_63o1s") [node name="QuestMenuGoto" type="Button" parent="MainMenu"] layout_mode = 0 offset_left = 1.0 -offset_top = 192.0 +offset_top = 288.0 offset_right = 639.0 -offset_bottom = 320.0 -text = "Take / Pass the quest" +offset_bottom = 352.0 +text = "Quests" script = ExtResource("3_63o1s") [node name="EquipmentMenuGoto" type="Button" parent="MainMenu"] layout_mode = 0 offset_left = 1.0 -offset_top = 320.0 +offset_top = 416.0 offset_right = 639.0 -offset_bottom = 448.0 -text = "Change your equipment" +offset_bottom = 480.0 +text = "Equipment" script = ExtResource("3_63o1s") -[node name="InfoMenuGoto" type="Button" parent="MainMenu"] +[node name="MainCloseButton" type="Button" parent="MainMenu"] layout_mode = 0 -offset_left = 1.0 -offset_top = 448.0 +offset_left = 600.0 +offset_top = 1.0 offset_right = 639.0 -offset_bottom = 576.0 -text = "About this station" -script = ExtResource("3_63o1s") - -[node name="Footer" type="Label" parent="MainMenu"] -layout_mode = 0 -offset_top = 576.0 -offset_right = 640.0 -offset_bottom = 640.0 -text = "Press [TAB] to show / hide menu -Fly off the base to exit menu" -horizontal_alignment = 1 -vertical_alignment = 1 +offset_bottom = 40.0 +text = "X" +script = SubResource("GDScript_ovke4") [node name="TradingMenu" type="NinePatchRect" parent="."] -visible = false layout_mode = 0 offset_left = 320.0 offset_top = 40.0 @@ -116,50 +116,117 @@ script = ExtResource("2_ld3o5") [node name="SellList" type="ItemList" parent="TradingMenu"] layout_mode = 0 offset_left = 1.0 -offset_top = 64.0 +offset_top = 96.0 offset_right = 320.0 -offset_bottom = 576.0 +offset_bottom = 512.0 [node name="BuyList" type="ItemList" parent="TradingMenu"] layout_mode = 0 offset_left = 320.0 -offset_top = 64.0 +offset_top = 96.0 offset_right = 639.0 -offset_bottom = 576.0 +offset_bottom = 512.0 [node name="SellInput" type="LineEdit" parent="TradingMenu"] layout_mode = 0 offset_left = 1.0 -offset_top = 576.0 +offset_top = 512.0 offset_right = 160.0 -offset_bottom = 639.0 +offset_bottom = 576.0 placeholder_text = "Amount to buy" alignment = 1 [node name="BuyInput" type="LineEdit" parent="TradingMenu"] layout_mode = 0 offset_left = 320.0 -offset_top = 576.0 +offset_top = 512.0 offset_right = 480.0 -offset_bottom = 639.0 +offset_bottom = 576.0 placeholder_text = "Amount to sell" alignment = 1 [node name="BuyButton" type="Button" parent="TradingMenu"] layout_mode = 0 offset_left = 160.0 -offset_top = 576.0 +offset_top = 512.0 offset_right = 320.0 -offset_bottom = 639.0 -text = "Buy selected item" +offset_bottom = 576.0 +text = "Buy" [node name="SellButton" type="Button" parent="TradingMenu"] layout_mode = 0 offset_left = 480.0 -offset_top = 576.0 +offset_top = 512.0 offset_right = 639.0 -offset_bottom = 639.0 -text = "Sell selected item" +offset_bottom = 576.0 +text = "Sell" + +[node name="LabelBuy" type="Label" parent="TradingMenu"] +layout_mode = 0 +offset_top = 64.0 +offset_right = 320.0 +offset_bottom = 96.0 +text = "Buy" +horizontal_alignment = 1 +vertical_alignment = 1 + +[node name="LabelSell" type="Label" parent="TradingMenu"] +offset_left = 320.0 +offset_top = 64.0 +offset_right = 640.0 +offset_bottom = 96.0 +text = "Sell" +horizontal_alignment = 1 +vertical_alignment = 1 + +[node name="Energy" type="Sprite2D" parent="TradingMenu"] +position = Vector2(17, 608) +texture = ExtResource("5_a74tb") + +[node name="Food" type="Sprite2D" parent="TradingMenu"] +position = Vector2(177, 608) +texture = ExtResource("6_36d3e") + +[node name="RawMaterials" type="Sprite2D" parent="TradingMenu"] +position = Vector2(337, 608) +texture = ExtResource("7_41v33") + +[node name="Water" type="Sprite2D" parent="TradingMenu"] +position = Vector2(497, 608) +texture = ExtResource("8_815di") + +[node name="EnergyCount" type="Label" parent="TradingMenu"] +layout_mode = 0 +offset_left = 41.0 +offset_top = 592.0 +offset_right = 161.0 +offset_bottom = 624.0 +text = "0" +vertical_alignment = 1 + +[node name="FoodCount" type="Label" parent="TradingMenu"] +offset_left = 201.0 +offset_top = 592.0 +offset_right = 321.0 +offset_bottom = 624.0 +text = "0" +vertical_alignment = 1 + +[node name="MineralsCount" type="Label" parent="TradingMenu"] +offset_left = 361.0 +offset_top = 592.0 +offset_right = 481.0 +offset_bottom = 624.0 +text = "0" +vertical_alignment = 1 + +[node name="WaterCount" type="Label" parent="TradingMenu"] +offset_left = 521.0 +offset_top = 592.0 +offset_right = 640.0 +offset_bottom = 624.0 +text = "0" +vertical_alignment = 1 [node name="QuestMenu" type="NinePatchRect" parent="."] visible = false @@ -498,3 +565,5 @@ text = "Actually, this section is WIP. Part of the factions system." horizontal_alignment = 1 vertical_alignment = 1 + +[connection signal="button_up" from="MainMenu/MainCloseButton" to="MainMenu/MainCloseButton" method="_on_button_up"] diff --git a/scripts/menu/BaseMenu.gd b/scripts/menu/BaseMenu.gd index 57f473c..ccd81bc 100644 --- a/scripts/menu/BaseMenu.gd +++ b/scripts/menu/BaseMenu.gd @@ -27,6 +27,10 @@ var base @onready var equip_primary = $EquipmentMenu/EquipPrimaryButton @onready var equip_secondary = $EquipmentMenu/EquipSecondaryButton @onready var label_mod_info = $EquipmentMenu/LabelInfoBlock +@onready var label_energy = $TradingMenu/EnergyCount +@onready var label_food = $TradingMenu/FoodCount +@onready var label_minerals = $TradingMenu/MineralsCount +@onready var label_water = $TradingMenu/WaterCount var base_types = ["Power Supply", "Mining", "Food Production", "Trading"] var equipment_category = "hull" var focused_mod_id = -1 @@ -78,6 +82,7 @@ func _ready(): shields_prices = base.shields_prices weapons_prices = base.weapons_prices select_hull_mod() + update_goods_numbers() ## Updates buy and sell list in trading menu with available items func update_lists(): @@ -123,7 +128,7 @@ func buy_item(): else: ship.hull.cargo[item_data[0]] = amount ship.money -= total_price - print(ship.hull.cargo) + update_goods_numbers() ## Event handler for sell option in trading menu func sell_item(): @@ -150,7 +155,7 @@ func sell_item(): return ship.hull.cargo[item_data[0]] -= amount ship.money += total_price - print(ship.hull.cargo) + update_goods_numbers() func buy_text_changed(_new_text): buy_input.placeholder_text = "Amount to sell" @@ -505,3 +510,22 @@ func set_module_info_text(item): } text += "Ammo type: {ammotype}\nAmmo consumption: {ammocons} units/usage\nFirerate: {firerate} usages/second\nSpread: {spread} degrees".format(format) label_mod_info.text = text + +func update_goods_numbers(): + var cargo = ship.hull.cargo + if cargo.has('Energy Cell'): + label_energy.text = str(cargo['Energy Cell']) + else: + label_energy.text = "0" + if cargo.has('Food Supplies'): + label_food.text = str(cargo['Food Supplies']) + else: + label_food.text = "0" + if cargo.has('Raw Materials'): + label_minerals.text = str(cargo['Raw Materials']) + else: + label_minerals.text = "0" + if cargo.has('Water Barrel'): + label_water.text = str(cargo['Water Barrel']) + else: + label_water.text = "0" diff --git a/scripts/menu/OpenMenuButton.gd b/scripts/menu/OpenMenuButton.gd index 5cf5710..bc25a6d 100644 --- a/scripts/menu/OpenMenuButton.gd +++ b/scripts/menu/OpenMenuButton.gd @@ -22,8 +22,6 @@ func open(): base_menu.quest_status_update() "EquipmentMenuGoto": menu = equipment_menu - "InfoMenuGoto": - menu = info_menu menu.visible = true if submenu != null: submenu.visible = true