lotrointerface.com
Search Downloads

LoTROInterface SVN Calendar

[/] [Release_3.4/] [FrostyPlugins/] [CustomPluginsManager/] [PluginSlot.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";

-- --------------------------------------------------------------
-- PluginSlot is a simple object that allows data to be saved and
-- loaded as part of the CustomPluginManager.
-- --------------------------------------------------------------

PluginSlot = class( Turbine.Object );

function PluginSlot:Constructor()
  Turbine.Object.Constructor( self );

  -- the Reset function both initialized and resets the PluginSlot
  self:Reset();
end

-- --------------------------------------------------------------
-- Reset
--
-- Description: reset the plugin slot to default values
-- --------------------------------------------------------------
function PluginSlot:Reset()
  -- what is the name of this plugin?
  self.PluginName = "";
  
  -- what version is the plugin?
  self.PluginVersion = "";
  
  -- who is the author?
  self.PluginAuthor = "";
  
  -- what is the plugin package?
  self.PluginPackage = "";
  
  -- what is the plugin script state?
  self.PluginScriptState = "";
  
  -- where is this plugin stored?
  self.PluginDirectory = "";
  
  -- what Icon do we use on the plugin manager?
  self.PluginIcon = "";
  
  -- is this plugin valid?  this will be used when the plugin information
  -- is saved to disk.  when we load it from disk, we will verify that the
  -- plugin still exists and set this member accordingly
  self.PluginValid = false;
  
  -- is this plugin currently loaded?
  self.PluginLoaded = false;

  -- has the user marked this plugin as one of their favorites?
  self.PluginFavorite = false;
end

-- --------------------------------------------------------------
-- Copy
--
-- Description: copy all the members from the input to our members
-- --------------------------------------------------------------
function PluginSlot:Copy( pluginData )
  self.PluginName         = pluginData.PluginName;
  self.PluginVersion      = pluginData.PluginVersion;
  self.PluginAuthor       = pluginData.PluginAuthor;
  self.PluginPackage      = pluginData.PluginPackage;
  self.PluginScriptState  = pluginData.PluginScriptState;
  self.PluginDirectory    = pluginData.PluginDirectory;
  self.PluginIcon         = pluginData.PluginIcon;
  self.PluginValid        = pluginData.PluginValid;
  self.PluginLoaded       = pluginData.PluginLoaded;
  self.PluginFavorite     = pluginData.PluginFavorite;
end

-- --------------------------------------------------------------
-- PluginSlotContainer is a simple object that allows interaction
-- with the plugin that lies within.  this is the interface class
-- that provides functionality to set favorites, load, and manager
-- the plugins.
-- --------------------------------------------------------------

PluginSlotContainer = class( Turbine.UI.Window );

-- --------------------------------------------------------------
-- Constructor
--
-- Description: the plugin slot container sets up its window, but
-- waits until the Initialize method to do anything with the
-- visual appearance of the slot.
-- --------------------------------------------------------------
function PluginSlotContainer:Constructor()
  Turbine.UI.Window.Constructor( self );

  -- --------------------------------------------
  -- members
  -- --------------------------------------------
  self.pluginSlot = FrostyPlugins.CustomPluginsManager.PluginSlot();
  self.owner = nil;
  
  -- --------------------------------------------
  -- window layout
  -- --------------------------------------------
  
  -- set window properties
  self:SetBackground( "FrostyPlugins/CustomPluginsManager/Resources/DefaultPluginBackground.tga" );
  self:SetSize( 32, 40 );
  
  -- we automatically add the frame around all icons (to provide a
  -- consistent interface!) in order to do that, we need a window
  -- that we can set a background on.  the window also applies a
  -- highlight indicator by shifting the background color.
  self.windowFrame = Turbine.UI.Window();
  self.windowFrame:SetBackground( "FrostyPlugins/CustomPluginsManager/Resources/PluginFrame.tga" );
  self.windowFrame:SetBackColorBlendMode( Turbine.UI.BlendMode.Overlay );
  self.windowFrame:SetParent( self );
  self.windowFrame:SetSize( 32, 40 );
  self.windowFrame:SetVisible( false );
  
  self.windowFrame.MouseEnter = function( sender, args )
          self.windowFrame:SetBackColor( Turbine.UI.Color( 0.5, 1, 1, 0 ) );
        end
  self.windowFrame.MouseLeave = function( sender, args )
          self.windowFrame:SetBackColor( Turbine.UI.Color( 0, 0, 0, 0 ) );
        end

  -- right click menu / mouse handling
  self.windowFrame.MouseDown = function( sender, args )
    if ( args.Button == Turbine.UI.MouseButton.Left ) then
      -- what happens if the user left clicks on our plugin? nothing now...
    end
    
    if ( args.Button == Turbine.UI.MouseButton.Right ) then
      -- build the menu items in the context menu
      local contextMenu = Turbine.UI.ContextMenu();
      local contextMenuItems = contextMenu:GetItems();

      local loadMenuItem = Turbine.UI.MenuItem( "Load Plugin" );
      loadMenuItem.Click = function( sender, args )
        self:LoadPlugin( true );
      end

      local unloadMenuItem = Turbine.UI.MenuItem( "Unload Plugin" );
      unloadMenuItem.Click = function( sender, args )
        self:LoadPlugin( false );
      end

      local favoriteMenuItem = Turbine.UI.MenuItem( "Load on Startup" );
      favoriteMenuItem.Click = function( sender, args )
        self:SetFavorite( true );
      end

      local notFavoriteMenuItem = Turbine.UI.MenuItem( "Unload from Startup" );
      notFavoriteMenuItem.Click = function( sender, args )
        self:SetFavorite( false );
      end

      local refreshMenuItem = Turbine.UI.MenuItem( "Refresh Plugins" );
      refreshMenuItem.Click = function( sender, args )
        self:RefreshPlugins();
      end

      local setIconMenuItem = Turbine.UI.MenuItem( "Select Icon" );
      setIconMenuItem.Click = function( sender, args )
        self:SetIcon();
      end

      -- initialize the context menu
      if( not self.pluginSlot.PluginLoaded ) then
        contextMenuItems:Add( loadMenuItem );
      end
      if( self.pluginSlot.PluginLoaded ) then
        contextMenuItems:Add( unloadMenuItem );
      end
      if( not self.pluginSlot.PluginFavorite ) then
        contextMenuItems:Add( favoriteMenuItem );
      end
      if( self.pluginSlot.PluginFavorite ) then
        contextMenuItems:Add( notFavoriteMenuItem );
      end
        -- we always show the refresh and icon options
      contextMenuItems:Add( refreshMenuItem );
      contextMenuItems:Add( setIconMenuItem );
      
      contextMenu:ShowMenu();
    end
  end

  -- the overlays are small icons that give status to the display.
  -- loaded is a green check in the lower right corner
  -- favorite is a red heart in the lower left corner
  self.loadedOverlay = Turbine.UI.Window();
  self.loadedOverlay:SetBackground( "FrostyPlugins/CustomPluginsManager/Resources/LoadedOverlay.tga" );
  self.loadedOverlay:SetBackColorBlendMode( Turbine.UI.BlendMode.Overlay );
  self.loadedOverlay:SetMouseVisible( false );
  self.loadedOverlay:SetParent( self );
  self.loadedOverlay:SetPosition( 16, 26 );
  self.loadedOverlay:SetSize( 16, 16 );
  self.loadedOverlay:SetVisible( false );

  self.favoriteOverlay = Turbine.UI.Window();
  self.favoriteOverlay:SetBackground( "FrostyPlugins/CustomPluginsManager/Resources/FavoriteOverlay.tga" );
  self.favoriteOverlay:SetBackColorBlendMode( Turbine.UI.BlendMode.Overlay );
  self.favoriteOverlay:SetMouseVisible( false );
  self.favoriteOverlay:SetParent( self );
  self.favoriteOverlay:SetPosition( 0, 26 );
  self.favoriteOverlay:SetSize( 16, 16 );
  self.favoriteOverlay:SetVisible( false );

end

-- --------------------------------------------------------------
-- SetOwner
--
-- Description: set the oner of this PluginSlotContainer.  It is
-- expected that this is the CustomPluginsManager
--
-- Params:
-- owner - CustomPluginsManager - the owner of the PluginSlotContainer.
--         used to callback when the state of the PluginSlot changes.
-- --------------------------------------------------------------
function PluginSlotContainer:SetOwner( owner )
  self.owner = owner;
end;

-- --------------------------------------------------------------
-- Initialize
--
-- Description: update the plugin slot with the information passed
-- into the function.
--
-- Params:
-- pluginData - pluginData - the information read from disk and used
--              to populate this container
-- --------------------------------------------------------------
function PluginSlotContainer:Initialize( pluginData, manager )
  self.pluginSlot:Copy( pluginData );
  
  -- use the plugin's icon for the display, otherwise, if it does
  -- not have one, use the unknown plugin background
  if( self.pluginSlot.PluginIcon == "" ) then
    self:SetBackground( "FrostyPlugins/CustomPluginsManager/Resources/UnknownPluginBackground.tga" );
  else
    self:SetBackground( self.pluginSlot.PluginIcon );
  end
  
  -- turn the frame on the window
  self.windowFrame:SetVisible( true );
  
  -- turn on the favorites or loaded frame
  self:RefreshOverlays();
  
  self:SetVisible( true );
end

-- --------------------------------------------------------------
-- RefreshOlverlays
--
-- Description: based on the state of the (member) pluginSlot
-- turn the overlays on or off
--
-- --------------------------------------------------------------
function PluginSlotContainer:RefreshOverlays()
  local visible = false;
  if( self.pluginSlot.PluginLoaded ) then
    visible = true;
  end
  self.loadedOverlay:SetVisible( visible );
  
  visible = false;
  if( self.pluginSlot.PluginFavorite ) then
    visible = true;
  end
  self.favoriteOverlay:SetVisible( visible );
end

-- --------------------------------------------------------------
-- Reset
--
-- Description: reset the plugin slot to an empty slot with no
-- graphics and all data reset to the default values
--
-- --------------------------------------------------------------
function PluginSlotContainer:Reset()
  self.pluginSlot:Reset();
  
  -- reset any window modifications
  self:SetBackground( "FrostyPlugins/CustomPluginsManager/Resources/DefaultPluginBackground.tga" );
  self.windowFrame:SetVisible( false );
  self.loadedOverlay:SetVisible( false );
  self.favoriteOverlay:SetVisible( false );
  self:SetVisible( false );
end

-- --------------------------------------------------------------
-- LoadPlugin
--
-- Description: the user has right clicked on this plugin and requested
-- that it be loaded.  Make it so!
--
-- Params:
-- bLoad - boolean - flag if the plugin should be loaded or unloaded
-- --------------------------------------------------------------
function PluginSlotContainer:LoadPlugin( bLoad )
  if( self.owner ) then
    self.owner:LoadPlugin( self, bLoad );
  end
end

-- --------------------------------------------------------------
-- SetFavorite
--
-- Description: the user has right clicked on this plugin and requested
-- that it be marked as a favorite (loaded on startup).
--
-- Params:
-- bFavorite - boolean - flag if the plugin should be marked as a
--             favorite or not
-- --------------------------------------------------------------
function PluginSlotContainer:SetFavorite( bFavorite )
  if( self.owner ) then
    self.owner:SetFavorite( self, bFavorite );
  end
end

-- --------------------------------------------------------------
-- RefreshPlugins
--
-- Description: the user has right clicked on a plugin and requested
-- that the manager refresh all plugins
-- --------------------------------------------------------------
function PluginSlotContainer:RefreshPlugins()
  if( self.owner ) then
    self.owner:RefreshAllPlugins();
  end
end

-- --------------------------------------------------------------
-- SetIcon
--
-- Description: the user has right clicked on this plugin and requested
-- that the icon be set.  forward on to the manager
-- --------------------------------------------------------------
function PluginSlotContainer:SetIcon()
  if( self.owner ) then
    self.owner:SetIcon( self );
  end
end

Compare with Previous | Blame


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


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