-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDressingRoom.lua
More file actions
193 lines (167 loc) · 6.4 KB
/
DressingRoom.lua
File metadata and controls
193 lines (167 loc) · 6.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
local addon, ns = ...
local initWidth = 200
local initHeight = 200
local xStep = 0.1 -- per wheel step
local yStep = 0.005 -- per pixel
local zStep = 0.003 -- per pixel
local facingStep = math.rad(0.75) -- per pixel
local modelX = {min = 0, max = 5}
local modelY = {min = -1, max = 1}
local modelZ = {min = -5, max = 5}
local frameBackdrop = {
bgFile = "Interface\\ChatFrame\\ChatFrameBackground",
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
tile = true, tileSize = 16, edgeSize = 16,
insets = { left = 3, right = 3, top = 3, bottom = 3 }
}
local function Model_OnMouseWheel(self, delta)
local x, y, z = self:GetPosition()
x = x + delta * xStep
local max, min = modelX.max, modelX.min
x = x > max and max or x
x = x < min and min or x
self:SetPosition(x, y ,z)
end
function ns:CreateDressingRoom(name, parent)
local frame = CreateFrame("Frame", name, parent)
frame:SetPoint("CENTER", UIParent, "CENTER", 0, 0)
frame:EnableMouse(false)
frame:SetMovable(true)
frame:SetResizable(true)
frame:SetSize(initWidth, initHeight)
frame:SetMinResize(initWidth, initHeight)
frame:SetMaxResize(initWidth, initHeight)
frame:SetFrameStrata("FULLSCREEN_DIALOG")
frame:SetBackdrop(frameBackdrop)
frame:SetBackdropColor(0.25, 0.25, 0.25, 1)
local model = CreateFrame("DressUpModel", nil, frame)
model:SetPoint("TOPLEFT", frameBackdrop.insets.left * 2, -frameBackdrop.insets.top * 2)
model:SetPoint("BOTTOMRIGHT", -frameBackdrop.insets.right * 2, frameBackdrop.insets.bottom * 2)
model:EnableMouse(false)
model:EnableMouseWheel(true)
model:SetUnit("player")
model:SetScript("OnMouseWheel", Model_OnMouseWheel)
local draggingDummy = CreateFrame("Frame", nil, model)
draggingDummy:SetPoint("TOPLEFT")
draggingDummy:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", 0, 24)
draggingDummy:EnableMouse(true)
--draggingDummy:SetBackdrop(bacgroundBackdrop)
draggingDummy:RegisterForDrag("LeftButton", "RightButton")
draggingDummy:SetMovable(true)
draggingDummy:SetScript("OnDragStart", function(self, button)
self:StartMoving()
local cursorX, cursorY = GetCursorPosition()
if button == "LeftButton" then
draggingDummy:RegisterForDrag("LeftButton")
self:SetScript("OnUpdate", function(self, elapsed)
local newX, newY = GetCursorPosition()
local deltaX = newX - cursorX
model:SetFacing(model:GetFacing() + deltaX * facingStep)
cursorX, cursorY = newX, newY
local x, y, z = model:GetPosition()
end)
elseif button == "RightButton" and not IsShiftKeyDown() then
draggingDummy:RegisterForDrag("RightButton")
self:SetScript("OnUpdate", function(self, elapsed)
local newX, newY = GetCursorPosition()
local deltaY = newY - cursorY
local x, y, z = model:GetPosition()
local zOffset = zStep * deltaY
z = z + zOffset
local max, min = modelZ.max, modelZ.min
z = z > max and max or z
z = z < min and min or z
model:SetPosition(x, y, z)
cursorX, cursorY = newX, newY
end)
elseif button == "RightButton" and IsShiftKeyDown() then
draggingDummy:RegisterForDrag("RightButton")
self:SetScript("OnUpdate", function(self, elapsed)
local newX, newY = GetCursorPosition()
local deltaX = newX - cursorX
local x, y, z = model:GetPosition()
local yOffset = yStep * deltaX
y = y + yOffset
local max, min = modelY.max, modelY.min
y = y > max and max or y
y = y < min and min or y
model:SetPosition(x, y, z)
cursorX, cursorY = newX, newY
end)
end
self:SetScript("OnReceiveDrag", function(self)
self:StopMovingOrSizing()
self:SetScript("OnUpdate", nil)
self:ClearAllPoints()
self:SetAllPoints()
draggingDummy:RegisterForDrag("LeftButton", "RightButton")
end)
end)
local dbgFrame = CreateFrame("Frame", nil, model)
dbgFrame:Hide()
dbgFrame:EnableMouse(false)
dbgFrame:EnableMouseWheel(false)
dbgFrame:SetAllPoints()
local dbgInfo = dbgFrame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
dbgInfo:SetAllPoints()
dbgInfo:SetJustifyH("LEFT")
dbgInfo:SetJustifyV("BOTTOM")
function frame:Undress()
model:Undress()
end
function frame:Reset()
local x, y, z = model:GetPosition()
local facing = model:GetFacing()
model:SetPosition(0, 0, 0)
model:SetFacing(0)
model:ClearModel()
model:SetUnit("player")
model:SetPosition(x, y, z)
model:SetFacing(facing)
end
function frame:TryOn(...)
model:TryOn(...)
end
function frame:ShowDebug()
dbgFrame:Show()
dbgFrame:SetScript("OnUpdate", function(self, elapsed)
local facing = model:GetFacing()
local x, y, z = model:GetPosition()
dbgInfo:SetFormattedText("Facing = %f\nX = %f\nY = %f\nZ = %f", facing, x, y, z)
end)
end
function frame:HideDebug()
dbgFrame:Hide()
dbgFrame:SetScript("OnUpdate", nil)
end
function frame:SetSequence(...)
model:SetSequence(...)
end
function frame:SetPosition(...)
local x, y, z = ...
x = (x > modelX.max and modelX.min) or (x < modelX.min and modelX.min) or x
y = (y > modelY.max and modelY.min) or (y < modelY.min and modelY.min) or y
z = (z > modelZ.max and modelZ.min) or (z < modelZ.min and modelZ.min) or z
model:SetPosition(x, y, z)
end
function frame:GetPosition()
return model:GetPosition()
end
function frame:SetFacing(...)
model:SetFacing(...)
end
function frame:GetFacing()
return model:GetFacing()
end
local oldSetScript = frame.SetScript
function frame:SetScript(event, ...)
if event == "OnUpdateModel" then
local func = ...
model:SetScript(event, function(self) func(frame) end)
else
oldSetScript(self, event, ...)
end
end
model:SetScript("OnShow", function(self) frame:Reset() end)
return frame
end