lotrointerface.com
Search Downloads

LoTROInterface SVN Calendar

[/] [Release_3.0/] [FrostyPlugins/] [Calendar/] [Options.lua] - Rev 25

Compare with Previous | Blame | View Log

-- A singleton class of Calendar options

import "Turbine";
import "Turbine.UI";
import "Turbine.UI.Lotro";
import "FrostyPlugins.Calendar.DropDownBox";

-- Lookup of languages
local languages = {
    en = "English",
    fr = "French",
    de = "German",
    ru = "Russian",
};

-- The available calendars to subscribe to
local availableCalendarSubscriptions = {
    'Personal',
    'Global',
};

--------------------------------------------------------------------------
--- The global options for the Calendar plugin
Options = {
        
        locale = "en"; -- english
    initiallyVisible = true;

        yearLimit = 3;
        maxEventDurationAllDays = 30;
        maxEventDurationPartialDays = 10;
        
        timezone = "-05:00"; -- eastern standard time (EST)
                -- Note: EDT is -4 in spring and ends in autumn
                -- when clocks fall back in autumn
                -- 12 pm utc = 12-5 = 7 am est = 7+1= 8 am edt = 12-4 am edt
                -- only save in EST, so that when DST starts it is added as an offset

    -- The set of calendars subscribed to
    subscribedCalendars = {
        Personal = 1,
        Global = 1,
    };

        eventFont = Turbine.UI.Lotro.Font.Verdana20;    

}

--------------------------------------------------------------------------
local function LoadSettings()
        --Turbine.Shell.WriteLine( "OptionsPanel:LoadSettings()" );
        
        -- Load user configurable options
        local loadedOptions = Turbine.PluginData.Load( 
                Turbine.DataScope.Account, 
                "CalendarOptions" );
        if( nil ~= loadedOptions ) then
                Options = loadedOptions;
        end

        -- Set initial visibility on load
        if( nil == Options.initiallyVisible ) then
                Options.initiallyVisible = true;
        end
    
        if( nil == Options[locale] ) then
                Options.locale = 'en'; -- Default to english
                if( Turbine.Language.French == Turbine.Engine:GetLanguage() ) then
                        Options.locale = 'fr';
                elseif( Turbine.Language.German == Turbine.Engine:GetLanguage() ) then
                        Options.locale = 'de';
                elseif( Turbine.Language.Russian == Turbine.Engine:GetLanguage() ) then
                        Options.locale = 'ru';
                end
        end
        
        -- Set default limits
        if( nil == Options.yearlimit ) then
                Options.yearlimit = 3;
        end
        if( nil == Options.maxEventDurationAllDays ) then
                Options.yearlimit = 30;
        end
        if( nil == Options.maxEventDurationPartialDays ) then
                Options.yearlimit = 10;
        end

    -- Load calendar subscriptions
        if( nil == Options.subscribedCalendars ) then
        Options.subscribedCalendars = {
            Personal = 1,
            Global = 1,
        };
    end

        --table.dump("Loaded Calender Options:",Options);
        
end
LoadSettings();

--------------------------------------------------------------------------
local function SaveSettings()
        --Turbine.Shell.WriteLine( "OptionsPanel:SaveSettings()" );
        
        -- Save user configurable options
        --table.dump("Saved Calender Options",Options);
        Turbine.PluginData.Save( 
                Turbine.DataScope.Account, 
                "CalendarOptions",
                Options );
    NotifyForChange();
end

--------------------------------------------------------------------------
local subscribedClients = {};
function SubscribeToChangeNotification(subscriber)
    --Turbine.Shell.WriteLine( string.format(
    --    "subscribeForChangeNotification [%s]",
    --    tostring(subscriber)));
    table.insert(subscribedClients, subscriber);
end

--------------------------------------------------------------------------
function NotifyForChange()
    for i,subscriber in ipairs(subscribedClients) do
        --Turbine.Shell.WriteLine( string.format(
        --    "NotifyForChange [%s]",
        --    tostring(subscriber)));
        subscriber:NotifyOptionsChanged()
    end
end

--------------------------------------------------------------------------

local optionsPanel = Turbine.UI.Control();
optionsPanel:SetSize( 400, 500 ); -- width,height
--optionsDialog:SetPosition( 200, 500 );-- left,top -- ignored
optionsPanel:SetBackColor(Turbine.UI.Color(.1,.1,.1));
optionsPanel:SetVisible( true );

local lblLanguage = Turbine.UI.Label();
lblLanguage:SetParent( optionsPanel );
lblLanguage:SetSize( 250, 20 ); -- width,height
lblLanguage:SetPosition( 5, 5 );-- left,top
lblLanguage:SetMultiline( false );
lblLanguage:SetText( "Language:" );
lblLanguage:SetTextAlignment( Turbine.UI.ContentAlignment.MiddleRight );

local dropdownLanguage = FrostyPlugins.Calendar.DropDownBox{
        itemList=table.values(languages),
        button=Turbine.UI.Lotro.Button()
        };
dropdownLanguage:SetParent( optionsPanel );
dropdownLanguage:SetSize(  -- width,height
        100, 
        lblLanguage:GetHeight() );
dropdownLanguage:SetPosition( -- left,top
        lblLanguage:GetLeft() + lblLanguage:GetWidth() + 10,
        lblLanguage:GetTop() ); 
--dropdownLanguage:SetBackColor( self:GetBackColor());
--dropdownLanguage:SetForeColor(Turbine.UI.Color.White);
--dropdownLanguage:SetTextAlignment( Turbine.UI.ContentAlignment.MiddleRight );
dropdownLanguage:SetOutlineColor( Turbine.UI.Color.Yellow );
dropdownLanguage:SetFontStyle( Turbine.UI.FontStyle.None );
dropdownLanguage:SetFont( Turbine.UI.Lotro.Font.Verdana20 );
dropdownLanguage:SetVisible( true );
--dropdownLanguage:SetSelectedIndex(Options.locale);

dropdownLanguage:SetText( dropdownLanguage:GetSelectedValue() );

dropdownLanguage.MouseEnter = function( sender, args )
        sender:SetFontStyle( Turbine.UI.FontStyle.Outline );
        sender:SetVisible( false );
        sender:SetVisible( true );
end

dropdownLanguage.MouseLeave = function( sender, args )
        sender:SetFontStyle( Turbine.UI.FontStyle.None );
        sender:SetVisible( false );
        sender:SetVisible( true );
end

dropdownLanguage.SelectionChanged = function( sender, args )
        local idx = sender:GetSelectedIndex();
        local value = sender:GetSelectedValue();
        --Turbine.Shell.WriteLine( string.format(
        --      "dropdownLanguage.SelectionChanged: [%d] = [%s]",
        --      idx, value) );
        
        --Turbine.Shell.WriteLine( "You selected language [" .. value .. "]" );
        --self.settings.view = viewName;
        --self:SaveSettings();
        --self:RebuildCalendar();
end

local lblInitialVisibility = Turbine.UI.Label();
lblInitialVisibility:SetParent( optionsPanel );
lblInitialVisibility:SetSize( lblLanguage:GetSize() ); -- width,height
lblInitialVisibility:SetPosition( -- left,top
    lblLanguage:GetLeft(), 
    lblLanguage:GetTop() + lblLanguage:GetHeight() + 5 );
lblInitialVisibility:SetMultiline( false );
lblInitialVisibility:SetText( "Initially Visible on Load:" );
lblInitialVisibility:SetTextAlignment( Turbine.UI.ContentAlignment.MiddleRight );

local chkInitialVisibility = Turbine.UI.Lotro.CheckBox();
chkInitialVisibility:SetParent( optionsPanel );
chkInitialVisibility:SetSize( 20,20 ); -- width,height
chkInitialVisibility:SetPosition( -- left,top
        lblInitialVisibility:GetLeft() + lblInitialVisibility:GetWidth() + 10,
        lblInitialVisibility:GetTop() ); 
chkInitialVisibility:SetChecked(Options.initiallyVisible);

chkInitialVisibility.CheckedChanged = function(sender,args)
        --Turbine.Shell.WriteLine( string.format(
        --      "chkInitialVisibility.CheckedChanged: [%s]",
        --      tostring(chkInitialVisibility:IsChecked()) ));
    Options.initiallyVisible = chkInitialVisibility:IsChecked();
        SaveSettings();
end

---
local lblYearLimit = Turbine.UI.Label();
lblYearLimit:SetParent( optionsPanel );
lblYearLimit:SetSize( lblInitialVisibility:GetSize() ); -- width,height
lblYearLimit:SetPosition( -- left,top
    lblInitialVisibility:GetLeft(), 
    lblInitialVisibility:GetTop() + lblInitialVisibility:GetHeight() + 5 );
lblYearLimit:SetMultiline( false );
lblYearLimit:SetText( "Year Range:" );
lblYearLimit:SetTextAlignment( Turbine.UI.ContentAlignment.MiddleRight );

yearLimitOptions={1,2,3,4};
local dropdownYearLimit = FrostyPlugins.Calendar.DropDownBox{
        itemList=yearLimitOptions,
        button=Turbine.UI.Lotro.Button()
        };
dropdownYearLimit:SetParent( optionsPanel );
dropdownYearLimit:SetSize(  -- width,height
        100, 
        lblYearLimit:GetHeight() );
dropdownYearLimit:SetPosition( -- left,top
        lblYearLimit:GetLeft() + lblYearLimit:GetWidth() + 10,
        lblYearLimit:GetTop() ); 
dropdownYearLimit:SetOutlineColor( Turbine.UI.Color.Yellow );
dropdownYearLimit:SetFontStyle( Turbine.UI.FontStyle.None );
dropdownYearLimit:SetFont( Turbine.UI.Lotro.Font.Verdana20 );
dropdownYearLimit:SetVisible( true );
dropdownYearLimit:SetSelectedValue( Options.yearLimit );
dropdownYearLimit:SetText( dropdownYearLimit:GetSelectedValue() );

dropdownYearLimit.SelectionChanged = function(sender,args)
        --Turbine.Shell.WriteLine( string.format(
        --      "dropdownYearLimit.SelectionChanged: [%s]",
        --      tostring(dropdownYearLimit:GetSelectedValue()) ));
    Options.yearLimit = dropdownYearLimit:GetSelectedValue();
        SaveSettings();
end

---
local lblMaxEventDurationAllDays = Turbine.UI.Label();
lblMaxEventDurationAllDays:SetParent( optionsPanel );
lblMaxEventDurationAllDays:SetSize( lblYearLimit:GetSize() ); -- width,height
lblMaxEventDurationAllDays:SetPosition( -- left,top
    lblYearLimit:GetLeft(), 
    lblYearLimit:GetTop() + lblYearLimit:GetHeight() + 5 );
lblMaxEventDurationAllDays:SetMultiline( false );
lblMaxEventDurationAllDays:SetText( "Max All Day Duration (days):" );
lblMaxEventDurationAllDays:SetTextAlignment( Turbine.UI.ContentAlignment.MiddleRight );

local lblMaxEventDurationAllDaysValue = Turbine.UI.Lotro.TextBox();
lblMaxEventDurationAllDaysValue:SetParent( optionsPanel );
lblMaxEventDurationAllDaysValue:SetSize( 50, 30 ); -- width,height
lblMaxEventDurationAllDaysValue:SetPosition( -- left,top
    lblMaxEventDurationAllDays:GetLeft() + lblMaxEventDurationAllDays:GetWidth(), 
    lblMaxEventDurationAllDays:GetTop() );
lblMaxEventDurationAllDaysValue:SetMultiline( false );
lblMaxEventDurationAllDaysValue:SetReadOnly( true );
lblMaxEventDurationAllDaysValue:SetText( Options.maxEventDurationAllDays );
lblMaxEventDurationAllDaysValue:SetTextAlignment( Turbine.UI.ContentAlignment.MiddleRight );

local sbMaxEventDurationAllDays = Turbine.UI.Lotro.ScrollBar();
sbMaxEventDurationAllDays:SetOrientation(Turbine.UI.Orientation.Horizontal);
sbMaxEventDurationAllDays:SetParent(optionsPanel);
sbMaxEventDurationAllDays:SetSize( -- width,height
    optionsPanel:GetWidth(),
    12); 
sbMaxEventDurationAllDays:SetPosition( -- left,top
    lblMaxEventDurationAllDays:GetLeft() + 30,
    lblMaxEventDurationAllDays:GetTop() + lblMaxEventDurationAllDays:GetHeight());
sbMaxEventDurationAllDays:GetMinimum(10);
sbMaxEventDurationAllDays:GetMaximum(60);
sbMaxEventDurationAllDays:SetValue(Options.maxEventDurationAllDays);
sbMaxEventDurationAllDays:SetVisible(true);

sbMaxEventDurationAllDays.ValueChanged = function(sender,args)
    Options.maxEventDurationAllDays = sbMaxEventDurationAllDays:GetValue();
    lblMaxEventDurationAllDaysValue:SetText( Options.maxEventDurationAllDays );    
        --Turbine.Shell.WriteLine( string.format(
        --      "sbMaxEventDurationAllDays.ValueChanged: [%s]",
        --      tostring(Options.maxEventDurationAllDays) ));
        SaveSettings();
end

---
local lblMaxEventDurationPartialDay = Turbine.UI.Label();
lblMaxEventDurationPartialDay:SetParent( optionsPanel );
lblMaxEventDurationPartialDay:SetSize( lblMaxEventDurationAllDays:GetSize() ); -- width,height
lblMaxEventDurationPartialDay:SetPosition( -- left,top
    lblMaxEventDurationAllDays:GetLeft(), 
    sbMaxEventDurationAllDays:GetTop() + sbMaxEventDurationAllDays:GetHeight() + 5 );
lblMaxEventDurationPartialDay:SetMultiline( false );
lblMaxEventDurationPartialDay:SetText( "Max Partial Day Duration (days):" );
lblMaxEventDurationPartialDay:SetTextAlignment( Turbine.UI.ContentAlignment.MiddleRight );

local lblMaxEventDurationPartialDayValue = Turbine.UI.Lotro.TextBox();
lblMaxEventDurationPartialDayValue:SetParent( optionsPanel );
lblMaxEventDurationPartialDayValue:SetSize( 50, 30 ); -- width,height
lblMaxEventDurationPartialDayValue:SetPosition( -- left,top
    lblMaxEventDurationPartialDay:GetLeft() + lblMaxEventDurationPartialDay:GetWidth(), 
    lblMaxEventDurationPartialDay:GetTop() );
lblMaxEventDurationPartialDayValue:SetMultiline( false );
lblMaxEventDurationPartialDayValue:SetReadOnly( true );
lblMaxEventDurationPartialDayValue:SetText( Options.maxEventDurationPartialDays );
lblMaxEventDurationPartialDayValue:SetTextAlignment( Turbine.UI.ContentAlignment.MiddleRight );

local sbMaxEventDurationPartialDay = Turbine.UI.Lotro.ScrollBar();
sbMaxEventDurationPartialDay:SetOrientation(Turbine.UI.Orientation.Horizontal);
sbMaxEventDurationPartialDay:SetParent(optionsPanel);
sbMaxEventDurationPartialDay:SetSize( -- width,height
    optionsPanel:GetWidth(),
    12); 
sbMaxEventDurationPartialDay:SetPosition( -- left,top
    lblMaxEventDurationPartialDay:GetLeft() + 30,
    lblMaxEventDurationPartialDay:GetTop() + lblMaxEventDurationPartialDay:GetHeight());
sbMaxEventDurationPartialDay:GetMinimum(3);
sbMaxEventDurationPartialDay:GetMaximum(20);
sbMaxEventDurationPartialDay:SetValue(Options.maxEventDurationPartialDays);
sbMaxEventDurationPartialDay:SetVisible(true);

sbMaxEventDurationPartialDay.ValueChanged = function(sender,args)
    Options.maxEventDurationPartialDays = sbMaxEventDurationPartialDay:GetValue();
    lblMaxEventDurationPartialDayValue:SetText( Options.maxEventDurationPartialDays );    
        --Turbine.Shell.WriteLine( string.format(
        --      "sbMaxEventDurationPartialDay.ValueChanged: [%s]",
        --      tostring(Options.maxEventDurationPartialDays) ));
        SaveSettings();
end

---
local lblCalendarSubscriptions = Turbine.UI.Label();
lblCalendarSubscriptions:SetParent( optionsPanel );
lblCalendarSubscriptions:SetSize( lblMaxEventDurationAllDays:GetSize() ); -- width,height
lblCalendarSubscriptions:SetPosition( -- left,top
    lblMaxEventDurationAllDays:GetLeft(), 
    sbMaxEventDurationPartialDay:GetTop() + sbMaxEventDurationPartialDay:GetHeight() + 5 );
lblCalendarSubscriptions:SetMultiline( false );
lblCalendarSubscriptions:SetText( "Subscribed Calendars:" );
lblCalendarSubscriptions:SetTextAlignment( Turbine.UI.ContentAlignment.MiddleRight );

local listboxCalendarSubscriptions = Turbine.UI.ListBox();
listboxCalendarSubscriptions:SetParent( optionsPanel );
listboxCalendarSubscriptions:SetSize(       -- width,height
    200, #availableCalendarSubscriptions * 30 ); 
listboxCalendarSubscriptions:SetPosition( -- left,top
    lblCalendarSubscriptions:GetLeft() + lblCalendarSubscriptions:GetWidth(),
    lblCalendarSubscriptions:GetTop() );
--listboxCalendarSubscriptions:SetBackColor(Turbine.UI.Color.Red);

--table.dump("availableCalendarSubscriptions",availableCalendarSubscriptions);
for idx,calendarName in ipairs(availableCalendarSubscriptions) do
    local item = Turbine.UI.Lotro.CheckBox();
    item:SetParent( listboxCalendarSubscriptions );
    item:SetSize( -- width,height
        listboxCalendarSubscriptions:GetWidth(), 
        30 );
    item:SetText(calendarName);
    item:SetChecked(Options.subscribedCalendars[calendarName]);

    item.CheckedChanged = function( sender, args )
        Options.subscribedCalendars[calendarName] = item:IsChecked();
        --Turbine.Shell.WriteLine( string.format(
        --    "Options: add calendar [%s] subscribed[%s]",
        --    item:GetText(),
        --    tostring(item:IsChecked())));
        SaveSettings();
    end
    
    --Turbine.Shell.WriteLine( string.format(
    --    "Options: calendar [%s] subscribed[%s]",
    --    item:GetText(),
    --    tostring(item:IsChecked())));
    
    listboxCalendarSubscriptions:AddItem(item);
    
end


--------------------------------------------------------------------------
-- fired when someone clicks on 'options' for plugin in plugin manager
plugin.GetOptionsPanel = function(self)
        --Turbine.Shell.WriteLine( "calendar:GetOptionsPanel" );
    optionsPanel:SetParent(self);
        return optionsPanel;
end

--------------------------------------------------------------------------
-- fired by plugin manager after plugin's Main package has finished loading
plugin.Load = function(self)

--    LoadSettings();
    
        local msg = "Loaded <pluginname> <version> by <author>";
        msg = string.gsub(msg, "<pluginname>", plugin:GetName());       
        msg = string.gsub(msg, "<version>", plugin:GetVersion());       
        msg = string.gsub(msg, "<author>", plugin:GetAuthor()); 
        print(msg);
        --Turbine.Shell.WriteLine( msg );
end

--------------------------------------------------------------------------
-- fired by plugin manager before a plugin is unloaded
plugin.Unload = function(self)
        local msg = "Unloading calendar plugin...";
    -- Note: At this point other plugin methods no longer available
        print( msg );
end

Compare with Previous | Blame


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


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