lotrointerface.com
Search Downloads

LoTROInterface SVN Calendar

[/] [Release_3.4/] [FrostyPlugins/] [CustomPluginsManager/] [CustomPluginsManagerWrapper.lua] - Rev 34

Compare with Previous | Blame | View Log

import "Turbine";
import "Turbine.Gameplay";
import "Turbine.UI";
import "Turbine.UI.Extensions";
import "Turbine.UI.Lotro";
import "Turbine.Utils";
import "FrostyPlugins.CustomPluginsManager.CustomPluginsManager"

-- -----------------------------------------------------------------------
-- CustomPluginsManagerWrapper is a small window / icon / button that
-- allows the manager to be shown and hidden.  the window is meant to be
-- permanently visible, but it shows and hides itself when in/not in use.
-- -----------------------------------------------------------------------

CustomPluginsManagerWrapper = class( Turbine.UI.Extensions.SimpleWindow);

-- --------------------------------------------------------------
-- Constructor
--
-- Description: this is where the window is laid out, the fields
-- and buttons are created, and events are trapped.
-- --------------------------------------------------------------
function CustomPluginsManagerWrapper:Constructor()
        Turbine.UI.Extensions.SimpleWindow.Constructor( self );

        -- load the last settings saved
        self:LoadSettings();

  -- has the mouse been moved?
  self.dragged = false;

  -- --------------------------------------------
  -- create the CustomPluginsManager
  -- we "own" the manager, so that we can show
  -- and hide it on command
  -- --------------------------------------------
  self.customPluginsManager = FrostyPlugins.CustomPluginsManager.CustomPluginsManager();
  self.customPluginsManager:SetVisible( false );
  -- fixme: frosty
  --        debug !
  -- self.customPluginsManager:SetVisible( true );
  
  -- --------------------------------------------
  -- window layout
  -- --------------------------------------------
  
        -- set window properties
        self:SetSize( 32, 40 );
        self:SetPosition( self.settings.positionX, self.settings.positionY );
        self:SetOpacity( 1 );
        self:SetAllowDrop( false );
        self:SetMouseVisible( true );

        -- create the activator button
        self.launcher = Turbine.UI.Button();
  self.launcher:SetBackground( "FrostyPlugins/CustomPluginsManager/Resources/WrapperIcon.tga" );
  self.launcher:SetBackColorBlendMode( Turbine.UI.BlendMode.Overlay );
        self.launcher:SetParent( self );
        self.launcher:SetPosition( 0, 0 );
        self.launcher:SetSize( 32, 40 );
        self.launcher:SetVisible( true );

  self.launcher.MouseEnter = function( sender, args )
    self:SetOpacity( 1 );
        end
  self.launcher.MouseLeave = function( sender, args )
    self:SetOpacity( .2 );
        end
        
  self.launcher.Click = function( sender, args )
    if( not self.dragged ) then
      self.customPluginsManager:SetVisible( not self.customPluginsManager:IsVisible() );
    end
        end
        
        self.launcher.MouseDown = function( sender, args )
          if ( args.Button == Turbine.UI.MouseButton.Left ) then
                  self.dragStartX = args.X;
                  self.dragStartY = args.Y;
                  self.dragging = true;
                  self.dragged = false;
          end
        
          if ( args.Button == Turbine.UI.MouseButton.Right ) then
            -- context menu?
          end
  end

  self.launcher.MouseMove = function( sender, args )
          local left, top = self:GetPosition();
        
          if ( self.dragging ) then
                  self:SetPosition( left + ( args.X - self.dragStartX ), top + ( args.Y - self.dragStartY ) );
                  self.dragged = true;            
          end
  end

  self.launcher.MouseUp = function( sender, args )
          if ( args.Button == Turbine.UI.MouseButton.Left ) then
                  self.dragging = false;
                  
                  -- verify the position is on the main screen
      if( self.dragged ) then
        local x, y = self:GetPosition();
        local validX = x;
        local validY = y;
        if( x < 0 ) then
          x = 0;
        end
        if( y < 0 ) then
          y = 0;
        end
        if( x + self:GetWidth() > Turbine.UI.Display.GetWidth() ) then
          x = Turbine.UI.Display.GetWidth() - self:GetWidth();
        end
        if( y + self:GetHeight() > Turbine.UI.Display.GetHeight() ) then
          y = Turbine.UI.Display.GetHeight() - self:GetHeight();
        end
        
        self:SetPosition( x, y );
      end
          end
  end

  -- window fading
        self:SetFadeSpeed( 0.6 );

        self.MouseEnter = function( sender, args )
                sender:SetOpacity( 1 );
        end

        self.MouseLeave = function( sender, args )
                sender:SetOpacity( 0.2 );
        end

  -- --------------------------------------------
  -- event handling
  -- --------------------------------------------
  
  --
  -- if the position changes, save the new window location
  --
        self.PositionChanged = function( sender, args )
    local x,y = self:GetPosition();
    self.settings.positionX = x;
    self.settings.positionY = y;
    self:SaveSettings();
        end


  -- --------------------------------------------
  -- initialize the custom plugins manager
  -- --------------------------------------------
  self.customPluginsManager:Initialize();
end



-- --------------------------------------------------------------
-- LoadSettings
--
-- Description: loads our internal settings from disk.  For this class,
-- this includes the position of the wrapper window.  if the position
-- does not exist, we set it to 0, 0
-- --------------------------------------------------------------
function CustomPluginsManagerWrapper:LoadSettings()
        -- load the settings.  If a value is not available, set a default value
        self.settings = Turbine.PluginData.Load( Turbine.DataScope.Character, "CustomPluginsManagerWrapperSettings" );

        if ( type( self.settings ) ~= "table" ) then
                self.settings = { };
        end

        if ( not self.settings.positionX ) then
                self.settings.positionX = 0; 
        end

        if ( not self.settings.positionY ) then
                self.settings.positionY = 0;
        end
end

-- --------------------------------------------------------------
-- SaveSettings
--
-- Description: save our internal settings to disk.  For this class,
-- this includes the position of the wrapper window and the list of
-- events that have been created.
-- --------------------------------------------------------------
function CustomPluginsManagerWrapper:SaveSettings()
        -- save the settings
        Turbine.PluginData.Save( Turbine.DataScope.Character, "CustomPluginsManagerWrapperSettings", self.settings );
end

Compare with Previous | Blame


All times are GMT -5. The time now is 11:39 AM.


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