From 53e5dd38b25483a525e6c46ec1823539cadb2dbf Mon Sep 17 00:00:00 2001 From: 2ndbeam <166764593+2ndbeam@users.noreply.github.com> Date: Wed, 22 May 2024 19:09:36 +0300 Subject: [PATCH] Buy/sell dialogue buttons --- .../{menu_buy.tres => menu_buy_sell.tres} | 10 +++--- menus/Base Menu/root_menu.tres | 4 +-- scripts/Base/Menu/buy_sell.gd | 6 ++-- scripts/Base/Menu/dialogue.gd | 6 +++- scripts/Base/actions_menu.gd | 31 +++++++++++++++++- translations/base_dialogue.csv | 10 +++--- translations/base_dialogue.en.translation | Bin 1134 -> 1174 bytes translations/base_dialogue.ru.translation | Bin 1533 -> 1565 bytes 8 files changed, 52 insertions(+), 15 deletions(-) rename menus/Base Menu/BuySell/{menu_buy.tres => menu_buy_sell.tres} (66%) diff --git a/menus/Base Menu/BuySell/menu_buy.tres b/menus/Base Menu/BuySell/menu_buy_sell.tres similarity index 66% rename from menus/Base Menu/BuySell/menu_buy.tres rename to menus/Base Menu/BuySell/menu_buy_sell.tres index 8688a26..3d27b90 100644 --- a/menus/Base Menu/BuySell/menu_buy.tres +++ b/menus/Base Menu/BuySell/menu_buy_sell.tres @@ -1,15 +1,15 @@ [gd_resource type="Resource" script_class="Menu" load_steps=4 format=3 uid="uid://cbvax7aprnrig"] -[ext_resource type="Script" path="res://scripts/Classes/Menu/combo_menu_resource.gd" id="1_xamua"] -[ext_resource type="Script" path="res://scripts/Classes/Menu/menu.gd" id="2_f8fna"] +[ext_resource type="Script" path="res://scripts/Classes/Menu/combo_menu_resource.gd" id="1_erxhv"] +[ext_resource type="Script" path="res://scripts/Classes/Menu/menu.gd" id="2_ppqjr"] [sub_resource type="Resource" id="Resource_5pmle"] -script = ExtResource("1_xamua") +script = ExtResource("1_erxhv") item_script = &"res://scripts/Base/Menu/send_message.gd" item_menu = &"res://menus/Base Menu/root_menu.tres" [resource] -script = ExtResource("2_f8fna") -item_ids = Array[String](["BASE_FETCH_BUY_CANCEL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL"]) +script = ExtResource("2_ppqjr") +item_ids = Array[String](["BASE_FETCH_BUY_SELL_CANCEL", "BASE_BUY_SELL", "BASE_BUY_SELL", "BASE_BUY_SELL", "BASE_BUY_SELL", "BASE_BUY_SELL", "BASE_BUY_SELL", "BASE_BUY_SELL_NEXT"]) item_actions = Array[int]([3, 0, 0, 0, 0, 0, 0, 0]) item_data = Array[Resource("res://scripts/Classes/Menu/menu_resource.gd")]([SubResource("Resource_5pmle"), null, null, null, null, null, null, null]) diff --git a/menus/Base Menu/root_menu.tres b/menus/Base Menu/root_menu.tres index cb42b86..70d4610 100644 --- a/menus/Base Menu/root_menu.tres +++ b/menus/Base Menu/root_menu.tres @@ -6,12 +6,12 @@ [sub_resource type="Resource" id="Resource_iiy7m"] script = ExtResource("1_d2x8v") item_script = &"res://scripts/Base/Menu/send_message.gd" -item_menu = &"res://menus/Base Menu/BuySell/menu_buy.tres" +item_menu = &"res://menus/Base Menu/BuySell/menu_buy_sell.tres" [sub_resource type="Resource" id="Resource_pbhiw"] script = ExtResource("1_d2x8v") item_script = &"res://scripts/Base/Menu/send_message.gd" -item_menu = &"res://menus/Base Menu/BuySell/menu_sell.tres" +item_menu = &"res://menus/Base Menu/BuySell/menu_buy_sell.tres" [resource] script = ExtResource("1_h4chp") diff --git a/scripts/Base/Menu/buy_sell.gd b/scripts/Base/Menu/buy_sell.gd index bf7454d..6dea844 100644 --- a/scripts/Base/Menu/buy_sell.gd +++ b/scripts/Base/Menu/buy_sell.gd @@ -24,8 +24,6 @@ func fetch_items(): 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: @@ -46,3 +44,7 @@ func get_buy_sell_list(buy: bool) -> String: for item in range(len(list)): total += item_description(buy, item) + "\n" return total + +func get_buy_sell_len(buy: bool) -> int: + var list = items_on_buy if buy else items_on_sell + return len(list) diff --git a/scripts/Base/Menu/dialogue.gd b/scripts/Base/Menu/dialogue.gd index 1d95b13..0dfa13d 100644 --- a/scripts/Base/Menu/dialogue.gd +++ b/scripts/Base/Menu/dialogue.gd @@ -7,6 +7,7 @@ const SELL_FETCH = "BASE_FETCH_SELL" @onready var dialogue = $DialogueView @onready var buy_sell = $"../../BuySell" +@onready var actions_menu = $"../Actions/ActionsMenu" func _ready(): var tween = create_tween() \ @@ -17,11 +18,14 @@ func send_message(msg: Message): match msg.fact: BUY_FETCH: format["sell_list"] = buy_sell.get_buy_sell_list(false) + actions_menu.buy = false + actions_menu.buy_sell_options = buy_sell.get_buy_sell_len(false) SELL_FETCH: format["buy_list"] = buy_sell.get_buy_sell_list(true) + actions_menu.buy = true + actions_menu.buy_sell_options = buy_sell.get_buy_sell_len(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/actions_menu.gd b/scripts/Base/actions_menu.gd index 9739a8b..38dcae7 100644 --- a/scripts/Base/actions_menu.gd +++ b/scripts/Base/actions_menu.gd @@ -12,18 +12,47 @@ extends Node $Action8 ] +var base + ## Script attached to transit buttons const TRANSIT_BUTTON_SCRIPT = preload("res://scripts/Classes/Menu/transit_button.gd") +## Buy/Sell item trigger +const BUY_SELL_ITEM = "BUY_SELL_ITEM" +## Buy/Sell button placeholder +const BASE_BUY_SELL = "BASE_BUY_SELL" +## Null button ID +const NULL = "NULL" +## Menu which is loaded on ready @export var menu: Menu = null +## Is base buying from player or vice versa +var buy: bool = false +## How many buy/sell options are available +var buy_sell_options: int = -1 +## Which buy/sell tab should be opened (tab holds 6 items) +var buy_sell_tab: int = 0 + func _ready(): load_menu() + get_tree().create_timer(0.05).timeout.connect(post_ready) + +func post_ready(): + base = get_parent().get_parent().get_parent().base ## Called when menu is changed func load_menu(): + var format = {} # iterating through all actions for i in range(len(menu.item_ids)): + match menu.item_ids[i]: + BASE_BUY_SELL: + if i <= buy_sell_options: + var list = base.items_on_buy if buy else base.items_on_sell + format["item_id"] = i + buy_sell_tab * 6 + format["item_name"] = tr(list[i - 1 + buy_sell_tab * 6].name) + menu.item_ids[i] = BUY_SELL_ITEM + # disconnect previous action if actions[i] is TransitButton: actions[i].button_up.disconnect(transit_menu) @@ -31,7 +60,7 @@ func load_menu(): actions[i].button_up.disconnect(actions[i].action) # disconnect previous script actions[i].set_script(null) - actions[i].text = menu.item_ids[i] + actions[i].text = tr(menu.item_ids[i]).format(format) # assign new script match menu.item_actions[i]: Menu.Action.TransitAction: diff --git a/translations/base_dialogue.csv b/translations/base_dialogue.csv index 10d4b80..6517067 100644 --- a/translations/base_dialogue.csv +++ b/translations/base_dialogue.csv @@ -7,8 +7,10 @@ BASE_FETCH_BUY_RECEIVED,I would like to buy something\nWe are selling:\n[ol]{sel 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,[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,Ничего не продавать -BASE_FETCH_SELL_CANCEL_RECEIVED,I changed my mind\nErm...Fine...\nAnything else?\n> ,Я передумал\nЧто ж...Ладно...\nЧто-то ещё?\n> +BASE_FETCH_BUY_SELL_CANCEL_LOCAL,Buy nothing,Ничего не покупать +BASE_FETCH_BUY_SELL_CANCEL_RECEIVED,I changed my mind\nErm...Fine...\nAnything else?\n> ,Я передумал\nЧто ж...Ладно...\nЧто-то ещё?\n> +BASE_BUY_SELL, , +BASE_BUY_SELL_NEXT,Next tab,Следующая вкладка +BASE_BUY_SELL_PREV,Previous tab,Предыдущая вкладка +BUY_SELL_ITEM,{item_id}. {item_name},{item_id}. {item_name} NULL, , \ No newline at end of file diff --git a/translations/base_dialogue.en.translation b/translations/base_dialogue.en.translation index eb9daea6aa7fd7f2e528e38ff657fea3dc4e9af5..d51b3688021e54bd04acf2562d86a231a915d522 100644 GIT binary patch delta 353 zcmaFIF^zMBG$U)4L5@+;WCcc}dIlh117ZOn76W1hApVa8)S!GFC~XF$ZP3&>q47PS zd{!W>0K`E+%m~G=tYtZTfgDaCABZRKWHe-zP{{94nEakmU7`Xg!vvH8VVI6XhH^6} z>oKXQ!UXdU*S-z`D&PZR5g^{TEx98MsG1wd=AE3*q^x=Gu)Lu+7Nb_&Wp+yhii-nP zf-uwM*-Yx3An(fqan&#CP==u3AZGxQqhf3T delta 266 zcmbQn`Ho|QG$U(4kwK2dWCcc})c-)h00dk>EC9q(KnxOt0R<>u4NB{v$%E7xp@~^Q z`K&-%0f^lupJy~?-QOnI9x|DoNnN6zk%55;C=S9vCK%t(-YGEIjY&lmCXjcy_H_tQ zk`IVQCigQb3zpAuTjC9r<^+oH0x|RC+f3?`-z95h6@a4JKoO8b*nn6bh#NO^Gy5^J Z{0rW+WwIuV5kF9f9f(232L%T?0{|m%SXKZ4 diff --git a/translations/base_dialogue.ru.translation b/translations/base_dialogue.ru.translation index 11aac60b5d91888304cf1bbe0552c1f1bd4dc2f7..be371f871adeb273a82f811e9b350eeaf44a23c2 100644 GIT binary patch delta 402 zcmey%J(p*LG$X5NX1;OBWCcdYdIlh117ZOn76W1hApVa8)S!GFC~XF$ZP3&>q47PS zd{!W>0K`E+%m~G=tYtZ-GBGeH0r@~Y`2?dOtAs*+htK4HjOr4ffHFV?#xNa+4CQ7{ zwq;UL1xbJe^A6X(J_Mxop?Kf6Ud5!&1@gW;5PxCX{F-ShQ?3HTg@qS(U)XwK%f;r4eHS|~Y`EC3aADJh zT|mJN7q$TD4Gb6NUu*!Y=mx98s-`-#BsDiaGo@Bf0m95n%uTIjP+(vOS_X1bP;ihl E0O_QVRsaA1 delta 293 zcmbQs^Ot*rG$X4)qN#!DWCcdY)c-)h00dk>EC9q(KnxOt0R<>u4NB{v$%E7xp@~^Q z`K&-%0f^lu-(xgp-QOnIzGJc&le)xzCI$u|0%JxX4Z`=ccM41nWl|A^3FIBFeSHWh zp%227=P@Y@md|lpG8w2(6(|D2%#&X+sY`vAtd;cvin;?uK$s1P<$;)yd9yV0R3^C# zb1&?;*nVN_h0PcCDO}ilVXMN0{TCZ9?7Oh#!iEc*CMU55@B>w|gLD9KP;ihl0EUrm AYXATM