优化项目架构
This commit is contained in:
87
SproutFarm-Frontend/Script/Dialog/AcceptDialog.gd
Normal file
87
SproutFarm-Frontend/Script/Dialog/AcceptDialog.gd
Normal file
@@ -0,0 +1,87 @@
|
||||
extends AcceptDialog
|
||||
|
||||
@export var dialog_min_size := Vector2(400, 200)
|
||||
@export var ok_text := "确认"
|
||||
@export var cancel_text := "取消"
|
||||
|
||||
func _ready() -> void:
|
||||
# 设置弹窗最小尺寸
|
||||
self.set("rect_min_size", dialog_min_size)
|
||||
|
||||
# 设置标题和内容(可通过函数修改)
|
||||
set_dialog_title("默认标题")
|
||||
set_dialog_content("默认内容")
|
||||
|
||||
# 添加取消按钮
|
||||
var cancel_btn = self.add_cancel_button(cancel_text)
|
||||
_customize_button(cancel_btn)
|
||||
|
||||
# 获取并设置确认按钮
|
||||
var ok_btn = self.get_ok_button()
|
||||
ok_btn.text = ok_text
|
||||
_customize_button(ok_btn)
|
||||
|
||||
# 设置按钮样式属性
|
||||
self.add_theme_constant_override("buttons_min_height", 40)
|
||||
self.add_theme_constant_override("buttons_min_width", 120)
|
||||
self.add_theme_constant_override("buttons_separation", 16)
|
||||
|
||||
# 添加样式美化
|
||||
_apply_custom_theme()
|
||||
|
||||
func set_dialog_position(new_position :Vector2):
|
||||
self.position = new_position
|
||||
pass
|
||||
|
||||
func set_dialog_title(title: String) -> void:
|
||||
self.title = title
|
||||
|
||||
|
||||
func set_dialog_content(content: String) -> void:
|
||||
self.dialog_text = content
|
||||
|
||||
|
||||
func set_ok_text(text: String) -> void:
|
||||
ok_text = text
|
||||
get_ok_button().text = text
|
||||
|
||||
|
||||
func set_cancel_text(text: String) -> void:
|
||||
cancel_text = text
|
||||
# 注意:add_cancel_button 只能调用一次,想动态更新需要重建按钮
|
||||
|
||||
|
||||
func _customize_button(button: Button) -> void:
|
||||
button.custom_minimum_size = Vector2(120, 40)
|
||||
button.add_theme_color_override("font_color", Color.WHITE)
|
||||
button.add_theme_color_override("font_color_pressed", Color.WHITE)
|
||||
button.add_theme_color_override("font_color_hover", Color.WHITE)
|
||||
button.add_theme_color_override("bg_color", Color("3c82f6")) # 蓝色
|
||||
button.add_theme_color_override("bg_color_hover", Color("2563eb"))
|
||||
button.add_theme_color_override("bg_color_pressed", Color("1e40af"))
|
||||
button.add_theme_color_override("bg_color_disabled", Color("94a3b8"))
|
||||
|
||||
|
||||
func _apply_custom_theme() -> void:
|
||||
# 设置面板背景颜色
|
||||
var panel_style := StyleBoxFlat.new()
|
||||
#panel_style.bg_color = Color.AQUA # very light gray
|
||||
panel_style.set_border_width_all(2)
|
||||
#panel_style.border_color = Color("cbd5e1")
|
||||
|
||||
self.add_theme_stylebox_override("panel", panel_style) # ✅ 修正方法名
|
||||
|
||||
# 设置文字颜色(内容部分)
|
||||
var label = self.get_label()
|
||||
label.add_theme_color_override("font_color", Color("1e293b")) # 深灰蓝
|
||||
|
||||
|
||||
|
||||
# 确认按钮点击
|
||||
func _on_confirmed() -> void:
|
||||
print("确认按钮被点击")
|
||||
|
||||
|
||||
# 取消按钮点击
|
||||
func _on_canceled() -> void:
|
||||
print("取消按钮被点击")
|
||||
1
SproutFarm-Frontend/Script/Dialog/AcceptDialog.gd.uid
Normal file
1
SproutFarm-Frontend/Script/Dialog/AcceptDialog.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://ce8xcp770tolo
|
||||
213
SproutFarm-Frontend/Script/Dialog/AddProduct2StorePopup.gd
Normal file
213
SproutFarm-Frontend/Script/Dialog/AddProduct2StorePopup.gd
Normal file
@@ -0,0 +1,213 @@
|
||||
extends PanelContainer
|
||||
#用于添加商品到玩家小卖部的弹窗
|
||||
@onready var title: Label = $VBox/Title #弹窗标题
|
||||
@onready var contents: Label = $VBox/Contents #这里显示弹窗内容
|
||||
@onready var sell_num_input: LineEdit = $VBox/SellNumInput #这里输入需要放入小卖部的商品数量
|
||||
@onready var sell_price_input: LineEdit = $VBox/SellPriceInput #这里输入每件商品的价格
|
||||
@onready var sure_button: Button = $VBox/HBox/SureButton #确定放入按钮
|
||||
@onready var cancel_button: Button = $VBox/HBox/CancelButton #取消按钮
|
||||
|
||||
# 当前要添加的商品信息
|
||||
var current_product_name: String = ""
|
||||
var current_max_count: int = 0
|
||||
var current_suggested_price: int = 0
|
||||
var current_product_desc: String = ""
|
||||
|
||||
# 回调函数,用于处理确认添加
|
||||
var confirm_callback: Callable
|
||||
var cancel_callback: Callable
|
||||
|
||||
func _ready():
|
||||
# 连接按钮信号
|
||||
sure_button.pressed.connect(_on_sure_button_pressed)
|
||||
cancel_button.pressed.connect(_on_cancel_button_pressed)
|
||||
|
||||
# 设置输入框的默认值和限制
|
||||
sell_num_input.text = "1"
|
||||
sell_num_input.placeholder_text = "请输入数量"
|
||||
sell_price_input.placeholder_text = "请输入单价"
|
||||
|
||||
# 只允许输入数字
|
||||
sell_num_input.text_changed.connect(_on_sell_num_changed)
|
||||
sell_price_input.text_changed.connect(_on_sell_price_changed)
|
||||
|
||||
# 连接可见性改变信号
|
||||
visibility_changed.connect(_on_visibility_changed)
|
||||
|
||||
# 默认隐藏弹窗
|
||||
self.hide()
|
||||
|
||||
#面板显示与隐藏切换处理
|
||||
func _on_visibility_changed():
|
||||
if visible:
|
||||
GlobalVariables.isZoomDisabled = true
|
||||
pass
|
||||
else:
|
||||
GlobalVariables.isZoomDisabled = false
|
||||
pass
|
||||
|
||||
# 显示添加商品弹窗
|
||||
func show_add_product_popup(product_name: String, max_count: int, suggested_price: int, product_desc: String, on_confirm: Callable, on_cancel: Callable = Callable()):
|
||||
current_product_name = product_name
|
||||
current_max_count = max_count
|
||||
current_suggested_price = suggested_price
|
||||
current_product_desc = product_desc
|
||||
confirm_callback = on_confirm
|
||||
cancel_callback = on_cancel
|
||||
|
||||
# 设置弹窗内容
|
||||
title.text = "添加商品到小卖部"
|
||||
|
||||
contents.text = str(
|
||||
"商品名称: " + product_name + "\n" +
|
||||
"可用数量: " + str(max_count) + " 个\n" +
|
||||
"建议价格: " + str(suggested_price) + " 元/个\n" +
|
||||
"描述: " + product_desc + "\n\n" +
|
||||
"请设置出售数量和价格:"
|
||||
)
|
||||
|
||||
# 设置默认值
|
||||
sell_num_input.text = "1"
|
||||
sell_price_input.text = str(suggested_price)
|
||||
|
||||
# 显示弹窗并居中
|
||||
self.show()
|
||||
self.move_to_front()
|
||||
|
||||
# 处理数量输入变化
|
||||
func _on_sell_num_changed(new_text: String):
|
||||
# 只允许输入数字
|
||||
var filtered_text = ""
|
||||
for char in new_text:
|
||||
if char.is_valid_int():
|
||||
filtered_text += char
|
||||
|
||||
# 检查是否超过最大值并自动修正
|
||||
if not filtered_text.is_empty():
|
||||
var quantity = filtered_text.to_int()
|
||||
if quantity > current_max_count:
|
||||
filtered_text = str(current_max_count)
|
||||
|
||||
if filtered_text != new_text:
|
||||
sell_num_input.text = filtered_text
|
||||
sell_num_input.caret_column = filtered_text.length()
|
||||
|
||||
# 更新预览信息
|
||||
_update_preview_info()
|
||||
|
||||
# 处理价格输入变化
|
||||
func _on_sell_price_changed(new_text: String):
|
||||
# 只允许输入数字
|
||||
var filtered_text = ""
|
||||
for char in new_text:
|
||||
if char.is_valid_int():
|
||||
filtered_text += char
|
||||
|
||||
# 检查是否超过最大值并自动修正
|
||||
if not filtered_text.is_empty():
|
||||
var price = filtered_text.to_int()
|
||||
if price > 999999999:
|
||||
filtered_text = "999999999"
|
||||
|
||||
if filtered_text != new_text:
|
||||
sell_price_input.text = filtered_text
|
||||
sell_price_input.caret_column = filtered_text.length()
|
||||
|
||||
# 更新预览信息
|
||||
_update_preview_info()
|
||||
|
||||
# 更新预览信息
|
||||
func _update_preview_info():
|
||||
var quantity = get_sell_quantity()
|
||||
var unit_price = get_sell_price()
|
||||
var total_value = quantity * unit_price
|
||||
|
||||
# 检查数量是否超过最大可用数量
|
||||
var quantity_status = ""
|
||||
if quantity > current_max_count:
|
||||
quantity_status = " (超出库存!)"
|
||||
|
||||
# 检查价格是否合理
|
||||
var price_status = ""
|
||||
if unit_price <= 0:
|
||||
price_status = " (价格无效!)"
|
||||
elif unit_price < current_suggested_price * 0.5:
|
||||
price_status = " (价格偏低)"
|
||||
elif unit_price > current_suggested_price * 2:
|
||||
price_status = " (价格偏高)"
|
||||
|
||||
var preview_info = "\n上架数量: " + str(quantity) + " 个" + quantity_status + "\n单价: " + str(unit_price) + " 元/个" + price_status + "\n总价值: " + str(total_value) + " 元"
|
||||
|
||||
# 更新内容显示
|
||||
var base_content = str(
|
||||
"商品名称: " + current_product_name + "\n" +
|
||||
"可用数量: " + str(current_max_count) + " 个\n" +
|
||||
"建议价格: " + str(current_suggested_price) + " 元/个\n" +
|
||||
"描述: " + current_product_desc + "\n\n" +
|
||||
"请设置出售数量和价格:"
|
||||
)
|
||||
|
||||
contents.text = base_content + preview_info
|
||||
|
||||
# 获取出售数量
|
||||
func get_sell_quantity() -> int:
|
||||
var text = sell_num_input.text.strip_edges()
|
||||
if text.is_empty():
|
||||
return 1
|
||||
|
||||
var quantity = text.to_int()
|
||||
quantity = max(1, quantity) # 至少出售1个
|
||||
quantity = min(quantity, current_max_count) # 不超过最大值
|
||||
return quantity
|
||||
|
||||
# 获取出售价格
|
||||
func get_sell_price() -> int:
|
||||
var text = sell_price_input.text.strip_edges()
|
||||
if text.is_empty():
|
||||
return current_suggested_price
|
||||
|
||||
var price = text.to_int()
|
||||
price = max(1, price) # 至少1元
|
||||
price = min(price, 999999999) # 不超过最大值
|
||||
return price
|
||||
|
||||
# 确认添加按钮处理
|
||||
func _on_sure_button_pressed():
|
||||
var quantity = get_sell_quantity()
|
||||
var unit_price = get_sell_price()
|
||||
|
||||
if quantity <= 0:
|
||||
_show_error("数量必须大于0")
|
||||
return
|
||||
|
||||
if quantity > current_max_count:
|
||||
_show_error("数量不能超过库存数量(" + str(current_max_count) + ")")
|
||||
return
|
||||
|
||||
if unit_price <= 0:
|
||||
_show_error("价格必须大于0")
|
||||
return
|
||||
|
||||
# 调用确认回调函数
|
||||
if confirm_callback.is_valid():
|
||||
confirm_callback.call(current_product_name, quantity, unit_price)
|
||||
|
||||
# 隐藏弹窗
|
||||
self.hide()
|
||||
|
||||
# 取消添加按钮处理
|
||||
func _on_cancel_button_pressed():
|
||||
# 调用取消回调函数
|
||||
if cancel_callback.is_valid():
|
||||
cancel_callback.call()
|
||||
|
||||
# 隐藏弹窗
|
||||
self.hide()
|
||||
|
||||
# 显示错误信息
|
||||
func _show_error(message: String):
|
||||
# 显示Toast错误提示
|
||||
if has_node("/root/Toast"):
|
||||
get_node("/root/Toast").show(message, Color.RED, 2.0, 1.0)
|
||||
else:
|
||||
print("添加商品弹窗错误: " + message)
|
||||
@@ -0,0 +1 @@
|
||||
uid://cha0uw4ra1trr
|
||||
163
SproutFarm-Frontend/Script/Dialog/BatchBuyPopup.gd
Normal file
163
SproutFarm-Frontend/Script/Dialog/BatchBuyPopup.gd
Normal file
@@ -0,0 +1,163 @@
|
||||
extends PanelContainer
|
||||
#这是批量购买弹窗
|
||||
@onready var title: Label = $VBox/Title #弹窗标题
|
||||
@onready var contents: Label = $VBox/Contents #弹窗内容
|
||||
@onready var buy_num_edit: LineEdit = $VBox/BuyNumEdit #购买数量
|
||||
@onready var sure_button: Button = $VBox/HBox/SureButton #确认购买
|
||||
@onready var cancel_button: Button = $VBox/HBox/CancelButton #取消购买
|
||||
|
||||
# 当前购买的商品信息
|
||||
var current_item_name: String = ""
|
||||
var current_item_cost: int = 0
|
||||
var current_item_desc: String = ""
|
||||
var current_buy_type: String = "" # "seed" 或 "item"
|
||||
var max_stock: int = 999999999 # 最大库存限制,默认无限制
|
||||
|
||||
# 回调函数,用于处理确认购买
|
||||
var confirm_callback: Callable
|
||||
var cancel_callback: Callable
|
||||
|
||||
func _ready():
|
||||
# 连接按钮信号
|
||||
sure_button.pressed.connect(_on_sure_button_pressed)
|
||||
cancel_button.pressed.connect(_on_cancel_button_pressed)
|
||||
|
||||
# 设置数量输入框的默认值和限制
|
||||
buy_num_edit.text = "1"
|
||||
buy_num_edit.placeholder_text = "请输入购买数量"
|
||||
|
||||
# 只允许输入数字
|
||||
buy_num_edit.text_changed.connect(_on_buy_num_changed)
|
||||
|
||||
# 默认隐藏弹窗
|
||||
self.hide()
|
||||
|
||||
#面板显示与隐藏切换处理
|
||||
func _on_visibility_changed():
|
||||
if visible:
|
||||
GlobalVariables.isZoomDisabled = true
|
||||
pass
|
||||
else:
|
||||
GlobalVariables.isZoomDisabled = false
|
||||
pass
|
||||
|
||||
# 显示批量购买弹窗
|
||||
func show_buy_popup(item_name: String, item_cost: int, item_desc: String, buy_type: String, on_confirm: Callable, on_cancel: Callable = Callable(), stock_limit: int = 999999999):
|
||||
current_item_name = item_name
|
||||
current_item_cost = item_cost
|
||||
current_item_desc = item_desc
|
||||
current_buy_type = buy_type
|
||||
confirm_callback = on_confirm
|
||||
cancel_callback = on_cancel
|
||||
max_stock = stock_limit
|
||||
|
||||
# 设置弹窗内容
|
||||
if buy_type == "seed":
|
||||
title.text = "批量购买种子"
|
||||
else:
|
||||
title.text = "批量购买道具"
|
||||
|
||||
# 添加库存信息到内容中
|
||||
var stock_info = ""
|
||||
if stock_limit < 999999999:
|
||||
stock_info = "\n当前库存: " + str(stock_limit) + " 个"
|
||||
|
||||
contents.text = str(
|
||||
"商品名称: " + item_name + "\n" +
|
||||
"单价: " + str(item_cost) + " 元\n" +
|
||||
"描述: " + item_desc + stock_info + "\n\n" +
|
||||
"请输入购买数量:"
|
||||
)
|
||||
|
||||
# 重置购买数量为1
|
||||
buy_num_edit.text = "1"
|
||||
|
||||
# 显示弹窗并居中
|
||||
self.show()
|
||||
|
||||
|
||||
# 处理数量输入变化
|
||||
func _on_buy_num_changed(new_text: String):
|
||||
# 只允许输入数字
|
||||
var filtered_text = ""
|
||||
for char in new_text:
|
||||
if char.is_valid_int():
|
||||
filtered_text += char
|
||||
|
||||
# 检查是否超过库存限制并自动修正
|
||||
if not filtered_text.is_empty():
|
||||
var quantity = filtered_text.to_int()
|
||||
if quantity > max_stock:
|
||||
filtered_text = str(max_stock)
|
||||
elif quantity > 999999999:
|
||||
filtered_text = "999999999"
|
||||
|
||||
if filtered_text != new_text:
|
||||
buy_num_edit.text = filtered_text
|
||||
buy_num_edit.caret_column = filtered_text.length()
|
||||
|
||||
# 更新总价显示
|
||||
_update_total_cost()
|
||||
|
||||
# 更新总价显示
|
||||
func _update_total_cost():
|
||||
var quantity = get_buy_quantity()
|
||||
var total_cost = quantity * current_item_cost
|
||||
|
||||
var cost_info = "\n总价: " + str(total_cost) + " 元"
|
||||
|
||||
# 更新内容显示
|
||||
var base_content = str(
|
||||
"商品名称: " + current_item_name + "\n" +
|
||||
"单价: " + str(current_item_cost) + " 元\n" +
|
||||
"描述: " + current_item_desc + "\n\n" +
|
||||
"请输入购买数量:"
|
||||
)
|
||||
|
||||
contents.text = base_content + cost_info
|
||||
|
||||
# 获取购买数量
|
||||
func get_buy_quantity() -> int:
|
||||
var text = buy_num_edit.text.strip_edges()
|
||||
if text.is_empty():
|
||||
return 1
|
||||
|
||||
var quantity = text.to_int()
|
||||
return max(1, quantity) # 至少购买1个
|
||||
|
||||
# 确认购买按钮处理
|
||||
func _on_sure_button_pressed():
|
||||
var quantity = get_buy_quantity()
|
||||
|
||||
if quantity <= 0:
|
||||
_show_error("购买数量必须大于0")
|
||||
return
|
||||
|
||||
# 检查是否超过库存限制
|
||||
if quantity > max_stock:
|
||||
_show_error("购买数量超过库存限制!最大可购买: " + str(max_stock))
|
||||
return
|
||||
|
||||
# 调用确认回调函数
|
||||
if confirm_callback.is_valid():
|
||||
confirm_callback.call(current_item_name, current_item_cost, quantity, current_buy_type)
|
||||
|
||||
# 隐藏弹窗
|
||||
self.hide()
|
||||
|
||||
# 取消购买按钮处理
|
||||
func _on_cancel_button_pressed():
|
||||
# 调用取消回调函数
|
||||
if cancel_callback.is_valid():
|
||||
cancel_callback.call()
|
||||
|
||||
# 隐藏弹窗
|
||||
self.hide()
|
||||
|
||||
# 显示错误信息
|
||||
func _show_error(message: String):
|
||||
# 这里可以显示Toast或者其他错误提示
|
||||
if has_node("/root/Toast"):
|
||||
get_node("/root/Toast").show(message, Color.RED, 2.0, 1.0)
|
||||
else:
|
||||
print("批量购买弹窗错误: " + message)
|
||||
1
SproutFarm-Frontend/Script/Dialog/BatchBuyPopup.gd.uid
Normal file
1
SproutFarm-Frontend/Script/Dialog/BatchBuyPopup.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://d4fvv2sjngajr
|
||||
163
SproutFarm-Frontend/Script/Dialog/BatchSellPopup.gd
Normal file
163
SproutFarm-Frontend/Script/Dialog/BatchSellPopup.gd
Normal file
@@ -0,0 +1,163 @@
|
||||
extends PanelContainer
|
||||
#用于作物批量出售作物弹窗
|
||||
@onready var title: Label = $VBox/Title #弹窗标题
|
||||
@onready var contents: Label = $VBox/Contents #这里显示弹窗内容
|
||||
@onready var sell_num_edit: LineEdit = $VBox/SellNumEdit #出售作物数量
|
||||
@onready var sure_button: Button = $VBox/HBox/SureButton #确定按钮
|
||||
@onready var cancel_button: Button = $VBox/HBox/CancelButton #取消按钮
|
||||
|
||||
# 当前出售的作物信息
|
||||
var current_crop_name: String = ""
|
||||
var current_max_count: int = 0
|
||||
var current_unit_price: int = 0
|
||||
var current_crop_desc: String = ""
|
||||
|
||||
# 回调函数,用于处理确认出售
|
||||
var confirm_callback: Callable
|
||||
var cancel_callback: Callable
|
||||
|
||||
func _ready():
|
||||
# 连接按钮信号
|
||||
sure_button.pressed.connect(_on_sure_button_pressed)
|
||||
cancel_button.pressed.connect(_on_cancel_button_pressed)
|
||||
|
||||
# 设置数量输入框的默认值和限制
|
||||
sell_num_edit.text = "1"
|
||||
sell_num_edit.placeholder_text = "请输入出售数量"
|
||||
|
||||
# 只允许输入数字
|
||||
sell_num_edit.text_changed.connect(_on_sell_num_changed)
|
||||
|
||||
# 连接可见性改变信号
|
||||
visibility_changed.connect(_on_visibility_changed)
|
||||
|
||||
# 默认隐藏弹窗
|
||||
self.hide()
|
||||
|
||||
#面板显示与隐藏切换处理
|
||||
func _on_visibility_changed():
|
||||
if visible:
|
||||
GlobalVariables.isZoomDisabled = true
|
||||
pass
|
||||
else:
|
||||
GlobalVariables.isZoomDisabled = false
|
||||
pass
|
||||
|
||||
# 显示批量出售弹窗
|
||||
func show_sell_popup(crop_name: String, max_count: int, unit_price: int, crop_desc: String, on_confirm: Callable, on_cancel: Callable = Callable()):
|
||||
current_crop_name = crop_name
|
||||
current_max_count = max_count
|
||||
current_unit_price = unit_price
|
||||
current_crop_desc = crop_desc
|
||||
confirm_callback = on_confirm
|
||||
cancel_callback = on_cancel
|
||||
|
||||
# 设置弹窗内容
|
||||
title.text = "批量出售作物"
|
||||
|
||||
contents.text = str(
|
||||
"作物名称: " + crop_name + "\n" +
|
||||
"单价: " + str(unit_price) + " 元/个\n" +
|
||||
"可出售数量: " + str(max_count) + " 个\n" +
|
||||
"描述: " + crop_desc + "\n\n" +
|
||||
"请输入出售数量:"
|
||||
)
|
||||
|
||||
# 重置出售数量为1
|
||||
sell_num_edit.text = "1"
|
||||
|
||||
# 显示弹窗并居中
|
||||
self.show()
|
||||
self.move_to_front()
|
||||
|
||||
# 处理数量输入变化
|
||||
func _on_sell_num_changed(new_text: String):
|
||||
# 只允许输入数字
|
||||
var filtered_text = ""
|
||||
for char in new_text:
|
||||
if char.is_valid_int():
|
||||
filtered_text += char
|
||||
|
||||
# 检查是否超过最大值并自动修正
|
||||
if not filtered_text.is_empty():
|
||||
var quantity = filtered_text.to_int()
|
||||
if quantity > current_max_count:
|
||||
filtered_text = str(current_max_count)
|
||||
|
||||
if filtered_text != new_text:
|
||||
sell_num_edit.text = filtered_text
|
||||
sell_num_edit.caret_column = filtered_text.length()
|
||||
|
||||
# 更新总价显示
|
||||
_update_total_income()
|
||||
|
||||
# 更新总收入显示
|
||||
func _update_total_income():
|
||||
var quantity = get_sell_quantity()
|
||||
var total_income = quantity * current_unit_price
|
||||
|
||||
# 检查数量是否超过最大可售数量
|
||||
var quantity_status = ""
|
||||
if quantity > current_max_count:
|
||||
quantity_status = " (超出库存!)"
|
||||
#quantity = current_max_count
|
||||
var income_info = "\n出售数量: " + str(quantity) + " 个" + quantity_status + "\n总收入: " + str(total_income) + " 元"
|
||||
|
||||
# 更新内容显示
|
||||
var base_content = str(
|
||||
"作物名称: " + current_crop_name + "\n" +
|
||||
"单价: " + str(current_unit_price) + " 元/个\n" +
|
||||
"可出售数量: " + str(current_max_count) + " 个\n" +
|
||||
"描述: " + current_crop_desc + "\n\n" +
|
||||
"请输入出售数量:"
|
||||
)
|
||||
|
||||
contents.text = base_content + income_info
|
||||
|
||||
# 获取出售数量
|
||||
func get_sell_quantity() -> int:
|
||||
var text = sell_num_edit.text.strip_edges()
|
||||
if text.is_empty():
|
||||
return 1
|
||||
|
||||
var quantity = text.to_int()
|
||||
quantity = max(1, quantity) # 至少出售1个
|
||||
quantity = min(quantity, current_max_count) # 不超过最大值
|
||||
return quantity
|
||||
|
||||
# 确认出售按钮处理
|
||||
func _on_sure_button_pressed():
|
||||
var quantity = get_sell_quantity()
|
||||
|
||||
if quantity <= 0:
|
||||
_show_error("出售数量必须大于0")
|
||||
return
|
||||
|
||||
if quantity > current_max_count:
|
||||
#quantity = current_max_count
|
||||
_show_error("出售数量不能超过库存数量(" + str(current_max_count) + ")")
|
||||
return
|
||||
|
||||
# 调用确认回调函数
|
||||
if confirm_callback.is_valid():
|
||||
confirm_callback.call(current_crop_name, quantity, current_unit_price)
|
||||
|
||||
# 隐藏弹窗
|
||||
self.hide()
|
||||
|
||||
# 取消出售按钮处理
|
||||
func _on_cancel_button_pressed():
|
||||
# 调用取消回调函数
|
||||
if cancel_callback.is_valid():
|
||||
cancel_callback.call()
|
||||
|
||||
# 隐藏弹窗
|
||||
self.hide()
|
||||
|
||||
# 显示错误信息
|
||||
func _show_error(message: String):
|
||||
# 显示Toast错误提示
|
||||
if has_node("/root/Toast"):
|
||||
get_node("/root/Toast").show(message, Color.RED, 2.0, 1.0)
|
||||
else:
|
||||
print("批量出售弹窗错误: " + message)
|
||||
1
SproutFarm-Frontend/Script/Dialog/BatchSellPopup.gd.uid
Normal file
1
SproutFarm-Frontend/Script/Dialog/BatchSellPopup.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://dsmmxivba06ab
|
||||
Reference in New Issue
Block a user