inventorygrid.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774
  1. // -----------------------------------------------------------
  2. class InventoryGridController extends ScriptedWidgetEventHandler
  3. {
  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) {}
  14. // float GetItemQuantity(InventoryGrid grid, InventoryItem item) {}
  15. int GetItemColor(ScriptedWidgetEventHandler grid, InventoryItem item)
  16. {
  17. return 0;
  18. }
  19. int GetQuickbarItemColor(InventoryGrid grid, InventoryItem item) {}
  20. vector GetItemSize(InventoryGrid grid, InventoryItem item)
  21. {
  22. return Vector(0, 1, 1);
  23. }
  24. string GetItemQuantityText( InventoryItem item ) {}
  25. int HasItemQuantity( InventoryItem item ) {}
  26. float GetItemQuantity( InventoryItem item ) {}
  27. int GetItemQuantityMax( InventoryItem item ) {}
  28. int GetItemCount( InventoryItem item ) {}
  29. bool CanAddItemInHandToInventory() {}
  30. };
  31. // -----------------------------------------------------------
  32. //! map: item x vector(index, width, height)
  33. typedef map<InventoryItem, vector> TItemsMap
  34. class InventoryGrid extends ScriptedWidgetEventHandler
  35. {
  36. // AARRGGBB
  37. static int ITEM_COLOR_QUICKBAR_NORMAL = 0x0AFFFFFF;
  38. static int ITEM_COLOR_QUICKBAR_H_GOOD = 0x2A6e980d;
  39. static int ITEM_COLOR_QUICKBAR_H_BAD = 0x2A980d0d;
  40. static int ITEM_COLOR_QUICKBAR_I_BAD = 0x2A986e0d;
  41. static int ITEM_COLOR_NORMAL = 0x0AFFFFFF;
  42. static int ITEM_COLOR_DRAG = 0x0AFFFFFF;
  43. reference bool m_IsDebugOutput;
  44. protected ref map<int, Widget> m_BackgroundWidgets;
  45. protected ref map<int, Widget> m_ItemWidgets;
  46. protected ref TItemsMap m_Items;
  47. protected InventoryGridController m_Controller;
  48. protected Widget m_Root;
  49. protected int m_GridSize;
  50. protected bool m_IsMouseLeftDown;
  51. protected bool m_CanAddItemInHandToInventory;
  52. void InventoryGrid()
  53. {
  54. m_Items = new TItemsMap;
  55. m_BackgroundWidgets = new map<int, Widget>;
  56. m_ItemWidgets = new map<int, Widget>;
  57. }
  58. protected void OnWidgetScriptInit(Widget w)
  59. {
  60. m_Root = w;
  61. m_Root.SetHandler(this);
  62. }
  63. // NOTE: This is a cached value, depending on when it is called it might not be 100% accurate
  64. bool CanAddItemInHandToInventory()
  65. {
  66. return m_CanAddItemInHandToInventory;
  67. }
  68. // ScriptedWidgetEventHandler override
  69. override bool OnUpdate(Widget w)
  70. {
  71. return false;
  72. }
  73. // -----------------------------------------------------------
  74. override bool OnMouseEnter(Widget w, int x, int y)
  75. {
  76. int col = GetCol( w );
  77. if ( !IsValidPos( col ) )
  78. return false;
  79. if (m_IsDebugOutput)
  80. {
  81. PrintString (m_Root.GetName() + "::OnMouseEnter(" + col.ToString() + ")");
  82. }
  83. if (m_Controller) m_Controller.OnItemEnter(this, w, 0, col);
  84. return true;
  85. }
  86. // -----------------------------------------------------------
  87. override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
  88. {
  89. if (m_Controller) m_Controller.OnItemLeave(this, w);
  90. return true;
  91. }
  92. // -----------------------------------------------------------
  93. override bool OnMouseButtonDown(Widget w, int x, int y, int button)
  94. {
  95. if (button == MouseState.RIGHT || button == MouseState.LEFT)
  96. {
  97. int col = GetCol( w );
  98. if ( !IsValidPos( col ) )
  99. return false;
  100. if (m_IsDebugOutput)
  101. {
  102. PrintString (m_Root.GetName() + "::OnMouseButtonDown(" + col.ToString() + ")");
  103. }
  104. if (m_Controller)
  105. {
  106. if (button == MouseState.RIGHT )
  107. {
  108. m_Controller.OnItemRightClick(this, w, 0, col);
  109. }
  110. if (button == MouseState.LEFT )
  111. {
  112. m_IsMouseLeftDown = true;
  113. }
  114. }
  115. return true;
  116. }
  117. else
  118. {
  119. return false;
  120. }
  121. }
  122. // -----------------------------------------------------------
  123. override bool OnMouseButtonUp(Widget w, int x, int y, int button)
  124. {
  125. if ( button == MouseState.LEFT )
  126. {
  127. if( m_IsMouseLeftDown )
  128. {
  129. m_Controller.OnItemLeftClick(this, w, 0, m_col);
  130. m_IsMouseLeftDown = false;
  131. }
  132. }
  133. if (button == MouseState.RIGHT || button == MouseState.LEFT)
  134. {
  135. int col = GetCol( w );
  136. if ( !IsValidPos( col ) )
  137. return false;
  138. if (m_IsDebugOutput)
  139. {
  140. PrintString (m_Root.GetName() + "::OnMouseButtonUp(" + col.ToString() + ")");
  141. }
  142. return true;
  143. }
  144. else
  145. {
  146. return false;
  147. }
  148. }
  149. // -----------------------------------------------------------
  150. override bool OnDoubleClick(Widget w, int x, int y, int button)
  151. {
  152. if (button != MouseState.LEFT) return false;
  153. int col = GetCol( w );
  154. if ( !IsValidPos( col ) )
  155. return false;
  156. if (m_IsDebugOutput)
  157. {
  158. PrintString (m_Root.GetName() + "::OnDoubleClick(" + col.ToString() + ")");
  159. }
  160. if (m_Controller) m_Controller.OnItemDoubleClick(this, w, 0, col);
  161. return true;
  162. }
  163. //--------------------------------------------------------------------------
  164. override bool OnDrop(Widget w, int x, int y, Widget reciever)
  165. {
  166. if (m_IsDebugOutput)
  167. {
  168. PrintString (m_Root.GetName() + "::OnDrop()");
  169. }
  170. if (m_Controller)
  171. {
  172. m_Controller.OnItemDrop(this, w, 0, m_col);
  173. }
  174. if (w)
  175. {
  176. ItemPreviewWidget item_preview = ItemPreviewWidget.Cast( w.FindAnyWidget("Preview") );
  177. if (item_preview)
  178. {
  179. item_preview.SetView( item_preview.GetItem().GetViewIndex() );
  180. }
  181. }
  182. return true;
  183. }
  184. int GetCol( Widget w )
  185. {
  186. int index;
  187. if( m_ItemWidgets.GetKeyByValueChecked( w, index ) )
  188. return index;
  189. else if( m_BackgroundWidgets.GetKeyByValueChecked( w, index ) )
  190. return index;
  191. else
  192. return -1;
  193. }
  194. int GetColFromBg( Widget w )
  195. {
  196. return m_BackgroundWidgets.GetKeyByValue( w );
  197. }
  198. int GetGridSize()
  199. {
  200. return m_GridSize;
  201. }
  202. void SetGridSize( int size )
  203. {
  204. m_GridSize = size;
  205. for( int i = 0; i < m_BackgroundWidgets.Count(); i++ )
  206. {
  207. if( i < size )
  208. {
  209. m_BackgroundWidgets.Get( i ).Show( true );
  210. }
  211. else
  212. {
  213. m_BackgroundWidgets.Get( i ).Show( false );
  214. }
  215. }
  216. }
  217. bool IsValidPos( int index )
  218. {
  219. return ( m_GridSize > index && index > -1 );
  220. }
  221. private Widget m_on_drag_item;
  222. private int m_col;
  223. //--------------------------------------------------------------------------
  224. override bool OnDrag(Widget w, int x, int y)
  225. {
  226. w.SetPos(x, y);
  227. m_col = GetCol( w );
  228. if ( !IsValidPos( m_col ) )
  229. return false;
  230. if (m_IsDebugOutput)
  231. {
  232. PrintString (m_Root.GetName() + "::OnDrag(" + m_col.ToString() + ")");
  233. }
  234. if (m_Controller) m_Controller.OnItemDrag(this, w, 0, m_col);
  235. ItemPreviewWidget item_preview = ItemPreviewWidget.Cast( w.FindAnyWidget("Preview") );
  236. if (item_preview)
  237. {
  238. item_preview.SetView( item_preview.GetItem().GetViewIndex() );
  239. }
  240. return true;
  241. }
  242. //--------------------------------------------------------------------------
  243. override bool OnDraggingOver(Widget w, int x, int y, Widget reciever)
  244. {
  245. int col = GetCol( reciever );
  246. if ( !IsValidPos( col ) )
  247. {
  248. return false;
  249. }
  250. if (m_IsDebugOutput)
  251. {
  252. PrintString (m_Root.GetName() + "::OnDraggingOver(" + col.ToString() + ")");
  253. }
  254. if (m_Controller) m_Controller.OnItemDraggingOver(this, w, 0, col);
  255. return true;
  256. }
  257. //--------------------------------------------------------------------------
  258. override bool OnDropReceived(Widget w, int x, int y, Widget reciever)
  259. {
  260. int col = GetCol( reciever );
  261. if ( !IsValidPos( col ) )
  262. return false;
  263. if (m_IsDebugOutput)
  264. {
  265. PrintString (m_Root.GetName() + "::OnDropReceived(" + col.ToString() + ")");
  266. }
  267. if (m_Controller) m_Controller.OnItemDropReceived(this, w, 0, col);
  268. return true;
  269. }
  270. TItemsMap GetItems() {
  271. return m_Items;
  272. }
  273. //--------------------------------------------------------------------------
  274. Widget GetItem(int index)
  275. {
  276. if( m_ItemWidgets.Contains( index ) )
  277. return m_ItemWidgets.Get( index );
  278. else
  279. return null;
  280. }
  281. //--------------------------------------------------------------------------
  282. Widget GetItemBackground(int index)
  283. {
  284. if( m_BackgroundWidgets.Contains( index ) )
  285. return m_BackgroundWidgets.Get( index );
  286. else
  287. return null;
  288. }
  289. Widget GetRoot()
  290. {
  291. return m_Root;
  292. }
  293. void SetItemColor(InventoryItem item, int color)
  294. {
  295. if (m_Items.Contains(item))
  296. {
  297. vector data = m_Items.Get(item);
  298. int index = Math.Round(data[0]);
  299. Widget w = GetItem(index);
  300. if (w)
  301. w.SetColor(color);
  302. }
  303. }
  304. void SetController(InventoryGridController controller) {
  305. m_Controller = controller;
  306. }
  307. InventoryGridController GetController() {
  308. return m_Controller;
  309. }
  310. //--------------------------------------------------------------------------
  311. void GenerateQuickBarBackgroundTiles(int count)
  312. {
  313. for (int i = 0; i < count; i++)
  314. {
  315. Widget root_widget = GetGame().GetWorkspace().CreateWidgets("gui/layouts/inventory/inventoryGridBackground.layout", m_Root);
  316. TextWidget label_widget = TextWidget.Cast( root_widget.FindAnyWidget( "Label1" ) );
  317. TextWidget label_widget2 = TextWidget.Cast( root_widget.FindAnyWidget( "Label2" ) );
  318. label_widget.SetText( (i+1).ToString() );
  319. label_widget2.SetText( (i+1).ToString() );
  320. m_BackgroundWidgets.Insert( i, root_widget );
  321. }
  322. }
  323. //--------------------------------------------------------------------------
  324. void UpdateQuickbarItems( TItemsMap items )
  325. {
  326. int i;
  327. int c;
  328. int index;
  329. int width;
  330. int height;
  331. int row;
  332. int col;
  333. InventoryItem item;
  334. vector data;
  335. Widget bck;
  336. Widget item_w;
  337. // remove not actual items
  338. c = m_Items.Count();
  339. for (i = 0; i < c; i++)
  340. {
  341. item = m_Items.GetKey(i);
  342. if( item != NULL )
  343. {
  344. bool remove_item = false;
  345. if (items.Contains(item) == false)
  346. {
  347. remove_item = true;
  348. }
  349. else
  350. {
  351. // check items position actual
  352. if ((m_Items.Get(item) - items.Get(item)).LengthSq() > 0.01)
  353. {
  354. // item has different position or size
  355. remove_item = true;
  356. }
  357. }
  358. if (remove_item)
  359. {
  360. RemoveItem(item);
  361. c--;
  362. i--;
  363. }
  364. }
  365. }
  366. // add new items
  367. for (i = 0; i < items.Count(); i++)
  368. {
  369. item = items.GetKey(i);
  370. data = items.Get(item);
  371. if (m_Items.Contains(item) == false)
  372. {
  373. AddItem(item, data, Vector(0,0,0) );
  374. }
  375. }
  376. // cache if entity in hands can be added to inventory
  377. m_CanAddItemInHandToInventory = m_Controller.CanAddItemInHandToInventory();
  378. // refresh quickbar
  379. for (i = 0; i < items.Count(); i++)
  380. {
  381. item = items.GetKey(i);
  382. data = items.Get(item);
  383. RefreshQuickbarItemVariables( item, data );
  384. }
  385. }
  386. //--------------------------------------------------------------------------
  387. void UpdateItems(TItemsMap items, bool show_quantity, bool show_temperature )
  388. {
  389. int i;
  390. int c;
  391. int index;
  392. int width;
  393. int height;
  394. int row;
  395. int col;
  396. InventoryItem item;
  397. vector data;
  398. Widget bck;
  399. Widget item_w;
  400. // remove not actual items
  401. c = m_Items.Count();
  402. for (i = 0; i < c; i++)
  403. {
  404. item = m_Items.GetKey(i);
  405. bool remove_item = false;
  406. if (items.Contains(item) == false)
  407. {
  408. remove_item = true;
  409. }
  410. else
  411. {
  412. // check items position actual
  413. if ((m_Items.Get(item) - items.Get(item)).LengthSq() > 0.01)
  414. {
  415. // item has different position or size
  416. remove_item = true;
  417. }
  418. }
  419. if (remove_item)
  420. {
  421. RemoveItem(item);
  422. c--;
  423. i--;
  424. }
  425. }
  426. // add new items
  427. for (i = 0; i < items.Count(); i++)
  428. {
  429. item = items.GetKey(i);
  430. data = items.Get(item);
  431. if (m_Items.Contains(item) == false)
  432. {
  433. AddItem(item, data, Vector(0,0,0) );
  434. }
  435. }
  436. // add new items
  437. for (i = 0; i < items.Count(); i++)
  438. {
  439. item = items.GetKey(i);
  440. data = items.Get(item);
  441. // refresh quantity
  442. RefreshItemVariables( item, data, show_quantity, show_temperature );
  443. }
  444. }
  445. //--------------------------------------------------------------------------
  446. void UpdateQuantityItems()
  447. {
  448. int i;
  449. int index;
  450. InventoryItem item;
  451. vector data;
  452. for (i = 0; i < m_Items.Count(); i++)
  453. {
  454. item = m_Items.GetKey(i);
  455. data = m_Items.Get(item);
  456. index = Math.Round(data[0]);
  457. RefreshItemVariables( item, data, true, false );
  458. }
  459. }
  460. //--------------------------------------------------------------------------
  461. void UpdateTemperatureItems()
  462. {
  463. int i;
  464. int index;
  465. InventoryItem item;
  466. vector data;
  467. for (i = 0; i < m_Items.Count(); i++)
  468. {
  469. item = m_Items.GetKey(i);
  470. data = m_Items.Get(item);
  471. index = Math.Round(data[0]);
  472. RefreshItemVariables( item, data, false, true );
  473. }
  474. }
  475. //--------------------------------------------------------------------------
  476. void RefreshQuickbarItemVariables(InventoryItem item, vector data)
  477. {
  478. int index = Math.Round(data[0]);
  479. Widget bck = GetItemBackground(index);
  480. if ( bck )
  481. {
  482. Widget item_w = bck.FindAnyWidget("GridItem");
  483. if ( item_w )
  484. {
  485. int color = m_Controller.GetQuickbarItemColor( this, item ); // !!!!!
  486. item_w.SetColor( color );
  487. }
  488. }
  489. RefreshItemVariables( item, data, true, false );
  490. }
  491. //--------------------------------------------------------------------------
  492. void RefreshItemVariables(InventoryItem item, vector data, bool show_quantity, bool show_temperature )
  493. {
  494. int index = Math.Round(data[0]);
  495. Widget bck = GetItemBackground(index);
  496. Widget item_w;
  497. if ( bck )
  498. {
  499. item_w = bck.FindAnyWidget("GridItem");
  500. if ( item_w )
  501. {
  502. int has_quantity = m_Controller.HasItemQuantity( item );
  503. Widget quantity_panel = bck.FindAnyWidget("QuantityPanel");
  504. TextWidget item_quantity = TextWidget.Cast( bck.FindAnyWidget("Quantity") );
  505. ProgressBarWidget quantity_progress = ProgressBarWidget.Cast( bck.FindAnyWidget("QuantityBar") );
  506. Widget quantity_stack = bck.FindAnyWidget("QuantityStackPanel");
  507. if ( has_quantity == QUANTITY_HIDDEN )
  508. {
  509. quantity_panel.Show( false );
  510. }
  511. else
  512. {
  513. quantity_panel.Show( true );
  514. if ( has_quantity == QUANTITY_COUNT )
  515. {
  516. item_quantity.SetText( m_Controller.GetItemQuantityText( item ) );
  517. quantity_stack.Show( true );
  518. quantity_progress.Show( false );
  519. }
  520. else if ( has_quantity == QUANTITY_PROGRESS )
  521. {
  522. float progress_max = quantity_progress.GetMax();
  523. int max = m_Controller.GetItemQuantityMax( item );
  524. int count = m_Controller.GetItemCount( item );
  525. float quantity = m_Controller.GetItemQuantity( item );
  526. if ( count > 0 )
  527. {
  528. max = count;
  529. }
  530. if ( max > 0 )
  531. {
  532. float value = Math.Round( ( quantity / max ) * 100 );
  533. quantity_progress.SetCurrent( value );
  534. }
  535. quantity_stack.Show( false );
  536. quantity_progress.Show( true );
  537. }
  538. }
  539. if ( show_temperature )
  540. {
  541. if ( item && item.IsInherited( InventoryItem ) )
  542. {
  543. int color = m_Controller.GetItemColor( this, item); // !!!!!
  544. if ( color )
  545. {
  546. item_w.SetColor( color );
  547. }
  548. }
  549. }
  550. }
  551. }
  552. }
  553. //--------------------------------------------------------------------------
  554. void AddItem(InventoryItem item, vector data, vector rotation)
  555. {
  556. m_Items.Set(item, data);
  557. int index = Math.Round(data[0]);
  558. int width = Math.Round(data[1]);
  559. int height = Math.Round(data[2]);
  560. Widget bck = GetItemBackground(index);
  561. Widget item_w_bck = GetGame().GetWorkspace().CreateWidgets("gui/layouts/inventory/inventoryGridItem.layout", bck);
  562. Widget item_w = item_w_bck.FindAnyWidget("GridItem");
  563. bck.FindAnyWidget("LabelTR").Show( true );
  564. bck.FindAnyWidget("LabelCC").Show( false );
  565. m_ItemWidgets.Insert( index, item_w );
  566. ResetItemWidget(item_w, width, height);
  567. if ( item )
  568. {
  569. ItemPreviewWidget item_preview = ItemPreviewWidget.Cast( item_w.FindAnyWidget("Preview") );
  570. item_preview.SetItem(item);
  571. item_preview.SetModelOrientation( rotation );
  572. item_preview.SetView( item_preview.GetItem().GetViewIndex() );
  573. RefreshItemVariables( item, data, true, true );
  574. }
  575. }
  576. //--------------------------------------------------------------------------
  577. void SetItem(InventoryItem item, vector data, vector rotation)
  578. {
  579. m_Items.Set(item, data);
  580. int index = Math.Round(data[0]);
  581. int width = Math.Round(data[1]);
  582. int height = Math.Round(data[2]);
  583. Widget bck = GetItemBackground(index);
  584. Widget item_w_bck = bck.FindAnyWidget("GridItemBck");
  585. if(item_w_bck)
  586. {
  587. bck.FindAnyWidget("LabelTR").Show( true );
  588. bck.FindAnyWidget("LabelCC").Show( false );
  589. Widget item_w = item_w_bck.FindAnyWidget("GridItem");
  590. ResetItemWidget(item_w, width, height);
  591. if ( item )
  592. {
  593. ItemPreviewWidget item_preview = ItemPreviewWidget.Cast( item_w.FindAnyWidget("Preview") );
  594. item_preview.SetItem(item);
  595. item_preview.Show( true );
  596. item_preview.SetModelOrientation( rotation );
  597. item_preview.SetView( item_preview.GetItem().GetViewIndex() );
  598. RefreshItemVariables( item, data, true, true );
  599. }
  600. else
  601. {
  602. item_preview = ItemPreviewWidget.Cast( item_w.FindAnyWidget("Preview") );
  603. item_preview.Show( false );
  604. }
  605. }
  606. }
  607. //--------------------------------------------------------------------------
  608. protected void ResetItemWidget(Widget item_w, int width, int height)
  609. {
  610. if( item_w )
  611. {
  612. item_w.SetColor(ITEM_COLOR_NORMAL);
  613. }
  614. }
  615. //--------------------------------------------------------------------------
  616. void ResetItem(InventoryItem item)
  617. {
  618. if (m_Items.Contains(item))
  619. {
  620. vector data = m_Items.Get(item);
  621. int index = Math.Round(data[0]);
  622. int width = Math.Round(data[1]);
  623. int height = Math.Round(data[2]);
  624. Widget bck = GetItemBackground(index);
  625. Widget item_w = bck.FindAnyWidget("GridItem");
  626. ResetItemWidget(item_w, width, height);
  627. RefreshItemVariables( item, data, true, true );
  628. }
  629. }
  630. //--------------------------------------------------------------------------
  631. bool HasItem(InventoryItem item)
  632. {
  633. return m_Items.Contains(item);
  634. }
  635. //--------------------------------------------------------------------------
  636. void RemoveItem(InventoryItem item)
  637. {
  638. Widget bck;
  639. Widget itemW;
  640. if ( item && m_Items.Contains( item ) )
  641. {
  642. vector data = m_Items.Get(item);
  643. int index = Math.Round(data[0]);
  644. int width = Math.Round(data[1]);
  645. int height = Math.Round(data[2]);
  646. bck = GetItemBackground(index);
  647. if( bck )
  648. {
  649. itemW = bck.FindAnyWidget("GridCell");
  650. if( itemW )
  651. delete itemW;
  652. bck.FindAnyWidget("LabelTR").Show( false );
  653. bck.FindAnyWidget("LabelCC").Show( true );
  654. }
  655. m_Items.Remove( item );
  656. m_ItemWidgets.Remove( index );
  657. }
  658. }
  659. };