ChocolateBird/widgets/SaveSlot.gd

66 lines
2.2 KiB
GDScript3
Raw Permalink Normal View History

2023-08-02 19:50:50 +09:30
extends PanelContainer
#warning-ignore-all:shadowed_variable
signal clicked
2023-08-02 19:50:50 +09:30
const PC := preload('res://PC.tscn')
var PCs = []
var data := {}
2023-08-02 19:50:50 +09:30
var dummy_data := {
'characters': [
{'character_id': 0},
{'character_id': 1},
{'character_id': 2},
{'character_id': 3},
],
'game_time_frames': randi() % 0x01000000,
'character_names_decoded': ['Butz', 'Lenna', 'Galuf', 'Faris', 'Krile'],
'config': {'menu_color_r': randi()%32, 'menu_color_g': randi()%32, 'menu_color_b': randi()%32},
'slot_in_use': true,
2023-08-02 19:50:50 +09:30
}
func _init_dummy():
for i in 4:
var c = dummy_data.characters[i]
c.level = 1 + (randi()%99)
c.current_job_id = randi()%22
c.hp_max = (50*c.level) + (randi()%(100 + 50*c.level))
c.hp_current = 1 + (randi()%c.hp_max)
dummy_data.characters.shuffle()
func set_data(data: Dictionary):
self.data = data
2023-08-02 19:50:50 +09:30
self.material.set_shader_param('MenuBGColour', Color(data.config.menu_color_r/31.0, data.config.menu_color_g/31.0, data.config.menu_color_b/31.0))
for i in 4:
var char_id: int = data.characters[i].character_id
var job_id: int = data.characters[i].current_job_id
var sprite_id := (char_id * 22) + job_id
PCs[i].material.set_shader_param('palette', SpriteLoader.character_battle_sprite_palette_textures[sprite_id])
PCs[i].texture = SpriteLoader.strip_textures[sprite_id]
2023-09-21 15:26:10 +09:30
$'%lbl_level_num'.text = '%d' % data.characters[0].level
$'%lbl_gametime'.text = Common.game_time_frames_to_hhmm(data.game_time_frames)
$'%lbl_name'.text = data.character_names_decoded[data.characters[0].character_id]
2023-09-21 15:26:10 +09:30
$'%lbl_hp'.text = '%d/%4d' % [data.characters[0].hp_current, data.characters[0].hp_max]
$HBoxContainer.visible = data.slot_in_use
$lbl_not_in_use.visible = !data.slot_in_use
2023-08-02 19:50:50 +09:30
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
_init_dummy()
self.material = self.material.duplicate()
for i in 4:
var pc = PC.instance()
pc.set_position(Vector2(i*24, 8))
2023-09-21 15:26:10 +09:30
$'%PCs'.add_child(pc)
2023-08-02 19:50:50 +09:30
PCs.append(pc)
set_data(dummy_data)
func _input(event: InputEvent) -> void:
if (event is InputEventMouseButton or event is InputEventScreenTouch) and event.pressed:
if get_rect().has_point(event.position):
# print(event.position)
get_tree().set_input_as_handled()
emit_signal('clicked')