mirror of
https://github.com/Rundll86/Dog-Lynx-And-HCN.git
synced 2026-05-27 22:41:56 +08:00
b3b4fdafc2
- Created a new SVG import for the energy texture, enabling better resource management and compression. - Added a StyleBoxFlat resource for the top left panel with specified margins, background color, border width, and corner radius. - Introduced a StyleBoxFlat resource for the top panel with similar properties, ensuring consistent UI design across panels.
72 lines
2.3 KiB
GDScript
72 lines
2.3 KiB
GDScript
@tool
|
|
extends PanelContainer
|
|
class_name Feed
|
|
|
|
@export var avatarTexture: Texture2D = preload("res://icon.svg")
|
|
@export var displayName: String = "未命名饲料"
|
|
@export var fields: Array[FieldStore.Entity] = []
|
|
@export var fieldValues: Array[float] = []
|
|
@export var costs: Array[ItemStore.ItemType] = []
|
|
@export var costCounts: Array[int] = []
|
|
|
|
@onready var avatarRect: TextureRect = $"%avatar"
|
|
@onready var nameLabel: RichTextLabel = $"%name"
|
|
@onready var fieldsBox: VBoxContainer = $"%fields"
|
|
@onready var costsBox: GridContainer = $"%costs"
|
|
@onready var selectButton: Button = $"%selectBtn"
|
|
|
|
func _ready():
|
|
selectButton.pressed.connect(
|
|
func():
|
|
if apply(UIState.player):
|
|
UIState.setPanel()
|
|
queue_free()
|
|
Wave.next()
|
|
)
|
|
avatarRect.texture = avatarTexture
|
|
nameLabel.text = "[b]" + displayName + "[/b]"
|
|
for i in fieldsBox.get_children():
|
|
i.queue_free()
|
|
var noField = true
|
|
for i in range(min(fields.size(), fieldValues.size())):
|
|
noField = false
|
|
var field = fields[i]
|
|
var value = fieldValues[i]
|
|
var fieldShow: FieldShow = preload("res://components/UI/FieldShow.tscn").instantiate()
|
|
fieldShow.field = field
|
|
fieldShow.value = value
|
|
fieldsBox.add_child(fieldShow)
|
|
if noField:
|
|
fieldsBox.add_child(QuickUI.smallText("无词条"))
|
|
for i in costsBox.get_children():
|
|
i.queue_free()
|
|
for i in range(min(costs.size(), costCounts.size())):
|
|
var cost = costs[i]
|
|
var count = costCounts[i]
|
|
var costShow: ItemShow = preload("res://components/UI/ItemShow.tscn").instantiate()
|
|
costShow.type = cost
|
|
costShow.count = count * multipiler()
|
|
costsBox.add_child(costShow)
|
|
|
|
func apply(entity: EntityBase):
|
|
var allHave = true
|
|
for i in range(min(costs.size(), costCounts.size())):
|
|
var item = costs[i]
|
|
var count = costCounts[i] * multipiler()
|
|
if entity.inventory[item] < count:
|
|
allHave = false
|
|
break
|
|
if allHave:
|
|
for i in range(min(costs.size(), costCounts.size())):
|
|
var item = costs[i]
|
|
var count = costCounts[i] * multipiler()
|
|
entity.inventory[item] -= count
|
|
for i in range(min(fields.size(), fieldValues.size())):
|
|
var field = fields[i]
|
|
var value = fieldValues[i]
|
|
var applier = FieldStore.entityApplier.get(field, null)
|
|
if !applier or applier.call(entity, value):
|
|
entity.fields[field] += value
|
|
return allHave
|
|
func multipiler():
|
|
return 1 - UIState.player.fields.get(FieldStore.Entity.PRICE_REDUCTION) |