4 protected ref TItemsMap m_Items;
5 protected InventoryGrid m_Grid;
6 protected int m_DraggingIndex;
8 void InventoryQuickbar(
Widget quickbarGridWidget)
11 m_Items =
new TItemsMap;
12 UpdateItems( quickbarGridWidget );
15 void ~InventoryQuickbar()
19 void UpdateItems(
Widget quickbarGridWidget )
21 if( !quickbarGridWidget )
35 quickbarGridWidget.GetScript( m_Grid );
36 m_Grid.SetController(
this );
37 m_Grid.GenerateQuickBarBackgroundTiles( 10 );
45 if( m_Grid.GetGridSize() != player.GetQuickBarSize() )
47 m_Grid.SetGridSize( player.GetQuickBarSize() );
51 for( i = 0; i < m_Grid.GetGridSize(); i++)
56 m_Items.Set( item,
Vector(i, 1, 1) );
62 m_Grid.UpdateQuickbarItems( m_Items );
70 for (
int i = 0; i < m_Grid.GetGridSize(); i++ )
73 if(item == itemToRemove)
75 player.RemoveQuickBarEntityShortcut( item );
81 override void OnItemEnter(InventoryGrid grid,
Widget w,
int row,
int col)
83 Widget quickbar = grid.GetRoot();
90 override void OnItemLeave(InventoryGrid grid,
Widget w)
92 Widget quickbar = grid.GetRoot();
99 override void OnItemDraggingOver(InventoryGrid grid,
Widget w,
int row,
int col)
106 string name = w.GetName();
107 name.Replace(
"PanelWidget",
"Render" );
111 if( !iw || !iw.GetItem() )
116 if(!dragged_item && iw)
119 if ( dragged_item == NULL)
122 if (dragged_item && dragged_item.GetInventory().CanRemoveEntity() ==
false)
126 color =
ARGB( 150, 255, 1, 1 );
128 if( w.FindAnyWidget(
"Cursor") )
130 w.FindAnyWidget(
"Cursor").SetColor( color );
135 name.Replace(
"PanelWidget",
"Cursor" );
136 if( w.FindAnyWidget(
name ) )
138 w.FindAnyWidget(
name ).SetColor( color );
144 color =
ARGB( 150, 1, 255, 1 );
146 if( w.FindAnyWidget(
"Cursor") )
148 w.FindAnyWidget(
"Cursor").SetColor( color );
153 name.Replace(
"PanelWidget",
"Cursor" );
154 if( w.FindAnyWidget(
name ) )
156 w.FindAnyWidget(
name ).SetColor( color );
162 override void OnItemDropReceived(InventoryGrid grid,
Widget w,
int row,
int col)
171 string name = w.GetName();
172 name.Replace(
"PanelWidget",
"Render" );
176 if(!dragged_item && iw)
177 dragged_item =
ItemBase.Cast( iw.GetItem() );
179 if(dragged_item && dragged_item.GetHierarchyRootPlayer()!=
GetGame().
GetPlayer())
186 dragged_item =
ItemBase.Cast( player.GetQuickBarEntity(m_DraggingIndex) );
189 if (dragged_item && dragged_item.GetInventory().CanRemoveEntity())
191 player.SetQuickBarEntityShortcut(dragged_item, col);
193 if (quickbar_item && quickbar_item != dragged_item && m_DraggingIndex !=
INDEX_NOT_FOUND)
195 player.SetQuickBarEntityShortcut(quickbar_item, m_DraggingIndex);
202 menu.RefreshQuickbar();
206 override void OnItemDrop(InventoryGrid grid,
Widget w,
int row,
int col)
219 menu.RefreshQuickbar();
224 override void OnItemDrag(InventoryGrid grid,
Widget w,
int row,
int col)
230 m_DraggingIndex = col;
231 m_Grid.SetItemColor(item, InventoryGrid.ITEM_COLOR_DRAG);
235 override int GetQuickbarItemColor( InventoryGrid grid,
InventoryItem item )
237 int color = 0x0AFFFFFF;
239 EntityAI itemInHand = player.GetHumanInventory().GetEntityInHands();
240 if ( player && itemInHand == item )
242 if ( player.GetHumanInventory().FindUserReservedLocationIndex(item) != -1 || grid.CanAddItemInHandToInventory() )
243 color = InventoryGrid.ITEM_COLOR_QUICKBAR_H_GOOD;
245 color = InventoryGrid.ITEM_COLOR_QUICKBAR_H_BAD;
247 else if ( itemInHand )
249 if ( !grid.CanAddItemInHandToInventory() && !
GameInventory.CanSwapEntitiesEx(item, itemInHand) )
250 color = InventoryGrid.ITEM_COLOR_QUICKBAR_I_BAD;
274 return ib.m_VarQuantityMax;
283 override bool CanAddItemInHandToInventory()
286 EntityAI itemInHand = player.GetHumanInventory().GetEntityInHands();
287 return itemInHand && player.GetInventory().CanAddEntityToInventory(itemInHand);