Skip to content

Commit

Permalink
Removed unecessary code and did some Cleanup
Browse files Browse the repository at this point in the history
Added Settings Page in "Options > AddOns" for Instance Portal Advanced with some NEW Settings!
  • Loading branch information
fuba82 committed Jul 30, 2024
1 parent 9ed7c3d commit 1cdd393
Show file tree
Hide file tree
Showing 4 changed files with 174 additions and 34 deletions.
119 changes: 119 additions & 0 deletions IPAConfig.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
local addonName, IPA = ...

_G["InstancePortalsAdv"] = IPA

local eventFrame = CreateFrame("FRAME")
eventFrame:RegisterEvent("ADDON_LOADED")
eventFrame:RegisterEvent("PLAYER_ENTERING_WORLD")

IPASettings = IPASettings or {}

function IPA:CreateSettings()

local function OnSettingChanged(_, setting, value)
local variable = setting:GetVariable();
IPASettings["options"][variable] = value;
end

local categoryMain = Settings.RegisterVerticalLayoutCategory("|rInstance Portals |cff0080ffAdvanced|r");
categoryMain.ID = addonName


-- pinsOnContinentMap
do
local name = "Pins on Continent Map"
local variable = "pinsOnContinentMap"
local tooltip = "Enable or Disable Dungeon Entrance Pins on the Continent Map"
local value = IPASettings["options"][variable]
local defaultValue = value == nil and true or value

local setting = Settings.RegisterAddOnSetting(categoryMain, name, variable, type(defaultValue), defaultValue)
Settings.SetOnValueChangedCallback(variable, OnSettingChanged)
Settings.CreateCheckbox(categoryMain, setting, tooltip)
end

-- useWaypointsZone
do
local name = "Waypoints on Zone Map"
local variable = "useWaypointsZone"
local tooltip = "Enable or Disable Waypoint Feature on Zone Maps\n\n|r|cffff0000Warning!|r\nThis will also disable the \"native\" Waypoint function added in TWW!"
local value = IPASettings["options"][variable]
local defaultValue = value == nil and true or value

local setting = Settings.RegisterAddOnSetting(categoryMain, name, variable, type(defaultValue), defaultValue)
Settings.SetOnValueChangedCallback(variable, OnSettingChanged)
Settings.CreateCheckbox(categoryMain, setting, tooltip)
end

-- useWaypointsContient
do
local name = "Waypoints on Continent Map"
local variable = "useWaypointsContient"
local tooltip = "Enable or Disable the Feature to add a Waypoint when click on a Dungeon Entrace Pin on the Contient Map"
local value = IPASettings["options"][variable]
local defaultValue = value == nil and true or value

local setting = Settings.RegisterAddOnSetting(categoryMain, name, variable, type(defaultValue), defaultValue)
Settings.SetOnValueChangedCallback(variable, OnSettingChanged)
Settings.CreateCheckbox(categoryMain, setting, tooltip)
end


if IsAddOnLoaded("TomTom") then
-- useTomTomZone
do
local name = "Use TomTom for Zone Map"
local variable = "useTomTomZone"
local tooltip = "Enable or Disable TomTom as Waypoint System for Zone Map\n\n\Enabled: Use TomTom\nDisabled: Use Native"
local value = IPASettings["options"][variable]
local defaultValue = value == nil and true or value


local setting = Settings.RegisterAddOnSetting(categoryMain, name, variable, type(defaultValue), defaultValue)
Settings.SetOnValueChangedCallback(variable, OnSettingChanged)
Settings.CreateCheckbox(categoryMain, setting, tooltip)
end

-- useTomTomContinent
do
local name = "Use TomTom for Continent Map"
local variable = "useTomTomContinent"
local tooltip = "Enable or Disable TomTom as Waypoint System for Continent Map\n\n\Enabled: Use TomTom\nDisabled: Use Native"
local value = IPASettings["options"][variable]
local defaultValue = value == nil and true or value

local setting = Settings.RegisterAddOnSetting(categoryMain, name, variable, type(defaultValue), defaultValue)
Settings.SetOnValueChangedCallback(variable, OnSettingChanged)
Settings.CreateCheckbox(categoryMain, setting, tooltip)
end
end

-- debug
do
local name = "Debug Mode"
local variable = "debug"
local tooltip = "Enable or Disable Dubug Mode\n\n\|r|cffff0000Warning!|r\nThis can overload your Chat!"
local value = IPASettings["options"][variable]
local defaultValue = value == nil and true or value

local setting = Settings.RegisterAddOnSetting(categoryMain, name, variable, type(defaultValue), defaultValue)
Settings.SetOnValueChangedCallback(variable, OnSettingChanged)
Settings.CreateCheckbox(categoryMain, setting, tooltip)
end

Settings.RegisterAddOnCategory(categoryMain)

_G['SLASH_' .. addonName .. 'Options' .. 1] = '/ipa'
_G['SLASH_' .. addonName .. 'Options' .. 2] = '/ipadv'
SlashCmdList[addonName .. 'Options'] = function(msg)
Settings.OpenToCategory(categoryMain.ID)
end
end

eventFrame:SetScript("OnEvent", function(self, event, ...)
if event == "PLAYER_ENTERING_WORLD" then
local isLogin, isReload = ...
-- Create Settings on "PLAYER_ENTERING_WORLD" because of TomTom Support
IPA:CreateSettings()
end
end)
38 changes: 23 additions & 15 deletions IPACore.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
local addonName, IPA = ...

local DefaultSettings = {
options = {
debug = false,
useWaypoints = true,
useTomTom = true,
pinsOnContinentMap = true,
useWaypointsContient = true,
useWaypointsZone = true,
useTomTomZone = true,
useTomTomContinent = true,
},
version = 1,
version = 2,
}

local function CreateDatabase()
Expand All @@ -15,8 +20,8 @@ local function ReCreateDatabase()
IPASettings = DefaultSettings
end

function IPAUIPrintDebug(debugtext)
if IPASettings and IPASettings.options and IPASettings.options.debug then
function IPAUIPrintDebug(debugtext, force)
if (IPASettings and IPASettings.options and IPASettings.options.debug == true) or (force == true) then
DEFAULT_CHAT_FRAME:AddMessage("|cffff8000IPADebug\[|r"..debugtext.."|cffff8000\]")
end
end
Expand All @@ -26,22 +31,22 @@ if not IPASettings then
IPAUIPrintDebug("Database: Create default Database because empty")
end

if IPASettings.version and IPASettings.version < DefaultSettings.version then
-- do something if "Database Version" is an older version and maybe need attention?!
IPAUIPrintDebug("Database: Old version found")
end

function InstancePortalAdvUI_OnLoad(self)
LoadAddOn("Blizzard_WorldMap")
self:RegisterEvent("ADDON_LOADED")
--LoadAddOn("Blizzard_WorldMap")
self:RegisterEvent("PLAYER_ENTERING_WORLD")

IPAUIPrintDebug("InstancePortalAdvUI_OnLoad()")
WorldMapFrame:AddDataProvider(CreateFromMixins(IPAInstancePortalMapDataProviderMixin));
end

function InstancePortalAdvUI_OnEvent(event, arg1)
if event == "ADDON_LOADED" then
IPAUIPrintDebug("ADDON_LOADED()")
if event == "PLAYER_ENTERING_WORLD" then
if IPASettings and IPASettings.version and IPASettings.version < DefaultSettings.version then
-- do something if "Database Version" is an older version and maybe need attention?!
IPAUIPrintDebug("Old Database found, Instance Portal Advanced Settings will resetted!", true)
IPAUIPrintDebug("Use the NEW Settings Page at \"Options >> AddOns\" from now on.", true)
ReCreateDatabase()
end
end
end

Expand Down Expand Up @@ -164,6 +169,8 @@ RegisterCVar("IPAUITrackInstancePortalsOnContinents")
/dump GetCVar("IPAUITrackInstancePortals")
]]


--[[
-- Slash Commands for "Config" until i maybe or not add an Optionsframe ;)
_G.SLASH_IPASETTINGS1 = '/ipa'
_G.SLASH_IPASETTINGS2 = '/ipadv'
Expand Down Expand Up @@ -223,4 +230,5 @@ SlashCmdList.IPASETTINGS = function(msg)
ReCreateDatabase()
print("|cffff8000[Instance Portal Advanced]|r Reseted Databse to Default")
end
end
end
]]
42 changes: 27 additions & 15 deletions IPAInstancePortalPinTemplate.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local addonName, addon = ...
local addonName, IPA = ...

IPAInstancePortalMapDataProviderMixin = CreateFromMixins(MapCanvasDataProviderMixin);

function IPAInstancePortalMapDataProviderMixin:RemoveAllData()
Expand All @@ -24,6 +25,11 @@ end

function IPAInstancePortalMapDataProviderMixin:RefreshAllData(fromOnShow)
self:RemoveAllData();

local pinsOnContinentMap = IPASettings and IPASettings.options.pinsOnContinentMap
pinsOnContinentMap = pinsOnContinentMap == nil and true or pinsOnContinentMap
if (pinsOnContinentMap ~= true) then return end

IPAUIPrintDebug("IPAInstancePortalMapDataProviderMixin:RefreshAllData")

local showDungeonEntrancesOnMap = C_CVar and C_CVar.GetCVarBool("showDungeonEntrancesOnMap") or false
Expand Down Expand Up @@ -121,11 +127,15 @@ end
function IPAInstancePortalProviderPinMixin:OnMouseClickAction(button)
if (not button) then return end

if (button == "LeftButton") then
local useTomTom = true
if IPASettings and IPASettings.options then
useTomTom = IPASettings.options.useTomTom and (TomTom ~= nil) or false
end
local useWaypointsContient = IPASettings and IPASettings.options.useWaypointsContient
useWaypointsContient = useWaypointsContient == nil and true or useWaypointsContient

local useTomTomContinent = IPASettings and IPASettings.options.useTomTomContinent
useTomTomContinent = useTomTomContinent == nil and false or useTomTomContinent
useTomTomContinent = useTomTomContinent and (TomTom ~= nil) or false
IPAUIPrintDebug("useTomTomContinent: "..tostring(useTomTomContinent))

if (button == "LeftButton") and (useWaypointsContient == true) then

local wp_mapid, wp_x, wp_y, wp_name
IPAUIPrintDebug("IPAInstancePortalProviderPinMixin:OnMouseClickAction, button: "..tostring(button))
Expand Down Expand Up @@ -193,7 +203,7 @@ function IPAInstancePortalProviderPinMixin:OnMouseClickAction(button)

IPAUIPrintDebug("\nWaypoint Info:\n MapID: "..wp_mapid.."\n X: "..wp_x.."\n Y: "..wp_y.."\n Name: "..wp_name.."\n System: "..(useTomTom and "TomTom" or "Blizzard").."\n")

if useTomTom ~= true then
if useTomTomContinent ~= true then
AddNativeWaypoint(wp_mapid, wp_x, wp_y)
else
AddTomTomWaypoint(wp_mapid, wp_x, wp_y, wp_name)
Expand All @@ -211,14 +221,16 @@ end
local function WaypointDungeonEntrancePinMixin(self, button)
if (not self) or (not button) then return end

if (button == "LeftButton") then
local useTomTom = true
if IPASettings and IPASettings.options then
useTomTom = IPASettings.options.useTomTom and (TomTom ~= nil) or false
end
IPAUIPrintDebug("useTomTom: "..tostring(useTomTom))
local useWaypointsZone = IPASettings and IPASettings.options.useWaypointsZone
useWaypointsZone = useWaypointsZone == nil and true or useWaypointsZone

local useTomTomZone = IPASettings and IPASettings.options.useTomTomZone
useTomTomZone = useTomTomZone == nil and false or useTomTomZone
useTomTomZone = useTomTomZone and (TomTom ~= nil) or false
IPAUIPrintDebug("useTomTomZone: "..tostring(useTomTomZone))

if (useTomTom == true) then
if (button == "LeftButton") and (useWaypointsZone == true) then
if (useTomTomZone == true) then
local wp_mapid, wp_x, wp_y, wp_name
local uiMapID = self:GetMap():GetMapID();
local journalInstanceID = self.journalInstanceID
Expand Down Expand Up @@ -250,7 +262,7 @@ local function WaypointDungeonEntrancePinMixin(self, button)
IPAUIPrintDebug("\nWaypoint Info:\n MapID: "..wp_mapid.."\n X: "..wp_x.."\n Y: "..wp_y.."\n Name: "..wp_name.."\n System: "..(useTomTom and "TomTom" or "Blizzard").."\n")
AddTomTomWaypoint(wp_mapid, wp_x, wp_y, wp_name)
else
-- useTomTom is NOT true, use Native Tracking system
-- useTomTomZone is NOT true, use Native Tracking system
SuperTrackablePinMixin.OnMouseClickAction(self, button);
end
elseif button == "RightButton" then
Expand Down
9 changes: 5 additions & 4 deletions InstancePortalsAdv.toc
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
## Author: fuba
## IconTexture: Interface\AddOns\InstancePortalsAdv\fubaLogo
## Title: Instance Portals |cff0080ffAdvanced|r
## Notes: Displays Dungeon & Raid Portals on the Worldmap|n|nThis is an Advanced Version of "Instance Portals" by StevenTroughtonSmith but with more Features and way more Accurate Dungeon & Raid Entrance Pins!
## Notes: Displays Dungeon & Raid Portals on the Continent Map|n|nThis is an Advanced Version of "Instance Portals" by StevenTroughtonSmith but with more Features and WAY MORE accurate Dungeon & Raid Entrance Pins that comes directly from Blizzard!
## SavedVariables: IPASettings
## SavedVariablesPerCharacter: IPAUITrackInstancePortals IPAUITrackInstancePortalsOnContinents

## X-Curse-Project-ID: 721768

IPACore.lua
IPAPinDB.lua
IPAInstanceDB.lua
IPAInstancePortalPinTemplate.xml
IPACore.lua
InstancePortalsAdv.xml
InstancePortalsAdv.xml

IPAConfig.lua

0 comments on commit 1cdd393

Please sign in to comment.