Vast improvements and a working finite state machine, working on new guild member registration.
This commit is contained in:
62
quest_progress_bar.gd
Normal file
62
quest_progress_bar.gd
Normal file
@@ -0,0 +1,62 @@
|
||||
class_name QuestProgressBar extends Control
|
||||
|
||||
const waypoint_template = preload("res://waypoint.tscn")
|
||||
var length : float
|
||||
var waypoints : Array = []
|
||||
@onready var hero_offset : Vector2 = %Hero.position
|
||||
@onready var hero : HeroIcon = %Hero
|
||||
@onready var startpoint : Endpoint = %Start
|
||||
@onready var endpoint : Endpoint = %End
|
||||
@onready var bar : TextureProgressBar = $ProgressBar
|
||||
var quest : Quest = null
|
||||
#signal value_changed(value : float)
|
||||
#var min_value
|
||||
#var max_value
|
||||
#var step
|
||||
#var page
|
||||
#var value
|
||||
#var exp_edit
|
||||
#var rounded
|
||||
#var allow_greater
|
||||
func _ready() -> void:
|
||||
length = size.x
|
||||
if quest:
|
||||
#Generate the waypoints
|
||||
generate_waypoints()
|
||||
#TODO: Change the hero's portrait
|
||||
bar.value = quest.progress
|
||||
hero.position = hero_offset + Vector2(length * bar.value / bar.max_value, 0)
|
||||
|
||||
func generate_waypoints():
|
||||
if len(waypoints) > 0:
|
||||
for wp in waypoints:
|
||||
wp.queue_free()
|
||||
waypoints = []
|
||||
|
||||
for i in range(1,quest.steps):
|
||||
var pct : float = i / float(quest.steps)
|
||||
add_waypoint( pct, quest.step_outcomes[i])
|
||||
|
||||
func add_waypoint(pct : float, msgs : Dictionary):
|
||||
var wp = waypoint_template.instantiate()
|
||||
waypoints.append(wp)
|
||||
wp.percent = pct
|
||||
%Waypoints.add_child(wp)
|
||||
wp.global_position = global_position + Vector2(pct * length - 16, -9)
|
||||
if bar.value / bar.max_value >= pct:
|
||||
wp.fill = true
|
||||
|
||||
func update_waypoints(value : float) -> void:
|
||||
startpoint.fill = (bar.value / bar.max_value >= startpoint.percent)
|
||||
for wp : Waypoint in waypoints:
|
||||
wp.fill = (bar.value / bar.max_value >= wp.percent)
|
||||
endpoint.fill = (bar.value / bar.max_value >= endpoint.percent)
|
||||
|
||||
func setup(quest : Quest) -> void:
|
||||
self.quest = quest
|
||||
|
||||
|
||||
|
||||
func _on_value_changed(value : float) -> void:
|
||||
hero.position = hero_offset + Vector2(length * bar.value / bar.max_value, 0)
|
||||
update_waypoints(value)
|
||||
Reference in New Issue
Block a user