4 void OnItemEnter(InventoryGrid grid,
Widget w,
int row,
int col) {}
5 void OnItemLeave(InventoryGrid grid,
Widget w) {}
6 void OnItemDrag(InventoryGrid grid,
Widget w,
int row,
int col) {}
7 void OnItemDraggingOver(InventoryGrid grid,
Widget w,
int row,
int col) {}
8 void OnItemDrop(InventoryGrid grid,
Widget w,
int row,
int col) {}
9 void OnItemDropReceived(InventoryGrid grid,
Widget w,
int row,
int col) {}
10 void OnItemClick(InventoryGrid grid,
Widget w,
int row,
int col) {}
11 void OnItemLeftClick(InventoryGrid grid,
Widget w,
int row,
int col) {}
12 void OnItemRightClick(InventoryGrid grid,
Widget w,
int row,
int col) {}
13 void OnItemDoubleClick(InventoryGrid grid,
Widget w,
int row,
int col) {}
19 int GetQuickbarItemColor(InventoryGrid grid,
InventoryItem item) {}
29 bool CanAddItemInHandToInventory() {}
39 static int ITEM_COLOR_QUICKBAR_NORMAL = 0x0AFFFFFF;
40 static int ITEM_COLOR_QUICKBAR_H_GOOD = 0x2A6e980d;
41 static int ITEM_COLOR_QUICKBAR_H_BAD = 0x2A980d0d;
42 static int ITEM_COLOR_QUICKBAR_I_BAD = 0x2A986e0d;
43 static int ITEM_COLOR_NORMAL = 0x0AFFFFFF;
44 static int ITEM_COLOR_DRAG = 0x0AFFFFFF;
46 reference
bool m_IsDebugOutput;
50 protected ref TItemsMap m_Items;
55 protected int m_GridSize;
56 protected bool m_IsMouseLeftDown;
57 protected bool m_CanAddItemInHandToInventory;
61 m_Items =
new TItemsMap;
73 bool CanAddItemInHandToInventory()
75 return m_CanAddItemInHandToInventory;
87 int col = GetCol( w );
89 if ( !IsValidPos( col ) )
97 if (m_Controller) m_Controller.OnItemEnter(
this, w, 0, col);
105 if (m_Controller) m_Controller.OnItemLeave(
this, w);
115 int col = GetCol( w );
117 if ( !IsValidPos( col ) )
129 m_Controller.OnItemRightClick(
this, w, 0, col);
134 m_IsMouseLeftDown =
true;
150 if( m_IsMouseLeftDown )
152 m_Controller.OnItemLeftClick(
this, w, 0, m_col);
153 m_IsMouseLeftDown =
false;
159 int col = GetCol( w );
161 if ( !IsValidPos( col ) )
182 int col = GetCol( w );
184 if ( !IsValidPos( col ) )
192 if (m_Controller) m_Controller.OnItemDoubleClick(
this, w, 0, col);
207 m_Controller.OnItemDrop(
this, w, 0, m_col);
215 item_preview.SetView( item_preview.GetItem().GetViewIndex() );
226 if( m_ItemWidgets.GetKeyByValueChecked( w, index ) )
228 else if( m_BackgroundWidgets.GetKeyByValueChecked( w, index ) )
234 int GetColFromBg(
Widget w )
236 return m_BackgroundWidgets.GetKeyByValue( w );
244 void SetGridSize(
int size )
247 for(
int i = 0; i < m_BackgroundWidgets.Count(); i++ )
251 m_BackgroundWidgets.Get( i ).Show(
true );
255 m_BackgroundWidgets.Get( i ).Show(
false );
260 bool IsValidPos(
int index )
262 return ( m_GridSize > index && index > -1 );
265 private Widget m_on_drag_item;
269 override bool OnDrag(
Widget w,
int x,
int y)
275 if ( !IsValidPos( m_col ) )
283 if (m_Controller) m_Controller.OnItemDrag(
this, w, 0, m_col);
288 item_preview.SetView( item_preview.GetItem().GetViewIndex() );
294 override bool OnDraggingOver(
Widget w,
int x,
int y,
Widget reciever)
296 int col = GetCol( reciever );
298 if ( !IsValidPos( col ) )
308 if (m_Controller) m_Controller.OnItemDraggingOver(
this, w, 0, col);
315 override bool OnDropReceived(
Widget w,
int x,
int y,
Widget reciever)
317 int col = GetCol( reciever );
319 if ( !IsValidPos( col ) )
327 if (m_Controller) m_Controller.OnItemDropReceived(
this, w, 0, col);
333 TItemsMap GetItems() {
340 if( m_ItemWidgets.Contains( index ) )
341 return m_ItemWidgets.Get( index );
347 Widget GetItemBackground(
int index)
349 if( m_BackgroundWidgets.Contains( index ) )
350 return m_BackgroundWidgets.Get( index );
362 if (m_Items.Contains(item))
364 vector data = m_Items.Get(item);
365 int index =
Math.Round(data[0]);
374 m_Controller = controller;
382 void GenerateQuickBarBackgroundTiles(
int count)
384 for (
int i = 0; i < count; i++)
386 Widget root_widget =
GetGame().GetWorkspace().CreateWidgets(
"gui/layouts/inventory/inventoryGridBackground.layout",
m_Root);
389 label_widget.SetText( (i+1).
ToString() );
390 label_widget2.SetText( (i+1).
ToString() );
391 m_BackgroundWidgets.Insert( i, root_widget );
396 void UpdateQuickbarItems( TItemsMap items )
412 for (i = 0; i < c; i++)
414 item = m_Items.GetKey(i);
417 bool remove_item =
false;
419 if (items.Contains(item) ==
false)
426 if ((m_Items.Get(item) - items.Get(item)).LengthSq() > 0.01)
443 for (i = 0; i < items.Count(); i++)
445 item = items.GetKey(i);
446 data = items.Get(item);
448 if (m_Items.Contains(item) ==
false)
450 AddItem(item, data,
Vector(0,0,0) );
455 m_CanAddItemInHandToInventory = m_Controller.CanAddItemInHandToInventory();
458 for (i = 0; i < items.Count(); i++)
460 item = items.GetKey(i);
461 data = items.Get(item);
462 RefreshQuickbarItemVariables( item, data );
468 void UpdateItems(TItemsMap items,
bool show_quantity,
bool show_temperature )
484 for (i = 0; i < c; i++)
486 item = m_Items.GetKey(i);
488 bool remove_item =
false;
490 if (items.Contains(item) ==
false)
497 if ((m_Items.Get(item) - items.Get(item)).LengthSq() > 0.01)
513 for (i = 0; i < items.Count(); i++)
515 item = items.GetKey(i);
516 data = items.Get(item);
518 if (m_Items.Contains(item) ==
false)
520 AddItem(item, data,
Vector(0,0,0) );
525 for (i = 0; i < items.Count(); i++)
527 item = items.GetKey(i);
528 data = items.Get(item);
530 RefreshItemVariables( item, data, show_quantity, show_temperature );
535 void UpdateQuantityItems()
541 for (i = 0; i < m_Items.Count(); i++)
543 item = m_Items.GetKey(i);
544 data = m_Items.Get(item);
545 index =
Math.Round(data[0]);
546 RefreshItemVariables( item, data,
true,
false );
551 void UpdateTemperatureItems()
557 for (i = 0; i < m_Items.Count(); i++)
559 item = m_Items.GetKey(i);
560 data = m_Items.Get(item);
561 index =
Math.Round(data[0]);
562 RefreshItemVariables( item, data,
false,
true );
569 int index =
Math.Round(data[0]);
570 Widget bck = GetItemBackground(index);
573 Widget item_w = bck.FindAnyWidget(
"GridItem");
576 int color = m_Controller.GetQuickbarItemColor(
this, item );
577 item_w.SetColor( color );
580 RefreshItemVariables( item, data,
true,
false );
584 void RefreshItemVariables(
InventoryItem item,
vector data,
bool show_quantity,
bool show_temperature )
586 int index =
Math.Round(data[0]);
587 Widget bck = GetItemBackground(index);
592 item_w = bck.FindAnyWidget(
"GridItem");
595 int has_quantity = m_Controller.HasItemQuantity( item );
596 Widget quantity_panel = bck.FindAnyWidget(
"QuantityPanel");
598 ProgressBarWidget quantity_progress = ProgressBarWidget.Cast( bck.FindAnyWidget(
"QuantityBar") );
599 Widget quantity_stack = bck.FindAnyWidget(
"QuantityStackPanel");
602 quantity_panel.Show(
false );
606 quantity_panel.Show(
true );
609 item_quantity.SetText( m_Controller.GetItemQuantityText( item ) );
610 quantity_stack.Show(
true );
611 quantity_progress.Show(
false );
615 float progress_max = quantity_progress.GetMax();
616 int max = m_Controller.GetItemQuantityMax( item );
617 int count = m_Controller.GetItemCount( item );
618 float quantity = m_Controller.GetItemQuantity( item );
626 float value =
Math.Round( ( quantity / max ) * 100 );
627 quantity_progress.SetCurrent( value );
629 quantity_stack.Show(
false );
630 quantity_progress.Show(
true );
634 if ( show_temperature )
638 int color = m_Controller.GetItemColor(
this, item);
641 item_w.SetColor( color );
652 m_Items.Set(item, data);
654 int index =
Math.Round(data[0]);
655 int width =
Math.Round(data[1]);
656 int height =
Math.Round(data[2]);
658 Widget bck = GetItemBackground(index);
659 Widget item_w_bck =
GetGame().GetWorkspace().CreateWidgets(
"gui/layouts/inventory/inventoryGridItem.layout", bck);
660 Widget item_w = item_w_bck.FindAnyWidget(
"GridItem");
662 bck.FindAnyWidget(
"LabelTR").Show(
true );
663 bck.FindAnyWidget(
"LabelCC").Show(
false );
665 m_ItemWidgets.Insert( index, item_w );
667 ResetItemWidget(item_w, width, height);
672 item_preview.SetItem(item);
673 item_preview.SetModelOrientation( rotation );
674 item_preview.SetView( item_preview.GetItem().GetViewIndex() );
676 RefreshItemVariables( item, data,
true,
true );
683 m_Items.Set(item, data);
685 int index =
Math.Round(data[0]);
686 int width =
Math.Round(data[1]);
687 int height =
Math.Round(data[2]);
689 Widget bck = GetItemBackground(index);
690 Widget item_w_bck = bck.FindAnyWidget(
"GridItemBck");
694 bck.FindAnyWidget(
"LabelTR").Show(
true );
695 bck.FindAnyWidget(
"LabelCC").Show(
false );
697 Widget item_w = item_w_bck.FindAnyWidget(
"GridItem");
698 ResetItemWidget(item_w, width, height);
703 item_preview.SetItem(item);
704 item_preview.Show(
true );
705 item_preview.SetModelOrientation( rotation );
706 item_preview.SetView( item_preview.GetItem().GetViewIndex() );
708 RefreshItemVariables( item, data,
true,
true );
713 item_preview.Show(
false );
719 protected void ResetItemWidget(
Widget item_w,
int width,
int height)
723 item_w.SetColor(ITEM_COLOR_NORMAL);
730 if (m_Items.Contains(item))
732 vector data = m_Items.Get(item);
733 int index =
Math.Round(data[0]);
734 int width =
Math.Round(data[1]);
735 int height =
Math.Round(data[2]);
736 Widget bck = GetItemBackground(index);
737 Widget item_w = bck.FindAnyWidget(
"GridItem");
738 ResetItemWidget(item_w, width, height);
739 RefreshItemVariables( item, data,
true,
true );
746 return m_Items.Contains(item);
754 if ( item && m_Items.Contains( item ) )
756 vector data = m_Items.Get(item);
757 int index =
Math.Round(data[0]);
758 int width =
Math.Round(data[1]);
759 int height =
Math.Round(data[2]);
760 bck = GetItemBackground(index);
763 itemW = bck.FindAnyWidget(
"GridCell");
766 bck.FindAnyWidget(
"LabelTR").Show(
false );
767 bck.FindAnyWidget(
"LabelCC").Show(
true );
770 m_Items.Remove( item );
771 m_ItemWidgets.Remove( index );