Buy/sell dialogue buttons
This commit is contained in:
parent
a6f9b11c43
commit
53e5dd38b2
8 changed files with 52 additions and 15 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue