进一步完善服务器功能,添加远程命令系统,踢人系统
This commit is contained in:
@@ -82,6 +82,12 @@ func _on_sell_num_changed(new_text: String):
|
||||
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()
|
||||
@@ -97,6 +103,12 @@ func _on_sell_price_changed(new_text: String):
|
||||
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()
|
||||
@@ -144,7 +156,9 @@ func get_sell_quantity() -> int:
|
||||
return 1
|
||||
|
||||
var quantity = text.to_int()
|
||||
return max(1, quantity) # 至少出售1个
|
||||
quantity = max(1, quantity) # 至少出售1个
|
||||
quantity = min(quantity, current_max_count) # 不超过最大值
|
||||
return quantity
|
||||
|
||||
# 获取出售价格
|
||||
func get_sell_price() -> int:
|
||||
@@ -153,7 +167,9 @@ func get_sell_price() -> int:
|
||||
return current_suggested_price
|
||||
|
||||
var price = text.to_int()
|
||||
return max(1, price) # 至少1元
|
||||
price = max(1, price) # 至少1元
|
||||
price = min(price, 999999999) # 不超过最大值
|
||||
return price
|
||||
|
||||
# 确认添加按钮处理
|
||||
func _on_sure_button_pressed():
|
||||
|
||||
@@ -11,6 +11,7 @@ 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
|
||||
@@ -41,13 +42,14 @@ func _on_visibility_changed():
|
||||
pass
|
||||
|
||||
# 显示批量购买弹窗
|
||||
func show_buy_popup(item_name: String, item_cost: int, item_desc: String, buy_type: String, on_confirm: Callable, on_cancel: Callable = Callable()):
|
||||
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":
|
||||
@@ -55,10 +57,15 @@ func show_buy_popup(item_name: String, item_cost: int, item_desc: String, buy_ty
|
||||
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 + "\n\n" +
|
||||
"描述: " + item_desc + stock_info + "\n\n" +
|
||||
"请输入购买数量:"
|
||||
)
|
||||
|
||||
@@ -77,6 +84,14 @@ func _on_buy_num_changed(new_text: String):
|
||||
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()
|
||||
@@ -118,6 +133,11 @@ func _on_sure_button_pressed():
|
||||
_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)
|
||||
|
||||
@@ -78,6 +78,12 @@ func _on_sell_num_changed(new_text: String):
|
||||
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()
|
||||
@@ -94,7 +100,7 @@ func _update_total_income():
|
||||
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) + " 元"
|
||||
|
||||
# 更新内容显示
|
||||
@@ -115,7 +121,9 @@ func get_sell_quantity() -> int:
|
||||
return 1
|
||||
|
||||
var quantity = text.to_int()
|
||||
return max(1, quantity) # 至少出售1个
|
||||
quantity = max(1, quantity) # 至少出售1个
|
||||
quantity = min(quantity, current_max_count) # 不超过最大值
|
||||
return quantity
|
||||
|
||||
# 确认出售按钮处理
|
||||
func _on_sure_button_pressed():
|
||||
@@ -126,6 +134,7 @@ func _on_sure_button_pressed():
|
||||
return
|
||||
|
||||
if quantity > current_max_count:
|
||||
#quantity = current_max_count
|
||||
_show_error("出售数量不能超过库存数量(" + str(current_max_count) + ")")
|
||||
return
|
||||
|
||||
@@ -151,4 +160,4 @@ func _show_error(message: String):
|
||||
if has_node("/root/Toast"):
|
||||
get_node("/root/Toast").show(message, Color.RED, 2.0, 1.0)
|
||||
else:
|
||||
print("批量出售弹窗错误: " + message)
|
||||
print("批量出售弹窗错误: " + message)
|
||||
|
||||
Reference in New Issue
Block a user