lotrointerface.com
Search Downloads

LoTROInterface SVN Calendar

[/] [Release_3.5/] [FrostyPlugins/] [Calendar/] [DateDropDownBox.lua] - Rev 35

Compare with Previous | Blame | View Log

-- A button with a Date Picker via DropDown menu.

import "Turbine";

import "FrostyPlugins.Calendar.DropDownBox";

--------------------------------------------------------------------------
--- DropDownBox
--
-- A button control that contains a drop-down menu.
-- Just pass the list of items to populate the menu.
-- Can recieve notification of changes (ValueChanged)
-- Can query for index or value of selected item.
--
DateDropDownBox = class( Turbine.UI.Control );


--------------------------------------------------------------------------
function DateDropDownBox:Constructor(args)
        Turbine.UI.Control.Constructor( self );
        --Turbine.Shell.WriteLine("DateDropDownBox:Constructor()");
        self.format = args.format or "%y-%m-%d";
        
        local now = DateTime:now();
        self.value = now;
        -- initialize min/max year for dropdown
        self.minYear = self.value.Year - 3;
        self.maxYear = self.value.Year + 3;

        local years = table.fill(self.minYear, self.maxYear);
        
    --self.button = Turbine.UI.Button();
    --self.button = Turbine.UI.Lotro.Button();
        
        -- yyyy-mm-dd
        
        self.buttonYear = FrostyPlugins.Calendar.DropDownBox{itemList=years};
        --self.buttonYear = Turbine.UI.Label();
    self.buttonYear:SetBlendMode( Turbine.UI.BlendMode.Overlay );
    self.buttonYear:SetParent( self );
    self.buttonYear:SetPosition( 0, 0 ); -- left,top
    self.buttonYear:SetSize( -- width,height
                --self:GetWidth()*.4,
                11*5,
                self:GetHeight()
                ); 
    self.buttonYear:SetVisible( true );
        --self.buttonYear:SetBackColor(Turbine.UI.Color.Purple);
    self.buttonYear:SetTextAlignment( Turbine.UI.ContentAlignment.MiddleCenter );
    self.buttonYear:SetFont( Turbine.UI.Lotro.Font.Verdana20 );
    --self.buttonYear:SetText( "yyyy" );
        self.buttonYear:SetSelectedValue(self.value.Year);
        self.buttonYear.fieldName = 'year';
        
    self.buttonYear.SelectionChanged = function( sender, args )
                local idx = sender:GetSelectedIndex();
                local value = sender:GetSelectedValue();
                --Turbine.Shell.WriteLine( string.format(
                --      "DateDropDownBox.buttonYear.SelectionChanged: [%d] = [%s]",
                --      idx, value) );
                if( self.value.Year ~= value ) then
                        local newDate = self.value:clone():set({Year=value});
                        self:SetValue(newDate);
                end
    end
        
    self.buttonYear.MouseEnter = function( sender, args )
                self:MouseEnterField(sender,args);
    end

    self.buttonYear.MouseLeave = function( sender, args )
                self:MouseLeaveField(sender,args);
    end
        
        self.dash1Label = Turbine.UI.Label();
    self.dash1Label:SetBlendMode( Turbine.UI.BlendMode.Overlay );
    self.dash1Label:SetParent( self );
    self.dash1Label:SetPosition( -- left,top
                self.buttonYear:GetLeft()+self.buttonYear:GetWidth(),
                self.buttonYear:GetTop() ); 
    self.dash1Label:SetSize( -- width,height
                --self:GetWidth()*.1,
                11,
                self:GetHeight()
                ); 
    self.dash1Label:SetVisible( true );
        --self.dash1Label:SetBackColor(Turbine.UI.Color.Blue);
    self.dash1Label:SetTextAlignment( Turbine.UI.ContentAlignment.MiddleCenter );
    self.dash1Label:SetFont( Turbine.UI.Lotro.Font.Verdana20 );
    self.dash1Label:SetText( "-" );
        
        local months = {}; -- = table.range(1, 12);
        for month = 1, 12 do
                table.insert(months,string.format("%02d",month));
        end
        
        self.buttonMonth = FrostyPlugins.Calendar.DropDownBox{itemList=months};
        --self.buttonMonth = Turbine.UI.Label();
    self.buttonMonth:SetBlendMode( Turbine.UI.BlendMode.Overlay );
    self.buttonMonth:SetParent( self );
    self.buttonMonth:SetPosition( -- left,top
                self.dash1Label:GetLeft()+self.dash1Label:GetWidth(),
                self.dash1Label:GetTop() ); 
    self.buttonMonth:SetSize( -- width,height
                --self:GetWidth()*.4,
                11*3,
                self:GetHeight()
                ); 
    self.buttonMonth:SetVisible( true );
        --self.buttonMonth:SetBackColor(Turbine.UI.Color.Green);
    self.buttonMonth:SetTextAlignment( Turbine.UI.ContentAlignment.MiddleCenter );
    self.buttonMonth:SetFont( Turbine.UI.Lotro.Font.Verdana20 );
    --self.buttonMonth:SetText( "mm" );
        self.buttonMonth:SetSelectedValue(string.format("%02d",self.value.Month));
        self.buttonMonth.fieldName = 'month';

    self.buttonMonth.SelectionChanged = function( sender, args )
                local idx = sender:GetSelectedIndex();
                local value = sender:GetSelectedValue();
                --Turbine.Shell.WriteLine( string.format(
                --      "DateDropDownBox.buttonMonth.SelectionChanged: [%d] = [%s]",
                --      idx, value) );
                -- use index to set day since value is a corresponding two-digit string
                if( self.value.Month ~= idx ) then
                        local newDate = self.value:clone():set({Month=idx});
                        if( newDate.Day > newDate:daysInMonth() ) then
                                newDate:set({Day = newDate:daysInMonth()});
                        end
                        self:SetValue(newDate);
                end
    end
        
    self.buttonMonth.MouseEnter = function( sender, args )
                self:MouseEnterField(sender,args);
    end
    self.buttonMonth.MouseLeave = function( sender, args )
                self:MouseLeaveField(sender,args);
    end
        
        
        self.dash2Label = Turbine.UI.Label();
    self.dash2Label:SetBlendMode( Turbine.UI.BlendMode.Overlay );
    self.dash2Label:SetParent( self );
    self.dash2Label:SetPosition( -- left,top
                self.buttonMonth:GetLeft()+self.buttonMonth:GetWidth(),
                self.buttonMonth:GetTop() ); 
    self.dash2Label:SetSize( -- width,height
                --self:GetWidth()*.2,
                11,
                self:GetHeight()
                ); 
    self.dash2Label:SetVisible( true );
        --self.dash2Label:SetBackColor(Turbine.UI.Color.Black);
    self.dash2Label:SetTextAlignment( Turbine.UI.ContentAlignment.MiddleCenter );
    self.dash2Label:SetFont( Turbine.UI.Lotro.Font.Verdana20 );
    self.dash2Label:SetText( "-" );
        
        local days = {};
        for day = 1, self.value:daysInMonth() do
                table.insert(days,string.format("%02d",day));
        end
        
        self.buttonDay = FrostyPlugins.Calendar.DropDownBox{itemList=days};
        --self.buttonDay = Turbine.UI.Label();
    self.buttonDay:SetBlendMode( Turbine.UI.BlendMode.Overlay );
    self.buttonDay:SetParent( self );
    self.buttonDay:SetPosition( -- left,top
                self.dash2Label:GetLeft()+self.dash2Label:GetWidth(),
                self.dash2Label:GetTop() ); 
    self.buttonDay:SetSize( -- width,height
                --self:GetWidth()*.2,
                11*3,
                self:GetHeight()
                ); 
    self.buttonDay:SetVisible( true );
        --self.buttonDay:SetBackColor(Turbine.UI.Color.Gray);
    self.buttonDay:SetTextAlignment( Turbine.UI.ContentAlignment.MiddleCenter );
    self.buttonDay:SetFont( Turbine.UI.Lotro.Font.Verdana20 );
    --self.buttonDay:SetText( "dd" );
        self.buttonDay:SetSelectedValue(string.format("%02d",self.value.Day));
        self.buttonDay.fieldName = 'day';

    self.buttonDay.SelectionChanged = function( sender, args )
                local idx = sender:GetSelectedIndex();
                local value = sender:GetSelectedValue();
                --Turbine.Shell.WriteLine( string.format(
                --      "DateDropDownBox.buttonMonth.SelectionChanged: [%d] = [%s]",
                --      idx, value) );
                -- use index to set day since value is a corresponding two-digit string
                if( self.value.Day ~= idx ) then
                        local newDate = self.value:clone():set({Day=idx});
                        self:SetValue(newDate);
                end
    end
        
    self.buttonDay.MouseEnter = function( sender, args )
                self:MouseEnterField(sender,args);
    end
    self.buttonDay.MouseLeave = function( sender, args )
                self:MouseLeaveField(sender,args);
    end

        -- Allow notification when a particular field is entered
    self.MouseEnterField = function( sender, args )
                -- intent is for user to override for notification of change
        --Turbine.Shell.WriteLine( "DateDropDownBox:MouseEnterField " .. tostring(args.fieldName) );
        --table.dump('sender',sender);
        --table.dump('args',args);
        end

        -- Allow notification when a particular field is entered
    self.MouseLeaveField = function( sender, args )
                -- intent is for user to override for notification of change
        --Turbine.Shell.WriteLine( "DateDropDownBox:MouseLeaveField " .. tostring(args.fieldName) );
        --table.dump('sender',sender);
        --table.dump('args',args);
        end

    self.SetYearRange = function( sender, minYear, maxYear )
        --Turbine.Shell.WriteLine( "DateDropDownBox:SetYearRange" );
                self.minYear = minYear;
                self.maxYear = maxYear;
                local years = table.fill(self.minYear, self.maxYear);
                self.buttonYear:SetDropDownList(years);
    end

    self.SetValue = function( sender, args )
        --Turbine.Shell.WriteLine( string.format(
                --      "DateDropDownBox:SetValue [%s] was [%s]",
                --      args:tostring(),
                --      self.value:tostring()));
                if( self.value ~= args ) then
                        self.value = args;
                        self.buttonYear:SetSelectedValue(self.value.Year);
                        --self.buttonMonth:SetSelectedValue(string.format("%02d",self.value.Month));
                        self.buttonMonth:SetSelectedIndex(self.value.Month);
                        -- update available days based on month/year
                        local days = table.fill(1, self.value:daysInMonth());
                        self.buttonDay:SetDropDownList(days);
                        --self.buttonDay:SetSelectedValue(string.format("%02d",self.value.Day));
                        self.buttonDay:SetSelectedIndex(self.value.Day);
                        self:ValueChanged(self.value);
                end
    end 

        -- notification of selection change
        self.ValueChanged = function( sender, args )
        --Turbine.Shell.WriteLine( "DateDropDownBox:ValueChanged" );
                -- intent is for user to override for notification of change
        end

    self.SizeChanged = function( sender, args )
        --Turbine.Shell.WriteLine( "DateDropDownBox:SizeChanged" );
                local ctls = self:GetControls();
                for idx = 1, ctls:GetCount() do
                        ctls:Get(idx):SetHeight(self:GetHeight());
                        --ctls:Get(idx):SetSize(self:GetSize());
                end
    end
        
        self.SetBackColor = function(self, value)
        --Turbine.Shell.WriteLine( "DateDropDownBox:SetBackColor " .. tostring(value) );
                local ctls = self:GetControls();
                for idx = 1, ctls:GetCount() do
                        ctls:Get(idx):SetBackColor(value);
                end
        end
        
        self.SetForeColor = function(self, value)
        --Turbine.Shell.WriteLine( "DateDropDownBox:SetForeColor " .. tostring(value) );
                local ctls = self:GetControls();
                for idx = 1, ctls:GetCount() do
                        ctls:Get(idx):SetForeColor(value);
                end
        end

        --self.SetText = function(self, value)
    --    --Turbine.Shell.WriteLine( "DateDropDownBox:SetText " .. tostring(value) );
        --      self.buttonYear:SetText(value);
        --end

        --self.SetTextAlignment = function(self, value)
    --    --Turbine.Shell.WriteLine( "DateDropDownBox:SetTextAlignment " .. tostring(value) );
        --      for ctl in (self:GetControls()) do
        --              ctl:SetTextAlignment(value);
        --      end             
        --end

        self.SetFont = function(self, value)
        --Turbine.Shell.WriteLine( "DateDropDownBox:SetFont " .. tostring(value) );
                local ctls = self:GetControls();
                for idx = 1, ctls:GetCount() do
                        ctls:Get(idx):SetFont(value);
                end
        end
        
        self.SetFontStyle = function(self, value)
        --Turbine.Shell.WriteLine( "DateDropDownBox:SetFontStyle " .. tostring(value) );
                local ctls = self:GetControls();
                for idx = 1, ctls:GetCount() do
                        ctls:Get(idx):SetFontStyle(value);
                end
        end     
        
        self.SetOutlineColor = function(self, value)
        --Turbine.Shell.WriteLine( "DateDropDownBox:SetOutlineColor " .. tostring(value) );
                local ctls = self:GetControls();
                for idx = 1, ctls:GetCount() do
                        ctls:Get(idx):SetOutlineColor(value);
                end
        end     
        
end

Compare with Previous | Blame


All times are GMT -5. The time now is 07:17 PM.


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