Add quest objectives to quest menu
This commit is contained in:
@@ -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()
|
||||
|
Reference in New Issue
Block a user