commit 2989faa080650b23241e4832e515e9ac33c93bfd Author: Les De Ridder Date: Fri Jan 11 20:18:17 2019 +0100 Initial commit Basic ignoring and unignoring in journal is implemented. diff --git a/CleanJournal.lua b/CleanJournal.lua new file mode 100644 index 0000000..fb33b56 --- /dev/null +++ b/CleanJournal.lua @@ -0,0 +1,128 @@ +-- TODO: Use localisation files +ZO_CreateStringId("SI_AO_IGNORED_QUEST_CATEGORY", "Ignored") +ZO_CreateStringId("SI_AO_IGNORE_QUEST_TOOLTIP", "Ignore") +ZO_CreateStringId("SI_AO_UNIGNORE_QUEST_TOOLTIP", "Unignore") + +AO_IGNORED_QUESTS = {} +AO_ORIG_QUEST_CATEGORY_NAMES = {} +AO_ORIG_QUEST_CATEGORY_TYPES = {} + +QUEST_CAT_AO_IGNORED = 4 + +-- +-- GetQuestListData +-- + +__GetQuestListData = QUEST_JOURNAL_MANAGER.GetQuestListData + +QUEST_JOURNAL_MANAGER.GetQuestListData = function(QUEST_JOURNAL_MANAGER) + local ignoredCategory = GetString(SI_AO_IGNORED_QUEST_CATEGORY) + + local quests, _, _ = __GetQuestListData(QUEST_JOURNAL_MANAGER) + + local categories = {} + local seenCategories = {} + + for i, quest in ipairs(quests) do + if AO_IGNORED_QUESTS[quest.name] then + quests[i].categoryName = ignoredCategory + quests[i].categoryType = QUEST_CAT_AO_IGNORED + elseif quest.categoryName == ignoredCategory then + quests[i].categoryName = AO_ORIG_QUEST_CATEGORY_NAMES[quest.name] + quests[i].categoryType = AO_ORIG_QUEST_CATEGORY_TYPES[quest.name] + end + + if not seenCategories[quest.categoryName] then + table.insert(categories, { name = quest.categoryName, type = quest.categoryType}) + seenCategories[quest.categoryName] = true + end + end + + table.sort(categories, AO_SortQuestCategories) + table.sort(quests, AO_SortQuestEntries) + + return quests, categories, seenCategories +end + +-- +-- AddOn Functions +-- + +function AO_ToggleIgnoreQuest(questIndex) + local quests, categories, seenCategories = QUEST_JOURNAL_MANAGER:GetQuestListData() + + local quest = AO_GetQuestByIndex(questIndex) + + if quest.categoryName == GetString(SI_AO_IGNORED_QUEST_CATEGORY) then + AO_IGNORED_QUESTS[quest.name] = nil + else + AO_IGNORED_QUESTS[quest.name] = true + AO_ORIG_QUEST_CATEGORY_NAMES[quest.name] = quest.categoryName + AO_ORIG_QUEST_CATEGORY_TYPES[quest.name] = quest.categoryType + end + + SYSTEMS:GetObject("questJournal"):OnQuestsUpdated() +end + +function AO_GetQuestByIndex(questIndex) + local quests, _, _ = QUEST_JOURNAL_MANAGER:GetQuestListData() + for _, quest in ipairs(quests) do + if quest.questIndex == questIndex then + return quest + end + end +end + + +function AO_SortQuestCategories(entry1, entry2) + if entry1.type == entry2.type then + return entry1.name < entry2.name + else + return entry1.type < entry2.type + end +end + +function AO_SortQuestEntries(entry1, entry2) + if entry1.categoryType == entry2.categoryType then + if entry1.categoryType == QUEST_CAT_AO_IGNORED then + if AO_ORIG_QUEST_CATEGORY_TYPES[entry1.name] == AO_ORIG_QUEST_CATEGORY_TYPES[entry2.name] then + if AO_ORIG_QUEST_CATEGORY_NAMES[entry1.name] == AO_ORIG_QUEST_CATEGORY_NAMES[entry2.name] then + return entry1.name < entry2.name + end + return AO_ORIG_QUEST_CATEGORY_NAMES[entry1.name] < AO_ORIG_QUEST_CATEGORY_NAMES[entry2.name] + end + return AO_ORIG_QUEST_CATEGORY_TYPES[entry1.name] < AO_ORIG_QUEST_CATEGORY_TYPES[entry2.name] + elseif entry1.categoryName == entry2.categoryName then + return entry1.name < entry2.name + end + + return entry1.categoryName < entry2.categoryName + end + return entry1.categoryType < entry2.categoryType +end + +-- +-- ZO_QuestJournalNavigationEntry_OnMouseUp +-- + +__ZO_QuestJournalNavigationEntry_OnMouseUp = ZO_QuestJournalNavigationEntry_OnMouseUp + +function ZO_QuestJournalNavigationEntry_OnMouseUp(label, button, upInside) + __ZO_QuestJournalNavigationEntry_OnMouseUp(label, button, upInside) + + if(button == MOUSE_BUTTON_INDEX_RIGHT and upInside) then + local quest = label.node.data + local questIndex = quest.questIndex + if questIndex then + local ignored = quest.categoryName == GetString(SI_AO_IGNORED_QUEST_CATEGORY) + + local ignoreString = GetString(SI_AO_IGNORE_QUEST_TOOLTIP) + local unignoreString = GetString(SI_AO_UNIGNORE_QUEST_TOOLTIP) + + AddMenuItem(ignored and unignoreString or ignoreString, function() AO_ToggleIgnoreQuest(questIndex) end) + + ShowMenu(label) + end + return + end +end diff --git a/CleanJournal.txt b/CleanJournal.txt new file mode 100644 index 0000000..5845cc6 --- /dev/null +++ b/CleanJournal.txt @@ -0,0 +1,14 @@ +## Title: CleanJournal +## License: NCSA +## Author: Les De Ridder +## AddOnVersion: 1 +## APIVersion: 100025 +## DependsOn: +## OptionalDependsOn: +## Version: 0.0.1 + +CleanJournal.lua + +# This Add-on is not created by, affiliated with, or sponsored by, ZeniMax Media Inc. or its affiliates. +# The Elder Scrolls® and related logos are registered trademarks or trademarks of ZeniMax Media Inc. in the United States +# and/or other countries. All rights reserved. diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..5dde46a --- /dev/null +++ b/LICENSE @@ -0,0 +1,31 @@ +University of Illinois/NCSA +Open Source License + +Copyright (c) 2019, Les De Ridder +All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal with +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +* Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimers. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimers in the + documentation and/or other materials provided with the distribution. + +* Neither the name of CleanJournal nor the names of its contributors may be used + to endorse or promote products derived from this Software without specific + prior written permission. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE +SOFTWARE.