uipropertyattachment.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. class UIPropertyAttachment
  2. {
  3. private Widget m_WgtRoot;
  4. private Widget m_WgtThis;
  5. private XComboBoxWidget m_WgtComboBox;
  6. private TextWidget m_WgtSlotName;
  7. private ref TStringArray m_ComboItems;
  8. private int m_PrevIndex;
  9. private EntityAI m_Obj;
  10. private int m_SlotID;
  11. void UIPropertyAttachment(Widget root)
  12. {
  13. m_WgtRoot = root;
  14. m_ComboItems = new TStringArray;
  15. m_WgtThis = GetGame().GetWorkspace().CreateWidgets("gui/layouts/scene_editor/day_z_scene_editor_attachment.layout", m_WgtRoot);
  16. m_WgtComboBox = XComboBoxWidget.Cast( m_WgtThis.FindAnyWidget("combo_box") );
  17. m_WgtSlotName = TextWidget.Cast( m_WgtThis.FindAnyWidget("txt_slot_name") );
  18. }
  19. void ~UIPropertyAttachment()
  20. {
  21. m_WgtRoot = NULL;
  22. m_WgtComboBox = NULL;
  23. delete m_WgtThis;
  24. }
  25. bool OnClick(Widget w, int x, int y, int button)
  26. {
  27. if ( w == m_WgtComboBox )
  28. {
  29. if ( m_PrevIndex != 0 )
  30. {
  31. EntityAI attachment = m_Obj.GetInventory().FindAttachment(m_SlotID);
  32. GetGame().ObjectDelete(attachment);
  33. }
  34. int curr_index = m_WgtComboBox.GetCurrentItem();
  35. if ( curr_index != 0 )
  36. {
  37. PluginDeveloper module_dev = PluginDeveloper.Cast( GetPlugin(PluginDeveloper) );
  38. EntityAI e = module_dev.SpawnEntityAsAttachment(PluginSceneManager.PLAYER, m_Obj, m_ComboItems.Get(curr_index), 1, -1);
  39. }
  40. m_PrevIndex = curr_index;
  41. return true;
  42. }
  43. return false;
  44. }
  45. void SetPos(float x, float y)
  46. {
  47. m_WgtThis.SetPos(x, y);
  48. }
  49. void SetSize(float width, float height)
  50. {
  51. m_WgtThis.SetSize(width, height);
  52. }
  53. void Show(EntityAI e, string slot_name, TStringArray att_items)
  54. {
  55. m_WgtThis.Show(true);
  56. m_Obj = e;
  57. m_ComboItems.Clear();
  58. m_ComboItems.Insert("none");
  59. m_ComboItems.InsertAll(att_items);
  60. m_WgtSlotName.SetText(slot_name);
  61. m_WgtComboBox.ClearAll();
  62. m_SlotID = InventorySlots.GetSlotIdFromString(slot_name);
  63. EntityAI attachment = e.GetInventory().FindAttachment(m_SlotID);
  64. int selected_index = 0;
  65. for ( int i = 0; i < m_ComboItems.Count(); ++i )
  66. {
  67. string item_name = m_ComboItems.Get(i);
  68. m_WgtComboBox.AddItem(item_name);
  69. if ( attachment != NULL && attachment.GetType() == item_name )
  70. {
  71. selected_index = i;
  72. }
  73. }
  74. m_WgtComboBox.SetCurrentItem(selected_index);
  75. m_PrevIndex = selected_index;
  76. }
  77. void Hide()
  78. {
  79. m_WgtThis.Show(false);
  80. m_Obj = NULL;
  81. m_SlotID = -1;
  82. }
  83. bool IsVisible()
  84. {
  85. return m_WgtThis.IsVisible();
  86. }
  87. }