enum operationsMode
{
	PLAYER = 0,
	FLATHEAD = 1,
	TOOLBOX = 2,
}

class PaperDollSlotController extends inkButtonDpadSupportedController
{
	protected var m_equipArea : gamedataEquipmentArea;
	protected var m_slotIndex : Int32;
	protected var m_areaTags : array< CName >;
	protected var m_itemID : ItemID;
	protected var m_slotName : String;
	protected var m_itemData : gameItemData;
	protected var m_locked : Bool;

	protected event OnInitialize()
	{
		m_locked = false;
		super.OnInitialize();
	}

	public function SetButtonDetails( const argText : ref< String >, equipArea : gamedataEquipmentArea, slotIndex : Int32, const areaTags : ref< array< CName > > )
	{
		var currListText : weak< inkText >;
		var currListIcon : weak< inkImage >;
		m_rootWidget = ( ( inkCanvas )( GetRootWidget() ) );
		m_areaTags = areaTags;
		m_equipArea = equipArea;
		m_slotIndex = slotIndex;
		currListText = ( ( inkText )( m_rootWidget.GetWidget( 'textLabel' ) ) );
		currListText.SetText( argText );
		m_slotName = argText;
		currListIcon = ( ( inkImage )( m_rootWidget.GetWidget( 'icon' ) ) );
		currListIcon.SetVisible( false );
	}

	public function SetItemInSlot( itemID : ItemID )
	{
		var currListText : weak< inkText >;
		var currListIcon : weak< inkImage >;
		var itemNameString : String;
		var itemName : CName;
		var qualityBg : weak< inkRectangle >;
		var color : CName;
		m_itemID = itemID;
		currListText = ( ( inkText )( m_rootWidget.GetWidget( 'itemName' ) ) );
		qualityBg = ( ( inkRectangle )( m_rootWidget.GetWidget( 'quality' ) ) );
		itemName = TweakDBInterface.GetItemRecord( ItemID.GetTDBID( itemID ) ).DisplayName();
		itemNameString = NameToString( itemName );
		currListText.SetText( itemNameString );
		color = StringToName( TweakDBInterface.GetItemRecord( ItemID.GetTDBID( itemID ) ).Quality().Name() );
		currListText.SetState( color );
		if( color != 'Poor' && color != 'Common' )
		{
			qualityBg.SetState( color );
			qualityBg.SetVisible( true );
		}
		else
		{
			qualityBg.SetVisible( false );
		}
		currListIcon = ( ( inkImage )( m_rootWidget.GetWidget( 'icon' ) ) );
		if( itemName != 'None' )
		{
			if( currListIcon.IsTexturePartExist( itemName ) )
			{
				currListIcon.SetTexturePart( itemName );
				currListIcon.SetVisible( true );
			}
			else
			{
				currListIcon.SetTexturePart( 'none' );
				currListIcon.SetVisible( true );
			}
		}
		else
		{
			currListIcon.SetTexturePart( 'none' );
			currListText.SetText( "" );
			currListIcon.SetVisible( false );
		}
	}

	public function SetSlotLocked( slotTweak : TweakDBID )
	{
		var currListText : weak< inkText >;
		var currListIcon : weak< inkImage >;
		var tweakID : TweakDBID;
		var skillName : String;
		var skillLevel : Int32;
		tweakID = slotTweak;
		TDBID.Append( tweakID, T".skillName" );
		skillName = TDB.GetString( tweakID, "" );
		tweakID = slotTweak;
		TDBID.Append( tweakID, T".skillLevel" );
		skillLevel = TDB.GetInt( tweakID );
		currListText = ( ( inkText )( m_rootWidget.GetWidget( 'itemName' ) ) );
		currListText.SetText( ( ( ( "[LOCKED]\n[" + skillName ) + "] : [" ) + ( ( String )( skillLevel ) ) ) + "]" );
		currListIcon = ( ( inkImage )( m_rootWidget.GetWidget( 'icon' ) ) );
		currListIcon.SetTexturePart( 'none' );
		currListIcon.SetVisible( true );
		m_locked = true;
	}

	public function IsLocked() : Bool
	{
		return m_locked;
	}

	public function GetItem() : ItemID
	{
		return m_itemID;
	}

	public function GetItemData() : gameItemData
	{
		return m_itemData;
	}

	public function GetAreaTags() : array< CName >
	{
		return m_areaTags;
	}

	public function GetEquipArea() : gamedataEquipmentArea
	{
		return m_equipArea;
	}

	public function GetSlotIndex() : Int32
	{
		return m_slotIndex;
	}

	public function GetSlotName() : String
	{
		return m_slotName;
	}

}

class ArmorEquipInventoryItemController extends inkButtonDpadSupportedController
{
	protected var m_itemID : ItemID;
	protected var m_itemData : gameItemData;
	protected var m_empty : Bool;

	protected event OnInitialize()
	{
		super.OnInitialize();
	}

	public function ClearButton()
	{
		var displayName : weak< inkText >;
		var quality : weak< inkText >;
		var statValue : weak< inkText >;
		var quantity : weak< inkText >;
		var statName : weak< inkText >;
		var qualityBg : weak< inkRectangle >;
		var currListIcon : weak< inkImage >;
		m_rootWidget = ( ( inkCanvas )( GetRootWidget() ) );
		displayName = ( ( inkText )( m_rootWidget.GetWidget( 'textLabel' ) ) );
		quality = ( ( inkText )( m_rootWidget.GetWidget( 'rarityLabel' ) ) );
		statValue = ( ( inkText )( m_rootWidget.GetWidget( 'summaryLabel' ) ) );
		statName = ( ( inkText )( m_rootWidget.GetWidget( 'summarySubText' ) ) );
		quantity = ( ( inkText )( m_rootWidget.GetWidget( 'txtQuantity' ) ) );
		currListIcon = ( ( inkImage )( m_rootWidget.GetWidget( 'icon' ) ) );
		qualityBg = ( ( inkRectangle )( m_rootWidget.GetWidget( 'quality' ) ) );
		qualityBg.SetVisible( false );
		displayName.SetText( "" );
		quality.SetText( "" );
		statValue.SetText( "" );
		statName.SetText( "" );
		quantity.SetText( "" );
		currListIcon.SetTexturePart( 'none' );
		currListIcon.SetVisible( false );
		m_empty = true;
	}

	public function SetButtonDetails( itemData : gameItemData, itemQuantity : Int32, disassemblable : Bool )
	{
		var displayName : weak< inkText >;
		var quality : weak< inkText >;
		var statValue : weak< inkText >;
		var statName : weak< inkText >;
		var quantity : weak< inkText >;
		var currListIcon : weak< inkImage >;
		var qualityBg : weak< inkRectangle >;
		var itemRecord : Item_Record;
		var itemName : CName;
		var itemNameString : String;
		var diss : String;
		var color : CName;
		m_rootWidget = ( ( inkCanvas )( GetRootWidget() ) );
		displayName = ( ( inkText )( m_rootWidget.GetWidget( 'textLabel' ) ) );
		quality = ( ( inkText )( m_rootWidget.GetWidget( 'rarityLabel' ) ) );
		statValue = ( ( inkText )( m_rootWidget.GetWidget( 'summaryLabel' ) ) );
		statName = ( ( inkText )( m_rootWidget.GetWidget( 'summarySubText' ) ) );
		currListIcon = ( ( inkImage )( m_rootWidget.GetWidget( 'icon' ) ) );
		quantity = ( ( inkText )( m_rootWidget.GetWidget( 'txtQuantity' ) ) );
		qualityBg = ( ( inkRectangle )( m_rootWidget.GetWidget( 'quality' ) ) );
		m_itemData = itemData;
		m_itemID = itemData.GetID();
		itemRecord = TweakDBInterface.GetItemRecord( ItemID.GetTDBID( m_itemID ) );
		itemName = itemRecord.DisplayName();
		itemNameString = NameToString( itemName );
		if( disassemblable )
		{
			diss = " [D]";
		}
		else
		{
			diss = "";
		}
		displayName.SetText( itemNameString + diss );
		quality.SetText( itemRecord.Quality().Name() );
		statValue.SetText( "" );
		statName.SetText( "" );
		if( itemQuantity > 1 )
		{
			quantity.SetText( IntToString( itemQuantity ) );
		}
		else
		{
			quantity.SetText( "" );
		}
		itemName = itemRecord.DisplayName();
		currListIcon.SetVisible( false );
		m_empty = false;
		color = StringToName( itemRecord.Quality().Name() );
		displayName.SetState( color );
		quality.SetState( color );
		quantity.SetState( color );
		if( color != 'Poor' && color != 'Common' )
		{
			qualityBg.SetState( color );
			qualityBg.SetVisible( true );
		}
		if( currListIcon.IsTexturePartExist( itemName ) )
		{
			currListIcon.SetTexturePart( itemName );
			currListIcon.SetVisible( true );
		}
		else
		{
			currListIcon.SetTexturePart( 'none' );
			currListIcon.SetVisible( true );
		}
		if( itemName == 'None' )
		{
			currListIcon.SetTexturePart( 'undefined' );
			quality.SetText( "!Undefined item" );
			displayName.SetText( "!No name defined" );
			currListIcon.SetVisible( true );
		}
	}

	public function GetItemData() : gameItemData
	{
		return m_itemData;
	}

	public function GetItemID() : ItemID
	{
		return m_itemID;
	}

	public function GetIsEmpty() : Bool
	{
		return m_empty;
	}

}

class ArmorEquipGameController extends gameuiMenuGameController
{
	protected var m_inventoryCanvas : weak< inkWidget >;
	protected var m_inventoryList : weak< inkVerticalPanel >;
	protected var m_inventory : array< weak< gameItemData > >;
	protected var player : weak< PlayerPuppet >;
	protected var m_equipmentSystem : weak< EquipmentSystem >;
	protected var m_subCharacterSystem : weak< SubCharacterSystem >;
	protected var m_transactionSystem : weak< TransactionSystem >;
	protected var m_craftingSystem : weak< CraftingSystem >;
	protected var buttonScrollUp : weak< inkCanvas >;
	protected var buttonScrollDn : weak< inkCanvas >;
	protected var buttonPlayer : weak< inkCanvas >;
	protected var buttonFlathead : weak< inkCanvas >;
	protected var buttonToolbox : weak< inkCanvas >;
	protected var panelPlayer : weak< inkCanvas >;
	protected var panelFlathead : weak< inkCanvas >;
	protected var panelToolbox : weak< inkCanvas >;
	protected var m_uiBB_Equipment : UI_EquipmentDef;
	protected var m_uiBB_EquipmentBlackboard : weak< IBlackboard >;
	protected var m_backgroundVideo : weak< inkVideo >;
	protected var m_paperdollVideo : weak< inkVideo >;
	protected var m_areaTags : array< CName >;
	protected var m_inventoryManager : InventoryDataManager;
	protected var m_equipArea : gamedataEquipmentArea;
	protected var m_slotIndex : Int32;
	protected var m_recipeItemList : array< TweakDBID >;
	protected var m_playerCraftBook : CraftBook;
	protected editable var m_tooltipsLibrary : ResRef;
	default m_tooltipsLibrary = R"base/gameplay/gui/common/tooltip/tooltipslibrary.inkwidget";
	protected editable var m_itemTooltipName : CName;
	default m_itemTooltipName = 'itemTooltip';
	protected editable var m_tooltipStylePath : ResRef;
	default m_tooltipStylePath = R"base/gameplay/gui/common/tooltip/tooltip_menu.inkstyle";
	protected var m_tooltipLeft : weak< InventorySlotTooltip >;
	protected var m_tooltipRight : weak< InventorySlotTooltip >;
	protected var m_tooltipContainer : weak< inkCompoundWidget >;
	protected var m_paperDollList : array< CName >;
	protected var scrollOffset : Int32;
	protected var faceTags : array< CName >;
	protected var headTags : array< CName >;
	protected var chestTags : array< CName >;
	protected var legTags : array< CName >;
	protected var weaponTags : array< CName >;
	protected var consumableTags : array< CName >;
	protected var modulesTags : array< CName >;
	protected var framesTags : array< CName >;
	protected var m_operationsMode : operationsMode;

	protected event OnInitialize()
	{
		var currWidget : weak< inkWidget >;
		var currButton : weak< inkCanvas >;
		m_equipArea = gamedataEquipmentArea.Invalid;
		m_operationsMode = operationsMode.PLAYER;
		m_inventoryList = ( ( inkVerticalPanel )( GetWidget( 'InventoryCanvas/vertInventoryList' ) ) );
		m_inventoryCanvas = ( ( inkWidget )( GetWidget( 'InventoryCanvas' ) ) );
		panelPlayer = ( ( inkCanvas )( GetWidget( 'playerPuppet' ) ) );
		panelFlathead = ( ( inkCanvas )( GetWidget( 'flatheadPuppet' ) ) );
		panelToolbox = ( ( inkCanvas )( GetWidget( 'toolboxPuppet' ) ) );
		panelPlayer.SetVisible( true );
		panelFlathead.SetVisible( false );
		panelToolbox.SetVisible( false );
		m_tooltipContainer = ( ( inkCompoundWidget )( GetWidget( 'tooltipContainer' ) ) );
		m_paperdollVideo = ( ( inkVideo )( GetWidget( 'playerPuppet/paperdollVideo' ) ) );
		m_backgroundVideo = ( ( inkVideo )( GetWidget( 'backgroundVideo' ) ) );
		m_paperdollVideo.SetVideoPath( R"base\gameplay\gui\widgets\menus\inventory\assets\v_weapon.bk2" );
		m_paperdollVideo.Play();
		player = ( ( PlayerPuppet )( GetOwnerEntity() ) );
		m_inventoryManager = new InventoryDataManager;
		m_inventoryManager.Initialize( player );
		m_uiBB_Equipment = GetAllBlackboardDefs().UI_Equipment;
		m_uiBB_EquipmentBlackboard = GetBlackboardSystem().Get( m_uiBB_Equipment );
		GameInstance.GetTransactionSystem( player.GetGame() ).GetItemList( player, m_inventory );
		m_equipmentSystem = ( ( EquipmentSystem )( GameInstance.GetScriptableSystemsContainer( player.GetGame() ).Get( 'EquipmentSystem' ) ) );
		m_subCharacterSystem = ( ( SubCharacterSystem )( GameInstance.GetScriptableSystemsContainer( player.GetGame() ).Get( 'SubCharacterSystem' ) ) );
		m_transactionSystem = GameInstance.GetTransactionSystem( player.GetGame() );
		m_craftingSystem = ( ( CraftingSystem )( GameInstance.GetScriptableSystemsContainer( player.GetGame() ).Get( 'CraftingSystem' ) ) );
		m_playerCraftBook = m_craftingSystem.GetPlayerCraftBook();
		faceTags.PushBack( 'FaceArmor' );
		headTags.PushBack( 'HeadArmor' );
		chestTags.PushBack( 'ChestArmor' );
		legTags.PushBack( 'LegArmor' );
		weaponTags.PushBack( 'Weapon' );
		weaponTags.PushBack( WeaponObject.GetMeleeWeaponTag() );
		consumableTags.PushBack( 'Drug' );
		consumableTags.PushBack( 'Gadget' );
		consumableTags.PushBack( 'Grenade' );
		modulesTags.PushBack( 'SpiderBotModule' );
		modulesTags.PushBack( 'CombatCore' );
		modulesTags.PushBack( 'TacticalCore' );
		framesTags.PushBack( 'Frame' );
		currButton = ( ( inkCanvas )( GetWidget( 'playerPuppet/slotHead' ) ) );
		m_paperDollList.PushBack( 'playerPuppet/slotHead' );
		HelperAddPaperdollButton( "HEAD", currButton, gamedataEquipmentArea.Head, 0, headTags );
		currButton = ( ( inkCanvas )( GetWidget( 'playerPuppet/slotFace' ) ) );
		m_paperDollList.PushBack( 'playerPuppet/slotFace' );
		HelperAddPaperdollButton( "FACE", currButton, gamedataEquipmentArea.Face, 0, faceTags );
		currButton = ( ( inkCanvas )( GetWidget( 'playerPuppet/slotShirt' ) ) );
		m_paperDollList.PushBack( 'playerPuppet/slotShirt' );
		HelperAddPaperdollButton( "SHIRT", currButton, gamedataEquipmentArea.InnerChest, 0, chestTags );
		currButton = ( ( inkCanvas )( GetWidget( 'playerPuppet/slotJacket' ) ) );
		m_paperDollList.PushBack( 'playerPuppet/slotJacket' );
		HelperAddPaperdollButton( "JACKET", currButton, gamedataEquipmentArea.OuterChest, 0, chestTags );
		currButton = ( ( inkCanvas )( GetWidget( 'playerPuppet/slotPants' ) ) );
		m_paperDollList.PushBack( 'playerPuppet/slotPants' );
		HelperAddPaperdollButton( "PANTS", currButton, gamedataEquipmentArea.Legs, 0, legTags );
		currButton = ( ( inkCanvas )( GetWidget( 'playerPuppet/slotBoots' ) ) );
		m_paperDollList.PushBack( 'playerPuppet/slotBoots' );
		HelperAddPaperdollButton( "BOOTS", currButton, gamedataEquipmentArea.Feet, 0, legTags );
		currButton = ( ( inkCanvas )( GetWidget( 'playerPuppet/slotArmUpgrade1_1' ) ) );
		m_paperDollList.PushBack( 'playerPuppet/slotArmUpgrade1_1' );
		HelperAddPaperdollButton( "MANTIS BLADE UPGRADES", currButton, gamedataEquipmentArea.Invalid, 0, faceTags );
		currButton = ( ( inkCanvas )( GetWidget( 'playerPuppet/slotArmUpgrade1_2' ) ) );
		m_paperDollList.PushBack( 'playerPuppet/slotArmUpgrade1_2' );
		HelperAddPaperdollButton( "", currButton, gamedataEquipmentArea.Invalid, 0, faceTags );
		currButton = ( ( inkCanvas )( GetWidget( 'playerPuppet/slotArmUpgrade2_1' ) ) );
		m_paperDollList.PushBack( 'playerPuppet/slotArmUpgrade2_1' );
		HelperAddPaperdollButton( "PROJECTILE LAUNCHER UPGRADES", currButton, gamedataEquipmentArea.Invalid, 0, faceTags );
		currButton = ( ( inkCanvas )( GetWidget( 'playerPuppet/slotArmUpgrade2_2' ) ) );
		m_paperDollList.PushBack( 'playerPuppet/slotArmUpgrade2_2' );
		HelperAddPaperdollButton( "", currButton, gamedataEquipmentArea.Invalid, 0, faceTags );
		currButton = ( ( inkCanvas )( GetWidget( 'playerPuppet/slotProgram1' ) ) );
		m_paperDollList.PushBack( 'playerPuppet/slotProgram1' );
		HelperAddPaperdollButton( "CYBERDECK PROGRAMS", currButton, gamedataEquipmentArea.Invalid, 0, faceTags );
		currButton = ( ( inkCanvas )( GetWidget( 'playerPuppet/slotProgram2' ) ) );
		m_paperDollList.PushBack( 'playerPuppet/slotProgram2' );
		HelperAddPaperdollButton( "", currButton, gamedataEquipmentArea.Invalid, 1, faceTags );
		currButton = ( ( inkCanvas )( GetWidget( 'playerPuppet/slotProgram3' ) ) );
		m_paperDollList.PushBack( 'playerPuppet/slotProgram3' );
		HelperAddPaperdollButton( "", currButton, gamedataEquipmentArea.Invalid, 2, faceTags );
		currButton = ( ( inkCanvas )( GetWidget( 'playerPuppet/quickSlot1' ) ) );
		m_paperDollList.PushBack( 'playerPuppet/quickSlot1' );
		HelperAddPaperdollButton( "QUICK SLOT 1", currButton, gamedataEquipmentArea.QuickSlot, 0, consumableTags );
		currButton = ( ( inkCanvas )( GetWidget( 'playerPuppet/quickSlot2' ) ) );
		m_paperDollList.PushBack( 'playerPuppet/quickSlot2' );
		HelperAddPaperdollButton( "QUICK SLOT 2", currButton, gamedataEquipmentArea.QuickSlot, 1, consumableTags );
		currButton = ( ( inkCanvas )( GetWidget( 'playerPuppet/quickSlot3' ) ) );
		m_paperDollList.PushBack( 'playerPuppet/quickSlot3' );
		HelperAddPaperdollButton( "QUICK SLOT 3", currButton, gamedataEquipmentArea.QuickSlot, 2, consumableTags );
		currButton = ( ( inkCanvas )( GetWidget( 'playerPuppet/quickSlot4' ) ) );
		m_paperDollList.PushBack( 'playerPuppet/quickSlot4' );
		HelperAddPaperdollButton( "QUICK SLOT 4", currButton, gamedataEquipmentArea.QuickSlot, 3, consumableTags );
		currButton = ( ( inkCanvas )( GetWidget( 'playerPuppet/quickSlot5' ) ) );
		m_paperDollList.PushBack( 'playerPuppet/quickSlot5' );
		HelperAddPaperdollButton( "QUICK SLOT 5", currButton, gamedataEquipmentArea.QuickSlot, 4, consumableTags );
		currButton = ( ( inkCanvas )( GetWidget( 'playerPuppet/slotWeapon1' ) ) );
		m_paperDollList.PushBack( 'playerPuppet/slotWeapon1' );
		HelperAddPaperdollButton( "WEAPON SLOT 1", currButton, gamedataEquipmentArea.Weapon, 0, weaponTags );
		currButton = ( ( inkCanvas )( GetWidget( 'playerPuppet/slotWeapon2' ) ) );
		m_paperDollList.PushBack( 'playerPuppet/slotWeapon2' );
		HelperAddPaperdollButton( "WEAPON SLOT 2", currButton, gamedataEquipmentArea.Weapon, 1, weaponTags );
		currButton = ( ( inkCanvas )( GetWidget( 'playerPuppet/slotWeapon3' ) ) );
		m_paperDollList.PushBack( 'playerPuppet/slotWeapon3' );
		HelperAddPaperdollButton( "WEAPON SLOT 3", currButton, gamedataEquipmentArea.Weapon, 2, weaponTags );
		currButton = ( ( inkCanvas )( GetWidget( 'flatheadPuppet/slotFlatheadModule1' ) ) );
		m_paperDollList.PushBack( 'flatheadPuppet/slotFlatheadModule1' );
		HelperAddPaperdollButton( "FLATHEAD EXPANSION MODULE", currButton, gamedataEquipmentArea.BotMainModule, 0, headTags );
		currButton = ( ( inkCanvas )( GetWidget( 'flatheadPuppet/slotFlatheadModule2' ) ) );
		m_paperDollList.PushBack( 'flatheadPuppet/slotFlatheadModule2' );
		HelperAddPaperdollButton( "CPU UPGRADES", currButton, gamedataEquipmentArea.BotCPU, 0, headTags );
		currButton = ( ( inkCanvas )( GetWidget( 'flatheadPuppet/slotFlatheadModule3' ) ) );
		m_paperDollList.PushBack( 'flatheadPuppet/slotFlatheadModule3' );
		HelperAddPaperdollButton( "", currButton, gamedataEquipmentArea.BotCPU, 1, headTags );
		currButton = ( ( inkCanvas )( GetWidget( 'flatheadPuppet/slotFlatheadModule4' ) ) );
		m_paperDollList.PushBack( 'flatheadPuppet/slotFlatheadModule4' );
		HelperAddPaperdollButton( "", currButton, gamedataEquipmentArea.BotCPU, 2, headTags );
		currButton = ( ( inkCanvas )( GetWidget( 'flatheadPuppet/slotFlatheadSoftware1' ) ) );
		m_paperDollList.PushBack( 'flatheadPuppet/slotFlatheadSoftware1' );
		HelperAddPaperdollButton( "", currButton, gamedataEquipmentArea.BotSoftware, 0, headTags );
		currButton = ( ( inkCanvas )( GetWidget( 'flatheadPuppet/slotFlatheadSoftware2' ) ) );
		m_paperDollList.PushBack( 'flatheadPuppet/slotFlatheadSoftware2' );
		HelperAddPaperdollButton( "", currButton, gamedataEquipmentArea.BotSoftware, 1, headTags );
		currButton = ( ( inkCanvas )( GetWidget( 'flatheadPuppet/slotFlatheadSoftware3' ) ) );
		m_paperDollList.PushBack( 'flatheadPuppet/slotFlatheadSoftware3' );
		HelperAddPaperdollButton( "", currButton, gamedataEquipmentArea.BotSoftware, 2, headTags );
		currButton = ( ( inkCanvas )( GetWidget( 'flatheadPuppet/slotFlatheadSoftware4' ) ) );
		m_paperDollList.PushBack( 'flatheadPuppet/slotFlatheadSoftware4' );
		HelperAddPaperdollButton( "", currButton, gamedataEquipmentArea.BotSoftware, 3, headTags );
		currButton = ( ( inkCanvas )( GetWidget( 'flatheadPuppet/slotFlatheadSoftware5' ) ) );
		m_paperDollList.PushBack( 'flatheadPuppet/slotFlatheadSoftware5' );
		HelperAddPaperdollButton( "SOFTWARE", currButton, gamedataEquipmentArea.BotSoftware, 4, headTags );
		( ( inkText )( GetWidget( 'toolboxPuppet/matCorrosive' ) ) ).SetText( GameInstance.GetTransactionSystem( player.GetGame() ).GetItemQuantity( player, ItemID.CreateQuery( T"Items.corrosive" ) ) + "x Corrosive materials" );
		( ( inkText )( GetWidget( 'toolboxPuppet/matExplosive' ) ) ).SetText( GameInstance.GetTransactionSystem( player.GetGame() ).GetItemQuantity( player, ItemID.CreateQuery( T"Items.explosive" ) ) + "x Explosive materials" );
		( ( inkText )( GetWidget( 'toolboxPuppet/matMedical' ) ) ).SetText( GameInstance.GetTransactionSystem( player.GetGame() ).GetItemQuantity( player, ItemID.CreateQuery( T"Items.medical" ) ) + "x Medical ingridients" );
		( ( inkText )( GetWidget( 'toolboxPuppet/matMetaplastic' ) ) ).SetText( GameInstance.GetTransactionSystem( player.GetGame() ).GetItemQuantity( player, ItemID.CreateQuery( T"Items.metaplastic" ) ) + "x Metaplastic" );
		( ( inkText )( GetWidget( 'toolboxPuppet/matCybertextile' ) ) ).SetText( GameInstance.GetTransactionSystem( player.GetGame() ).GetItemQuantity( player, ItemID.CreateQuery( T"Items.cybertextile" ) ) + "x Cybertextile" );
		( ( inkText )( GetWidget( 'toolboxPuppet/matCarbon' ) ) ).SetText( GameInstance.GetTransactionSystem( player.GetGame() ).GetItemQuantity( player, ItemID.CreateQuery( T"Items.carbon" ) ) + "x Carbon fibers" );
		( ( inkText )( GetWidget( 'toolboxPuppet/matDetector' ) ) ).SetText( GameInstance.GetTransactionSystem( player.GetGame() ).GetItemQuantity( player, ItemID.CreateQuery( T"Items.detector" ) ) + "x Detectors" );
		( ( inkText )( GetWidget( 'toolboxPuppet/matTrigger' ) ) ).SetText( GameInstance.GetTransactionSystem( player.GetGame() ).GetItemQuantity( player, ItemID.CreateQuery( T"Items.trigger" ) ) + "x Triggers" );
		( ( inkText )( GetWidget( 'toolboxPuppet/matScraps' ) ) ).SetText( GameInstance.GetTransactionSystem( player.GetGame() ).GetItemQuantity( player, ItemID.CreateQuery( T"Items.parts" ) ) + "x Scraps" );
		buttonScrollUp = ( ( inkCanvas )( GetWidget( 'scrollUp' ) ) );
		buttonScrollUp.RegisterToCallback( 'OnRelease', this, 'OnScrollUp' );
		buttonScrollDn = ( ( inkCanvas )( GetWidget( 'scrollDn' ) ) );
		buttonScrollDn.RegisterToCallback( 'OnRelease', this, 'OnScrollDn' );
		buttonScrollUp.SetVisible( false );
		buttonPlayer = ( ( inkCanvas )( GetWidget( 'btnPlayer' ) ) );
		buttonPlayer.RegisterToCallback( 'OnRelease', this, 'OnSelectPlayer' );
		buttonFlathead = ( ( inkCanvas )( GetWidget( 'btnFlathead' ) ) );
		buttonFlathead.RegisterToCallback( 'OnRelease', this, 'OnSelectFlathead' );
		buttonToolbox = ( ( inkCanvas )( GetWidget( 'btnToolbox' ) ) );
		buttonToolbox.RegisterToCallback( 'OnRelease', this, 'OnSelectToolbox' );
		if( m_transactionSystem.HasItem( player, ItemID.FromTDBID( T"Items.toolBox" ) ) )
		{
			buttonToolbox.SetVisible( true );
		}
		else
		{
			buttonToolbox.SetVisible( false );
		}
		RefreshEquipment();
		RefreshInventoryList();
		CreateTooltip( m_tooltipLeft );
		CreateTooltip( m_tooltipRight );
		SetCursorOverWidget( currWidget );
	}

	protected function CreateTooltip( out tooltipController : weak< InventorySlotTooltip > )
	{
		var tooltip : weak< inkWidget >;
		if( ResRef.IsValid( m_tooltipsLibrary ) == false )
		{
			m_tooltipsLibrary = R"base/gameplay/gui/common/tooltip/tooltipslibrary.inkwidget";
		}
		tooltip = SpawnFromExternal( m_tooltipContainer, m_tooltipsLibrary, m_itemTooltipName );
		tooltipController = ( ( InventorySlotTooltip )( tooltip.GetController() ) );
		if( ResRef.IsValid( m_tooltipStylePath ) == false )
		{
			m_tooltipStylePath = R"base/gameplay/gui/common/tooltip/tooltip_menu.inkstyle";
		}
		tooltipController.SetStyle( m_tooltipStylePath );
		tooltipController.Hide();
	}

	protected function HelperAddPaperdollButton( const argTitle : ref< String >, containerSlot : inkCanvas, equipArea : gamedataEquipmentArea, slotIndex : Int32, const areaTags : ref< array< CName > > )
	{
		var currButton : weak< inkCanvas >;
		var currLogic : weak< PaperDollSlotController >;
		currButton = ( ( inkCanvas )( containerSlot ) );
		currButton.UnregisterFromCallback( 'OnRelease', this, 'OnPaperDollCursor' );
		currButton.UnregisterFromCallback( 'OnEnter', this, 'OnPaperdollItemEnter' );
		currButton.UnregisterFromCallback( 'OnLeave', this, 'OnPaperdollItemExit' );
		currButton.RegisterToCallback( 'OnRelease', this, 'OnPaperDollCursor' );
		currButton.RegisterToCallback( 'OnEnter', this, 'OnPaperdollItemEnter' );
		currButton.RegisterToCallback( 'OnLeave', this, 'OnPaperdollItemExit' );
		currLogic = ( ( PaperDollSlotController )( currButton.GetController() ) );
		currLogic.SetButtonDetails( argTitle, equipArea, slotIndex, areaTags );
	}

	protected function HelperAddInventoryButton( itemData : gameItemData, slotId : Int32 )
	{
		var itemButton : weak< inkCompoundWidget >;
		var itemLogic : weak< ArmorEquipInventoryItemController >;
		var disassemblable : Bool;
		disassemblable = RPGManager.CanItemBeDisassembled( player.GetGame(), itemData.GetID() );
		if( slotId == 0 )
		{
			itemButton = ( ( inkCanvas )( GetWidget( 'inventoryItem1' ) ) );
		}
		else if( slotId == 1 )
		{
			itemButton = ( ( inkCanvas )( GetWidget( 'inventoryItem2' ) ) );
		}
		else if( slotId == 2 )
		{
			itemButton = ( ( inkCanvas )( GetWidget( 'inventoryItem3' ) ) );
		}
		else if( slotId == 3 )
		{
			itemButton = ( ( inkCanvas )( GetWidget( 'inventoryItem4' ) ) );
		}
		else if( slotId == 4 )
		{
			itemButton = ( ( inkCanvas )( GetWidget( 'inventoryItem5' ) ) );
		}
		else if( slotId == 5 )
		{
			itemButton = ( ( inkCanvas )( GetWidget( 'inventoryItem6' ) ) );
		}
		else if( slotId == 6 )
		{
			itemButton = ( ( inkCanvas )( GetWidget( 'inventoryItem7' ) ) );
		}
		else if( slotId == 7 )
		{
			itemButton = ( ( inkCanvas )( GetWidget( 'inventoryItem8' ) ) );
		}
		else if( slotId == 8 )
		{
			itemButton = ( ( inkCanvas )( GetWidget( 'inventoryItem9' ) ) );
		}
		else if( slotId == 9 )
		{
			itemButton = ( ( inkCanvas )( GetWidget( 'inventoryItem10' ) ) );
		}
		else if( slotId == 10 )
		{
			itemButton = ( ( inkCanvas )( GetWidget( 'inventoryItem11' ) ) );
		}
		else if( slotId == 11 )
		{
			itemButton = ( ( inkCanvas )( GetWidget( 'inventoryItem12' ) ) );
		}
		else if( slotId == 12 )
		{
			itemButton = ( ( inkCanvas )( GetWidget( 'inventoryItem13' ) ) );
		}
		else if( slotId == 13 )
		{
			itemButton = ( ( inkCanvas )( GetWidget( 'inventoryItem14' ) ) );
		}
		else if( slotId == 14 )
		{
			itemButton = ( ( inkCanvas )( GetWidget( 'inventoryItem15' ) ) );
		}
		else if( slotId == 15 )
		{
			itemButton = ( ( inkCanvas )( GetWidget( 'inventoryItem16' ) ) );
		}
		else if( slotId == 16 )
		{
			itemButton = ( ( inkCanvas )( GetWidget( 'inventoryItem17' ) ) );
		}
		else if( slotId == 17 )
		{
			itemButton = ( ( inkCanvas )( GetWidget( 'inventoryItem18' ) ) );
		}
		else if( slotId == 18 )
		{
			itemButton = ( ( inkCanvas )( GetWidget( 'inventoryItem19' ) ) );
		}
		else if( slotId == 19 )
		{
			itemButton = ( ( inkCanvas )( GetWidget( 'inventoryItem20' ) ) );
		}
		else if( slotId == 20 )
		{
			itemButton = ( ( inkCanvas )( GetWidget( 'inventoryItem21' ) ) );
		}
		else if( slotId == 21 )
		{
			itemButton = ( ( inkCanvas )( GetWidget( 'inventoryItem22' ) ) );
		}
		else if( slotId == 22 )
		{
			itemButton = ( ( inkCanvas )( GetWidget( 'inventoryItem23' ) ) );
		}
		else if( slotId == 23 )
		{
			itemButton = ( ( inkCanvas )( GetWidget( 'inventoryItem24' ) ) );
		}
		else if( slotId == 24 )
		{
			itemButton = ( ( inkCanvas )( GetWidget( 'inventoryItem25' ) ) );
		}
		else if( slotId == 25 )
		{
			itemButton = ( ( inkCanvas )( GetWidget( 'inventoryItem26' ) ) );
		}
		else if( slotId == 26 )
		{
			itemButton = ( ( inkCanvas )( GetWidget( 'inventoryItem27' ) ) );
		}
		else if( slotId == 27 )
		{
			itemButton = ( ( inkCanvas )( GetWidget( 'inventoryItem28' ) ) );
		}
		else if( slotId == 28 )
		{
			itemButton = ( ( inkCanvas )( GetWidget( 'inventoryItem29' ) ) );
		}
		else if( slotId == 29 )
		{
			itemButton = ( ( inkCanvas )( GetWidget( 'inventoryItem30' ) ) );
		}
		else
		{
			return;
		}
		itemButton.UnregisterFromCallback( 'OnRelease', this, 'OnInventoryItemPush' );
		itemButton.UnregisterFromCallback( 'OnEnter', this, 'OnInventoryItemEnter' );
		itemButton.UnregisterFromCallback( 'OnLeave', this, 'OnInventoryItemExit' );
		itemButton.RegisterToCallback( 'OnRelease', this, 'OnInventoryItemPush' );
		itemButton.RegisterToCallback( 'OnEnter', this, 'OnInventoryItemEnter' );
		itemButton.RegisterToCallback( 'OnLeave', this, 'OnInventoryItemExit' );
		itemLogic = ( ( ArmorEquipInventoryItemController )( itemButton.GetController() ) );
		itemLogic.SetButtonDetails( itemData, m_transactionSystem.GetItemQuantity( player, itemData.GetID() ), disassemblable );
	}

	protected function HelperClearButton( slotId : Int32 )
	{
		var itemButton : weak< inkCompoundWidget >;
		var itemLogic : weak< ArmorEquipInventoryItemController >;
		if( slotId == 0 )
		{
			itemButton = ( ( inkCanvas )( GetWidget( 'inventoryItem1' ) ) );
		}
		else if( slotId == 1 )
		{
			itemButton = ( ( inkCanvas )( GetWidget( 'inventoryItem2' ) ) );
		}
		else if( slotId == 2 )
		{
			itemButton = ( ( inkCanvas )( GetWidget( 'inventoryItem3' ) ) );
		}
		else if( slotId == 3 )
		{
			itemButton = ( ( inkCanvas )( GetWidget( 'inventoryItem4' ) ) );
		}
		else if( slotId == 4 )
		{
			itemButton = ( ( inkCanvas )( GetWidget( 'inventoryItem5' ) ) );
		}
		else if( slotId == 5 )
		{
			itemButton = ( ( inkCanvas )( GetWidget( 'inventoryItem6' ) ) );
		}
		else if( slotId == 6 )
		{
			itemButton = ( ( inkCanvas )( GetWidget( 'inventoryItem7' ) ) );
		}
		else if( slotId == 7 )
		{
			itemButton = ( ( inkCanvas )( GetWidget( 'inventoryItem8' ) ) );
		}
		else if( slotId == 8 )
		{
			itemButton = ( ( inkCanvas )( GetWidget( 'inventoryItem9' ) ) );
		}
		else if( slotId == 9 )
		{
			itemButton = ( ( inkCanvas )( GetWidget( 'inventoryItem10' ) ) );
		}
		else if( slotId == 10 )
		{
			itemButton = ( ( inkCanvas )( GetWidget( 'inventoryItem11' ) ) );
		}
		else if( slotId == 11 )
		{
			itemButton = ( ( inkCanvas )( GetWidget( 'inventoryItem12' ) ) );
		}
		else if( slotId == 12 )
		{
			itemButton = ( ( inkCanvas )( GetWidget( 'inventoryItem13' ) ) );
		}
		else if( slotId == 13 )
		{
			itemButton = ( ( inkCanvas )( GetWidget( 'inventoryItem14' ) ) );
		}
		else if( slotId == 14 )
		{
			itemButton = ( ( inkCanvas )( GetWidget( 'inventoryItem15' ) ) );
		}
		else if( slotId == 15 )
		{
			itemButton = ( ( inkCanvas )( GetWidget( 'inventoryItem16' ) ) );
		}
		else if( slotId == 16 )
		{
			itemButton = ( ( inkCanvas )( GetWidget( 'inventoryItem17' ) ) );
		}
		else if( slotId == 17 )
		{
			itemButton = ( ( inkCanvas )( GetWidget( 'inventoryItem18' ) ) );
		}
		else if( slotId == 18 )
		{
			itemButton = ( ( inkCanvas )( GetWidget( 'inventoryItem19' ) ) );
		}
		else if( slotId == 19 )
		{
			itemButton = ( ( inkCanvas )( GetWidget( 'inventoryItem20' ) ) );
		}
		else if( slotId == 20 )
		{
			itemButton = ( ( inkCanvas )( GetWidget( 'inventoryItem21' ) ) );
		}
		else if( slotId == 21 )
		{
			itemButton = ( ( inkCanvas )( GetWidget( 'inventoryItem22' ) ) );
		}
		else if( slotId == 22 )
		{
			itemButton = ( ( inkCanvas )( GetWidget( 'inventoryItem23' ) ) );
		}
		else if( slotId == 23 )
		{
			itemButton = ( ( inkCanvas )( GetWidget( 'inventoryItem24' ) ) );
		}
		else if( slotId == 24 )
		{
			itemButton = ( ( inkCanvas )( GetWidget( 'inventoryItem25' ) ) );
		}
		else if( slotId == 25 )
		{
			itemButton = ( ( inkCanvas )( GetWidget( 'inventoryItem26' ) ) );
		}
		else if( slotId == 26 )
		{
			itemButton = ( ( inkCanvas )( GetWidget( 'inventoryItem27' ) ) );
		}
		else if( slotId == 27 )
		{
			itemButton = ( ( inkCanvas )( GetWidget( 'inventoryItem28' ) ) );
		}
		else if( slotId == 28 )
		{
			itemButton = ( ( inkCanvas )( GetWidget( 'inventoryItem29' ) ) );
		}
		else if( slotId == 29 )
		{
			itemButton = ( ( inkCanvas )( GetWidget( 'inventoryItem30' ) ) );
		}
		else
		{
			return;
		}
		itemButton.UnregisterFromCallback( 'OnRelease', this, 'OnInventoryItemPush' );
		itemButton.UnregisterFromCallback( 'OnEnter', this, 'OnInventoryItemEnter' );
		itemButton.UnregisterFromCallback( 'OnLeave', this, 'OnInventoryItemExit' );
		itemLogic = ( ( ArmorEquipInventoryItemController )( itemButton.GetController() ) );
		itemLogic.ClearButton();
	}

	protected function OnInventoryChange( value : Variant )
	{
		m_inventory = ( ( array< weak< gameItemData > > )value );
	}

	protected function OnEquipmentChange( value : Variant )
	{
		RefreshEquipment();
		RefreshInventoryList();
	}

	protected function RefreshEquipment()
	{
		switch( m_operationsMode )
		{
			case operationsMode.PLAYER:
				RefreshPlayerEquipment();
			break;
			case operationsMode.FLATHEAD:
				RefreshFlatheadEquipment();
			break;
			case operationsMode.TOOLBOX:
				break;
		}
	}

	protected function RefreshFlatheadEquipment()
	{
		var i : Int32;
		var paperDollButton : weak< inkCanvas >;
		var paperDollController : weak< PaperDollSlotController >;
		for( i = 0; i < m_paperDollList.Size(); i += 1 )
		{
			paperDollButton = ( ( inkCanvas )( GetWidget( m_paperDollList[ i ] ) ) );
			paperDollController = ( ( PaperDollSlotController )( paperDollButton.GetController() ) );
			paperDollController.SetItemInSlot( m_subCharacterSystem.GetFlatheadEquipment().GetItemInEquipSlot( paperDollController.GetEquipArea(), paperDollController.GetSlotIndex() ) );
		}
	}

	protected function RefreshPlayerEquipment()
	{
		var i : Int32;
		var paperDollButton : weak< inkCanvas >;
		var paperDollController : weak< PaperDollSlotController >;
		for( i = 0; i < m_paperDollList.Size(); i += 1 )
		{
			paperDollButton = ( ( inkCanvas )( GetWidget( m_paperDollList[ i ] ) ) );
			paperDollController = ( ( PaperDollSlotController )( paperDollButton.GetController() ) );
			paperDollController.SetItemInSlot( m_equipmentSystem.GetItemInEquipSlot( player, paperDollController.GetEquipArea(), paperDollController.GetSlotIndex() ) );
		}
	}

	protected function RemovedCyberware( const items : ref< array< weak< gameItemData > > > ) : array< weak< gameItemData > >
	{
		var validItems : array< weak< gameItemData > >;
		var i : Int32;
		for( i = 0; i < items.Size(); i += 1 )
		{
			if( !( m_transactionSystem.HasTag( player, 'Cyberware', items[ i ].GetID() ) ) )
			{
				validItems.PushBack( items[ i ] );
			}
		}
		return validItems;
	}

	protected virtual function RefreshInventoryList()
	{
		var i : Int32;
		var validItems : array< weak< gameItemData > >;
		var inventorySlotId : Int32;
		if( m_equipArea == gamedataEquipmentArea.Invalid )
		{
			m_transactionSystem.GetItemList( player, validItems );
		}
		else if( m_equipArea == gamedataEquipmentArea.BotMainModule )
		{
			m_transactionSystem.GetItemListByTags( player, m_areaTags, validItems );
		}
		validItems = RemovedCyberware( validItems );
		for( i = 0; i < 30; i += 1 )
		{
			HelperClearButton( i );
		}
		inventorySlotId = 0;
		if( scrollOffset > validItems.Size() )
		{
			scrollOffset = validItems.Size();
			buttonScrollDn.SetVisible( false );
		}
		else
		{
			buttonScrollDn.SetVisible( true );
		}
		for( i = scrollOffset; i < ( scrollOffset + validItems.Size() ); i += 1 )
		{
			if( !( m_equipmentSystem.IsEquipped( player, validItems[ i ].GetID() ) ) && !( m_subCharacterSystem.GetFlatheadEquipment().IsEquipped( validItems[ i ].GetID() ) ) )
			{
				HelperAddInventoryButton( validItems[ i ], inventorySlotId );
				inventorySlotId += 1;
			}
		}
	}

	protected function SetCraftList()
	{
		var PlayerCraftItems : array< weak< Item_Record > >;
		var i : Int32;
		m_recipeItemList.Clear();
		PlayerCraftItems = m_playerCraftBook.GetCraftableItems();
		for( i = 0; i < PlayerCraftItems.Size(); i += 1 )
		{
			m_recipeItemList.PushBack( PlayerCraftItems[ i ].GetID() );
		}
	}

	public function OnPaperDollCursor( e : inkPointerEvent )
	{
		if( e.IsAction( 'click' ) )
		{
			switch( m_operationsMode )
			{
				case operationsMode.PLAYER:
					ProcessPaperDollPlayerClick( e );
				break;
				case operationsMode.FLATHEAD:
					ProcessPaperDollFlatheadClick( e );
				break;
			}
		}
		RefreshInventoryList();
		RefreshEquipment();
	}

	public function OnInventoryItemPush( e : inkPointerEvent )
	{
		if( e.IsAction( 'click' ) )
		{
			switch( m_operationsMode )
			{
				case operationsMode.PLAYER:
					ProcessPlayerClick( e );
				break;
				case operationsMode.FLATHEAD:
					ProcessFlatheadClick( e );
				break;
				case operationsMode.TOOLBOX:
					ProcessToolboxClick( e );
				break;
			}
		}
		RefreshInventoryList();
		RefreshEquipment();
	}

	public virtual function OnInventoryItemEnter( e : inkPointerEvent )
	{
		var equippedItem : ItemID;
		var inspectedItemData : gameItemData;
		var button : weak< inkCompoundWidget >;
		var controller : weak< ArmorEquipInventoryItemController >;
		var cursorPos : Vector2;
		cursorPos = e.GetScreenSpacePosition();
		m_tooltipContainer.SetMargin( inkMargin( cursorPos.X + 40.0, cursorPos.Y + 30.0, 0.0, 0.0 ) );
		button = ( ( inkCompoundWidget )( e.GetCurrentTarget() ) );
		controller = ( ( ArmorEquipInventoryItemController )( button.GetController() ) );
		if( !( controller.GetIsEmpty() ) )
		{
			inspectedItemData = controller.GetItemData();
			equippedItem = m_inventoryManager.GetEquippedItemIdInArea( m_inventoryManager.GetItemEquipArea( inspectedItemData.GetID() ) );
			RefreshTooltipsInventory( inspectedItemData, equippedItem );
		}
		else
		{
			HideTooltips();
		}
	}

	public virtual function OnInventoryItemExit( e : inkPointerEvent )
	{
		HideTooltips();
	}

	public virtual function OnPaperdollItemEnter( e : inkPointerEvent )
	{
		var equippedItem : ItemID;
		var button : weak< inkCompoundWidget >;
		var controller : weak< PaperDollSlotController >;
		var cursorPos : Vector2;
		cursorPos = e.GetScreenSpacePosition();
		m_tooltipContainer.SetMargin( inkMargin( cursorPos.X + 40.0, cursorPos.Y + 30.0, 0.0, 0.0 ) );
		button = ( ( inkCompoundWidget )( e.GetCurrentTarget() ) );
		controller = ( ( PaperDollSlotController )( button.GetController() ) );
		equippedItem = m_equipmentSystem.GetItemInEquipSlot( player, controller.GetEquipArea(), controller.GetSlotIndex() );
		if( ItemID.IsValid( equippedItem ) )
		{
			RefreshTooltipsPaperdoll( m_inventoryManager.GetPlayerItemStats( equippedItem ) );
		}
	}

	public function OnPaperdollItemExit( e : inkPointerEvent )
	{
		HideTooltips();
	}

	public function OnScrollUp( e : inkPointerEvent )
	{
		scrollOffset -= 5;
		if( scrollOffset < 0 )
		{
			buttonScrollUp.SetVisible( false );
			scrollOffset = 0;
		}
		else
		{
			buttonScrollUp.SetVisible( true );
		}
		RefreshInventoryList();
	}

	public function OnScrollDn( e : inkPointerEvent )
	{
		scrollOffset += 5;
		buttonScrollUp.SetVisible( true );
		RefreshInventoryList();
	}

	protected function ProcessPaperDollPlayerClick( e : inkPointerEvent )
	{
		var button : weak< inkCanvas >;
		var controller : weak< PaperDollSlotController >;
		var unequipRequest : UnequipRequest;
		if( e.IsAction( 'click' ) )
		{
			button = ( ( inkCanvas )( e.GetCurrentTarget() ) );
			controller = ( ( PaperDollSlotController )( button.GetController() ) );
			button = ( ( inkCanvas )( e.GetCurrentTarget() ) );
			controller = ( ( PaperDollSlotController )( button.GetController() ) );
			unequipRequest = new UnequipRequest;
			unequipRequest.areaType = controller.GetEquipArea();
			unequipRequest.slotIndex = controller.GetSlotIndex();
			unequipRequest.owner = player;
			m_equipmentSystem.QueueRequest( unequipRequest );
			RefreshEquipment();
			RefreshInventoryList();
		}
	}

	protected function ProcessPaperDollFlatheadClick( e : inkPointerEvent )
	{
		var button : weak< inkCanvas >;
		var controller : weak< PaperDollSlotController >;
		var unequipRequest : SubCharUnequipRequest;
		if( e.IsAction( 'click' ) )
		{
			button = ( ( inkCanvas )( e.GetCurrentTarget() ) );
			controller = ( ( PaperDollSlotController )( button.GetController() ) );
			button = ( ( inkCanvas )( e.GetCurrentTarget() ) );
			controller = ( ( PaperDollSlotController )( button.GetController() ) );
			unequipRequest = new SubCharUnequipRequest;
			unequipRequest.areaType = controller.GetEquipArea();
			unequipRequest.slotIndex = controller.GetSlotIndex();
			unequipRequest.subCharType = gamedataSubCharacter.Flathead;
			m_equipmentSystem.QueueRequest( unequipRequest );
			RefreshEquipment();
			RefreshInventoryList();
		}
	}

	protected function ProcessPlayerClick( e : inkPointerEvent )
	{
		var equipRequest : EquipRequest;
		var button : weak< inkCompoundWidget >;
		var controller : weak< ArmorEquipInventoryItemController >;
		button = ( ( inkCompoundWidget )( e.GetCurrentTarget() ) );
		controller = ( ( ArmorEquipInventoryItemController )( button.GetController() ) );
		if( !( controller.GetIsEmpty() ) && e.IsLeftControlDown() )
		{
			DisassembleItem( controller.GetItemID(), 1 );
			HideTooltips();
			RefreshInventoryList();
			return;
		}
		if( !( controller.GetIsEmpty() ) )
		{
			equipRequest = new EquipRequest;
			equipRequest.itemID = controller.GetItemID();
			equipRequest.owner = player;
			m_equipmentSystem.QueueRequest( equipRequest );
		}
		RefreshEquipment();
		RefreshInventoryList();
		HideTooltips();
	}

	protected function ProcessFlatheadClick( e : inkPointerEvent )
	{
		var button : weak< inkCompoundWidget >;
		var controller : weak< ArmorEquipInventoryItemController >;
		var equipRequest : SubCharEquipRequest;
		button = ( ( inkCompoundWidget )( e.GetCurrentTarget() ) );
		controller = ( ( ArmorEquipInventoryItemController )( button.GetController() ) );
		equipRequest = new SubCharEquipRequest;
		equipRequest.itemID = controller.GetItemID();
		equipRequest.subCharType = gamedataSubCharacter.Flathead;
		m_subCharacterSystem.QueueRequest( equipRequest );
		RefreshEquipment();
		RefreshInventoryList();
		HideTooltips();
	}

	protected function RefreshTooltipsInventory( tooltipItemData : gameItemData, equippedItemId : ItemID )
	{
		var tooltipData : InventoryTooltipData;
		var inspectingEquippedItem : Bool;
		HideTooltips();
		inspectingEquippedItem = equippedItemId == tooltipItemData.GetID();
		if( ItemID.IsValid( equippedItemId ) )
		{
			if( inspectingEquippedItem || m_inventoryManager.CanCompareItems( tooltipItemData.GetID(), equippedItemId ) )
			{
				tooltipData = InventoryTooltipData.FromItemViewData( m_inventoryManager.GetPlayerItemStats( equippedItemId ) );
				tooltipData.isEquipped = true;
				m_tooltipRight.Show( tooltipData );
			}
			if( inspectingEquippedItem )
			{
				return;
			}
		}
		tooltipData = InventoryTooltipData.FromItemViewData( m_inventoryManager.GetItemStatsByData( tooltipItemData, m_inventoryManager.GetPlayerItemData( equippedItemId ) ) );
		m_tooltipLeft.Show( tooltipData );
	}

	protected function RefreshTooltipsPaperdoll( const tooltipItemData : ref< ItemViewData > )
	{
		var tooltipData : InventoryTooltipData;
		HideTooltips();
		tooltipData = InventoryTooltipData.FromItemViewData( tooltipItemData );
		tooltipData.isEquipped = true;
		m_tooltipLeft.Show( tooltipData );
	}

	protected virtual function HideTooltips()
	{
		m_tooltipLeft.Hide();
		m_tooltipRight.Hide();
	}

	protected function ProcessToolboxClick( e : inkPointerEvent ) {}

	protected function DisassembleItem( itemID : ItemID, quantity : Int32 ) {}

	public function OnSelectPlayer( e : inkPointerEvent )
	{
		m_operationsMode = operationsMode.PLAYER;
		m_equipArea = gamedataEquipmentArea.Invalid;
		m_slotIndex = -1;
		panelPlayer.SetVisible( true );
		panelFlathead.SetVisible( false );
		panelToolbox.SetVisible( false );
		RefreshEquipment();
		RefreshInventoryList();
	}

	public function OnSelectFlathead( e : inkPointerEvent )
	{
		m_operationsMode = operationsMode.FLATHEAD;
		m_equipArea = gamedataEquipmentArea.BotMainModule;
		m_slotIndex = 1;
		m_areaTags = modulesTags;
		panelPlayer.SetVisible( false );
		panelFlathead.SetVisible( true );
		panelToolbox.SetVisible( false );
		RefreshEquipment();
		RefreshInventoryList();
	}

	public function OnSelectToolbox( e : inkPointerEvent )
	{
		m_operationsMode = operationsMode.TOOLBOX;
		m_equipArea = gamedataEquipmentArea.BotMainModule;
		m_slotIndex = 1;
		m_areaTags = framesTags;
		panelPlayer.SetVisible( false );
		panelFlathead.SetVisible( false );
		panelToolbox.SetVisible( true );
		RefreshInventoryList();
	}

}

