继续更新UI

This commit is contained in:
2025-09-24 15:06:30 +08:00
parent 26b856d74e
commit df57f3c5ec
59 changed files with 1415 additions and 2898 deletions

View File

@@ -644,7 +644,7 @@ func _load_stock_data():
if file:
var json_string = file.get_as_text()
file.close()
print("读取到的JSON数据", json_string)
#print("读取到的JSON数据", json_string)
var json = JSON.new()
var parse_result = json.parse(json_string)
@@ -653,7 +653,7 @@ func _load_stock_data():
crop_stock_data = data.get("stock", {})
last_refresh_date = data.get("last_refresh_date", "")
print("库存数据加载成功,库存条目数:", crop_stock_data.size())
print("加载的库存数据:", crop_stock_data)
#print("加载的库存数据:", crop_stock_data)
print("上次刷新日期:", last_refresh_date)
# 如果库存数据为空,重新生成
@@ -678,7 +678,7 @@ func _save_stock_data():
}
print("准备保存库存数据到:", stock_file_path)
print("保存的数据:", data)
#print("保存的数据:", data)
var file = FileAccess.open(stock_file_path, FileAccess.WRITE)
if file:
@@ -710,7 +710,7 @@ func _generate_initial_stock():
var stock_amount = _get_stock_amount_by_quality(crop["品质"])
crop_stock_data[crop_name] = stock_amount
generated_count += 1
print("生成库存:", crop_name, " - ", crop["品质"], " - ", stock_amount, "")
#print("生成库存:", crop_name, " - ", crop["品质"], " - ", stock_amount, "个")
# 设置当前日期为刷新日期
last_refresh_date = _get_current_date()
@@ -760,7 +760,7 @@ func _check_daily_refresh():
# 每日刷新库存
func _refresh_daily_stock():
_generate_initial_stock()
Toast.show("种子商店库存已刷新!", Color.GREEN, 3.0, 1.0)
#Toast.show("种子商店库存已刷新!", Color.GREEN, 3.0, 1.0)
# 获取作物当前库存
func _get_crop_stock(crop_name: String) -> int:

View File

@@ -530,7 +530,7 @@ func _get_crop_harvest_texture(crop_name: String) -> Texture2D:
if ResourceLoader.exists(harvest_texture_path):
var texture = load(harvest_texture_path)
if texture:
print("仓库加载作物收获物图片:", crop_name)
#print("仓库加载作物收获物图片:", crop_name)
return texture
# 如果没有找到,使用默认的收获物图片

View File

@@ -252,7 +252,7 @@ func _update_button_item_image(button: Button, item_name: String):
# CropImage是Sprite2D直接设置texture属性
item_image.texture = texture
item_image.visible = true
print("道具商店更新道具图片:", item_name)
#print("道具商店更新道具图片:", item_name)
else:
# 如果没有图片,隐藏图片节点
item_image.visible = false

View File

@@ -128,10 +128,10 @@ func _update_button_pet_image(button: Button, pet_name: String):
if pet_config.has(pet_name):
var pet_info = pet_config[pet_name]
var scene_path = pet_info.get("pet_image", "") # 使用服务器数据的pet_image字段
print("宠物背包 ", pet_name, " 的图片路径:", scene_path)
#print("宠物背包 ", pet_name, " 的图片路径:", scene_path)
if scene_path != "" and ResourceLoader.exists(scene_path):
print("宠物背包开始加载宠物场景:", scene_path)
#print("宠物背包开始加载宠物场景:", scene_path)
# 加载宠物场景并获取PetImage的纹理
var pet_scene = load(scene_path)
if pet_scene:
@@ -145,7 +145,7 @@ func _update_button_pet_image(button: Button, pet_name: String):
var frame_count = pet_instance.sprite_frames.get_frame_count(default_animation)
if frame_count > 0:
texture = pet_instance.sprite_frames.get_frame_texture(default_animation, 0)
print("宠物背包成功获取宠物纹理:", pet_name)
#print("宠物背包成功获取宠物纹理:", pet_name)
else:
print("宠物背包场景没有动画:", pet_name)
else:
@@ -155,8 +155,7 @@ func _update_button_pet_image(button: Button, pet_name: String):
print("宠物背包无法加载宠物场景:", scene_path)
else:
print("宠物背包图片路径无效或文件不存在:", scene_path)
else:
print("宠物背包配置中没有找到:", pet_name)
# 设置图片
if texture:
@@ -165,26 +164,10 @@ func _update_button_pet_image(button: Button, pet_name: String):
pet_image.scale = Vector2(10, 10)
# 确保图片居中显示
pet_image.centered = true
print("宠物背包成功设置宠物图片:", pet_name)
#print("宠物背包成功设置宠物图片:", pet_name)
else:
pet_image.visible = false
print("宠物背包无法获取宠物图片:", pet_name)
# 加载宠物配置数据
func _load_pet_config() -> Dictionary:
var file = FileAccess.open("res://Data/pet_data.json", FileAccess.READ)
if file == null:
return {}
var json = JSON.new()
var json_string = file.get_as_text()
file.close()
var parse_result = json.parse(json_string)
if parse_result != OK:
return {}
return json.data
# 计算宠物年龄(以天为单位)
func _calculate_pet_age(birthday: String) -> int:

View File

@@ -59,12 +59,11 @@ func update_pet_store_ui():
child.queue_free()
print("更新宠物商店UI宠物种类", pet_config.size())
print("宠物配置数据:", pet_config)
# 为每个宠物配置创建按钮
for pet_name in pet_config.keys():
var pet_info = pet_config[pet_name]
print("处理宠物:", pet_name, ",数据:", pet_info)
#print("处理宠物:", pet_name, ",数据:", pet_info)
# 适配扁平化数据格式
var can_buy = pet_info.get("can_purchase", false)
@@ -93,7 +92,7 @@ func update_pet_store_ui():
button.pressed.connect(func(): _on_store_pet_selected(pet_name, pet_cost, pet_desc))
store_grid.add_child(button)
print("已添加宠物按钮:", pet_name)
#print("已添加宠物按钮:", pet_name)
# 检查玩家是否已拥有某种宠物
func _check_pet_owned(pet_name: String) -> bool:
@@ -157,10 +156,10 @@ func _update_button_pet_image(button: Button, pet_name: String):
if pet_config.has(pet_name):
var pet_info = pet_config[pet_name]
var scene_path = pet_info.get("pet_image", "")
print("宠物 ", pet_name, " 的图片路径:", scene_path)
#print("宠物 ", pet_name, " 的图片路径:", scene_path)
if scene_path != "" and ResourceLoader.exists(scene_path):
print("开始加载宠物场景:", scene_path)
#print("开始加载宠物场景:", scene_path)
# 加载宠物场景并获取PetImage的纹理
var pet_scene = load(scene_path)
if pet_scene:
@@ -175,7 +174,7 @@ func _update_button_pet_image(button: Button, pet_name: String):
var frame_count = pet_image_node.sprite_frames.get_frame_count(default_animation)
if frame_count > 0:
texture = pet_image_node.sprite_frames.get_frame_texture(default_animation, 0)
print("成功获取宠物纹理:", pet_name)
#print("成功获取宠物纹理:", pet_name)
else:
print("宠物场景没有动画:", pet_name)
else:
@@ -195,7 +194,7 @@ func _update_button_pet_image(button: Button, pet_name: String):
pet_image.scale = Vector2(10, 10)
# 确保图片居中显示
pet_image.centered = true
print("成功设置宠物图片:", pet_name)
#print("成功设置宠物图片:", pet_name)
else:
# 如果无法获取图片,隐藏图片节点但保留按钮
pet_image.visible = false

View File

@@ -9,19 +9,24 @@ var TETRIS = preload('res://Scene/SmallGame/Tetris.tscn').instantiate()
func _on_game_button_pressed() -> void:
self.add_child(_2048_GAME)
pass # Replace with function body.
pass
func _on_push_box_button_pressed() -> void:
self.add_child(PUSH_BOX)
pass # Replace with function body.
pass
func _on_snake_game_button_pressed() -> void:
self.add_child(SNAKE_GAME)
pass # Replace with function body.
pass
func _on_tetris_button_pressed() -> void:
self.add_child(TETRIS)
pass # Replace with function body.
pass
func _on_quit_button_pressed() -> void:
self.hide()
pass

View File

@@ -17,6 +17,8 @@ extends Panel
@onready var accept_dialog: AcceptDialog = $'../../DiaLog/AcceptDialog'
@onready var tcp_network_manager_panel: Panel = $'../../BigPanel/TCPNetworkManagerPanel'
@onready var http_texture_rect: HTTPTextureRect = $VBox1/HBox1/HTTPTextureRect
# 存储待执行的操作类型
var pending_action = ""
@@ -188,11 +190,14 @@ func _refresh_player_info():
user_password_input.text = main_game.user_password if main_game.user_password != "" else ""
# 优先从 login_data 获取数据,如果没有则从 data 获取
var player_data = main_game.login_data #if main_game.login_data.size() > 0 else main_game.data
var player_data = main_game.login_data
player_name_input.text = player_data.get("玩家昵称", "")
farm_name_input.text = player_data.get("农场名称", "")
personal_profile_input.text = player_data.get("个人简介", "")
# 尝试加载玩家头像(使用用户名/QQ号加载头像而不是显示名
if user_name_input.text.is_valid_int():
http_texture_rect.load_from_url("http://q1.qlogo.cn/g?b=qq&nk=" + user_name_input.text + "&s=100")
#显示消息提示

View File

@@ -81,9 +81,6 @@ func send_broadcast_message():
if success:
# 清空输入框
input_message.text = ""
Toast.show("消息发送成功", Color.GREEN, 2.0, 1.0)
else:
Toast.show("消息发送失败", Color.RED, 2.0, 1.0)
# 统一的消息处理函数
func _add_message_to_history(data: Dictionary):
@@ -241,9 +238,6 @@ func receive_history_messages(data: Dictionary):
# 保存到本地
save_chat_history()
Toast.show("历史消息加载完成,共%d条消息" % messages.size(), Color.GREEN, 2.0, 1.0)
else:
Toast.show("没有找到历史消息", Color.YELLOW, 2.0, 1.0)
# 保存聊天历史记录
func save_chat_history():
@@ -278,7 +272,7 @@ func clear_message_history():
# 获取最新消息用于主界面显示
func get_latest_message() -> String:
print("get_latest_message 被调用,消息历史大小: ", message_history.size())
#print("get_latest_message 被调用,消息历史大小: ", message_history.size())
if message_history.size() > 0:
# 确保消息按时间排序
message_history.sort_custom(func(a, b): return a.get("timestamp", 0) < b.get("timestamp", 0))
@@ -286,5 +280,5 @@ func get_latest_message() -> String:
var result = latest.get("display_name", "匿名") + ": " + latest.get("content", "")
print("返回最新消息: ", result)
return result
print("没有消息历史,返回'暂无消息'")
#print("没有消息历史,返回'暂无消息'")
return "暂无消息"

View File

@@ -88,10 +88,10 @@ func _get_pet_texture(pet_name: String) -> Texture2D:
if pet_config.has(pet_name):
var pet_info = pet_config[pet_name]
var scene_path = pet_info.get("pet_image", "") # 使用服务器数据的pet_image字段
print("宠物信息面板 ", pet_name, " 的图片路径:", scene_path)
#print("宠物信息面板 ", pet_name, " 的图片路径:", scene_path)
if scene_path != "" and ResourceLoader.exists(scene_path):
print("宠物信息面板开始加载宠物场景:", scene_path)
#print("宠物信息面板开始加载宠物场景:", scene_path)
var pet_scene = load(scene_path)
if pet_scene:
var pet_instance = pet_scene.instantiate()
@@ -103,7 +103,7 @@ func _get_pet_texture(pet_name: String) -> Texture2D:
var frame_count = pet_instance.sprite_frames.get_frame_count(default_animation)
if frame_count > 0:
var texture = pet_instance.sprite_frames.get_frame_texture(default_animation, 0)
print("宠物信息面板成功获取宠物纹理:", pet_name)
#print("宠物信息面板成功获取宠物纹理:", pet_name)
pet_instance.queue_free()
return texture
else:
@@ -119,22 +119,6 @@ func _get_pet_texture(pet_name: String) -> Texture2D:
print("宠物信息面板配置中没有找到:", pet_name)
return null
# 加载宠物配置数据
func _load_pet_config() -> Dictionary:
var file = FileAccess.open("res://Data/pet_data.json", FileAccess.READ)
if file == null:
return {}
var json = JSON.new()
var json_string = file.get_as_text()
file.close()
var parse_result = json.parse(json_string)
if parse_result != OK:
return {}
return json.data
# 设置宠物详细信息使用bbcode美化- 新格式
func _set_pet_detailed_info(pet_name: String, pet_data: Dictionary):
# 计算宠物年龄