继续更新UI
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
# 如果没有找到,使用默认的收获物图片
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user