1 |
131 |
MrJackdaw-1942 |
--Adds a small on-screen backpack counter |
2 |
144 |
MrJackdaw-1942 |
--No longer tests for accuracy of the count, as this appears to have been fixed. |
3 |
131 |
MrJackdaw-1942 |
|
4 |
|
MrJackdaw-1942 |
if Counter==nil then Counter={} end |
5 |
|
MrJackdaw-1942 |
if Counter.x==nil then Counter.x=100 end |
6 |
|
MrJackdaw-1942 |
if Counter.y==nil then Counter.y=100 end |
7 |
|
MrJackdaw-1942 |
if Counter.Scale==nil then Counter.Scale=1 end |
8 |
|
MrJackdaw-1942 |
if Counter.Show==nil then Counter.Show=true end |
9 |
|
MrJackdaw-1942 |
|
10 |
132 |
MrJackdaw-1942 |
--Structure; Window, Cover, Label |
11 |
131 |
MrJackdaw-1942 |
|
12 |
|
MrJackdaw-1942 |
Count=Turbine.UI.Window() |
13 |
|
MrJackdaw-1942 |
Count:SetVisible(true) |
14 |
|
MrJackdaw-1942 |
Count:SetPosition(Counter.x,Counter.y) |
15 |
|
MrJackdaw-1942 |
Count:SetMouseVisible(false) |
16 |
143 |
MrJackdaw-1942 |
Count:SetBackColor( Turbine.UI.Color( 0.3,0,0,0.4 ) ) |
17 |
131 |
MrJackdaw-1942 |
|
18 |
|
MrJackdaw-1942 |
--Initialise bag count |
19 |
|
MrJackdaw-1942 |
Count.bag=0 |
20 |
|
MrJackdaw-1942 |
|
21 |
|
MrJackdaw-1942 |
for i=1,size do |
22 |
|
MrJackdaw-1942 |
local item = backpack:GetItem(i) |
23 |
|
MrJackdaw-1942 |
if item~=nil then Count.bag=Count.bag+1 end |
24 |
|
MrJackdaw-1942 |
end |
25 |
|
MrJackdaw-1942 |
|
26 |
132 |
MrJackdaw-1942 |
--Function to set the label text. The hide/show stops an over-writing bug. |
27 |
|
MrJackdaw-1942 |
function SetLabel() |
28 |
|
MrJackdaw-1942 |
Count.label:SetVisible(false) |
29 |
|
MrJackdaw-1942 |
if Counter.Remain then |
30 |
|
MrJackdaw-1942 |
Count.label:SetText( size-Count.bag ) |
31 |
|
MrJackdaw-1942 |
else |
32 |
|
MrJackdaw-1942 |
Count.label:SetText( Count.bag.."/"..size ) |
33 |
|
MrJackdaw-1942 |
end |
34 |
|
MrJackdaw-1942 |
Count.label:SetVisible(true) |
35 |
|
MrJackdaw-1942 |
end |
36 |
131 |
MrJackdaw-1942 |
|
37 |
132 |
MrJackdaw-1942 |
--Set the size of the window |
38 |
|
MrJackdaw-1942 |
function SetCountSize() |
39 |
|
MrJackdaw-1942 |
if Counter.Remain then |
40 |
|
MrJackdaw-1942 |
Count:SetSize(20*Counter.Scale,14*Counter.Scale) |
41 |
|
MrJackdaw-1942 |
else |
42 |
|
MrJackdaw-1942 |
Count:SetSize(36*Counter.Scale,14*Counter.Scale) |
43 |
|
MrJackdaw-1942 |
end |
44 |
|
MrJackdaw-1942 |
end |
45 |
|
MrJackdaw-1942 |
|
46 |
131 |
MrJackdaw-1942 |
Count.label=Turbine.UI.Label() |
47 |
|
MrJackdaw-1942 |
Count.label:SetFont(Turbine.UI.Lotro.Font.TrajanProBold36) |
48 |
|
MrJackdaw-1942 |
Count.label:SetMultiline(false) |
49 |
|
MrJackdaw-1942 |
Count.label:SetTextAlignment( Turbine.UI.ContentAlignment.MiddleCenter ) |
50 |
|
MrJackdaw-1942 |
Count.label:SetMouseVisible (false) |
51 |
132 |
MrJackdaw-1942 |
Count.label:SetSize(36*36/14,36) |
52 |
131 |
MrJackdaw-1942 |
Count.label:SetParent(Count) |
53 |
|
MrJackdaw-1942 |
Count.label:SetStretchMode(1) |
54 |
|
MrJackdaw-1942 |
|
55 |
|
MrJackdaw-1942 |
Count.DragBar = Deusdictum.UI.DragBar( Count,"Count") |
56 |
|
MrJackdaw-1942 |
Count.DragBar:SetZOrder(9999) |
57 |
|
MrJackdaw-1942 |
|
58 |
|
MrJackdaw-1942 |
Count.Cover=Turbine.UI.Control() |
59 |
|
MrJackdaw-1942 |
Count.Cover:SetParent(Count) |
60 |
|
MrJackdaw-1942 |
Count.Cover:SetVisible(false) |
61 |
|
MrJackdaw-1942 |
|
62 |
|
MrJackdaw-1942 |
Count.SizeChanged=function() |
63 |
132 |
MrJackdaw-1942 |
Count.label:SetSize(36*Counter.Scale,14*Counter.Scale) |
64 |
|
MrJackdaw-1942 |
Count.Cover:SetSize(Count:GetSize()) |
65 |
|
MrJackdaw-1942 |
Count.DragBar:Refresh() |
66 |
|
MrJackdaw-1942 |
if Counter.Remain then |
67 |
|
MrJackdaw-1942 |
Count.label:SetPosition( -8.5*Counter.Scale,0) |
68 |
|
MrJackdaw-1942 |
else |
69 |
|
MrJackdaw-1942 |
Count.label:SetPosition(0,0) |
70 |
|
MrJackdaw-1942 |
end |
71 |
131 |
MrJackdaw-1942 |
end |
72 |
|
MrJackdaw-1942 |
|
73 |
|
MrJackdaw-1942 |
--When UI is unlocked then make the cover visible. |
74 |
|
MrJackdaw-1942 |
Count.DragEnable=function() |
75 |
|
MrJackdaw-1942 |
Count.Cover:SetVisible(true) |
76 |
|
MrJackdaw-1942 |
end |
77 |
|
MrJackdaw-1942 |
|
78 |
|
MrJackdaw-1942 |
Count.DragDisable=function() |
79 |
|
MrJackdaw-1942 |
Count.Cover:SetVisible(false) |
80 |
|
MrJackdaw-1942 |
end |
81 |
|
MrJackdaw-1942 |
|
82 |
|
MrJackdaw-1942 |
--Cover events - resize the Button. |
83 |
|
MrJackdaw-1942 |
Count.Cover.MouseDown=function(sender,args) |
84 |
|
MrJackdaw-1942 |
if ( args.Button == Turbine.UI.MouseButton.Left ) then |
85 |
|
MrJackdaw-1942 |
moving=true |
86 |
|
MrJackdaw-1942 |
else |
87 |
|
MrJackdaw-1942 |
Counter.Remain=not(Counter.Remain) |
88 |
|
MrJackdaw-1942 |
if Counter.Remain then |
89 |
132 |
MrJackdaw-1942 |
Count:SetSize(20*Counter.Scale,14*Counter.Scale) |
90 |
131 |
MrJackdaw-1942 |
else |
91 |
132 |
MrJackdaw-1942 |
Count:SetSize(36*Counter.Scale,14*Counter.Scale) |
92 |
131 |
MrJackdaw-1942 |
end |
93 |
132 |
MrJackdaw-1942 |
SetLabel() |
94 |
131 |
MrJackdaw-1942 |
end |
95 |
|
MrJackdaw-1942 |
end |
96 |
|
MrJackdaw-1942 |
|
97 |
|
MrJackdaw-1942 |
Count.Cover.MouseUp=function(sender,args) |
98 |
|
MrJackdaw-1942 |
moving=false |
99 |
|
MrJackdaw-1942 |
end |
100 |
|
MrJackdaw-1942 |
|
101 |
|
MrJackdaw-1942 |
Count.Cover.MouseMove=function(sender,args) |
102 |
|
MrJackdaw-1942 |
if moving then |
103 |
|
MrJackdaw-1942 |
local x,y=Count.Cover:GetMousePosition() |
104 |
|
MrJackdaw-1942 |
|
105 |
132 |
MrJackdaw-1942 |
Counter.Scale=y/14 |
106 |
131 |
MrJackdaw-1942 |
if Counter.Scale<1 then Counter.Scale=1 end |
107 |
|
MrJackdaw-1942 |
|
108 |
132 |
MrJackdaw-1942 |
SetCountSize() |
109 |
131 |
MrJackdaw-1942 |
end |
110 |
|
MrJackdaw-1942 |
end |
111 |
|
MrJackdaw-1942 |
|
112 |
|
MrJackdaw-1942 |
Count.PositionChanged=function() |
113 |
|
MrJackdaw-1942 |
Counter.x,Counter.y=Count:GetPosition() |
114 |
|
MrJackdaw-1942 |
end |
115 |
|
MrJackdaw-1942 |
|
116 |
144 |
MrJackdaw-1942 |
--Functions to watch for the addition or subtraction of items. |
117 |
142 |
MrJackdaw-1942 |
Count.Add=function(sender,args) |
118 |
132 |
MrJackdaw-1942 |
--Turbine.Shell.WriteLine("Count.Add") |
119 |
142 |
MrJackdaw-1942 |
|
120 |
131 |
MrJackdaw-1942 |
Count.bag=Count.bag+1 |
121 |
132 |
MrJackdaw-1942 |
SetLabel() |
122 |
131 |
MrJackdaw-1942 |
end |
123 |
|
MrJackdaw-1942 |
|
124 |
142 |
MrJackdaw-1942 |
Count.Remove=function(sender,args) |
125 |
132 |
MrJackdaw-1942 |
--Turbine.Shell.WriteLine("Count.Remove") |
126 |
131 |
MrJackdaw-1942 |
Count.bag=Count.bag-1 |
127 |
132 |
MrJackdaw-1942 |
SetLabel() |
128 |
|
MrJackdaw-1942 |
end |
129 |
|
MrJackdaw-1942 |
|
130 |
142 |
MrJackdaw-1942 |
Count.Move=function(sender,args) |
131 |
|
MrJackdaw-1942 |
--Turbine.Shell.WriteLine("Count.Move") |
132 |
|
MrJackdaw-1942 |
|
133 |
|
MrJackdaw-1942 |
--I have no faith in this hack but... it is the only way I have found to fix the new turbine behaviour! |
134 |
|
MrJackdaw-1942 |
|
135 |
|
MrJackdaw-1942 |
local n=0 |
136 |
|
MrJackdaw-1942 |
for i=1,size do |
137 |
|
MrJackdaw-1942 |
local item = backpack:GetItem(i) |
138 |
|
MrJackdaw-1942 |
if item~=nil then n=n+1 end |
139 |
|
MrJackdaw-1942 |
end |
140 |
|
MrJackdaw-1942 |
|
141 |
|
MrJackdaw-1942 |
--Turbine.Shell.WriteLine(n.." "..Count.bag) |
142 |
|
MrJackdaw-1942 |
|
143 |
|
MrJackdaw-1942 |
if Count.bag>n then Count.bag=Count.bag-1 end |
144 |
|
MrJackdaw-1942 |
|
145 |
|
MrJackdaw-1942 |
SetLabel() |
146 |
|
MrJackdaw-1942 |
end |
147 |
|
MrJackdaw-1942 |
|
148 |
132 |
MrJackdaw-1942 |
AddCallback(backpack, "ItemAdded", Count.Add) |
149 |
|
MrJackdaw-1942 |
AddCallback(backpack, "ItemRemoved", Count.Remove) |
150 |
142 |
MrJackdaw-1942 |
AddCallback(backpack, "ItemMoved", Count.Move) |
151 |
132 |
MrJackdaw-1942 |
|
152 |
|
MrJackdaw-1942 |
--Initialise the size, label and back colour. |
153 |
|
MrJackdaw-1942 |
SetCountSize() |
154 |
|
MrJackdaw-1942 |
SetLabel() |
155 |
139 |
MrJackdaw-1942 |
|
156 |
|
MrJackdaw-1942 |
--This fixes a very odd bug that has crept in - I have no idea what is causing it, but it is most annoying. |
157 |
|
MrJackdaw-1942 |
--The label just doesn't seem to scale properly... |
158 |
|
MrJackdaw-1942 |
Count.label:SetSize(36*Counter.Scale,14*Counter.Scale) |