Advertisement
stoneharry

Untitled

Feb 22nd, 2014
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.18 KB | None | 0 0
  1. --[[
  2. Status list:
  3. - CURRENT
  4. - REACHABLE
  5. - DISTANT
  6. - NONE
  7. ]]
  8. -- X, Y, Name, NumRoutes, Cost (100 = 1 silver), nodes accessable, npc name, status, available to faction in string
  9. local coords_m = {
  10.     {0.5, 0.3, "Blackrock Mountain", 4, 0, {2, 3, 4, 5}, "Lae Dualade", "NONE", "BOTH"},
  11.     {0.9, 0.3, "The Race Track", 1, 0, {1}, "stuff3", "NONE", "BOTH"},
  12.     {0.52, 0.25, "Redridge, Stonewatch", 1, 0, {1}, "Black War Gryphon", "NONE", "BOTH"},
  13.     {100.56, 100.28, "Badlands", 1, 0, {1}, "Gorrik", "NONE", "BOTH"},
  14.     {0.5, 0.51, "Arathi Highlands, Stromgarde City", 3, 0, {1, 6, 7, 8, 9,10,11,12,13}, "Shavalius the Fancy", "NONE", "BOTH"},
  15.     {0.45, 0.6, "Silverpine Forest", 1, 0, {5}, "DEBUG", "NONE", "Alliance"},
  16.     {0.54, 0.52, "Arathi Highlands, Refugee Point", 1, 0, {5}, "Kip Trawlskip", "NONE", "Alliance"},
  17.     {0.4, 0.58, "Silverpine Forest, The Sepulcher", 1, 0, {5}, "Karos Razok", "NONE", "Horde"},
  18.     {0.56, 0.49, "Arathi Highlands, Hammerfall", 1, 0, {5}, "DEBUG3", "NONE", "Horde"},
  19.     {0.85, 0.77, "Snowdrift Peaks, Excavation Camp", 1, 0, {5}, "DEBUGZ", "NONE", "BOTH"},
  20.     {0.76, 0.79, "Snowdrift Peaks, Illidari Camp", 1, 0, {5}, "DEBUGZ", "NONE", "BOTH"},
  21.     {0.82, 0.87, "Sandy Plains, Taunka'le Village", 1, 0, {5}, "DEBUGZ", "NONE", "BOTH"},
  22.     {0.89, 0.84, "Sandy Plains, Oomlot Village", 1, 0, {5}, "DEBUGZ", "NONE", "BOTH"},
  23.    
  24.     --kalimdor--14+
  25.    
  26.     {0.6, 0.67, "Snowdrift Peaks, Excavation Camp", 1, 0, {15,16,17,18}, "Breck Rockbrow", "NONE", "BOTH"},
  27.     {0.85, 0.81, "Arathi Highlands, Stromgarde City", 3, 0, {15}, "DEBUGZ", "NONE", "BOTH"},
  28.     {0.5, 0.70, "Snowdrift Peaks, Illidari Camp", 1, 0, {14,15,17,18}, "Maddix", "NONE", "BOTH"},
  29.     {0.65, 0.77, "Sandy Plains, Oomlot Village", 1, 0, {14,15,16,18}, "Nutral", "NONE", "BOTH"},
  30.     {0.6, 0.79, "Sandy Plains, Taunka'le Village", 1, 0, {14,15,16,17}, "Helidan Lightwing", "NONE", "BOTH"},
  31.     --{0.9, 0.2, "Test2", 3, 1000, {1, 2, 4}, "stuff2", "DISTANT"},
  32. }
  33.  
  34. local current = 0
  35.  
  36. TAXI_MAP_WIDTH = 316;
  37. TAXI_MAP_HEIGHT = 352;
  38. NUM_TAXI_BUTTONS = 0;
  39. NUM_TAXI_ROUTES = 0;
  40.  
  41. TaxiButtonTypes = { };
  42. TaxiButtonTypes["CURRENT"] = {
  43.     file = "Interface\\TaxiFrame\\UI-Taxi-Icon-Green"
  44. }
  45. TaxiButtonTypes["REACHABLE"] = {
  46.     file = "Interface\\TaxiFrame\\UI-Taxi-Icon-White"
  47. }
  48. TaxiButtonTypes["DISTANT"] = {
  49.     file = "Interface\\TaxiFrame\\UI-Taxi-Icon-Yellow"
  50. }
  51.  
  52. TAXI_BUTTON_HALF_WIDTH = 8;
  53. TAXI_BUTTON_HALF_HEIGHT = 8;
  54.  
  55.  
  56. function TaxiFrame_OnLoad(self)
  57.     self:RegisterEvent("TAXIMAP_OPENED");
  58.     self:RegisterEvent("TAXIMAP_CLOSED");
  59. end
  60.  
  61. function TaxiFrame_OnEvent(self, event, ...)
  62.     if ( event == "TAXIMAP_OPENED" ) then
  63.         -- Show the merchant we're dealing with
  64.         local name = UnitName("npc")
  65.         TaxiMerchant:SetText(name);
  66.         SetPortraitTexture(TaxiPortrait, "npc");
  67.        
  68.         current = 0
  69.         for i=1, #coords_m do
  70.             coords_m[i][8] = "NONE";
  71.             if name == coords_m[i][7] then
  72.                 current = i
  73.                 coords_m[current][8] = "CURRENT";
  74.             end
  75.         end
  76.         if current == 0 then
  77.             UIErrorsFrame:AddMessage("ERROR: No path found for this creature.", 1.0, 0.1, 0.1, 1.0);
  78.             HideUIPanel(TaxiFrame);
  79.             return;
  80.         end
  81.         for k,v in pairs(coords_m[current][6]) do
  82.             coords_m[v][8] = "REACHABLE";
  83.         end
  84.  
  85.         -- Set the texture coords on the map
  86.         TaxiMap:SetTexCoord(0,1,0,1);
  87.         SetTaxiMap(TaxiMap)
  88.        
  89.         -- Show the taxi node map and buttons
  90.         local num_nodes = #coords_m
  91.         if ( num_nodes > NUM_TAXI_BUTTONS ) then
  92.             local button;
  93.             for i = NUM_TAXI_BUTTONS+1, num_nodes do
  94.                 button = CreateFrame("Button", "TaxiButton"..i, TaxiRouteMap, "TaxiButtonTemplate");
  95.                 button:SetID(i);
  96.             end
  97.         end
  98.         -- Draw nodes
  99.         local taxiNodePositions = {};
  100.         local numValidFlightNodes = 0;
  101.         for index = 1, #coords_m do
  102.             local type = coords_m[index][8]
  103.             local button = _G["TaxiButton"..index];
  104.             local PlrFaction = UnitFactionGroup("player")
  105.             taxiNodePositions[index] = {};
  106.             if ( type ~= "NONE" ) and ( coords_m[index][9] == PlrFaction or coords_m[index][9] == "BOTH" ) then
  107.                 numValidFlightNodes = numValidFlightNodes + 1;
  108.                 local x, y = coords_m[index][1], coords_m[index][2]
  109.                 local currX = x*TAXI_MAP_WIDTH;
  110.                 local currY = y*TAXI_MAP_HEIGHT;
  111.                 taxiNodePositions[index].x = currX;
  112.                 taxiNodePositions[index].y = currY;
  113.                 -- check if we are obscuring a previous placement (eg: Ebon Hold and Light's Hope Chapel)
  114.                 --[[if ( numValidFlightNodes > 1 ) then
  115.                     for checkNode = 1, index do
  116.                         local checkX = taxiNodePositions[checkNode].x;
  117.                         local checkY = taxiNodePositions[checkNode].y;
  118.                         if ( taxiNodePositions[checkNode].x ) then
  119.                             if ( (currX > checkX - TAXI_BUTTON_HALF_WIDTH) and (currX < checkX + TAXI_BUTTON_HALF_WIDTH) ) then
  120.                                 if ( (currY > checkY - TAXI_BUTTON_HALF_HEIGHT) and (currY < checkY + TAXI_BUTTON_HALF_HEIGHT) ) then
  121.                                     taxiNodePositions[index].x = currX + (currX - checkX) * 0.5;
  122.                                     taxiNodePositions[index].y = currY + (currY - checkY) * 0.5;
  123.                                     taxiNodePositions[checkNode].x = checkX + (checkX - currX) * 0.5;
  124.                                     taxiNodePositions[checkNode].y = checkY + (checkY - currY) * 0.5;
  125.                                 end
  126.                             end
  127.                         end
  128.                     end
  129.                 end]]
  130.                 -- set the button position
  131.                 button:ClearAllPoints();
  132.                 button:SetPoint("CENTER", "TaxiMap", "BOTTOMLEFT", taxiNodePositions[index].x, taxiNodePositions[index].y);
  133.                 button:SetNormalTexture(TaxiButtonTypes[type].file);
  134.                 button:Show();
  135.             else
  136.                 button:Hide();
  137.             end
  138.         end
  139.  
  140.         if ( num_nodes > NUM_TAXI_BUTTONS ) then
  141.             NUM_TAXI_BUTTONS = num_nodes
  142.         end
  143.  
  144.         -- All set...
  145.         ShowUIPanel(self);
  146.         if ( not self:IsShown() ) then
  147.             CloseTaxiMap();
  148.         end
  149.         return;
  150.     end
  151.     if ( event == "TAXIMAP_CLOSED" ) then
  152.         HideUIPanel(self);
  153.         return;
  154.     end
  155. end
  156.  
  157. function TaxiNodeOnButtonEnter(button)
  158.     local index = button:GetID();
  159.     GameTooltip:SetOwner(button, "ANCHOR_RIGHT");
  160.     GameTooltip:AddLine(coords_m[index][3], "", 1.0, 1.0, 1.0);
  161.    
  162.     -- Setup variables
  163.     local numRoutes = coords_m[current][4];
  164.     local line;
  165.     local sX, sY, dX, dY;
  166.     local w = TaxiRouteMap:GetWidth();
  167.     local h = TaxiRouteMap:GetHeight();
  168.    
  169.     local type = coords_m[index][8]
  170.     if ( type == "REACHABLE" ) then
  171.         SetTooltipMoney(GameTooltip, coords_m[index][5]);
  172.         TaxiNodeSetCurrent(index);
  173.        
  174.         if ( numRoutes > NUM_TAXI_ROUTES ) then
  175.             for i = NUM_TAXI_ROUTES+1, numRoutes do
  176.                 line = TaxiRouteMap:CreateTexture("TaxiRoute"..i, "BACKGROUND");
  177.                 line:SetTexture("Interface\\TaxiFrame\\UI-Taxi-Line");
  178.             end
  179.             NUM_TAXI_ROUTES = numRoutes;
  180.         end
  181.  
  182.         for i=1, NUM_TAXI_ROUTES do
  183.             line = _G["TaxiRoute"..i];
  184.             if ( i <= numRoutes ) then
  185.                 sX = coords_m[current][1]*w;
  186.                 sY = coords_m[current][2]*h;
  187.                 dX = coords_m[index][1]*w;
  188.                 dY = coords_m[index][2]*h;
  189.                 DrawRouteLine(line, "TaxiRouteMap", sX, sY, dX, dY, 32);
  190.                 line:Show();
  191.             else
  192.                 line:Hide();
  193.             end
  194.         end
  195.     elseif ( type == "CURRENT" ) then
  196.         GameTooltip:AddLine(TAXINODEYOUAREHERE, "", 0.5, 1.0, 0.5);
  197.         DrawOneHopLines();
  198.     end
  199.  
  200.     GameTooltip:Show();
  201. end
  202.  
  203. -- Draw all flightpaths within one hop of current location
  204. function DrawOneHopLines()
  205.     local line;
  206.     local sX, sY, dX, dY;
  207.     local w = TaxiRouteMap:GetWidth();
  208.     local h = TaxiRouteMap:GetHeight();
  209.     local numNodes = #coords_m
  210.     local numLines = 0;
  211.     local numSingleHops = 0;
  212.     for i=1, numNodes  do
  213.         --if ( GetNumRoutes(i) == 1 ) then
  214.             numSingleHops = numSingleHops + 1;
  215.             numLines = numLines + 1;
  216.             if ( numLines > NUM_TAXI_ROUTES ) then
  217.                 line = TaxiRouteMap:CreateTexture("TaxiRoute"..numLines, "BACKGROUND");
  218.                 line:SetTexture("Interface\\TaxiFrame\\UI-Taxi-Line");
  219.                 NUM_TAXI_ROUTES = numLines;
  220.             else
  221.                 line = _G["TaxiRoute"..numLines];
  222.             end
  223.             if ( line ) then
  224.                 sX = coords_m[current][1]*w;
  225.                 sY = coords_m[current][2]*h;
  226.                 dX = coords_m[current][1]*w;
  227.                 dY = coords_m[current][2]*h;
  228.                 DrawRouteLine(line, "TaxiRouteMap", sX, sY, dX, dY, 32);
  229.                 line:Show();
  230.             end
  231.         --end
  232.     end
  233.     for i=numLines+1, NUM_TAXI_ROUTES do
  234.         _G["TaxiRoute"..i]:Hide();
  235.     end
  236.     if ( numSingleHops == 0 ) then
  237.         UIErrorsFrame:AddMessage(ERR_TAXINOPATHS, 1.0, 0.1, 0.1, 1.0);
  238.         HideUIPanel(TaxiFrame);
  239.     end
  240. end
  241.  
  242.  
  243. -- The following function is used with permission from Daniel Stephens <iriel@vigilance-committee.org>
  244. TAXIROUTE_LINEFACTOR = 32/30; -- Multiplying factor for texture coordinates
  245. TAXIROUTE_LINEFACTOR_2 = TAXIROUTE_LINEFACTOR / 2; -- Half o that
  246.  
  247. -- T        - Texture
  248. -- C        - Canvas Frame (for anchoring)
  249. -- sx,sy    - Coordinate of start of line
  250. -- ex,ey    - Coordinate of end of line
  251. -- w        - Width of line
  252. -- relPoint - Relative point on canvas to interpret coords (Default BOTTOMLEFT)
  253. function DrawRouteLine(T, C, sx, sy, ex, ey, w, relPoint)
  254.    if (not relPoint) then relPoint = "BOTTOMLEFT"; end
  255.  
  256.    -- Determine dimensions and center point of line
  257.    local dx,dy = ex - sx, ey - sy;
  258.    local cx,cy = (sx + ex) / 2, (sy + ey) / 2;
  259.  
  260.    -- Normalize direction if necessary
  261.    if (dx < 0) then
  262.       dx,dy = -dx,-dy;
  263.    end
  264.  
  265.    -- Calculate actual length of line
  266.    local l = sqrt((dx * dx) + (dy * dy));
  267.  
  268.    -- Quick escape if it's zero length
  269.    if (l == 0) then
  270.       T:SetTexCoord(0,0,0,0,0,0,0,0);
  271.       T:SetPoint("BOTTOMLEFT", C, relPoint, cx,cy);
  272.       T:SetPoint("TOPRIGHT",   C, relPoint, cx,cy);
  273.       return;
  274.    end
  275.  
  276.    -- Sin and Cosine of rotation, and combination (for later)
  277.    local s,c = -dy / l, dx / l;
  278.    local sc = s * c;
  279.  
  280.    -- Calculate bounding box size and texture coordinates
  281.    local Bwid, Bhgt, BLx, BLy, TLx, TLy, TRx, TRy, BRx, BRy;
  282.    if (dy >= 0) then
  283.       Bwid = ((l * c) - (w * s)) * TAXIROUTE_LINEFACTOR_2;
  284.       Bhgt = ((w * c) - (l * s)) * TAXIROUTE_LINEFACTOR_2;
  285.       BLx, BLy, BRy = (w / l) * sc, s * s, (l / w) * sc;
  286.       BRx, TLx, TLy, TRx = 1 - BLy, BLy, 1 - BRy, 1 - BLx;
  287.       TRy = BRx;
  288.    else
  289.       Bwid = ((l * c) + (w * s)) * TAXIROUTE_LINEFACTOR_2;
  290.       Bhgt = ((w * c) + (l * s)) * TAXIROUTE_LINEFACTOR_2;
  291.       BLx, BLy, BRx = s * s, -(l / w) * sc, 1 + (w / l) * sc;
  292.       BRy, TLx, TLy, TRy = BLx, 1 - BRx, 1 - BLx, 1 - BLy;
  293.       TRx = TLy;
  294.    end
  295.  
  296.    -- Set texture coordinates and anchors
  297.    T:ClearAllPoints();
  298.    T:SetTexCoord(TLx, TLy, BLx, BLy, TRx, TRy, BRx, BRy);
  299.    T:SetPoint("BOTTOMLEFT", C, relPoint, cx - Bwid, cy - Bhgt);
  300.    T:SetPoint("TOPRIGHT",   C, relPoint, cx + Bwid, cy + Bhgt);
  301. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement