1 |
131 |
MrJackdaw-1942 |
--Adds a small on-screen backpack counter |
2 |
|
MrJackdaw-1942 |
|
3 |
|
MrJackdaw-1942 |
--Add to button |
4 |
|
MrJackdaw-1942 |
|
5 |
|
MrJackdaw-1942 |
if Counter==nil then Counter={} end |
6 |
|
MrJackdaw-1942 |
if Counter.x==nil then Counter.x=100 end |
7 |
|
MrJackdaw-1942 |
if Counter.y==nil then Counter.y=100 end |
8 |
|
MrJackdaw-1942 |
if Counter.Scale==nil then Counter.Scale=1 end |
9 |
|
MrJackdaw-1942 |
if Counter.Show==nil then Counter.Show=true end |
10 |
|
MrJackdaw-1942 |
|
11 |
|
MrJackdaw-1942 |
--Structure; Window, Label, Icon. |
12 |
|
MrJackdaw-1942 |
|
13 |
|
MrJackdaw-1942 |
Count=Turbine.UI.Window() |
14 |
|
MrJackdaw-1942 |
Count:SetVisible(true) |
15 |
|
MrJackdaw-1942 |
Count:SetPosition(Counter.x,Counter.y) |
16 |
|
MrJackdaw-1942 |
Count:SetSize(35,14) |
17 |
|
MrJackdaw-1942 |
Count:SetMouseVisible(false) |
18 |
|
MrJackdaw-1942 |
|
19 |
|
MrJackdaw-1942 |
--Initialise bag count |
20 |
|
MrJackdaw-1942 |
Count.bag=0 |
21 |
|
MrJackdaw-1942 |
|
22 |
|
MrJackdaw-1942 |
for i=1,size do |
23 |
|
MrJackdaw-1942 |
local item = backpack:GetItem(i) |
24 |
|
MrJackdaw-1942 |
if item~=nil then Count.bag=Count.bag+1 end |
25 |
|
MrJackdaw-1942 |
end |
26 |
|
MrJackdaw-1942 |
|
27 |
|
MrJackdaw-1942 |
|
28 |
|
MrJackdaw-1942 |
Count.label=Turbine.UI.Label() |
29 |
|
MrJackdaw-1942 |
Count.label:SetBackColor( Turbine.UI.Color( 0.3,0,0,0.4 ) ) |
30 |
|
MrJackdaw-1942 |
Count.label:SetFont(Turbine.UI.Lotro.Font.TrajanProBold36) |
31 |
|
MrJackdaw-1942 |
Count.label:SetMultiline(false) |
32 |
|
MrJackdaw-1942 |
Count.label:SetTextAlignment( Turbine.UI.ContentAlignment.MiddleCenter ) |
33 |
|
MrJackdaw-1942 |
if Counter.Remain then |
34 |
|
MrJackdaw-1942 |
Count.label:SetText( size-Count.bag ) |
35 |
|
MrJackdaw-1942 |
else |
36 |
|
MrJackdaw-1942 |
Count.label:SetText( Count.bag.."/"..size ) |
37 |
|
MrJackdaw-1942 |
end |
38 |
|
MrJackdaw-1942 |
Count.label:SetMouseVisible (false) |
39 |
|
MrJackdaw-1942 |
Count.label:SetSize(35*36/14,36) |
40 |
|
MrJackdaw-1942 |
Count.label:SetParent(Count) |
41 |
|
MrJackdaw-1942 |
Count.label:SetStretchMode(1) |
42 |
|
MrJackdaw-1942 |
|
43 |
|
MrJackdaw-1942 |
Count.DragBar = Deusdictum.UI.DragBar( Count,"Count") |
44 |
|
MrJackdaw-1942 |
Count.DragBar:SetZOrder(9999) |
45 |
|
MrJackdaw-1942 |
|
46 |
|
MrJackdaw-1942 |
Count.Cover=Turbine.UI.Control() |
47 |
|
MrJackdaw-1942 |
Count.Cover:SetParent(Count) |
48 |
|
MrJackdaw-1942 |
Count.Cover:SetVisible(false) |
49 |
|
MrJackdaw-1942 |
|
50 |
|
MrJackdaw-1942 |
Count.SizeChanged=function() |
51 |
|
MrJackdaw-1942 |
Count.label:SetSize(35*Counter.Scale,14*Counter.Scale) |
52 |
|
MrJackdaw-1942 |
Count.Cover:SetSize(35*Counter.Scale,14*Counter.Scale) |
53 |
|
MrJackdaw-1942 |
end |
54 |
|
MrJackdaw-1942 |
|
55 |
|
MrJackdaw-1942 |
Count:SetSize(35*Counter.Scale,14*Counter.Scale) |
56 |
|
MrJackdaw-1942 |
Count.DragBar:Refresh() |
57 |
|
MrJackdaw-1942 |
|
58 |
|
MrJackdaw-1942 |
--When UI is unlocked then make the cover visible. |
59 |
|
MrJackdaw-1942 |
Count.DragEnable=function() |
60 |
|
MrJackdaw-1942 |
Count.Cover:SetVisible(true) |
61 |
|
MrJackdaw-1942 |
end |
62 |
|
MrJackdaw-1942 |
|
63 |
|
MrJackdaw-1942 |
Count.DragDisable=function() |
64 |
|
MrJackdaw-1942 |
Count.Cover:SetVisible(false) |
65 |
|
MrJackdaw-1942 |
end |
66 |
|
MrJackdaw-1942 |
|
67 |
|
MrJackdaw-1942 |
--Cover events - resize the Button. |
68 |
|
MrJackdaw-1942 |
Count.Cover.MouseDown=function(sender,args) |
69 |
|
MrJackdaw-1942 |
if ( args.Button == Turbine.UI.MouseButton.Left ) then |
70 |
|
MrJackdaw-1942 |
moving=true |
71 |
|
MrJackdaw-1942 |
else |
72 |
|
MrJackdaw-1942 |
Counter.Remain=not(Counter.Remain) |
73 |
|
MrJackdaw-1942 |
if Counter.Remain then |
74 |
|
MrJackdaw-1942 |
Count.label:SetText( size-Count.bag ) |
75 |
|
MrJackdaw-1942 |
else |
76 |
|
MrJackdaw-1942 |
Count.label:SetText( Count.bag.."/"..size ) |
77 |
|
MrJackdaw-1942 |
end |
78 |
|
MrJackdaw-1942 |
end |
79 |
|
MrJackdaw-1942 |
end |
80 |
|
MrJackdaw-1942 |
|
81 |
|
MrJackdaw-1942 |
Count.Cover.MouseUp=function(sender,args) |
82 |
|
MrJackdaw-1942 |
moving=false |
83 |
|
MrJackdaw-1942 |
end |
84 |
|
MrJackdaw-1942 |
|
85 |
|
MrJackdaw-1942 |
Count.Cover.MouseMove=function(sender,args) |
86 |
|
MrJackdaw-1942 |
if moving then |
87 |
|
MrJackdaw-1942 |
local x,y=Count.Cover:GetMousePosition() |
88 |
|
MrJackdaw-1942 |
|
89 |
|
MrJackdaw-1942 |
Counter.Scale=x/35 |
90 |
|
MrJackdaw-1942 |
if Counter.Scale<1 then Counter.Scale=1 end |
91 |
|
MrJackdaw-1942 |
|
92 |
|
MrJackdaw-1942 |
Count:SetSize(35*Counter.Scale,14*Counter.Scale) |
93 |
|
MrJackdaw-1942 |
Count.DragBar:Refresh() |
94 |
|
MrJackdaw-1942 |
end |
95 |
|
MrJackdaw-1942 |
end |
96 |
|
MrJackdaw-1942 |
|
97 |
|
MrJackdaw-1942 |
Count.PositionChanged=function() |
98 |
|
MrJackdaw-1942 |
Counter.x,Counter.y=Count:GetPosition() |
99 |
|
MrJackdaw-1942 |
end |
100 |
|
MrJackdaw-1942 |
|
101 |
|
MrJackdaw-1942 |
Count.Add=function() |
102 |
|
MrJackdaw-1942 |
Count.bag=Count.bag+1 |
103 |
|
MrJackdaw-1942 |
if Counter.Remain then |
104 |
|
MrJackdaw-1942 |
Count.label:SetText( size-Count.bag ) |
105 |
|
MrJackdaw-1942 |
else |
106 |
|
MrJackdaw-1942 |
Count.label:SetText( Count.bag.."/"..size ) |
107 |
|
MrJackdaw-1942 |
end |
108 |
|
MrJackdaw-1942 |
end |
109 |
|
MrJackdaw-1942 |
|
110 |
|
MrJackdaw-1942 |
Count.Remove=function() |
111 |
|
MrJackdaw-1942 |
Count.bag=Count.bag-1 |
112 |
|
MrJackdaw-1942 |
if Counter.Remain then |
113 |
|
MrJackdaw-1942 |
Count.label:SetText( size-Count.bag ) |
114 |
|
MrJackdaw-1942 |
else |
115 |
|
MrJackdaw-1942 |
Count.label:SetText( Count.bag.."/"..size ) |
116 |
|
MrJackdaw-1942 |
end |
117 |
|
MrJackdaw-1942 |
end |
118 |
|
MrJackdaw-1942 |
|
119 |
|
MrJackdaw-1942 |
AddCallback(backpack, "ItemAdded", Count.Add) |
120 |
|
MrJackdaw-1942 |
AddCallback(backpack, "ItemRemoved", Count.Remove) |