v9.7.2: Ebonhold Database integration and core logic refinements
This commit is contained in:
@@ -0,0 +1,156 @@
|
||||
---@type QuestieJourney
|
||||
local QuestieJourney = QuestieLoader:CreateModule("QuestieJourney")
|
||||
local _QuestieJourney = QuestieJourney.private
|
||||
_QuestieJourney.myJourney = {}
|
||||
_QuestieJourney.notePopup = nil
|
||||
|
||||
---@type QuestieJourneyUtils
|
||||
local QuestieJourneyUtils = QuestieLoader:ImportModule("QuestieJourneyUtils")
|
||||
---@type QuestieDB
|
||||
local QuestieDB = QuestieLoader:ImportModule("QuestieDB")
|
||||
---@type l10n
|
||||
local l10n = QuestieLoader:ImportModule("l10n")
|
||||
|
||||
--- COMPATIBILITY ---
|
||||
local CALENDAR_WEEKDAY_NAMES = QuestieCompat.CALENDAR_WEEKDAY_NAMES
|
||||
local CALENDAR_FULLDATE_MONTH_NAMES = QuestieCompat.CALENDAR_FULLDATE_MONTH_NAMES
|
||||
|
||||
local AceGUI = LibStub("AceGUI-3.0");
|
||||
local journeyTreeFrame
|
||||
|
||||
-- manage the journey tree
|
||||
function _QuestieJourney.myJourney:ManageTree(container)
|
||||
if not journeyTreeFrame then
|
||||
journeyTreeFrame = AceGUI:Create("TreeGroup");
|
||||
journeyTreeFrame:SetFullWidth(true);
|
||||
journeyTreeFrame:SetFullHeight(true);
|
||||
|
||||
journeyTreeFrame.treeframe:SetWidth(220);
|
||||
|
||||
local journeyTree = _QuestieJourney:GetHistory();
|
||||
journeyTreeFrame:SetTree(journeyTree);
|
||||
local latestMonth, latestYear = _QuestieJourney:GetMonthAndYearOfLatestEntry()
|
||||
if latestMonth and latestYear then
|
||||
journeyTreeFrame:SelectByPath(latestYear, latestMonth)
|
||||
end
|
||||
journeyTreeFrame:SetCallback("OnGroupSelected", function(group)
|
||||
Questie:Debug(Questie.DEBUG_DEVELOP, "[Journey] OnGroupSelected - Path:", group.localstatus.selected)
|
||||
|
||||
local _, _, e = strsplit("\001", group.localstatus.selected);
|
||||
|
||||
if e then
|
||||
local master = group.frame.obj;
|
||||
master:ReleaseChildren();
|
||||
master:SetLayout("fill");
|
||||
master:SetFullWidth(true);
|
||||
master:SetFullHeight(true);
|
||||
|
||||
local f = AceGUI:Create("ScrollFrame");
|
||||
f:SetLayout("flow");
|
||||
master:AddChild(f);
|
||||
|
||||
local header = AceGUI:Create("Heading");
|
||||
header:SetFullWidth(true);
|
||||
f:AddChild(header);
|
||||
|
||||
QuestieJourneyUtils:Spacer(f);
|
||||
|
||||
local created = AceGUI:Create("Label");
|
||||
created:SetFullWidth(true);
|
||||
|
||||
local entry = Questie.db.char.journey[tonumber(e)];
|
||||
local day = CALENDAR_WEEKDAY_NAMES[ tonumber(date('%w', entry.Timestamp)) + 1 ];
|
||||
local month = CALENDAR_FULLDATE_MONTH_NAMES[ tonumber(date('%m', entry.Timestamp)) ];
|
||||
local timestamp = Questie:Colorize(date( day ..', '.. month ..' %d @ %H:%M' , entry.Timestamp), 'blue');
|
||||
|
||||
if entry.Event == "Note" then
|
||||
header:SetText(l10n('Note: %s', entry.Title));
|
||||
|
||||
local note = AceGUI:Create("Label");
|
||||
note:SetFullWidth(true);
|
||||
note:SetText(Questie:Colorize( entry.Note , 'yellow'));
|
||||
f:AddChild(note);
|
||||
QuestieJourneyUtils:Spacer(f);
|
||||
|
||||
created:SetText(l10n('Note Created: %s', timestamp));
|
||||
f:AddChild(created);
|
||||
|
||||
elseif entry.Event == "Level" then
|
||||
header:SetText(l10n('You Reached Level %s', entry.NewLevel));
|
||||
|
||||
local congrats = AceGUI:Create("Label");
|
||||
congrats:SetText(l10n('Congratulations! You reached %s !', entry.NewLevel));
|
||||
congrats:SetFullWidth(true);
|
||||
f:AddChild(congrats);
|
||||
|
||||
created:SetText(timestamp);
|
||||
f:AddChild(created);
|
||||
|
||||
elseif entry.Event == "Quest" then
|
||||
local state
|
||||
if entry.SubType == "Accept" then
|
||||
state = l10n("Accepted");
|
||||
elseif entry.SubType == "Complete" then
|
||||
state = l10n("Completed");
|
||||
elseif entry.SubType == "Abandon" then
|
||||
state = l10n("Abandoned");
|
||||
else
|
||||
state = "ERROR!!";
|
||||
end
|
||||
|
||||
local quest = QuestieDB.GetQuest(entry.Quest)
|
||||
if quest then
|
||||
local qName = quest.name;
|
||||
header:SetText(l10n('Quest %s: %s', state, qName));
|
||||
|
||||
|
||||
local obj = AceGUI:Create("Label");
|
||||
obj:SetFullWidth(true);
|
||||
obj:SetText(_QuestieJourney:CreateObjectiveText(quest.Description));
|
||||
f:AddChild(obj);
|
||||
end
|
||||
|
||||
QuestieJourneyUtils:Spacer(f);
|
||||
|
||||
created:SetText(l10n('Quest %s: %s', state, timestamp));
|
||||
f:AddChild(created);
|
||||
|
||||
else
|
||||
header:SetText("ERROR!!");
|
||||
end
|
||||
|
||||
end
|
||||
end);
|
||||
|
||||
container:AddChild(journeyTreeFrame);
|
||||
else
|
||||
container:ReleaseChildren();
|
||||
journeyTreeFrame = nil;
|
||||
_QuestieJourney.myJourney:ManageTree(container);
|
||||
end
|
||||
end
|
||||
|
||||
--- Get the month and year of the latest entry in the Journey.
|
||||
--- This is used to select it in the tree view.
|
||||
---@return number @The month of the latest entry
|
||||
---@return number @The year of the latest entry
|
||||
function _QuestieJourney:GetMonthAndYearOfLatestEntry()
|
||||
local journeyEntries = _QuestieJourney:GetJourneyEntries()
|
||||
local years = {}
|
||||
local months = {}
|
||||
|
||||
for year, _ in pairs(journeyEntries) do
|
||||
table.insert(years, year)
|
||||
end
|
||||
if not next(years) then
|
||||
return nil, nil
|
||||
end
|
||||
local maxYear = math.max(unpack(years))
|
||||
|
||||
for month, _ in pairs(journeyEntries[maxYear]) do
|
||||
table.insert(months, month)
|
||||
end
|
||||
local maxMonth = math.max(unpack(months))
|
||||
|
||||
return maxMonth, maxYear
|
||||
end
|
||||
@@ -0,0 +1,102 @@
|
||||
---@type QuestieJourney
|
||||
local QuestieJourney = QuestieLoader:CreateModule("QuestieJourney")
|
||||
local _QuestieJourney = QuestieJourney.private
|
||||
-------------------------
|
||||
--Import modules.
|
||||
-------------------------
|
||||
---@type QuestieJourneyUtils
|
||||
local QuestieJourneyUtils = QuestieLoader:ImportModule("QuestieJourneyUtils");
|
||||
---@type QuestieDB
|
||||
local QuestieDB = QuestieLoader:ImportModule("QuestieDB");
|
||||
---@type l10n
|
||||
local l10n = QuestieLoader:ImportModule("l10n")
|
||||
|
||||
--- COMPATIBILITY ---
|
||||
local CALENDAR_WEEKDAY_NAMES = QuestieCompat.CALENDAR_WEEKDAY_NAMES
|
||||
local CALENDAR_FULLDATE_MONTH_NAMES = QuestieCompat.CALENDAR_FULLDATE_MONTH_NAMES
|
||||
|
||||
local AceGUI = LibStub("AceGUI-3.0");
|
||||
|
||||
--- Draw the "My Journey" tab
|
||||
---@param container Frame
|
||||
---@return SimpleGroup
|
||||
function _QuestieJourney.myJourney:DrawTab(container)
|
||||
local header = AceGUI:Create("Heading");
|
||||
header:SetText(l10n('Your Recent History'));
|
||||
header:SetFullWidth(true);
|
||||
container:AddChild(header);
|
||||
QuestieJourneyUtils:Spacer(container);
|
||||
|
||||
-- get last 5 elements from table for history
|
||||
local counter = #Questie.db.char.journey;
|
||||
local recentEvents = {};
|
||||
for i = counter, counter-4, -1 do
|
||||
if i <= 0 then
|
||||
break;
|
||||
end
|
||||
|
||||
recentEvents[i] = {};
|
||||
recentEvents[i] = AceGUI:Create("Label");
|
||||
recentEvents[i]:SetFullWidth(true);
|
||||
|
||||
local day = CALENDAR_WEEKDAY_NAMES[tonumber(date('%w', Questie.db.char.journey[i].Timestamp)) + 1];
|
||||
local month = CALENDAR_FULLDATE_MONTH_NAMES[tonumber(date('%m', Questie.db.char.journey[i].Timestamp))];
|
||||
|
||||
local timestamp = Questie:Colorize(date( '[ '..day ..', '.. month ..' %d @ %H:%M ] ' , Questie.db.char.journey[i].Timestamp), 'blue');
|
||||
|
||||
-- if it's a quest event
|
||||
if Questie.db.char.journey[i].Event == "Quest" then
|
||||
local qName = QuestieDB.QueryQuestSingle(Questie.db.char.journey[i].Quest, "name");
|
||||
if qName then
|
||||
qName = Questie:Colorize(qName, 'gray');
|
||||
|
||||
if Questie.db.char.journey[i].SubType == "Accept" then
|
||||
recentEvents[i]:SetText(timestamp .. Questie:Colorize(l10n('You Accepted the quest %s', qName), 'yellow'));
|
||||
elseif Questie.db.char.journey[i].SubType == "Abandon" then
|
||||
recentEvents[i]:SetText(timestamp .. Questie:Colorize(l10n('You Abandoned the quest %s', qName), 'yellow'));
|
||||
elseif Questie.db.char.journey[i].SubType == "Complete" then
|
||||
recentEvents[i]:SetText(timestamp .. Questie:Colorize(l10n('You Completed the quest %s', qName), 'yellow'));
|
||||
end
|
||||
end
|
||||
elseif Questie.db.char.journey[i].Event == "Level" then
|
||||
local level = Questie:Colorize(l10n('Level %s', Questie.db.char.journey[i].NewLevel), 'gray');
|
||||
recentEvents[i]:SetText(timestamp .. Questie:Colorize(l10n('Congratulations! You reached %s !', level), 'yellow'));
|
||||
elseif Questie.db.char.journey[i].Event == "Note" then
|
||||
local title = Questie:Colorize(Questie.db.char.journey[i].Title, 'gray');
|
||||
recentEvents[i]:SetText(timestamp .. Questie:Colorize(l10n('Note Created: %s', title), 'yellow'));
|
||||
end
|
||||
|
||||
container:AddChild(recentEvents[i]);
|
||||
end
|
||||
|
||||
if counter == 0 then
|
||||
local justdoit = AceGUI:Create("Label");
|
||||
justdoit:SetFullWidth(true);
|
||||
justdoit:SetText(Questie:Colorize(l10n("It's about time you embark on your first Journey!"), 'yellow'));
|
||||
container:AddChild(justdoit);
|
||||
end
|
||||
|
||||
QuestieJourneyUtils:Spacer(container);
|
||||
|
||||
local treeHeader = AceGUI:Create("Heading");
|
||||
treeHeader:SetText(l10n("%s's Journey", UnitName("player")));
|
||||
treeHeader:SetFullWidth(true);
|
||||
container:AddChild(treeHeader);
|
||||
|
||||
local noteButton = AceGUI:Create("Button");
|
||||
noteButton:SetText(l10n('Add New Adventure Note'));
|
||||
noteButton:SetPoint("RIGHT");
|
||||
noteButton:SetCallback("OnClick", _QuestieJourney.ShowNotePopup);
|
||||
container:AddChild(noteButton);
|
||||
|
||||
QuestieJourneyUtils:Spacer(container);
|
||||
|
||||
---@class SimpleGroup
|
||||
local treeGroup = AceGUI:Create("SimpleGroup");
|
||||
treeGroup:SetLayout("fill");
|
||||
treeGroup:SetFullHeight(true);
|
||||
treeGroup:SetFullWidth(true);
|
||||
container:AddChild(treeGroup);
|
||||
|
||||
return treeGroup
|
||||
end
|
||||
@@ -0,0 +1,132 @@
|
||||
---@type QuestieJourney
|
||||
local QuestieJourney = QuestieLoader:CreateModule("QuestieJourney")
|
||||
local _QuestieJourney = QuestieJourney.private
|
||||
_QuestieJourney.notePopup = nil
|
||||
-------------------------
|
||||
--Import modules
|
||||
-------------------------
|
||||
---@type QuestieJourneyUtils
|
||||
local QuestieJourneyUtils = QuestieLoader:ImportModule("QuestieJourneyUtils")
|
||||
---@type l10n
|
||||
local l10n = QuestieLoader:ImportModule("l10n")
|
||||
|
||||
--- COMPATIBILITY ---
|
||||
local CALENDAR_WEEKDAY_NAMES = QuestieCompat.CALENDAR_WEEKDAY_NAMES
|
||||
local CALENDAR_FULLDATE_MONTH_NAMES = QuestieCompat.CALENDAR_FULLDATE_MONTH_NAMES
|
||||
|
||||
local AceGUI = LibStub("AceGUI-3.0")
|
||||
local titleBox, messageBox
|
||||
|
||||
local _CreateNoteWindow, _CreateContainer, _CreateDescription, _CreateTitleBox, _CreateMessageBox
|
||||
local _CreateNoteAddButton, _HandleNoteEntry
|
||||
|
||||
|
||||
function _QuestieJourney:ShowNotePopup()
|
||||
if (not _QuestieJourney.notePopup) then
|
||||
_QuestieJourney.notePopup = _CreateNoteWindow()
|
||||
elseif (not _QuestieJourney.notePopup:IsShown()) then
|
||||
_QuestieJourney.notePopup:Show()
|
||||
else
|
||||
_QuestieJourney.notePopup:Hide()
|
||||
end
|
||||
end
|
||||
|
||||
_CreateNoteWindow = function ()
|
||||
local notePopup = AceGUI:Create("Window")
|
||||
notePopup:Show()
|
||||
notePopup:SetTitle(l10n('Add New Adventure Note'))
|
||||
notePopup:SetWidth(400)
|
||||
notePopup:SetHeight(400)
|
||||
notePopup:EnableResize(false)
|
||||
notePopup.frame:SetFrameStrata(_QuestieJourney.containerCache.frame:GetFrameStrata())
|
||||
notePopup.frame:SetFrameLevel(_QuestieJourney.containerCache.frame:GetFrameLevel())
|
||||
notePopup.frame:Raise()
|
||||
notePopup:SetCallback("OnClose", function()
|
||||
notePopup:Hide()
|
||||
end)
|
||||
|
||||
local container = _CreateContainer()
|
||||
notePopup:AddChild(container)
|
||||
|
||||
local desc = _CreateDescription()
|
||||
container:AddChild(desc)
|
||||
|
||||
QuestieJourneyUtils:Spacer(container)
|
||||
|
||||
titleBox = _CreateTitleBox()
|
||||
container:AddChild(titleBox)
|
||||
|
||||
messageBox = _CreateMessageBox()
|
||||
container:AddChild(messageBox)
|
||||
|
||||
local addEntryBtn = _CreateNoteAddButton()
|
||||
container:AddChild(addEntryBtn)
|
||||
|
||||
return notePopup
|
||||
end
|
||||
|
||||
_CreateContainer = function ()
|
||||
-- Setup Note Taking
|
||||
local day = CALENDAR_WEEKDAY_NAMES[tonumber(date('%w', time())) + 1]
|
||||
local month = CALENDAR_FULLDATE_MONTH_NAMES[tonumber(date('%m', time()))]
|
||||
local today = date(day ..', '.. month ..' %d', time())
|
||||
local container = AceGUI:Create("InlineGroup")
|
||||
container:SetFullHeight(true)
|
||||
container:SetFullWidth(true)
|
||||
container:SetLayout('flow')
|
||||
container:SetTitle(l10n('New Note For: %s', today))
|
||||
return container
|
||||
end
|
||||
|
||||
_CreateDescription =function ()
|
||||
local desc = AceGUI:Create("Label")
|
||||
desc:SetText(Questie:Colorize(l10n('Create an entry in your journal to remember a specific moment. Simply supply a title and description and Questie will remember it for you!'), 'yellow'))
|
||||
desc:SetFullWidth(true)
|
||||
return desc
|
||||
end
|
||||
|
||||
_CreateTitleBox = function ()
|
||||
local box = AceGUI:Create("EditBox")
|
||||
box:SetFullWidth(true)
|
||||
box:SetLabel(l10n('Entry Title'))
|
||||
box:DisableButton(true)
|
||||
box:SetFocus()
|
||||
return box
|
||||
end
|
||||
|
||||
_CreateMessageBox = function ()
|
||||
local box = AceGUI:Create("MultiLineEditBox")
|
||||
box:SetFullWidth(true)
|
||||
box:SetNumLines(12)
|
||||
box:SetLabel(l10n('Journal Entry'))
|
||||
box:DisableButton(true)
|
||||
return box
|
||||
end
|
||||
|
||||
_CreateNoteAddButton = function ()
|
||||
local addEntryBtn = AceGUI:Create("Button")
|
||||
addEntryBtn:SetText(l10n('Add Entry'))
|
||||
addEntryBtn:SetCallback("OnClick", _HandleNoteEntry)
|
||||
return addEntryBtn
|
||||
end
|
||||
|
||||
_HandleNoteEntry = function ()
|
||||
local error = Questie:Colorize('[Questie] ', 'blue')
|
||||
if titleBox:GetText() == '' then
|
||||
print (error .. l10n('No Title was entered. You must enter a title before submitting your note.'))
|
||||
return
|
||||
elseif messageBox:GetText() == '' then
|
||||
print (error .. l10n('No Note was entered. You must enter a note before submitting.'))
|
||||
return
|
||||
end
|
||||
local data = {}
|
||||
data.Event = "Note"
|
||||
data.Note = messageBox:GetText()
|
||||
data.Title = titleBox:GetText()
|
||||
data.Timestamp = time()
|
||||
|
||||
tinsert(Questie.db.char.journey, data)
|
||||
|
||||
_QuestieJourney.myJourney:ManageTree(_QuestieJourney.treeCache)
|
||||
_QuestieJourney.notePopup:Hide()
|
||||
end
|
||||
Reference in New Issue
Block a user