Add quest objectives to quest menu

This commit is contained in:
2025-05-07 11:49:52 -05:00
parent 55081f777a
commit cf149e676c
11 changed files with 132 additions and 30 deletions

View File

@@ -2,16 +2,18 @@ class_name EventShowQuest extends "res://scripts/Event/Event.gd"
@export var quest:QuestSystem.QuestKey = QuestSystem.QuestKey.TEST_QUEST
@export var waitUntilClosed:bool = true
@export var showQuest:bool = true
func start():
UI.QUEST_MENU.open(quest)
if showQuest:
UI.QUEST_MENU.open(quest)
pass
func isDone() -> bool:
if !super.isDone():
return false
if waitUntilClosed:
if waitUntilClosed and showQuest:
return !UI.QUEST_MENU.isOpen()
return true

View File

@@ -0,0 +1,6 @@
class_name EventStartQuest extends "res://scripts/Event/Quest/EventShowQuest.gd"
func start():
assert(QUEST.quests.has(quest), "Quest not found.")
QUEST.quests[quest].start()
super.start()

View File

@@ -0,0 +1 @@
uid://c4d7nithqnx5y

View File

@@ -2,3 +2,26 @@ class_name Quest extends Node
@export var questName:String = "Some quest"
@export var questKey:QuestSystem.QuestKey = QuestSystem.QuestKey.TEST_QUEST
var questStarted:bool = false
var questComplete:bool = false
var objectives:Array[QuestObjective]
func _ready() -> void:
objectives = []
for child in get_children():
if child is QuestObjective:
objectives.append(child)
func start() -> void:
questStarted = true
questComplete = false
QUEST.questStarted.emit(questKey)
QUEST.questUpdated.emit(questKey)
func isCompleted() -> bool:
return questComplete
func isStarted() -> bool:
return questStarted

View File

@@ -1,9 +1,7 @@
class_name QuestObjective extends Node
enum Type {
Item,
}
# enum Type {
# }
@export var objectiveName:String = "Some objective"
@export var objectiveType:Type = Type.Item
# @export var objectiveType:Type = Type.Item

View File

@@ -1,3 +0,0 @@
class_name QuestStage extends Node
@export var stageName:String = "Some stage"

View File

@@ -6,6 +6,10 @@ enum QuestKey {
var quests:Dictionary[int, Quest]
signal questStarted(questKey:QuestKey)
signal questUpdated(questKey:QuestKey)
signal questCompleted(questKey:QuestKey)
func _ready() -> void:
_updateQuests()

View File

@@ -3,44 +3,100 @@ class_name QuestMenu extends Panel
@export var questList:ItemList
@export var questName:Label
@export var closeButton:Button
@export var questObjectiveList:ItemList
@export var questObjectiveInfo:Label
var currentQuestKey
var currentQuestObjective
func _ready() -> void:
hide()
# Setup quests
questList.clear()
for questKey in QUEST.quests:
var q = QUEST.quests[questKey]
questList.add_item(q.questName)
_updateQuestList()
setQuest(null)
# Connect signals
questList.item_selected.connect(_onQuestSelected)
closeButton.pressed.connect(_onCloseClicked)
questObjectiveList.item_selected.connect(_onQuestObjectiveSelected)
QUEST.questUpdated.connect(_onQuestUpdated)
func _onQuestSelected(index:int) -> void:
setQuest(index)
pass
func setQuest(questKey = null):
if questKey == null:
if questKey == null || questKey == -1:
currentQuestKey = -1
setQuestObjective(-1)
questList.deselect_all()
return
assert(QUEST.quests.has(questKey), "Quest with key %s does not exist" % questKey)
currentQuestKey = questKey
setQuestObjective(-1)
var quest = QUEST.quests[questKey];
questList.select(questKey)
questName.text = quest.questName
pass
questObjectiveList.clear()
questObjectiveList.deselect_all()
for objective in quest.objectives:
questObjectiveList.add_item(objective.objectiveName)
func setQuestObjective(objective = null):
if objective == null || objective == -1:
currentQuestObjective = -1
questObjectiveList.deselect_all()
questObjectiveList.clear()
return
assert(QUEST.quests.has(objective), "Quest with key %s does not exist" % objective)
currentQuestObjective = objective
var quest = QUEST.quests[currentQuestKey];
var questObjective = quest.objectives[objective]
questObjectiveList.select(objective)
questObjectiveInfo.text = questObjective.objectiveName + "\n"
func _onCloseClicked() -> void:
self.close()
func open(questKey = null) -> void:
setQuest(questKey)
self.show()
func close() -> void:
self.hide()
func isOpen() -> bool:
return self.visible
# Private methods
func _updateQuestList():
questList.clear()
questList.deselect_all()
for questKey in QUEST.quests:
var q = QUEST.quests[questKey]
var n = q.questName;
if q.isCompleted():
n += " (Complete)"
elif q.isStarted():
n += " (Started)"
questList.add_item(n)
# Event handlers
func _onQuestSelected(index:int) -> void:
setQuest(index)
func _onQuestObjectiveSelected(index:int) -> void:
setQuestObjective(index)
func _onQuestUpdated(questKey:QuestSystem.QuestKey) -> void:
_updateQuestList()
func _onCloseClicked() -> void:
self.close()