Buy/sell dialogue buttons

This commit is contained in:
2ndbeam 2024-05-22 19:09:36 +03:00
commit 53e5dd38b2
8 changed files with 52 additions and 15 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -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, ,
1 en ru
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 [img=26x26]{item_img}[/img]{item_name} — {item_price} [img=26x26]{item_img}[/img]{item_name} — {item_price}
10 BASE_FETCH_BUY_CANCEL_LOCAL BASE_FETCH_BUY_SELL_CANCEL_LOCAL Buy nothing Ничего не покупать
11 BASE_FETCH_BUY_CANCEL_RECEIVED BASE_FETCH_BUY_SELL_CANCEL_RECEIVED I changed my mind\nErm...Fine...\nAnything else?\n> Я передумал\nЧто ж...Ладно...\nЧто-то ещё?\n>
12 BASE_FETCH_SELL_CANCEL_LOCAL BASE_BUY_SELL Sell nothing Ничего не продавать
13 BASE_FETCH_SELL_CANCEL_RECEIVED BASE_BUY_SELL_NEXT I changed my mind\nErm...Fine...\nAnything else?\n> Next tab Я передумал\nЧто ж...Ладно...\nЧто-то ещё?\n> Следующая вкладка
14 BASE_BUY_SELL_PREV Previous tab Предыдущая вкладка
15 BUY_SELL_ITEM {item_id}. {item_name} {item_id}. {item_name}
16 NULL