mirror of
https://github.com/Rundll86/Dog-Lynx-And-HCN.git
synced 2026-05-27 22:41:56 +08:00
feat: 添加武器升华系统及相关UI组件
实现武器升华功能,包括: - 新增SublimateOption类处理升华选项 - 添加SublimateOptionHandler UI组件 - 在武器卡片中集成升华界面 - 重构武器描述生成逻辑 - 新增钻石资源消耗机制 - 优化UI布局和样式 - 修复多处类型引用错误
This commit is contained in:
@@ -6,8 +6,8 @@ signal selected(applied: bool)
|
||||
|
||||
@export var avatarTexture: Texture2D = null
|
||||
@export var displayName: String = "未命名饲料"
|
||||
@export var quality: FeedName.Quality = FeedName.Quality.COMMON
|
||||
@export var topic: FeedName.Topic = FeedName.Topic.SURVIVAL
|
||||
@export var quality: CategoryStore.Quality = CategoryStore.Quality.COMMON
|
||||
@export var topic: CategoryStore.Topic = CategoryStore.Topic.SURVIVAL
|
||||
@export var fields: Array[FieldStore.Entity] = []
|
||||
@export var fieldValues: Array[float] = []
|
||||
@export var weapons: Array[PackedScene] = []
|
||||
|
||||
@@ -1,15 +1,21 @@
|
||||
class_name SublimateOption
|
||||
|
||||
signal applied()
|
||||
|
||||
var displayName: String = "升华"
|
||||
var description: String = "描述"
|
||||
var executor: Callable = func(_weapon: Weapon, _entity: EntityBase): return
|
||||
var cost: int = 1
|
||||
var quality: CategoryStore.Quality = CategoryStore.Quality.COMMON
|
||||
|
||||
func _init(displayNames: String, descriptions: String, executors: Callable):
|
||||
func _init(displayNames: String, descriptions: String, executors: Callable, costs: int, qualities: CategoryStore.Quality):
|
||||
displayName = displayNames
|
||||
description = descriptions
|
||||
executor = executors
|
||||
cost = costs
|
||||
quality = qualities
|
||||
|
||||
func apply(entity: EntityBase, index: int):
|
||||
var weapon = entity.weapons[index]
|
||||
if weapon is Weapon:
|
||||
executor.call(weapon, entity)
|
||||
func apply(entity: EntityBase, weapon: Weapon):
|
||||
cost += 1
|
||||
executor.call(weapon, entity)
|
||||
applied.emit()
|
||||
|
||||
@@ -48,6 +48,8 @@ enum EmitType {
|
||||
@onready var extractBtn: Button = $%extractBtn
|
||||
@onready var inlayBtn: Button = $%inlayBtn
|
||||
|
||||
@onready var sublimateOptionsBox: Control = $%sublimateOptions
|
||||
|
||||
var cooldownTimer: CooldownTimer = null
|
||||
var originalStore: Dictionary = {}
|
||||
var chargedTime: float = 0
|
||||
@@ -55,6 +57,7 @@ var attackSpeed: float = 1
|
||||
var looping: bool = false
|
||||
var autoUpdate: bool = false
|
||||
var storeExtra: Dictionary = {}
|
||||
var sublimateOptionsStored: Array[SublimateOption] = []
|
||||
|
||||
func _ready():
|
||||
cooldownTimer = CooldownTimer.new()
|
||||
@@ -126,6 +129,7 @@ func _ready():
|
||||
for i in sounds.get_children():
|
||||
i.process_mode = ProcessMode.PROCESS_MODE_ALWAYS
|
||||
debugRebuild = false # 只能在编辑器里打开
|
||||
rebuildInfo()
|
||||
func _physics_process(_delta):
|
||||
if debugRebuild:
|
||||
rebuildInfo()
|
||||
@@ -153,6 +157,10 @@ func multipiler() -> float:
|
||||
else:
|
||||
return 1
|
||||
func rebuildInfo(showNext: bool = false):
|
||||
rebuildBaseInfo()
|
||||
rebuildDescription(showNext)
|
||||
rebuildSublimateOptions(showNext)
|
||||
func rebuildBaseInfo():
|
||||
avatarRect.texture = avatarTexture
|
||||
nameLabel.displayName = displayName
|
||||
nameLabel.quality = quality
|
||||
@@ -171,7 +179,6 @@ func rebuildInfo(showNext: bool = false):
|
||||
if is_instance_valid(UIState.player):
|
||||
beachball.enough = canUpdate(UIState.player)
|
||||
soul.enough = canInlay()
|
||||
descriptionLabel.text = buildDescription(showNext && (canUpdate(UIState.player) || canInlay()))
|
||||
func formatValue(value: Variant, type: FieldStore.DataType) -> String:
|
||||
if type == FieldStore.DataType.VALUE:
|
||||
return "%.2f" % value
|
||||
@@ -186,11 +193,10 @@ func formatValue(value: Variant, type: FieldStore.DataType) -> String:
|
||||
else:
|
||||
return str(value)
|
||||
func buildDescription(showNext: bool = false) -> String:
|
||||
var current = store
|
||||
var next = update(level + 1, originalStore.duplicate(), UIState.player)
|
||||
var result = descriptionTemplate
|
||||
for key in store.keys():
|
||||
var data = current[key]
|
||||
var data = readStore(key)
|
||||
var nextData = next[key]
|
||||
var type = storeType.get(key, FieldStore.DataType.VALUE)
|
||||
data = formatValue(data, type)
|
||||
@@ -202,6 +208,24 @@ func buildDescription(showNext: bool = false) -> String:
|
||||
text = "[color=cyan]%s[/color]" % data
|
||||
result = result.replace("$" + key, text)
|
||||
return result
|
||||
func rebuildDescription(showNext: bool):
|
||||
descriptionLabel.text = buildDescription(showNext && (canUpdate(UIState.player) || canInlay()))
|
||||
func rebuildSublimateOptions(showNext: bool):
|
||||
for i in sublimateOptionsBox.get_children():
|
||||
sublimateOptionsBox.remove_child(i)
|
||||
for sublimate in getSublimateOptions():
|
||||
var instance = ComponentManager.getUIComponent("SublimateOption").instantiate() as SublimateOptionHandler
|
||||
instance.use = sublimate
|
||||
instance.apply.connect(
|
||||
func():
|
||||
sublimate.apply(UIState.player, self )
|
||||
rebuildBaseInfo()
|
||||
rebuildDescription(showNext)
|
||||
instance.rebuildInfo()
|
||||
disruptSublimateOptions()
|
||||
)
|
||||
sublimateOptionsBox.add_child(instance)
|
||||
disruptSublimateOptions()
|
||||
func readStore(key: String):
|
||||
return store.get(key, 0) + readStoreExtra(key)
|
||||
func playSound(sound: String):
|
||||
@@ -246,8 +270,23 @@ func addStoreExtra(key: String, value: float):
|
||||
if !storeExtra.has(key):
|
||||
storeExtra[key] = 0
|
||||
storeExtra[key] += value
|
||||
storeExtra[key] = clamp(storeExtra[key], 0, INF)
|
||||
func readStoreExtra(key: String):
|
||||
return storeExtra.get(key, 0)
|
||||
func getSublimateOptions() -> Array[SublimateOption]:
|
||||
if len(sublimateOptionsStored) == 0:
|
||||
sublimateOptionsStored = sublimateOptions()
|
||||
return sublimateOptionsStored
|
||||
func disruptSublimateOptions():
|
||||
var children = sublimateOptionsBox.get_children()
|
||||
children.shuffle()
|
||||
for index in len(children):
|
||||
sublimateOptionsBox.remove_child(children[index])
|
||||
for index in len(children):
|
||||
var child = children[index]
|
||||
if child is SublimateOptionHandler:
|
||||
child.visible = index < 3
|
||||
sublimateOptionsBox.add_child(child)
|
||||
|
||||
# 抽象
|
||||
func sublimateOptions() -> Array[SublimateOption]:
|
||||
|
||||
Reference in New Issue
Block a user