107 lines
2.5 KiB
GDScript
107 lines
2.5 KiB
GDScript
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
|
|
_updateQuestList()
|
|
setQuest(null)
|
|
|
|
# Connect signals
|
|
questList.item_selected.connect(_onQuestSelected)
|
|
closeButton.pressed.connect(_onCloseClicked)
|
|
questObjectiveList.item_selected.connect(_onQuestObjectiveSelected)
|
|
QUEST.questUpdated.connect(_onQuestUpdated)
|
|
|
|
func _exit_tree() -> void:
|
|
questList.item_selected.disconnect(_onQuestSelected)
|
|
closeButton.pressed.disconnect(_onCloseClicked)
|
|
questObjectiveList.item_selected.disconnect(_onQuestObjectiveSelected)
|
|
QUEST.questUpdated.disconnect(_onQuestUpdated)
|
|
|
|
func setQuest(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.title
|
|
questObjectiveList.clear()
|
|
questObjectiveList.deselect_all()
|
|
for objective in quest.objectives:
|
|
questObjectiveList.add_item(objective.title)
|
|
|
|
|
|
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.title + "\n"
|
|
|
|
|
|
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.title;
|
|
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(_q:Quest) -> void:
|
|
_updateQuestList()
|
|
|
|
func _onCloseClicked() -> void:
|
|
self.close()
|