diff --git a/items/Valuables/energy_cell.tres b/items/Valuables/energy_cell.tres index 5aa91e9..d9786fe 100644 --- a/items/Valuables/energy_cell.tres +++ b/items/Valuables/energy_cell.tres @@ -1,11 +1,11 @@ [gd_resource type="Resource" script_class="Item" load_steps=3 format=3 uid="uid://16xqvcrmuga6"] -[ext_resource type="Texture2D" uid="uid://daojdy0tpvsoh" path="res://sprites/items_icons/energy.png" id="1_1ocvl"] +[ext_resource type="Texture2D" uid="uid://buh2eg0sjlcx0" path="res://sprites/items_icons/energy_cell.png" id="1_1ocvl"] [ext_resource type="Script" path="res://scripts/Classes/item.gd" id="1_wdaj0"] [resource] script = ExtResource("1_wdaj0") -name = "Energy Cell" +name = "ENERGY_CELL" description = "" min_price = 1.0 max_price = 20.0 diff --git a/items/Valuables/food_supplies.tres b/items/Valuables/food_supplies.tres index 905c16c..2fb3a18 100644 --- a/items/Valuables/food_supplies.tres +++ b/items/Valuables/food_supplies.tres @@ -1,11 +1,11 @@ [gd_resource type="Resource" script_class="Item" load_steps=3 format=3 uid="uid://ca8cpmd1aluut"] [ext_resource type="Script" path="res://scripts/Classes/item.gd" id="1_gmqal"] -[ext_resource type="Texture2D" uid="uid://w3aft10s2hxd" path="res://sprites/items_icons/food.png" id="1_w33w6"] +[ext_resource type="Texture2D" uid="uid://bvun3kxlvs712" path="res://sprites/items_icons/food_supplies.png" id="1_w33w6"] [resource] script = ExtResource("1_gmqal") -name = "Food Supplies" +name = "FOOD_SUPPLY" description = "" min_price = 10.0 max_price = 100.0 diff --git a/items/Valuables/raw_materials.tres b/items/Valuables/raw_materials.tres index 2e5078d..914f37f 100644 --- a/items/Valuables/raw_materials.tres +++ b/items/Valuables/raw_materials.tres @@ -1,11 +1,11 @@ [gd_resource type="Resource" script_class="Item" load_steps=3 format=3 uid="uid://dlnl6w416qylo"] -[ext_resource type="Texture2D" uid="uid://dlh6eyywjrsk4" path="res://sprites/items_icons/raw_materials.png" id="1_an4j4"] +[ext_resource type="Texture2D" uid="uid://fttis3gwgq02" path="res://sprites/items_icons/raw_materials.png" id="1_an4j4"] [ext_resource type="Script" path="res://scripts/Classes/item.gd" id="1_l7wcw"] [resource] script = ExtResource("1_l7wcw") -name = "Raw Materials" +name = "RAW_MATERIALS" description = "" min_price = 10.0 max_price = 50.0 diff --git a/items/Valuables/water_barrel.tres b/items/Valuables/water_barrel.tres index e51a2f4..5472829 100644 --- a/items/Valuables/water_barrel.tres +++ b/items/Valuables/water_barrel.tres @@ -1,11 +1,11 @@ [gd_resource type="Resource" script_class="Item" load_steps=3 format=3 uid="uid://b4jy8uknltolk"] -[ext_resource type="Texture2D" uid="uid://cova10yh1rlk1" path="res://sprites/items_icons/water.png" id="1_fv1u8"] +[ext_resource type="Texture2D" uid="uid://cvimydsdecmom" path="res://sprites/items_icons/water_barrel.png" id="1_fv1u8"] [ext_resource type="Script" path="res://scripts/Classes/item.gd" id="1_w7v0g"] [resource] script = ExtResource("1_w7v0g") -name = "Water Barrel" +name = "WATER_BARREL" description = "" min_price = 5.0 max_price = 30.0 diff --git a/project.godot b/project.godot index 5a89d26..a99fa60 100644 --- a/project.godot +++ b/project.godot @@ -94,7 +94,7 @@ dock={ [internationalization] -locale/translations=PackedStringArray("res://translations/gui.en.translation", "res://translations/gui.ru.translation", "res://translations/base_dialogue.en.translation", "res://translations/base_dialogue.ru.translation") +locale/translations=PackedStringArray("res://translations/gui.en.translation", "res://translations/gui.ru.translation", "res://translations/base_dialogue.en.translation", "res://translations/base_dialogue.ru.translation", "res://translations/items.en.translation", "res://translations/items.ru.translation") [layer_names] diff --git a/scenes/Base/base_menu.tscn b/scenes/Base/base_menu.tscn index 4ed0b35..85257b1 100644 --- a/scenes/Base/base_menu.tscn +++ b/scenes/Base/base_menu.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=9 format=3 uid="uid://crq284yed2if5"] +[gd_scene load_steps=10 format=3 uid="uid://crq284yed2if5"] [ext_resource type="Script" path="res://scripts/Base/base_menu.gd" id="1_3hgu4"] [ext_resource type="Theme" uid="uid://dmb8bcdghdjd" path="res://main_theme.tres" id="1_p1gsn"] @@ -8,6 +8,7 @@ [ext_resource type="Script" path="res://scripts/Base/close_button.gd" id="4_68ool"] [ext_resource type="Script" path="res://scripts/Base/Menu/dialogue.gd" id="4_swpa1"] [ext_resource type="Resource" uid="uid://2ohcxoor22hr" path="res://menus/Base Menu/root_menu.tres" id="6_78in3"] +[ext_resource type="Script" path="res://scripts/Base/Menu/buy_sell.gd" id="9_u6g71"] [node name="BaseMenu" type="Control"] layout_mode = 3 @@ -184,4 +185,7 @@ offset_bottom = 73.0 icon = ExtResource("2_ceeiv") script = ExtResource("4_68ool") +[node name="BuySell" type="Node" parent="."] +script = ExtResource("9_u6g71") + [connection signal="button_up" from="MenuBackground/CloseButtonBack/CloseButton" to="MenuBackground/CloseButtonBack/CloseButton" method="_on_button_up"] diff --git a/scenes/Star System/star_system_debug.tscn b/scenes/Star System/star_system_debug.tscn index f4d305c..c88f793 100644 --- a/scenes/Star System/star_system_debug.tscn +++ b/scenes/Star System/star_system_debug.tscn @@ -1,10 +1,14 @@ -[gd_scene load_steps=6 format=3 uid="uid://crneq2enhxsw5"] +[gd_scene load_steps=10 format=3 uid="uid://crneq2enhxsw5"] [ext_resource type="PackedScene" uid="uid://bsnrcw64qr2hr" path="res://scenes/Star System/star_system_template.tscn" id="1_2ai1l"] [ext_resource type="PackedScene" uid="uid://dk3nvl8f0v24e" path="res://scenes/Base/base_template.tscn" id="3_m5ica"] [ext_resource type="PackedScene" uid="uid://pev6k21vqaem" path="res://scenes/Ships/NPC Ships/kamikaze_ship.tscn" id="4_i6rbg"] +[ext_resource type="Resource" uid="uid://b4jy8uknltolk" path="res://items/Valuables/water_barrel.tres" id="4_xwim1"] [ext_resource type="PackedScene" uid="uid://yso8f0y5kg50" path="res://scenes/Ships/NPC Ships/shooter_ship.tscn" id="5_o3ny8"] +[ext_resource type="Resource" uid="uid://ca8cpmd1aluut" path="res://items/Valuables/food_supplies.tres" id="5_oxe5h"] +[ext_resource type="Resource" uid="uid://dlnl6w416qylo" path="res://items/Valuables/raw_materials.tres" id="6_mrd6j"] [ext_resource type="PackedScene" uid="uid://dok3i8u5t1ka4" path="res://scenes/Ships/player_ship.tscn" id="7_jyplv"] +[ext_resource type="Resource" uid="uid://16xqvcrmuga6" path="res://items/Valuables/energy_cell.tres" id="7_x535v"] [node name="StarSystem" instance=ExtResource("1_2ai1l")] width = 16384 @@ -23,7 +27,9 @@ process_mode = 0 position = Vector2(19, 10) [node name="Base" parent="FactionPeaceful" index="0" instance=ExtResource("3_m5ica")] -position = Vector2(1706, -5) +position = Vector2(719, -559) +items_on_sell = Array[Resource("res://scripts/Classes/item.gd")]([ExtResource("4_xwim1"), ExtResource("5_oxe5h"), ExtResource("6_mrd6j")]) +items_on_buy = Array[Resource("res://scripts/Classes/item.gd")]([ExtResource("7_x535v"), ExtResource("6_mrd6j")]) [node name="KamikazeShip" parent="FactionAggressive" index="0" instance=ExtResource("4_i6rbg")] position = Vector2(-1712, -608) diff --git a/scripts/Base/Menu/buy_sell.gd b/scripts/Base/Menu/buy_sell.gd new file mode 100644 index 0000000..bf7454d --- /dev/null +++ b/scripts/Base/Menu/buy_sell.gd @@ -0,0 +1,48 @@ +extends Node + +@onready var base = get_parent().base + +const ITEM_TEMPLATE = "BASE_FETCH_PRICE_ITEM" + +## List of items that this base sells +var items_on_sell +## List of items that this base buys +var items_on_buy +## List of prices of items that this base sells +var sell_prices +## List of prices of items that this base buys +var buy_prices + +var template = tr(ITEM_TEMPLATE) + +func _ready(): + get_tree().create_timer(0.05).timeout.connect(fetch_items) + +## Fetches items and pricelists from base +func fetch_items(): + items_on_sell = base.items_on_sell + items_on_buy = base.items_on_buy + sell_prices = base.sell_prices + buy_prices = base.buy_prices + print(base) + print(items_on_sell, "\n", items_on_buy) + +## Returns buy/sell description of a selected item +func item_description(buy: bool, id: int) -> String: + assert(id >= 0) + var item = items_on_buy[id] if buy else items_on_sell[id] + var price = buy_prices[id] if buy else sell_prices[id] + var format = { + "item_img": item.icon.resource_path, + "item_name": tr(item.name), + "item_price": price + } + return template.format(format) + +## Returns buy/sell list of all items +func get_buy_sell_list(buy: bool) -> String: + var total = "" + var list = buy_prices if buy else sell_prices + for item in range(len(list)): + total += item_description(buy, item) + "\n" + return total diff --git a/scripts/Base/Menu/dialogue.gd b/scripts/Base/Menu/dialogue.gd index 1a5d3c8..1d95b13 100644 --- a/scripts/Base/Menu/dialogue.gd +++ b/scripts/Base/Menu/dialogue.gd @@ -1,14 +1,27 @@ extends NinePatchRect +## This message will trigger buy/sell node to fetch buy prices +const BUY_FETCH = "BASE_FETCH_BUY" +## This message will trigger buy/sell node to fetch sell prices +const SELL_FETCH = "BASE_FETCH_SELL" + @onready var dialogue = $DialogueView +@onready var buy_sell = $"../../BuySell" func _ready(): var tween = create_tween() \ .tween_property(dialogue,"visible_ratio",1.0, 2) - print(len(dialogue.text)) func send_message(msg: Message): - var new_msg = tr(msg.fact + "_RECEIVED") + var format = {} + match msg.fact: + BUY_FETCH: + format["sell_list"] = buy_sell.get_buy_sell_list(false) + SELL_FETCH: + format["buy_list"] = buy_sell.get_buy_sell_list(true) + + var new_msg = tr(msg.fact + "_RECEIVED").format(format) + print(format) var old_len = len(dialogue.get_parsed_text()) dialogue.append_text(new_msg) dialogue.visible_characters = old_len diff --git a/scripts/Base/base.gd b/scripts/Base/base.gd index aa0e29c..bc9eab7 100644 --- a/scripts/Base/base.gd +++ b/scripts/Base/base.gd @@ -125,14 +125,14 @@ func generate_prices(): var item = items_on_buy[i] if item in items_on_sell: # buy not higher than avg price - buy_prices[i] = randi_range(item.min_price * 100, (item.max_price + item.min_price) * 50) / 100.0 + buy_prices.append(randi_range(item.min_price * 100, (item.max_price + item.min_price) * 50) / 100.0) else: - buy_prices[i] = randi_range(item.min_price * 100, item.max_price * 100) / 100.0 + buy_prices.append(randi_range(item.min_price * 100, item.max_price * 100) / 100.0) # gen prices for items in sell for i in range(len(items_on_sell)): var item = items_on_sell[i] if item in items_on_buy: # sell not lower than avg price - sell_prices[i] = randi_range((item.min_price + item.max_price) * 50, item.max_price * 100) / 100.0 + sell_prices.append(randi_range((item.min_price + item.max_price) * 50, item.max_price * 100) / 100.0) else: - sell_prices[i] = randi_range(item.min_price * 100, item.max_price * 100) / 100.0 + sell_prices.append(randi_range(item.min_price * 100, item.max_price * 100) / 100.0) diff --git a/translations/base_dialogue.csv b/translations/base_dialogue.csv index 0791d5b..10d4b80 100644 --- a/translations/base_dialogue.csv +++ b/translations/base_dialogue.csv @@ -2,11 +2,11 @@ DIALOGUE_ENTRY_POINT,Entering chat with {race}...\nLogged in as {profile_name}.\n> ,Осуществление связи с {race}...\nВы вошли в систему как {profile_name}\n> BASE_TEST_MESSAGE_LOCAL,Greet,Поприветствовать BASE_TEST_MESSAGE_RECEIVED,"Hello, gryadki!\nBye, ponos!\n> ","Хеллоу, грядки!\nБай, понос!\n> " -BASE_FETCH_BUY_LOCAL,"Ask, what they sell","Спросить, что они покупают" +BASE_FETCH_BUY_LOCAL,"Ask, what they sell","Спросить, что они продают" BASE_FETCH_BUY_RECEIVED,I would like to buy something\nWe are selling:\n[ol]{sell_list}[/ol]\n> ,Я бы хотел что-нибудь купить\nМы продаём:\n[ol]{sell_list}[/ol]\n> -BASE_FETCH_SELL_LOCAL,"Ask, what they buy","Спросить, что они продают" +BASE_FETCH_SELL_LOCAL,"Ask, what they buy","Спросить, что они покупают" BASE_FETCH_SELL_RECEIVED,I have some items to sell\nWe can buy:\n[ol]{buy_list}[/ol]\n> ,У меня есть кое-что на продажу\nМы готовы купить:\n[ol]{buy_list}[/ol]\n> -BASE_FETCH_PRICE_ITEM,[li][img=26x26]{item_img}[/img]\t{item_name} — {item_price}[/li],[li][img=26x26]{item_img}[/img]\t{item_name} — {item_price}[/li] +BASE_FETCH_PRICE_ITEM,[img=26x26]{item_img}[/img]{item_name} — {item_price},[img=26x26]{item_img}[/img]{item_name} — {item_price} BASE_FETCH_BUY_CANCEL_LOCAL,Buy nothing,Ничего не покупать BASE_FETCH_BUY_CANCEL_RECEIVED,I changed my mind\nErm...Fine...\nAnything else?\n> ,Я передумал\nЧто ж...Ладно...\nЧто-то ещё?\n> BASE_FETCH_SELL_CANCEL_LOCAL,Sell nothing,Ничего не продавать diff --git a/translations/base_dialogue.en.translation b/translations/base_dialogue.en.translation index ef11769..eb9daea 100644 Binary files a/translations/base_dialogue.en.translation and b/translations/base_dialogue.en.translation differ diff --git a/translations/base_dialogue.ru.translation b/translations/base_dialogue.ru.translation index 6c0c416..11aac60 100644 Binary files a/translations/base_dialogue.ru.translation and b/translations/base_dialogue.ru.translation differ diff --git a/translations/items.csv b/translations/items.csv new file mode 100644 index 0000000..c98c83f --- /dev/null +++ b/translations/items.csv @@ -0,0 +1,5 @@ +,en,ru +ENERGY_CELL,Energy Cell,Энергоячейка +WATER_BARREL,Water Barrel,Бочка с водой +FOOD_SUPPLY,Food Supplies,Запас продуктов +RAW_MATERIALS,Raw Materials,Сырьё \ No newline at end of file diff --git a/translations/items.csv.import b/translations/items.csv.import new file mode 100644 index 0000000..e3a28ad --- /dev/null +++ b/translations/items.csv.import @@ -0,0 +1,17 @@ +[remap] + +importer="csv_translation" +type="Translation" +uid="uid://y0nwi52agw87" + +[deps] + +files=["res://translations/items.en.translation", "res://translations/items.ru.translation"] + +source_file="res://translations/items.csv" +dest_files=["res://translations/items.en.translation", "res://translations/items.ru.translation"] + +[params] + +compress=true +delimiter=0 diff --git a/translations/items.en.translation b/translations/items.en.translation new file mode 100644 index 0000000..76a7572 Binary files /dev/null and b/translations/items.en.translation differ diff --git a/translations/items.ru.translation b/translations/items.ru.translation new file mode 100644 index 0000000..1bd8862 Binary files /dev/null and b/translations/items.ru.translation differ