Added dialogue with pricelists
This commit is contained in:
parent
20de519cd1
commit
a6f9b11c43
17 changed files with 114 additions and 21 deletions
48
scripts/Base/Menu/buy_sell.gd
Normal file
48
scripts/Base/Menu/buy_sell.gd
Normal 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
|
||||
|
|
@ -1,14 +1,27 @@
|
|||
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 buy_sell = $"../../BuySell"
|
||||
|
||||
func _ready():
|
||||
var tween = create_tween() \
|
||||
.tween_property(dialogue,"visible_ratio",1.0, 2)
|
||||
print(len(dialogue.text))
|
||||
|
||||
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())
|
||||
dialogue.append_text(new_msg)
|
||||
dialogue.visible_characters = old_len
|
||||
|
|
|
|||
|
|
@ -125,14 +125,14 @@ func generate_prices():
|
|||
var item = items_on_buy[i]
|
||||
if item in items_on_sell:
|
||||
# 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:
|
||||
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
|
||||
for i in range(len(items_on_sell)):
|
||||
var item = items_on_sell[i]
|
||||
if item in items_on_buy:
|
||||
# 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:
|
||||
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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue