lotrointerface.com
Search Downloads

LoTROInterface SVN KragenBars

[/] [branches/] [3.11/] [UI/] [Tooltip.lua] - Rev 40

Go to most recent revision | Compare with Previous | Blame | View Log

import "Turbine.UI";

Tooltip = class(Turbine.UI.Window);

-- colors
Tooltip.BackgroundColor = Turbine.UI.Color(.925, 0, 0, 0);

function Tooltip:Constructor()
    Turbine.UI.Window.Constructor(self);
    self:SetMouseVisible(false);
    self:SetVisible(false);
    self:SetZOrder(100);
    
    -- center
    self.center = Turbine.UI.Control();
    self.center:SetParent(self);
    self.center:SetBackColor(Tooltip.BackgroundColor);

    -- label
    self.label = KragenPlugs.UI.Label();
    self.label:SetParent(self);
    self.label:SetMultiline(true);
    self.label:SetFont(Turbine.UI.Lotro.Font.TrajanPro16);
    self.label:SetTextAlignment(Turbine.UI.ContentAlignment.TopLeft);
    self.label:SetBackColor(Tooltip.BackgroundColor);

    -- top left corner
    self.topLeft = Turbine.UI.Control();
    self.topLeft:SetParent(self);
    self.topLeft:SetSize(19, 19);
    self.topLeft:SetMouseVisible(false);
    self.topLeft:SetBlendMode(Turbine.UI.BlendMode.AlphaBlend);
    self.topLeft:SetBackground("KragenPlugs/UI/Resources/basepanel_topleft.tga");

    -- topRight
    self.topRight = Turbine.UI.Control();
    self.topRight:SetParent(self);
    self.topRight:SetSize(19, 19);
    self.topRight:SetMouseVisible(false);
    self.topRight:SetBlendMode(Turbine.UI.BlendMode.AlphaBlend);
    self.topRight:SetBackground("KragenPlugs/UI/Resources/basepanel_topright.tga");
    
    -- bottomLeft
    self.bottomLeft = Turbine.UI.Control();
    self.bottomLeft:SetParent(self);
    self.bottomLeft:SetSize(19, 19);
    self.bottomLeft:SetMouseVisible(false);
    self.bottomLeft:SetBlendMode(Turbine.UI.BlendMode.AlphaBlend);
    self.bottomLeft:SetBackground("KragenPlugs/UI/Resources/basepanel_bottomleft.tga");

    -- bottomRight
    self.bottomRight = Turbine.UI.Control();
    self.bottomRight:SetParent(self);
    self.bottomRight:SetSize(19, 19);
    self.bottomRight:SetMouseVisible(false);
    self.bottomRight:SetBlendMode(Turbine.UI.BlendMode.AlphaBlend);
    self.bottomRight:SetBackground("KragenPlugs/UI/Resources/basepanel_bottomright.tga");

    -- top side
    self.top = Turbine.UI.Control();
    self.top:SetParent(self);
    self.top:SetSize(0, 3);
    self.top:SetMouseVisible(false);
    self.top:SetBlendMode(Turbine.UI.BlendMode.AlphaBlend);
    self.top:SetBackground("KragenPlugs/UI/Resources/basepanel_topmid.tga");

    -- left side
    self.left = Turbine.UI.Control();
    self.left:SetParent(self);
    self.left:SetSize(3, 0);
    self.left:SetMouseVisible(false);
    self.left:SetBlendMode(Turbine.UI.BlendMode.AlphaBlend);
    self.left:SetBackground("KragenPlugs/UI/Resources/basepanel_midleft.tga");

    -- right side
    self.right = Turbine.UI.Control();
    self.right:SetParent(self);
    self.right:SetSize(3, 0);
    self.right:SetMouseVisible(false);
    self.right:SetBlendMode(Turbine.UI.BlendMode.AlphaBlend);
    self.right:SetBackground("KragenPlugs/UI/Resources/basepanel_midright.tga");
    
    -- bottom side
    self.bottom = Turbine.UI.Control();
    self.bottom:SetParent(self);
    self.bottom:SetSize(0, 3);
    self.bottom:SetMouseVisible(false);
    self.bottom:SetBlendMode(Turbine.UI.BlendMode.AlphaBlend);
    self.bottom:SetBackground("KragenPlugs/UI/Resources/basepanel_bottommid.tga");
end

function Tooltip:SetText(text)
    self.label:SetText(text);
end

function Tooltip:SetControl(control)
    self.control = control;
    -- once mouse hover works we can get rid of the timer and mouse enter
    self.timer = KragenPlugs.Utils.Timer(.450);
    self.timer.Signal = function(sender, args)
        KragenPlugs.Utils.ExecuteListener(self.control, "MouseHover", {});
    end
    
    KragenPlugs.Utils.AddListener(self.control, "MouseEnter", function(sender, args)
        self.timer:Start();
    end);
    
    KragenPlugs.Utils.AddListener(self.control, "MouseHover", function(sender, args)
        local x, y = Turbine.UI.Display.GetMousePosition();
        x = x + 32;
        y = y + 32;
        x, y = KragenPlugs.Utils.ValidatePosition(x, y, self:GetSize());
        self:SetPosition(x, y);
        self:SetVisible(true);
    end);
    
    KragenPlugs.Utils.AddListener(self.control, "MouseLeave", function(sender, args)
        self.timer:Stop();
        self:SetVisible(false);
    end);
end

function Tooltip:SetSize(width, height)
    -- turbine default tooltips are 480 in size
    width = math.max(width, 38);
    height = math.max(height, 22);

    Turbine.UI.Window.SetSize(self, width, height);
end

function Tooltip:SizeChanged(args)
    local width, height = self:GetSize();
    
    -- special case to prevent the shadows on the corners from overlapping
    if (height < 38) then
        self.topLeft:SetPosition(0, 0);
        self.top:SetPosition(19, 0);
        self.topRight:SetPosition(width - 19, 0);
        self.bottom:SetPosition(1, height - 3);
        self.left:SetPosition(0, 19);
        self.right:SetPosition(width - 3, 19);
        self.center:SetPosition(3, 3);
        self.label:SetPosition(7, 3);
        
        self.top:SetWidth(width - 38);
        self.bottom:SetWidth(width - 2);
        self.left:SetHeight(height - 22);
        self.right:SetHeight(height - 22);
        self.center:SetSize(width - 6, height - 6);
        self.label:SetSize(width - 14, height - 6);
        self.bottomLeft:SetSize(0, 0);
        self.bottomRight:SetSize(0, 0);
    else
        self.topLeft:SetPosition(0, 0);
        self.top:SetPosition(19, 0);
        self.topRight:SetPosition(width - 19, 0);
        self.bottomLeft:SetPosition(0, height - 19);
        self.bottom:SetPosition(19, height - 3);
        self.bottomRight:SetPosition(width - 19, height - 19);
        self.left:SetPosition(0, 19);
        self.right:SetPosition(width - 3, 19);
        self.center:SetPosition(3, 3);
        self.label:SetPosition(7, 3);
        
        self.top:SetWidth(width - 38);
        self.bottom:SetWidth(width - 38);
        self.left:SetHeight(height - 38);
        self.right:SetHeight(height - 38);
        self.center:SetSize(width - 6, height - 6);
        self.label:SetSize(width - 14, height - 6);
    end
end

Go to most recent revision | Compare with Previous | Blame


All times are GMT -5. The time now is 05:12 PM.


Our Network
EQInterface | EQ2Interface | Minion | WoWInterface | ESOUI | LoTROInterface | MMOUI | Swtorui