118 lines
3.5 KiB
GDScript
118 lines
3.5 KiB
GDScript
extends Control
|
|
|
|
var player: Node = null
|
|
@onready var close_button: Button = $MenuPanel/MainVBox/CloseButton
|
|
|
|
# ===== SELL BUTTONS =====
|
|
@onready var sell_buttons = {
|
|
"Marijuana Seeds": $MenuPanel/MainVBox/MainColumns/SellVBox/Sell_MarijuanaSeeds,
|
|
"Soy Bean Seeds": $MenuPanel/MainVBox/MainColumns/SellVBox/Sell_SoyBeanSeeds,
|
|
"Ration Pack": $MenuPanel/MainVBox/MainColumns/SellVBox/Sell_RationPack,
|
|
"Dried Noodles": $MenuPanel/MainVBox/MainColumns/SellVBox/Sell_DriedNoodles,
|
|
"Protein Paste": $MenuPanel/MainVBox/MainColumns/SellVBox/Sell_ProteinPaste,
|
|
"Scrap Metal": $MenuPanel/MainVBox/MainColumns/SellVBox/Sell_ScrapMetal,
|
|
"Multitool": $MenuPanel/MainVBox/MainColumns/SellVBox/Sell_Multitool,
|
|
"Plasma Cutter (Damaged)": $MenuPanel/MainVBox/MainColumns/SellVBox/Sell_PlasmaCutter,
|
|
"Cooking Knife": $MenuPanel/MainVBox/MainColumns/SellVBox/Sell_CookingKnife,
|
|
"Circuit Board": $MenuPanel/MainVBox/MainColumns/SellVBox/Sell_CircuitBoard,
|
|
"Beer Can": $MenuPanel/MainVBox/MainColumns/SellVBox/Sell_BeerCan,
|
|
"Hotdog": $MenuPanel/MainVBox/MainColumns/SellVBox/Sell_Hotdog
|
|
}
|
|
|
|
# ===== BUY BUTTONS =====
|
|
@onready var buy_buttons = {
|
|
"Ration Pack": $MenuPanel/MainVBox/MainColumns/BuyVBox/Buy_RationPack,
|
|
"Dried Noodles": $MenuPanel/MainVBox/MainColumns/BuyVBox/Buy_DriedNoodles,
|
|
"Protein Paste": $MenuPanel/MainVBox/MainColumns/BuyVBox/Buy_ProteinPaste,
|
|
"Beer Can": $MenuPanel/MainVBox/MainColumns/BuyVBox/Buy_BeerCan,
|
|
"Hotdog": $MenuPanel/MainVBox/MainColumns/BuyVBox/Buy_Hotdog
|
|
}
|
|
|
|
var sell_prices = {
|
|
"Marijuana Seeds": 40,
|
|
"Soy Bean Seeds": 25,
|
|
"Ration Pack": 18,
|
|
"Dried Noodles": 10,
|
|
"Protein Paste": 14,
|
|
"Scrap Metal": 15,
|
|
"Multitool": 50,
|
|
"Plasma Cutter (Damaged)": 65,
|
|
"Cooking Knife": 28,
|
|
"Circuit Board": 42,
|
|
"Beer Can": 8,
|
|
"Hotdog": 8
|
|
}
|
|
|
|
var buy_prices = {
|
|
"Ration Pack": 15,
|
|
"Dried Noodles": 12,
|
|
"Protein Paste": 16,
|
|
"Beer Can": 10,
|
|
"Hotdog": 15
|
|
}
|
|
|
|
func _ready() -> void:
|
|
for item_name in sell_buttons.keys():
|
|
var button = sell_buttons[item_name]
|
|
if button:
|
|
button.pressed.connect(_sell.bind(item_name, sell_prices[item_name]))
|
|
else:
|
|
print("Missing sell button for: ", item_name)
|
|
|
|
for item_name in buy_buttons.keys():
|
|
var button = buy_buttons[item_name]
|
|
if button:
|
|
button.pressed.connect(_buy.bind(item_name, buy_prices[item_name]))
|
|
else:
|
|
print("Missing buy button for: ", item_name)
|
|
|
|
if close_button:
|
|
close_button.pressed.connect(_on_close_pressed)
|
|
|
|
visible = false
|
|
|
|
func open_menu(player_ref: Node) -> void:
|
|
player = player_ref
|
|
visible = true
|
|
_update_button_states()
|
|
print("Vendor menu opened")
|
|
|
|
func _update_button_states() -> void:
|
|
if player == null:
|
|
return
|
|
|
|
for item_name in sell_buttons.keys():
|
|
var button = sell_buttons[item_name]
|
|
if button:
|
|
button.disabled = not player.inventory.has(item_name)
|
|
|
|
for item_name in buy_buttons.keys():
|
|
var button = buy_buttons[item_name]
|
|
if button:
|
|
button.disabled = player.money < buy_prices[item_name]
|
|
|
|
func _sell(item_name: String, price: int) -> void:
|
|
if player == null:
|
|
return
|
|
if player.remove_item(item_name):
|
|
player.add_money(price)
|
|
print("Sold ", item_name, " for ", price, " credits")
|
|
_update_button_states()
|
|
else:
|
|
print("You don't have ", item_name)
|
|
|
|
func _buy(item_name: String, price: int) -> void:
|
|
if player == null:
|
|
return
|
|
if player.money >= price:
|
|
player.add_money(-price)
|
|
player.add_item(item_name)
|
|
print("Bought ", item_name)
|
|
_update_button_states()
|
|
else:
|
|
print("Not enough credits")
|
|
|
|
func _on_close_pressed() -> void:
|
|
visible = false
|
|
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
|