Added dialogue with pricelists

This commit is contained in:
2ndbeam 2024-05-22 13:51:54 +03:00
commit a6f9b11c43
17 changed files with 114 additions and 21 deletions

View file

@ -1,11 +1,11 @@
[gd_resource type="Resource" script_class="Item" load_steps=3 format=3 uid="uid://16xqvcrmuga6"] [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"] [ext_resource type="Script" path="res://scripts/Classes/item.gd" id="1_wdaj0"]
[resource] [resource]
script = ExtResource("1_wdaj0") script = ExtResource("1_wdaj0")
name = "Energy Cell" name = "ENERGY_CELL"
description = "" description = ""
min_price = 1.0 min_price = 1.0
max_price = 20.0 max_price = 20.0

View file

@ -1,11 +1,11 @@
[gd_resource type="Resource" script_class="Item" load_steps=3 format=3 uid="uid://ca8cpmd1aluut"] [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="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] [resource]
script = ExtResource("1_gmqal") script = ExtResource("1_gmqal")
name = "Food Supplies" name = "FOOD_SUPPLY"
description = "" description = ""
min_price = 10.0 min_price = 10.0
max_price = 100.0 max_price = 100.0

View file

@ -1,11 +1,11 @@
[gd_resource type="Resource" script_class="Item" load_steps=3 format=3 uid="uid://dlnl6w416qylo"] [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"] [ext_resource type="Script" path="res://scripts/Classes/item.gd" id="1_l7wcw"]
[resource] [resource]
script = ExtResource("1_l7wcw") script = ExtResource("1_l7wcw")
name = "Raw Materials" name = "RAW_MATERIALS"
description = "" description = ""
min_price = 10.0 min_price = 10.0
max_price = 50.0 max_price = 50.0

View file

@ -1,11 +1,11 @@
[gd_resource type="Resource" script_class="Item" load_steps=3 format=3 uid="uid://b4jy8uknltolk"] [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"] [ext_resource type="Script" path="res://scripts/Classes/item.gd" id="1_w7v0g"]
[resource] [resource]
script = ExtResource("1_w7v0g") script = ExtResource("1_w7v0g")
name = "Water Barrel" name = "WATER_BARREL"
description = "" description = ""
min_price = 5.0 min_price = 5.0
max_price = 30.0 max_price = 30.0

View file

@ -94,7 +94,7 @@ dock={
[internationalization] [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] [layer_names]

View file

@ -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="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"] [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/close_button.gd" id="4_68ool"]
[ext_resource type="Script" path="res://scripts/Base/Menu/dialogue.gd" id="4_swpa1"] [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="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"] [node name="BaseMenu" type="Control"]
layout_mode = 3 layout_mode = 3
@ -184,4 +185,7 @@ offset_bottom = 73.0
icon = ExtResource("2_ceeiv") icon = ExtResource("2_ceeiv")
script = ExtResource("4_68ool") 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"] [connection signal="button_up" from="MenuBackground/CloseButtonBack/CloseButton" to="MenuBackground/CloseButtonBack/CloseButton" method="_on_button_up"]

View file

@ -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://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://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="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="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="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")] [node name="StarSystem" instance=ExtResource("1_2ai1l")]
width = 16384 width = 16384
@ -23,7 +27,9 @@ process_mode = 0
position = Vector2(19, 10) position = Vector2(19, 10)
[node name="Base" parent="FactionPeaceful" index="0" instance=ExtResource("3_m5ica")] [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")] [node name="KamikazeShip" parent="FactionAggressive" index="0" instance=ExtResource("4_i6rbg")]
position = Vector2(-1712, -608) position = Vector2(-1712, -608)

View file

@ -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

View file

@ -1,14 +1,27 @@
extends NinePatchRect 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 dialogue = $DialogueView
@onready var buy_sell = $"../../BuySell"
func _ready(): func _ready():
var tween = create_tween() \ var tween = create_tween() \
.tween_property(dialogue,"visible_ratio",1.0, 2) .tween_property(dialogue,"visible_ratio",1.0, 2)
print(len(dialogue.text))
func send_message(msg: Message): 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()) var old_len = len(dialogue.get_parsed_text())
dialogue.append_text(new_msg) dialogue.append_text(new_msg)
dialogue.visible_characters = old_len dialogue.visible_characters = old_len

View file

@ -125,14 +125,14 @@ func generate_prices():
var item = items_on_buy[i] var item = items_on_buy[i]
if item in items_on_sell: if item in items_on_sell:
# buy not higher than avg price # 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: 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 # gen prices for items in sell
for i in range(len(items_on_sell)): for i in range(len(items_on_sell)):
var item = items_on_sell[i] var item = items_on_sell[i]
if item in items_on_buy: if item in items_on_buy:
# sell not lower than avg price # 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: 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)

View file

@ -2,11 +2,11 @@
DIALOGUE_ENTRY_POINT,Entering chat with {race}...\nLogged in as {profile_name}.\n> ,Осуществление связи с {race}...\nВы вошли в систему как {profile_name}\n> 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_LOCAL,Greet,Поприветствовать
BASE_TEST_MESSAGE_RECEIVED,"Hello, gryadki!\nBye, ponos!\n> ","Хеллоу, грядки!\nБай, понос!\n> " 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_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_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_LOCAL,Buy nothing,Ничего не покупать
BASE_FETCH_BUY_CANCEL_RECEIVED,I changed my mind\nErm...Fine...\nAnything else?\n> ,Я передумал\nЧто ж...Ладно...\nЧто-то ещё?\n> BASE_FETCH_BUY_CANCEL_RECEIVED,I changed my mind\nErm...Fine...\nAnything else?\n> ,Я передумал\nЧто ж...Ладно...\nЧто-то ещё?\n>
BASE_FETCH_SELL_CANCEL_LOCAL,Sell nothing,Ничего не продавать BASE_FETCH_SELL_CANCEL_LOCAL,Sell nothing,Ничего не продавать

1 en ru
2 DIALOGUE_ENTRY_POINT Entering chat with {race}...\nLogged in as {profile_name}.\n> Осуществление связи с {race}...\nВы вошли в систему как {profile_name}\n>
3 BASE_TEST_MESSAGE_LOCAL Greet Поприветствовать
4 BASE_TEST_MESSAGE_RECEIVED Hello, gryadki!\nBye, ponos!\n> Хеллоу, грядки!\nБай, понос!\n>
5 BASE_FETCH_BUY_LOCAL Ask, what they sell Спросить, что они покупают Спросить, что они продают
6 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>
7 BASE_FETCH_SELL_LOCAL Ask, what they buy Спросить, что они продают Спросить, что они покупают
8 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>
9 BASE_FETCH_PRICE_ITEM [li][img=26x26]{item_img}[/img]\t{item_name} — {item_price}[/li] [img=26x26]{item_img}[/img]{item_name} — {item_price} [li][img=26x26]{item_img}[/img]\t{item_name} — {item_price}[/li] [img=26x26]{item_img}[/img]{item_name} — {item_price}
10 BASE_FETCH_BUY_CANCEL_LOCAL Buy nothing Ничего не покупать
11 BASE_FETCH_BUY_CANCEL_RECEIVED I changed my mind\nErm...Fine...\nAnything else?\n> Я передумал\nЧто ж...Ладно...\nЧто-то ещё?\n>
12 BASE_FETCH_SELL_CANCEL_LOCAL Sell nothing Ничего не продавать

5
translations/items.csv Normal file
View file

@ -0,0 +1,5 @@
,en,ru
ENERGY_CELL,Energy Cell,Энергоячейка
WATER_BARREL,Water Barrel,Бочка с водой
FOOD_SUPPLY,Food Supplies,Запас продуктов
RAW_MATERIALS,Raw Materials,Сырьё
1 en ru
2 ENERGY_CELL Energy Cell Энергоячейка
3 WATER_BARREL Water Barrel Бочка с водой
4 FOOD_SUPPLY Food Supplies Запас продуктов
5 RAW_MATERIALS Raw Materials Сырьё

View file

@ -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

Binary file not shown.

Binary file not shown.