Skip to content

Commit dad1999

Browse files
committedSep 15, 2014
libring code fragments
1 parent 1588ac3 commit dad1999

File tree

2 files changed

+146
-0
lines changed

2 files changed

+146
-0
lines changed
 

‎wow5.0/rLibRing/core/core.lua

+140
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
2+
---------------------------------
3+
-- INIT
4+
---------------------------------
5+
6+
local addon, ns = ...
7+
ns.rLibRing = {}
8+
local rLibRing = ns.rLibRing
9+
local _G = _G
10+
11+
12+
---------------------------------
13+
-- VARIABLES / CONSTANTS
14+
---------------------------------
15+
16+
local rad = rad
17+
local sqrt = sqrt
18+
local floor = floor
19+
local tinsert = tinsert
20+
21+
-- ring segment layout
22+
-- ____ ____
23+
-- / | \
24+
-- | 4 | 1 |
25+
-- ----+----
26+
-- | 3 | 2 |
27+
-- \____|____/
28+
--
29+
30+
local ringSegmentSettings = {
31+
{ defaultRotation = 0, primeNum = 2, point = "TOPRIGHT", }, --segment 1
32+
{ defaultRotation = 270, primeNum = 3, point = "BOTTOMRIGHT", }, --segment 2
33+
{ defaultRotation = 180, primeNum = 5, point = "BOTTOMLEFT", }, --segment 3
34+
{ defaultRotation = 90, primeNum = 7, point = "TOPLEFT", }, --segment 4
35+
}
36+
37+
---------------------------------
38+
-- LOCAL FUNCTIONS
39+
---------------------------------
40+
41+
local function CreateRingSegment(ringFrame,i)
42+
43+
--scrollframe
44+
local scrollFrame = CreateFrame("ScrollFrame", ringFrame.name.."ScrollFrame"..i, ringFrame.lastParent)
45+
scrollFrame:SetSize(ringFrame.size/2,ringFrame.size/2)
46+
scrollFrame:SetPoint(ringSegmentSettings[i].point,ringFrame)
47+
scrollFrame.defaultRotation = ringSegmentSettings[i].defaultRotation
48+
scrollFrame.primeNum = ringSegmentSettings[i].primeNum
49+
scrollFrame.segmentId = i
50+
51+
--scrollchild
52+
local scrollChild = CreateFrame("Frame", ringFrame.name.."ScrollChild"..i, scrollFrame)
53+
scrollChild:SetSize(ringFrame.size/2,ringFrame.size/2)
54+
--scrollChild:SetBackdrop(cfg.backdrop)
55+
scrollFrame:SetScrollChild(scrollChild)
56+
scrollFrame.scrollChild = scrollChild
57+
58+
ringFrame.lastParent = scrollFrame
59+
tinsert(ringFrame.segments, scrollFrame)
60+
61+
end
62+
63+
--calculate the segment id based on direction, index and starting point
64+
local function CalculateRingSegmentID(start,direction,i)
65+
i = i - 1
66+
if direction == 0 then
67+
if start-i < 1 then
68+
return start-i+4
69+
else
70+
return start-i
71+
end
72+
else
73+
if start+i > 4 then
74+
return start+i-4
75+
else
76+
return start+i
77+
end
78+
end
79+
end
80+
81+
82+
---------------------------------
83+
-- rLibRing:FUNCTIONS
84+
---------------------------------
85+
86+
--create one ring frame containing a scrollFrame for each ring segment (4 segments per ring)
87+
88+
function rLibRing:CreateRingFrame(parent,size)
89+
90+
local ringFrame = CreateFrame("Frame", "$parentRingFrame", parent)
91+
ringFrame:SetPoint("CENTER")
92+
ringFrame:SetSize(size,size)
93+
ringFrame.size = size
94+
ringFrame.name = ringFrame:GetName()
95+
96+
ringFrame.segments = {}
97+
ringFrame.lastParent = ringFrame
98+
99+
for i=1, 4 do
100+
CreateRingSegment(ringFrame, i)
101+
end
102+
103+
return ringFrame
104+
105+
end
106+
107+
--create a ring table that references to the correct ringFrame segments
108+
function rLibRing:CreateRing(ringFrame,start,num,direction,radius,type)
109+
local ring = {}
110+
ring.size = ringFrame.size
111+
ring.start = start
112+
ring.type = type or "default"
113+
ring.num = num
114+
ring.direction = direction
115+
ring.modulo = 1
116+
ring.segments = {}
117+
ring.textures = {}
118+
for i=1, num do
119+
local id = CalculateRingSegmentID(start,direction,i)
120+
ring.segments[i] = ringFrame.semgents[id]
121+
ring.textures[i] = {}
122+
ring.textures[i].bg = CreateRingTexture()
123+
ring.textures[i].fill = CreateRingTexture()
124+
ring.textures[i].spark = CreateRingTexture()
125+
if type == "castring" then
126+
ring.textures[i].latency = CreateRingTexture()
127+
end
128+
ring.modulo = ring.modulo * ringFrame.segments[id].primeNum
129+
end
130+
return ring
131+
end
132+
133+
134+
135+
136+
---------------------------------
137+
-- REGISTER
138+
---------------------------------
139+
140+
_G["rLibRing"] = rLibRing

‎wow5.0/rLibRing/rLibRing.toc

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
## Interface: 50300
2+
## Author: zork
3+
## Title: rLibRing
4+
## Notes: A library for ring creation
5+
6+
core\core.lua

0 commit comments

Comments
 (0)
Please sign in to comment.