From 5b6d7c820e7e45dc0dc29beacf93e3bbb0b713b6 Mon Sep 17 00:00:00 2001 From: James Whitehead Ii Date: Fri, 22 Feb 2008 10:51:36 +0000 Subject: [PATCH] * Working changes to the new AceConfig GUI --- Config.lua | 315 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ TomTom.lua | 96 +++++++++++++++--- 2 files changed, 395 insertions(+), 16 deletions(-) diff --git a/Config.lua b/Config.lua index e69de29..ea63da1 100644 --- a/Config.lua +++ b/Config.lua @@ -0,0 +1,315 @@ +local options = {} +local db = {} + +local L = setmetatable({}, {__index = function(t,k) return k end}) + +options.type = "group" +options.name = "TomTom" + +function options.get(info) + local ns,opt = string.split(".", info.arg) + local val = TomTom.db.profile[ns][opt] + if type(val) == "table" then + return unpack(val) + else + return val + end +end + +function options.set(info, arg1, arg2, arg3, arg4) + local ns,opt = string.split(".", info.arg) + --TomTom:Print(ns, opt, arg1, arg2, arg3, arg4) + if arg2 then + local entry = TomTom.db.profile[ns][opt] + entry[1] = arg1 + entry[2] = arg2 + entry[3] = arg3 + entry[4] = arg4 + else + TomTom.db.profile[ns][opt] = arg1 + end + + if ns == "block" then + TomTom:ShowHideBlockCoords() + elseif ns == "mapcoords" then + TomTom:ShowHideWorldCoords() + end +end + +options.args = {} + +options.args.coordblock = { + type = "group", + name = L["Coordinate Block"], + desc = L["Options that alter the coordinate block"], + args = { + desc = { + order = 1, + type = "description", + name = L["TomTom provides you with a floating coordinate display that can be used to determine your current position. These options can be used to enable or disable this display, or customize the block's display."], + }, + enable = { + order = 2, + type = "toggle", + name = L["Enable coordinate block"], + desc = L["Enables a floating block that displays your current position in the current zone"], + arg = "block.enable", + }, + accuracy = { + order = 3, + type = "range", + name = "Accuracy", + desc = L["Coordinates can be displayed as simple XX, YY coordinate, or as more precise XX.XX, YY.YY. This setting allows you to control that precision"], + min = 0, max = 2, step = 1, + arg = "block.accuracy", + }, + lock = { + order = 4, + type = "toggle", + name = L["Lock coordinate block"], + arg = "block.lock", + }, + display = { + order = 4, + type = "group", + name = L["Display Settings"], + inline = true, + args = { + bordercolor = { + type = "color", + name = L["Border color"], + arg = "block.bordercolor", + }, + bgcolor = { + type = "color", + name = L["Background color"], + arg = "block.bgcolor", + }, + height = { + type = "range", + name = L["Block height"], + arg = "block.height", + min = 5, max = 50, step = 1, + }, + width = { + type = "range", + name = L["Block width"], + arg = "block.width", + min = 50, max = 250, step = 5, + }, + fontsize = { + type = "range", + name = L["Font size"], + arg = "block.fontsize", + min = 1, max = 24, step = 1, + }, + }, + }, + }, +} -- End coordinate block settings + +options.args.mapcoord = { + type = "group", + name = L["Map Coordinates"], + desc = L["Options that customize the map coordinate display"], + args = { + help = { + order = 1, + type = "description", + name = L["TomTom is capable of displaying the player's coordinates on the world map, as well as the current coordinate position of the cursor. These options can be used to enable or disable these displays"], + }, + player = { + type = "group", + inline = true, + name = L["Player Coordinates"], + args = { + enableplayer = { + order = 1, + type = "toggle", + name = L["Enable player coordinates"], + arg = "mapcoords.playerenable", + }, + playeraccuracy = { + order = 4, + type = "range", + name = L["Player coordinate accuracy"], + desc = L["Coordinates can be displayed as simple XX, YY coordinate, or as more precise XX.XX, YY.YY. This setting allows you to control that precision"], + min = 0, max = 2, step = 1, + arg = "mapcoords.playeraccuracy", + }, + }, + }, + cursor = { + type = "group", + inline = true, + name = L["Cursor Coordinates"], + args = { + enablecursor = { + order = 3, + type = "toggle", + name = L["Enable cursor coordinates"], + arg = "mapcoords.cursorenable", + }, + + cursoraccuracy = { + order = 5, + type = "range", + name = L["Cursor coordinate accuracy"], + desc = L["Coordinates can be displayed as simple XX, YY coordinate, or as more precise XX.XX, YY.YY. This setting allows you to control that precision"], + min = 0, max = 2, step = 1, + arg = "mapcoords.cursoraccuracy", + }, + }, + }, + }, +} -- end map coord options + +options.args.crazytaxi = { + type = "group", + name = L["Waypoint Arrow"], + args = { + help = { + order = 1, + type = "description", + name = L["TomTom provides an arrow that can be placed anywhere on the screen. Similar to the arrow in \"Crazy Taxi\" it will point you towards your next waypoint"], + }, + enable = { + order = 2, + type = "toggle", + name = L["Enable floating waypoint arrow"], + width = "double", + arg = "arrow.enable", + }, + color = { + type = "group", + name = L["Arrow colors"], + inline = true, + args = { + help = { + order = 1, + type = "description", + name = L["The floating waypoint arrow can change color depending on whether or nor you are facing your destination. By default it will display green when you are facing it directly, and red when you are facing away from it. These colors can be changed in this section. Setting these options to the same color will cause the arrow to not change color at all"], + }, + colorstart = { + type = "color", + name = L["Good color"], + arg = "arrow.goodcolor", + }, + colorend = { + type = "color", + name = L["Bad color"], + arg = "arrow.badcolor", + }, + }, + }, + }, +} -- End crazy taxi options + +options.args.minimap = { + type = "group", + name = L["Minimap"], + args = { + help = { + order = 1, + type = "description", + name = L["TomTom can display multiple waypoint arrows on the minimap. These options control the display of these waypoints"], + }, + enable = { + order = 2, + type = "toggle", + name = L["Enable minimap waypoints"], + width = "double", + arg = "minimap.enable", + }, + otherzone = { + type = "toggle", + name = L["Display waypoints from other zones"], + desc = L["TomTom can hide waypoints in other zones, this setting toggles that functionality"], + width = "double", + arg = "minimap.otherzone", + }, + tooltip = { + type = "toggle", + name = L["Enable mouseover tooltips"], + desc = L["TomTom can display a tooltip containing information abouto waypoints, when they are moused over. This setting toggles that functionality"], + arg = "minimap.tooltip", + }, + + }, +} -- End minimap options + +options.args.worldmap = { + type = "group", + name = L["World Map"], + args = { + help = { + order = 1, + type = "description", + name = L["TomTom can display multiple waypoints on the world map. These options control the display of these waypoints"], + }, + enable = { + order = 2, + type = "toggle", + name = L["Enable world map waypoints"], + width = "double", + arg = "worldmap.enable", + }, + otherzone = { + type = "toggle", + name = L["Display waypoints from other zones"], + desc = L["TomTom can hide waypoints in other zones, this setting toggles that functionality"], + width = "double", + arg = "worldmap.otherzone", + }, + tooltip = { + type = "toggle", + name = L["Enable mouseover tooltips"], + desc = L["TomTom can display a tooltip containing information abouto waypoints, when they are moused over. This setting toggles that functionality"], + arg = "worldmap.tooltip", + }, + createclick = { + type = "toggle", + name = L["Allow control-clicking on map to create new waypoint"], + width = "double", + arg = "worldmap.clickcreate", + }, + }, +} -- End world map options + +options.args.general = { + type = "group", + name = L["General Options"], + args = { + help = { + order = 1, + type = "description", + name = L["TomTom is able to accept and send waypoints to guild and party members who are also running TomTom. In addition, waypoints may be stored between sessions."], + }, + comm = { + type = "toggle", + name = L["Accept waypoints from guild and party members"], + width = "double", + arg = "comm.enable", + }, + promptcomm = { + type = "toggle", + name = L["Prompt before accepting sent waypoints"], + width = "double", + arg = "comm.prompt", + }, + persistence = { + type = "toggle", + name = L["Save waypoints in between sessions"], + width = "double", + arg = "persistence.savewaypoints", + }, + }, +} + +LibStub("AceConfig-3.0"):RegisterOptionsTable("TomTom", options) + +SLASH_TOMTOM1 = "/tomtom" +SlashCmdList["TOMTOM"] = function(msg) + LibStub("AceConfigDialog-3.0"):Open("TomTom") +end + diff --git a/TomTom.lua b/TomTom.lua index 3b3f28e..07a3c58 100755 --- a/TomTom.lua +++ b/TomTom.lua @@ -19,16 +19,44 @@ local Block_OnDragStart,Block_OnDragStop function TomTom:Initialize() self.defaults = { profile = { - cleardistance = 10, - lock = false, - coords_worldmap = true, - coords_cursor = true, - coords_block = true, - clearzone = false, - waypoints = { + block = { + enable = true, + accuracy = 2, + bordercolor = {1, 0.8, 0, 0.8}, + bgcolor = {0, 0, 0, 0.4}, + lock = false, + height = 30, + width = 100, + fontsize = 12, }, - positions = { - ["*"] = {}, + mapcoords = { + playerenable = true, + playeraccuracy = 2, + cursorenable = true, + cursoraccuracy = 2, + }, + arrow = { + enable = true, + goodcolor = {0, 1, 0, 1}, + badcolor = {1, 0, 0, 1}, + }, + minimap = { + enable = true, + otherzone = true, + tooltip = true, + }, + worldmap = { + enable = true, + otherzone = true, + tooltip = true, + clickcreate = true, + }, + comm = { + enable = true, + prompt = false, + }, + persistence = { + savewaypoints = true, }, }, } @@ -47,7 +75,7 @@ end function TomTom:ShowHideWorldCoords() -- Bail out if we're not supposed to be showing this frame - if self.db.profile.coords_worldmap then + if self.db.profile.mapcoords.playerenable or self.db.profile.mapcoords.cursorenable then -- Create the frame if it doesn't exist if not TomTomWorldFrame then TomTomWorldFrame = CreateFrame("Frame", nil, WorldMapFrame) @@ -59,6 +87,18 @@ function TomTom:ShowHideWorldCoords() TomTomWorldFrame:SetScript("OnUpdate", WorldMap_OnUpdate) end + + TomTomWorldFrame.Player:Hide() + TomTomWorldFrame.Cursor:Hide() + + if self.db.profile.mapcoords.playerenable then + TomTomWorldFrame.Player:Show() + end + + if self.db.profile.mapcoords.cursorenable then + TomTomWorldFrame.Cursor:Show() + end + -- Show the frame TomTomWorldFrame:Show() elseif TomTomWorldFrame then @@ -68,7 +108,7 @@ end function TomTom:ShowHideBlockCoords() -- Bail out if we're not supposed to be showing this frame - if self.db.profile.coords_block then + if self.db.profile.block.enable then -- Create the frame if it doesn't exist if not TomTomBlock then -- Create the coordinate display @@ -107,6 +147,21 @@ function TomTom:ShowHideBlockCoords() end -- Show the frame TomTomBlock:Show() + + local opt = self.db.profile.block + + -- Update the backdrop color, and border color + TomTomBlock:SetBackdropColor(unpack(opt.bgcolor)) + TomTomBlock:SetBackdropBorderColor(unpack(opt.bordercolor)) + + -- Update the height and width + TomTomBlock:SetHeight(opt.height) + TomTomBlock:SetWidth(opt.width) + + -- Update the font size + local font,height = TomTomBlock.Text:GetFont() + TomTomBlock.Text:SetFont(font, opt.fontsize, select(3, TomTomBlock.Text:GetFont())) + elseif TomTomBlock then TomTomBlock:Hide() end @@ -137,7 +192,7 @@ local function WaypointCallback(event, data, dist, lastdist) end end --- TODO: Make this now suck +-- TODO: Make this not suck function TomTom:AddWaypoint(x,y,desc) local oc,oz = Astrolabe:GetCurrentPlayerPosition() SetMapToCurrentZone() @@ -294,13 +349,20 @@ do return cX, cY end + local coord_fmt = "%%.%df, %%.%df" + function RoundCoords(x,y,prec) + local fmt = coord_fmt:format(prec, prec) + return fmt:format(x*100, y*100) + end + function WorldMap_OnUpdate(self, elapsed) local c,z,x,y = Astrolabe:GetCurrentPlayerPosition() + local opt = TomTom.db.profile if not x or not y then self.Player:SetText("Player: ---") else - self.Player:SetText(string.format("Player: %.2f, %.2f", x*100, y*100)) + self.Player:SetFormattedText("Player: %s", RoundCoords(x, y, opt.mapcoords.playeraccuracy)) end local cX, cY = GetCurrentCursorPosition() @@ -308,7 +370,7 @@ do if not cX or not cY then self.Cursor:SetText("Cursor: ---") else - self.Cursor:SetText(string.format("Cursor: %.2f, %.2f", cX*100, cY*100)) + self.Cursor:SetFormattedText("Cursor: %s", RoundCoords(cX, cY, opt.mapcoords.cursoraccuracy)) end end end @@ -316,16 +378,18 @@ end do function Block_OnUpdate(self, elapsed) local c,z,x,y = Astrolabe:GetCurrentPlayerPosition() + local opt = TomTom.db.profile + if not x or not y then -- Hide the frame when we have no coordinates self:Hide() else - self.Text:SetText(string.format("%.2f, %.2f", x*100, y*100)) + self.Text:SetFormattedText("%s", RoundCoords(x, y, opt.block.accuracy)) end end function Block_OnDragStart(self, button, down) - if not TomTom.db.profile.lock then + if not TomTom.db.profile.block.lock then self:StartMoving() end end -- 1.7.9.5