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 eb9daea..d51b368 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 11aac60..be371f8 100644 Binary files a/translations/base_dialogue.ru.translation and b/translations/base_dialogue.ru.translation differ