Skip to content

Commit a9dd0a7

Browse files
first commit
0 parents  commit a9dd0a7

File tree

6 files changed

+317
-0
lines changed

6 files changed

+317
-0
lines changed

api.lua

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
ADDON_API = {
2+
File = {},
3+
Unit = {},
4+
Team = {},
5+
Log = {},
6+
Interface = {},
7+
Cursor = {},
8+
Input = {},
9+
Time = {},
10+
Player = {},
11+
Bag = {},
12+
-- This is the 'addons' directory at runtime
13+
baseDir = "",
14+
rootWindow = {},
15+
timers = {}
16+
}
17+
18+
19+
-- ======
20+
-- Logging
21+
-- ======
22+
23+
-- Logs a message to chat in YELLOW
24+
function ADDON_API.Log:Info(message)
25+
end
26+
27+
-- Logs a message to chat in RED
28+
function ADDON_API.Log:Err(message)
29+
end
30+
31+
32+
-- ======
33+
-- File Handling
34+
-- ======
35+
36+
function ADDON_API.File:Write(path, tbl)
37+
end
38+
39+
function ADDON_API.File:Read(path)
40+
end
41+
42+
43+
function ADDON_API.GetSettings(addonId)
44+
end
45+
46+
function ADDON_API.SaveSettings()
47+
end
48+
-- ======
49+
-- Interface
50+
-- ======
51+
function ADDON_API.Interface:CreateWindow(id, title, x, y, tabs)
52+
end
53+
54+
function ADDON_API.Interface:CreateEmptyWindow(id)
55+
end
56+
57+
function ADDON_API.Interface:CreateWidget(type, id, parent)
58+
end
59+
60+
function ADDON_API.Interface:CreateStatusBar(name, parent, type)
61+
end
62+
63+
function ADDON_API.Interface:CreateComboBox(window)
64+
end
65+
66+
function ADDON_API.Interface:ApplyButtonSkin(btn, skin)
67+
end
68+
69+
-- ======
70+
-- Unit
71+
-- ======
72+
function ADDON_API.Unit:GetUnitNameById(id)
73+
end
74+
75+
function ADDON_API.Unit:GetUnitInfoById(id)
76+
end
77+
78+
-- Note: "unit" in the below can be player, target, team1 through team50, playerpet1 or playerpet2
79+
function ADDON_API.Unit:GetUnitScreenPosition(unit)
80+
end
81+
82+
function ADDON_API.Unit:UnitDistance(unit)
83+
end
84+
85+
function ADDON_API.Unit:GetUnitId(unit)
86+
end
87+
88+
function ADDON_API.Unit:UnitBuffCount(unit)
89+
end
90+
91+
function ADDON_API.Unit:UnitBuff(unit, index)
92+
end
93+
94+
-- Returns the x,y,z coords of the provided unit
95+
function ADDON_API.Unit:UnitWorldPosition(unit)
96+
end
97+
98+
function ADDON_API.Unit:UnitDeBuffCount(unit)
99+
end
100+
101+
function ADDON_API.Unit:UnitDeBuff(unit, index)
102+
end
103+
104+
105+
-- ======
106+
-- Team
107+
-- ======
108+
function ADDON_API.Team:InviteToTeam(name, party)
109+
end
110+
111+
function ADDON_API.Team:SetRole(role)
112+
end
113+
114+
-- ======
115+
-- Bag
116+
-- ======
117+
function ADDON_API.Bag:EquipBagItem(bagSlot, isAux)
118+
end
119+
120+
--[[
121+
@function GetBagItemInfo
122+
@desc Get item information at the index, in the bag specified. 1 = Inventory
123+
]]
124+
function ADDON_API.Bag:GetBagItemInfo(bagType, index)
125+
end
126+
127+
-- ======
128+
-- Cursor
129+
-- ======
130+
function ADDON_API.Cursor:ClearCursor()
131+
end
132+
133+
function ADDON_API.Cursor:SetCursorImage(image, x, y)
134+
end
135+
136+
-- ======
137+
-- Time
138+
-- ======
139+
function ADDON_API.Time:GetUiMsec()
140+
end
141+
142+
-- ======
143+
-- Input
144+
-- ======
145+
function ADDON_API.Input:IsShiftKeyDown()
146+
end
147+
148+
149+
-- ======
150+
-- Player
151+
-- ======
152+
153+
--[[
154+
@function ChangeAppellation
155+
@desc Changes the player's title
156+
@param type (number) The ID of the title to set
157+
@returns (nil|true)
158+
]]
159+
function ADDON_API.Player:ChangeAppellation(type)
160+
end
161+
162+
-- ======
163+
-- Events & Timers
164+
-- ======
165+
function ADDON_API.On(event, callback)
166+
end
167+
168+
function ADDON_API:DoIn(msec, callback)
169+
end
170+
171+
172+
return ADDON_API

bigger_raid_text.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
-- This is perhaps the simplest example we can provide. This just makes the font size bigger for Commander chat.
2+
-- Here we set it to 24 and it becomes very large!
3+
-- As you can see, it grabs an existing window
4+
5+
local raidCommandMessage = ADDON:GetContent(UIC.RAID_COMMAND_MESSAGE)
6+
raidCommandMessage.style:SetFontSize(20)
7+
8+
-- If you need to learn, you could try to make it a setting instead of a static value.
9+
-- That would be a cool addon people would love :)

main.lua

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
local api = require("api")
2+
3+
-- First up is the addon definition!
4+
-- This information is shown in the Addon Manager.
5+
-- You also specify "unload" which is the function called when unloading your addon.
6+
local example_addon = {
7+
name = "Example Addon",
8+
author = "Aguru",
9+
desc = "Example addon showcasing some features of the API",
10+
version = "0.2"
11+
}
12+
13+
-- The Load Function is called as soon as the game loads its UI. Use it to initialize anything you need!
14+
local function Load()
15+
-- To print a message to the chat, you can use this. Only you can see it! It's good for debugging
16+
-- This will be called BEFORE load!
17+
api.Log:Info("Loading test addon...")
18+
19+
-- This is how you load another file. Here we just want to execute what's in bigger_raid_text.lua
20+
-- Check the file out to figure out what it does!
21+
require("example_addon/bigger_raid_text")
22+
require("example_addon/raid_role_saver")
23+
24+
-- This is how you load a file and get a result out of it.
25+
-- Here we get world_marker and later use it in the Unload function
26+
World_marker = require("example_addon/world_marker")
27+
28+
29+
-- api test: getting inventory slots
30+
-- on load, get first item in inventory
31+
-- note: inventory has "real" slots and "displayed" slots. Display = sorted, Real = where it actually is
32+
33+
--api.GetBagItemInfo()
34+
end
35+
36+
-- Unload is called when addons are reloaded.
37+
-- Here you want to destroy your windows and do other tasks you find useful.
38+
local function Unload()
39+
if World_marker ~= nil then
40+
World_marker.window:Show(false)
41+
World_marker.window = nil
42+
end
43+
end
44+
45+
-- Here we make sure to bind the functions we defined to our addon. This is how the game knows what function to use!
46+
example_addon.OnLoad = Load
47+
example_addon.OnUnload = Unload
48+
49+
return example_addon

raid_role_saver.lua

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
local api = require("api")
2+
-- This module here is a tiny addon: Saving last used raid role!
3+
4+
-- First off: Define a function called when our role is changed.
5+
-- Here, we will write to a file and contain our role.
6+
local function OnRoleChanged(role)
7+
api.File:Write("example_addon/raid_role.txt", { role = role})
8+
end
9+
10+
-- Second: Detect a team change, and set our new role!
11+
-- We read the previously written file.
12+
local function OnTeamChanged()
13+
local savedRole = api.File:Read("example_addon/raid_role.txt")
14+
api.Team:SetRole(savedRole.role)
15+
end
16+
17+
-- Last: Register the event listeners so that the code is actually called.
18+
api.On("raid_role_changed", OnRoleChanged)
19+
api.On("TEAM_MEMBERS_CHANGED", OnTeamChanged)

raid_wnd.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

world_marker.lua

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
local world_marker = {}
2+
3+
-- First, we create an empty window. This will be a layer on the screen we can draw on.
4+
local canvas = api.Interface:CreateEmptyWindow("TargetArrow")
5+
canvas:Show(true)
6+
7+
-- Second, we create a label. It's just text!
8+
local label = canvas:CreateChildWidget("label", "label", 0, true)
9+
label:Show(true)
10+
label:AddAnchor("TOPLEFT", canvas, "TOPLEFT", 0, 42)
11+
12+
local playerId = api.Unit:GetUnitId("player")
13+
14+
-- Now we want to save the coordinates of our player when the addon loads
15+
local settings = api.GetSettings("example_addon")
16+
17+
--local x, y, z = api.GetUnitWorldPosition("player")
18+
local message = settings.message or ""
19+
local x = settings.x or 0
20+
local y = settings.y or 0
21+
local z = settings.z or 0
22+
23+
label:SetText(message)
24+
-- We then define a function that will be called on every frame.
25+
-- The function will grab the screen coordinates of our initial player coords.
26+
-- Then it checks if it's on the screen (offsetZ) and hide/show it accordingly.
27+
-- Lastly, we adjust the Anchor of the canvas to place it on the right spot on the screen!
28+
local function OnUpdate()
29+
local offsetX, offsetY, offsetZ = X2Util:ConvertWorldToScreen(x, y, z)
30+
31+
if offsetZ < 0 or offsetZ > 100 then
32+
canvas:Show(false)
33+
else
34+
canvas:Show(true)
35+
end
36+
37+
canvas:AddAnchor("BOTTOM", "UIParent", "TOPLEFT", offsetX, offsetY-92)
38+
end
39+
40+
local function OnChatMessage(chatType, speakerId, isHostile, speakerName, message)
41+
if speakerId == playerId then
42+
local prefix = "/note "
43+
if string.sub(message, 1, #prefix) == prefix then
44+
local note = string.sub(message, #prefix + 1)
45+
x, y, z = api.Unit:GetUnitWorldPosition("player")
46+
message = note
47+
label:SetText(message)
48+
49+
local settings = api.GetSettings("example_addon")
50+
settings.message = message
51+
settings.x = x
52+
settings.y = y
53+
settings.z = z
54+
api.SaveSettings()
55+
end
56+
end
57+
end
58+
59+
-- Now we register the above function so that it is actually called on every update.
60+
api.On("UPDATE", OnUpdate)
61+
api.On("CHAT_MESSAGE", OnChatMessage)
62+
63+
-- This is just so we can use the canvas and label in our main file. We do it for the Unload function!
64+
world_marker.window = canvas
65+
world_marker.label = label
66+
67+
return world_marker

0 commit comments

Comments
 (0)