Restructured files and worked on more complex quest progression
This commit is contained in:
@@ -1,16 +1,20 @@
|
||||
class_name QuestProgressBar extends Control
|
||||
|
||||
const waypoint_template = preload("res://waypoint.tscn")
|
||||
const waypoint_template = preload("res://templates/waypoint.tscn")
|
||||
var length : float
|
||||
var waypoints : Array = []
|
||||
var waypoints : Array[Waypoint] = []
|
||||
@onready var hero_offset : Vector2 = %Hero.position
|
||||
@onready var hero : HeroIcon = %Hero
|
||||
@onready var heroLabel : Label = %HeroLabel
|
||||
@onready var startpoint : Endpoint = %Start
|
||||
@onready var endpoint : Endpoint = %End
|
||||
@onready var bar : TextureProgressBar = $ProgressBar
|
||||
@onready var path : Control = %Path
|
||||
@onready var speech_bubble = %SpeechBubble
|
||||
var quest : Quest = null
|
||||
var current_event : Quest.Event = null
|
||||
var time_elapsed : float = 0
|
||||
var next_waypoint = 0
|
||||
#signal value_changed(value : float)
|
||||
#var min_value
|
||||
#var max_value
|
||||
@@ -22,17 +26,16 @@ var time_elapsed : float = 0
|
||||
#var allow_greater
|
||||
func _ready() -> void:
|
||||
length = path.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 _process(delta: float) -> void:
|
||||
if time_elapsed < quest.length:
|
||||
time_elapsed += delta
|
||||
progress_quest()
|
||||
if current_event != null:
|
||||
if current_event.type != Quest.Event.Type.COMBAT:
|
||||
current_event.process(delta)
|
||||
else:
|
||||
time_elapsed += delta
|
||||
progress_quest()
|
||||
|
||||
func generate_waypoints():
|
||||
if len(waypoints) > 0:
|
||||
@@ -40,16 +43,20 @@ func generate_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])
|
||||
#Include the "end" in the count
|
||||
var num = quest.num_events()+1
|
||||
for i in range(1,num):
|
||||
var pct : float = i / float(num)
|
||||
add_waypoint( pct, quest.events[i-1])
|
||||
|
||||
func add_waypoint(pct : float, msgs : Dictionary):
|
||||
func add_waypoint(pct : float, event : Quest.Event):
|
||||
var wp = waypoint_template.instantiate()
|
||||
waypoints.append(wp)
|
||||
wp.percent = pct
|
||||
#TODO: Make events matter
|
||||
wp.event = event
|
||||
%Waypoints.add_child(wp)
|
||||
wp.global_position = global_position + Vector2(pct * length - 16, -9)
|
||||
wp.global_position = %Waypoints.global_position + Vector2(pct * length - 16, -9)
|
||||
if bar.value / bar.max_value >= pct:
|
||||
wp.fill = true
|
||||
|
||||
@@ -59,13 +66,36 @@ func update_waypoints(value : float) -> void:
|
||||
wp.fill = (bar.value / bar.max_value >= wp.percent)
|
||||
endpoint.fill = (bar.value / bar.max_value >= endpoint.percent)
|
||||
|
||||
func start_event(event : Quest.Event, offset : float) -> void:
|
||||
current_event = event
|
||||
current_event.completed.connect(_on_event_complete)
|
||||
event.time_elapsed = offset
|
||||
|
||||
func setup(quest : Quest) -> void:
|
||||
self.quest = quest
|
||||
heroLabel.text = quest.questor.full_name()
|
||||
time_elapsed = 0
|
||||
#Generate the waypoints
|
||||
generate_waypoints()
|
||||
#TODO: Change the hero's portrait
|
||||
bar.value = quest.progress
|
||||
|
||||
func progress_quest() -> void:
|
||||
bar.value = clampf(time_elapsed / quest.length, 0, bar.max_value)
|
||||
var pct = time_elapsed / quest.length
|
||||
if next_waypoint < len(waypoints) and pct >= waypoints[next_waypoint].percent:
|
||||
start_event(waypoints[next_waypoint].event, (pct - waypoints[next_waypoint].percent) * quest.length)
|
||||
pct = waypoints[next_waypoint].percent
|
||||
waypoints[next_waypoint].blink(true)
|
||||
bar.value = clampf(pct, 0, bar.max_value)
|
||||
hero.position = hero_offset + Vector2(length * bar.value / bar.max_value, 0)
|
||||
if time_elapsed >= quest.length:
|
||||
quest.complete()
|
||||
update_waypoints(bar.value)
|
||||
|
||||
|
||||
func _on_event_complete() -> void:
|
||||
#TODO: Show event message!
|
||||
speech_bubble.show_message("Event complete!")
|
||||
waypoints[next_waypoint].blink(false)
|
||||
next_waypoint += 1
|
||||
current_event = null
|
||||
|
||||
Reference in New Issue
Block a user