lotrointerface.com
Search Downloads

LoTROInterface SVN KragenBars

[/] [trunk/] [KragenPlugs/] [KragenBars/] [Main.lua] - Rev 135

Compare with Previous | Blame | View Log

import "Turbine.UI";
import "Turbine.UI.Lotro";
import "KragenPlugs.Utils";
import "KragenPlugs.KragenBars";

-- load settings file
function LoadSettings()
        -- Set main version number
        vars = { };
        vars.vers = 5.08;
        vars.player = Turbine.Gameplay.LocalPlayer.GetInstance();
        vars.playerlevel = vars.player:GetLevel();
        vars.effects = vars.player:GetEffects();
        vars.classid = vars.player:GetClass();
        vars.classattr = vars.player:GetClassAttributes();
                vars.locale = Turbine.Engine.GetLocale();
                
                limbo = Turbine.UI.Window();
                limbo:SetPosition(-35, -35);
                limbo:SetVisible(false);
                
                settings = DecodeObject(Turbine.PluginData.Load( Turbine.DataScope.Character, "KragenBarsSettings" ));
        
        -- declare settings as a table and set default opacity
        if ( type( settings ) ~= "table" ) then
                settings = { };
                settings.opacity = 1;
                settings.lockslots = false;
                settings.snaptogrid = true;
                                settings.gridspacing = 35;
                                settings.userbars = 0;
                                settings.vers = vars.vers;
                                if(settings.language == nil) then
                                        if (vars.locale == "fr") then
                                                settings.language = 2;
                                        elseif (vars.locale == "de") then
                                                settings.language = 3;
                                        else
                                                settings.language = 1;
                                        end
                                end
        end
        
        -- if version is not declared then wipe settings file and set version number
                -- if version <3.00 (prior versions had string version number) then add required settings
        if (settings.vers == nil or type(settings.vers) == "string" or settings.vers < 3.00) then
                        settings = nil;
            settings = { };
            settings.vers = vars.vers;
            settings.opacity = 1;
            settings.lockslots = false;
            settings.snaptogrid = true;
                        settings.advanceonclick = false;
                        settings.gridspacing = 35;
                        settings.userbars = 0;
                        settings.kbbutton = { x = 10, y = 10 };
                        if(settings.language == nil) then
                                if (vars.locale == "fr") then
                                        settings.language = 2;
                                elseif (vars.locale == "de") then
                                        settings.language = 3;
                                else
                                        settings.language = 1;
                                end
                        end
            SaveSettings();
                elseif (settings.vers < 3.20) then
                        settings.gridspacing = 35;
                        settings.userbars = 0;
                        settings.kbbutton = { x = 10, y = 10 };
                        if(settings.language == nil) then
                                if (vars.locale == "fr") then
                                        settings.language = 2;
                                elseif (vars.locale == "de") then
                                        settings.language = 3;
                                else
                                        settings.language = 1;
                                end
                        end
                elseif (settings.vers < 4.00) then
                        settings.gridspacing = 35;
                        settings.userbars = 0;
                        settings.kbbutton = { x = 10, y = 10 };


                end
                
                if (settings.kbbutton == nil) then
                        settings.kbbutton = { x = 10, y = 10 };
                end

        if (vars.classid == 40) then
            vars.playerclass = "Burglar";
            KragenBars = BurglarBars();
        elseif (vars.classid == 24) then
            vars.playerclass = "Captain";
            KragenBars = CaptainBars();
        elseif (vars.classid == 172) then
            vars.playerclass = "Champion";
            KragenBars = ChampionBars();
        elseif (vars.classid == 23) then
            vars.playerclass = "Guardian";
            KragenBars = GuardianBars();
        elseif (vars.classid == 162) then
            vars.playerclass = "Hunter";
            KragenBars = HunterBars();
        elseif (vars.classid == 185) then
            vars.playerclass = "Loremaster";
            KragenBars = LoreBars();
        elseif (vars.classid == 31) then
            vars.playerclass = "Minstrel";
            KragenBars = MiniBars();
        elseif (vars.classid == 193) then
            vars.playerclass = "Runekeeper";
            KragenBars = RuneBars();
        elseif (vars.classid == 194) then
            vars.playerclass = "Warden";
                        Turbine.Shell.WriteLine("KragenBars: Warden is not currently implemented in KragenBars.  Look for this feature in a future version.");
            -- KragenBars = WardenBars();
        end        

                Turbine.Shell.WriteLine("KragenBars: Loaded version " ..vars.vers);

        
end

-- save to settings file
function SaveSettings()
    Turbine.PluginData.Save( Turbine.DataScope.Character, "KragenBarsSettings", EncodeObject(settings) );
end

function EncodeObject(obj)
        if ((vars.locale == "de" or vars.locale == "fr") and obj ~= nil) then
                local encoded = {};
                local function _copyObject(obj)
                        local function _encodeObject(obj)
                                if (type(obj) == "number") then return (("<num>%f</num>"):format(obj)); else return obj end;
                        end
                        if (type(obj) ~= "table") then 
                                return _encodeObject(obj);
                        elseif (encoded[obj] ~= nil) then
                                return encoded[obj];
                        end
                        local newtable = { };
                        for k,v in pairs(obj) do
                                local key = _copyObject(k);
                                local value = _copyObject(v);
                                newtable[key] = value;
                                encoded[obj] = newtable[key];
                        end
                        return newtable;
                end
                
                return _copyObject(obj);
        else
                return obj;
        end
end

function DecodeObject(data)
        if ((vars.locale == "de" or vars.locale == "fr") and data ~= nil) then
                local decoded = { };
                local function _copyObject(obj)
                        local function _decodeObject(obj)
                                if (type(obj) == "string") then 
                                        local match = obj:match("<num>(%d+.%d+)</num>");
                                        if (match ~= nil) then
                                                return tonumber(match);
                                        else
                                                return obj
                                        end
                                else
                                        return obj;
                                end
                        end
                        if (obj == nil) then return nil; end
                        if (type(obj) ~= "table") then
                                return _decodeObject(obj);
                        elseif (decoded[obj]) then
                                return decoded[obj];
                        end
                        local newtable = { };
                        decoded[obj] = newtable;
                        for k,v in pairs(obj) do
                                local key = _copyObject(k);
                                local value = _copyObject(v);
                                newtable[key] = value;
                                decoded[obj] = newtable[key];
                        end
                        return newtable;
                end
                
                return _copyObject(data);
        else
                return data;
        end
end

-- on unload call each instances unload function to save settings
function UnloadPlugin()
    KragenBars:SaveSettings();
end


function ValidatePosition(x, y, width, height)
    x = math.min(math.max(x, 0), Turbine.UI.Display:GetWidth() - width);
    y = math.min(math.max(y, 0), Turbine.UI.Display:GetHeight() - height);
    return x, y;
        
end


-- setup user chat commands
KragenBarsCommand = Turbine.ShellCommand();

function KragenBarsCommand:Execute( command, arguments )
        if (arguments == "setup") then
                KragenBars:ShowSetup();
        elseif (arguments == "refresh") then
                KragenBars:Refresh();
        elseif (arguments == "save") then
                KragenBars:SaveSettings();
                elseif (arguments == "reset") then
                        KragenBars:DefaultPosition();
                        KragenBars:DefaultSettings();
                        KragenBars:Refresh();
        elseif (arguments == "defaultpos") then
                        KragenBars:DefaultPosition();
        else
        Turbine.Shell.WriteLine("KragenBars Help:\n - /Kragenbars setup - Opens Kragens setup window\n - /Kragenbars refresh - Refreshes Kragens bar settings (ie. after level up)\n - /Kragenbars reset - Resets settings to default\n - /Kragenbars defaultpos - Sets window positions to default");
        end

end


function AddCallback(object, event, callback)
        if (object[event] == nil) then
                object[event] = callback;
        else
                if (type(object[event]) == "table") then
                        table.insert(object[event], callback);
                else
                        object[event] = {object[event], callback};
                end
        end
end


-- inialize plugin
function init()
    settings = { };
        altfunction = nil;
        
        altCheck = Turbine.UI.Control();
        altCheck:SetWantsUpdates(true);
        altCheck.Update = function(sender, args)
                if (altCheck:IsAltKeyDown() and altCheck:IsControlKeyDown()) then
                        if (type(altfunction) == "function") then
                                altfunction(true);
                        end
                end
        end
        
        altCheck.Add = function(func)
                if (func ~= altfunction) then
                        altCheck.Clear();
                        altfunction = func;
                end
        end
        
        altCheck.Clear = function()
                if (type(altfunction) == "function") then
                        altfunction(false);
                end
                altfunction = nil;
        end

        -- setup plugin unload function to save setting on unload.
        pluginName="KragenBars";
        window = Turbine.UI.Window();
        window:SetWantsUpdates(true);
        window.Update = function(sender,args)
                        if (Plugins[pluginName] ~= nil) then
                                        Plugins[pluginName].Unload = function(self,sender,args)
                                                        UnloadPlugin();
                                        end
                                        window:SetWantsUpdates(false);
                        end
        end

    Turbine.Shell.AddCommand( "Kragenbars", KragenBarsCommand );
    LoadSettings();
end


-- codeblock
init();

Compare with Previous | Blame


All times are GMT -5. The time now is 02:45 PM.


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