prop 加载优化
This commit is contained in:
parent
1cb4e17309
commit
533a68d9ca
@ -85,14 +85,14 @@ func _ready() -> void:
|
||||
display_prop.gui_input.connect(_on_prop_gui_input.bind(-1))
|
||||
_load_items_config_to_dict("ImportantPropItems")
|
||||
_load_items_config_to_dict("PropItems")
|
||||
_load_from_archive()
|
||||
_reload_cache_and_realign_display()
|
||||
selecting_bg.modulate.a = 0.0
|
||||
prop_scroll.scroll_horizontal = PROP_CONTAINER_X
|
||||
props_bag_scroll.scroll_horizontal = 0.0
|
||||
props_bag_scroll.custom_minimum_size.x = 0.0
|
||||
# focus_exited.connect(_on_focus_exited)
|
||||
# 存档更新时,从存档加载 prop
|
||||
ArchiveManager.archive_loaded.connect(_load_from_archive)
|
||||
ArchiveManager.archive_loaded.connect(_reload_cache_and_realign_display)
|
||||
# tween timer
|
||||
timer.wait_time = display_time
|
||||
timer.one_shot = true
|
||||
@ -158,11 +158,11 @@ func _load_items_config_to_dict(title: String):
|
||||
# return content
|
||||
|
||||
|
||||
func _load_from_archive() -> void:
|
||||
func _reload_cache_and_realign_display() -> void:
|
||||
if ArchiveManager.archive:
|
||||
inventory = ArchiveManager.archive.prop_inventory
|
||||
_align_container_size()
|
||||
_load_texture_cache()
|
||||
_align_container_size()
|
||||
_update_prop_display_with_texture()
|
||||
|
||||
|
||||
@ -171,9 +171,7 @@ func checkout_inventory(character: String) -> void:
|
||||
printerr("PropHud checkout_inventory: No inventory found.")
|
||||
return
|
||||
inventory.checkout(character)
|
||||
_align_container_size()
|
||||
_load_texture_cache()
|
||||
_update_prop_display_with_texture()
|
||||
_reload_cache_and_realign_display()
|
||||
|
||||
|
||||
func hide_hud():
|
||||
@ -201,6 +199,9 @@ func _load_texture_cache() -> void:
|
||||
# 以 items_dict 为准,如果 enabled_items 中的 key 不存在,则删除
|
||||
if not key in items_dict:
|
||||
inventory.disable_item(key)
|
||||
printerr(
|
||||
"PropHud _load_texture_cache: key not found in items_dict:", key, ". remove item."
|
||||
)
|
||||
continue
|
||||
var path = items_dict[key].texture_path
|
||||
if not path:
|
||||
@ -262,7 +263,15 @@ func _display_texture_by_key(button, key) -> void:
|
||||
button.texture_normal = null
|
||||
return
|
||||
var item = items_dict[key]
|
||||
button.texture_normal = cached_inventory_textures[item.key]
|
||||
var texture = cached_inventory_textures.get(item.key)
|
||||
if not texture:
|
||||
if item.texture_path:
|
||||
texture = load(item.texture_path) as Texture2D
|
||||
if not texture:
|
||||
printerr("PropHud _display_texture_by_key: No texture found for item:", item)
|
||||
else:
|
||||
cached_inventory_textures[item.key] = texture
|
||||
button.texture_normal = texture
|
||||
var t_size = button.texture_normal.get_size()
|
||||
var max_x = max(t_size.x, t_size.y)
|
||||
var p_scale = min(PROP_CONTROL_X / t_size.x, PROP_CONTROL_X / t_size.y)
|
||||
@ -480,9 +489,7 @@ func enable_prop_item(prop_key: String, inspect := true) -> void:
|
||||
push_error("PropItem not found! key=" + prop_key)
|
||||
return
|
||||
inventory.enable_item(prop_key)
|
||||
_align_container_size()
|
||||
_load_texture_cache()
|
||||
_update_prop_display_with_texture()
|
||||
_reload_cache_and_realign_display()
|
||||
if GlobalConfig.DEBUG:
|
||||
print("PropHUD Enable prop item:", prop_key)
|
||||
if inspect:
|
||||
@ -519,9 +526,7 @@ func disable_prop_item(prop_key: String) -> void:
|
||||
if not inventory or not prop_key:
|
||||
return
|
||||
inventory.disable_item(prop_key)
|
||||
_align_container_size()
|
||||
_load_texture_cache()
|
||||
_update_prop_display_with_texture()
|
||||
_reload_cache_and_realign_display()
|
||||
|
||||
|
||||
func _align_container_size() -> void:
|
||||
|
@ -66,7 +66,7 @@ func disable_item(prop_key: String) -> void:
|
||||
# if enabled_items.has(prop_key):
|
||||
enabled_items.erase(prop_key)
|
||||
# wrap index
|
||||
current_index = wrapi(current_index, 0, enabled_items.size())
|
||||
current_index = clampi(current_index, 0, enabled_items.size())
|
||||
|
||||
|
||||
# return true if the index changed
|
||||
|
Loading…
Reference in New Issue
Block a user