Compare with Previous |
Blame |
View Log
Nudger = class(Turbine.UI.Control);
function Nudger:Constructor(parent, font, value, minValue, maxValue, zeroPadDigits)
Turbine.UI.Control.Constructor(self);
self:SetParent(parent);
self.zeroPadDigits = zeroPadDigits or 1;
local function CreateButton(normalBackground, highlightedBackground)
local button = Turbine.UI.Control();
button:SetParent(self);
button:SetSize(10, 10);
button.normalBackground = normalBackground;
button.highlightedBackground = highlightedBackground;
button.MouseEnter = function(btn)
btn:SetBackground(btn.highlightedBackground);
end
button.MouseLeave = function(btn)
btn:SetBackground(btn.normalBackground);
end
button.MouseDown = function(btn)
btn:SetWantsUpdates(true);
btn.lastTime = Turbine.Engine.GetGameTime() + 0.25;
end
button.Update = function(btn)
local gameTime = Turbine.Engine.GetGameTime();
if ((gameTime - btn.lastTime) >= 0.1) then
btn:Action();
btn.lastTime = gameTime;
end
end
button.MouseUp = function(btn)
btn:SetWantsUpdates(false);
btn:Action();
end
button:SetBlendMode(Turbine.UI.BlendMode.Overlay);
button:MouseLeave();
return button;
end
local upButton = CreateButton(0x4100028C, 0x4100028D);
upButton.Action = function()
self.textBox:SetText(self.textBox:GetText() + 1);
self.textBox:Constrain();
DoCallbacks(self, "ValueChanged");
self.textBox:Focus();
end
self.upButton = upButton;
local textBox = Turbine.UI.Lotro.TextBox();
textBox:SetParent(self);
textBox:SetPosition(0, 12);
textBox:SetForeColor(Turbine.UI.Color.PaleGoldenrod);
textBox:SetFont(font);
textBox:SetTextAlignment(Turbine.UI.ContentAlignment.MiddleCenter);
textBox:SetMultiline(false);
textBox:SetHeight(22);
textBox.GetText = function(tb)
local value = Turbine.UI.Lotro.TextBox.GetText(tb);
return tonumber(value) or 0;
end
textBox.minValue = minValue;
textBox.maxValue = maxValue;
textBox.Constrain = function(tb)
local value = math.modf(tonumber(tb:GetText()));
if (tb.minValue) then
value = math.max(tb.minValue, value);
self.downButton:SetVisible(value > tb.minValue);
end
if (tb.maxValue) then
value = math.min(tb.maxValue, value);
self.upButton:SetVisible(value < tb.maxValue);
end
value = tostring(value);
local zerosNeeded = self.zeroPadDigits - value:len();
if (zerosNeeded > 0) then
value = string.rep("0", zerosNeeded) .. value;
end
if (value ~= tb:GetText()) then
tb:SetText(value);
end
end
textBox.FocusGained = function()
DoCallbacks(self, "FocusGained");
end
textBox.FocusLost = function(tb)
tb:Constrain();
DoCallbacks(self, "FocusLost");
DoCallbacks(self, "ValueChanged");
end
self.textBox = textBox;
local downButton = CreateButton(0x4100028E, 0x4100028F);
downButton:SetTop(36);
downButton.Action = function()
self.textBox:SetText(self.textBox:GetText() - 1);
self.textBox:Constrain();
self.textBox:Focus();
DoCallbacks(self, "ValueChanged");
end
self.downButton = downButton;
Turbine.UI.Control.SetHeight(self, 12 + 22 + 12);
self:SetText(value);
end
function Nudger:SetText(text)
self.textBox:SetText(text);
self.textBox:Constrain();
end
function Nudger:GetText()
return self.textBox:GetText();
end
function Nudger:SetSize(width, height)
self:SetWidth(width);
end
function Nudger:SetHeight(height)
-- Do nothing. Height is not adjustable.
end
function Nudger:SetWidth(width)
self.textBox:SetWidth(width);
local btnLeft = math.floor(0.5 + (width - 10) / 2);
self.upButton:SetLeft(btnLeft);
self.downButton:SetLeft(btnLeft);
end
Compare with Previous |
Blame
All times are GMT -5. The time now is 07:04 AM.