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