This repository was archived by the owner on Feb 1, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUI.lua
More file actions
158 lines (136 loc) · 4.38 KB
/
UI.lua
File metadata and controls
158 lines (136 loc) · 4.38 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
local _G = getfenv()
local Gamepad = _G.Gamepad
local L = Gamepad.Locales[_G.GetLocale()].Strings
local UI = CreateFrame('Frame', 'GamepadFrame', _G.UIParent)
Gamepad.UI = UI
UI:SetPoint('CENTER', 0, 0)
UI:SetWidth(64+64+16)
UI:SetHeight(64)
UI:SetBackdrop({
bgFile=[[Interface\Glues\Common\Glue-Tooltip-Background]],
edgeFile=[[Interface\Glues\Common\Glue-Tooltip-Border]],
tile = false,
tileSize = 64,
edgeSize = 16,
insets = { left = 8, right = 6, top = 6, bottom = 8 }
})
UI:SetMovable(true)
UI:SetClampedToScreen(true)
UI:EnableMouse(true)
UI:RegisterForDrag('LeftButton')
UI:SetScript('OnDragStart', function()
this:StartMoving()
end)
UI:SetScript('OnDragStop', function()
this:StopMovingOrSizing()
end)
do
local button_action = CreateFrame('CheckButton', 'GamepadActionButton', UI, 'ActionButtonTemplate')
UI.button_action = button_action
button_action:SetPoint('CENTER', 2, 1)
button_action.icon = _G[button_action:GetName()..'Icon']
button_action.cooldown = _G[button_action:GetName()..'Cooldown']
button_action.macroName = _G[button_action:GetName()..'Name']
button_action.normalTexture = _G[button_action:GetName()..'NormalTexture']
button_action.hotKey = _G[button_action:GetName()..'HotKey']
button_action.count = _G[button_action:GetName()..'Count']
button_action:SetScript('OnClick', function()
UseAction(Gamepad.currentActionID, 0)
end)
button_action:SetScript('OnEnter', function()
GameTooltip:SetOwner(this, 'ANCHOR_RIGHT')
GameTooltip:SetAction(Gamepad.currentActionID)
end)
button_action:SetScript('OnLeave', function()
GameTooltip:Hide()
end)
end
do
local button_previous = CreateFrame('Button', nil, UI, 'UIPanelButtonTemplate')
UI.button_previous = button_previous
button_previous:SetPoint('RIGHT', UI.button_action, 'LEFT', -5, 0)
button_previous:SetText('<')
button_previous:SetWidth(36)
button_previous:SetHeight(36)
button_previous:SetScript('OnClick', function()
UI.SetActionButton(-1)
end)
end
do
local button_next = CreateFrame('Button', nil, UI, 'UIPanelButtonTemplate')
UI.button_next = button_next
button_next:SetPoint('LEFT', UI.button_action, 'RIGHT', 5, 0)
button_next:SetText('>')
button_next:SetWidth(36)
button_next:SetHeight(36)
button_next:SetScript('OnClick', function()
UI.SetActionButton(1)
end)
end
function UI.Load()
UI.SetActionButton()
end
function UI.UpdateActionButton()
local texture = GetActionTexture(Gamepad.currentActionID)
if ( texture ) then
UI.button_action.icon:SetTexture(texture)
UI.button_action.icon:Show()
else
UI.button_action.icon:Hide()
end
UI.button_action.macroName:SetText(GetActionText(Gamepad.currentActionID))
UI.button_action.hotKey:SetText(Gamepad.currentActionID)
end
function UI.UpdateActionButtonState()
if ( IsCurrentAction(Gamepad.currentActionID) or IsAutoRepeatAction(Gamepad.currentActionID) ) then
UI.button_action:SetChecked(1)
else
UI.button_action:SetChecked(0)
end
end
function UI.UpdateActionButtonCooldown()
local start, duration, enable = GetActionCooldown(Gamepad.currentActionID)
CooldownFrame_SetTimer(UI.button_action.cooldown, start, duration, enable)
end
function UI.UpdateActionButtoUsable()
local isUsable, notEnoughMana = IsUsableAction(Gamepad.currentActionID)
if isUsable then
UI.button_action.icon:SetVertexColor(1.0, 1.0, 1.0)
UI.button_action.normalTexture:SetVertexColor(1.0, 1.0, 1.0)
elseif notEnoughMana then
UI.button_action.icon:SetVertexColor(0.5, 0.5, 1.0)
UI.button_action.normalTexture:SetVertexColor(0.5, 0.5, 1.0)
else
UI.button_action.icon:SetVertexColor(0.4, 0.4, 0.4)
UI.button_action.normalTexture:SetVertexColor(1.0, 1.0, 1.0)
end
end
function UI.UpdateActionButtoCount()
if IsConsumableAction(Gamepad.currentActionID) then
UI.button_action.count:SetText(GetActionCount(ActionButton_GetPagedID(this)))
else
UI.button_action.count:SetText('')
end
end
function UI.SetActionButton(direction)
if direction == 1 then
if Gamepad.currentAction == Gamepad.actionsLength then
Gamepad.currentAction = 1
else
Gamepad.currentAction = Gamepad.currentAction + 1
end
elseif direction == -1 then
if Gamepad.currentAction == 1 then
Gamepad.currentAction = Gamepad.actionsLength
else
Gamepad.currentAction = Gamepad.currentAction - 1
end
else
Gamepad.currentAction = 1
end
Gamepad.UpdateActionID()
UI.UpdateActionButton()
UI.UpdateActionButtoCount()
UI.UpdateActionButtoUsable()
UI.UpdateActionButtonCooldown()
end