private void InitInventory(IPerson person) { var inventoryModule = person.GetModuleSafe <IInventoryModule>(); if (inventoryModule is null) { throw new InvalidOperationException( "Active person must be able to use equipment to shown in this dialog."); } var currentInventoryItemList = new List <InventoryUiItem>(); var inventoryItems = inventoryModule.CalcActualItems(); foreach (var prop in inventoryItems) { if (prop is null) { continue; } const int EQUIPMENT_ROW_HEIGHT = EQUIPMENT_ITEM_SIZE + EQUIPMENT_ITEM_SPACING; var lastIndex = currentInventoryItemList.Count; var columnIndex = lastIndex % MAX_INVENTORY_ROW_ITEMS; var rowIndex = lastIndex / MAX_INVENTORY_ROW_ITEMS; var relativeX = columnIndex * (EQUIPMENT_ITEM_SIZE + EQUIPMENT_ITEM_SPACING); var relativeY = rowIndex * (EQUIPMENT_ITEM_SIZE + EQUIPMENT_ITEM_SPACING); var buttonRect = new Rectangle( relativeX + ContentRect.Left, ContentRect.Top + relativeY + EQUIPMENT_ROW_HEIGHT, EQUIPMENT_ITEM_SIZE, EQUIPMENT_ITEM_SIZE); var sid = prop.Scheme.Sid; if (string.IsNullOrEmpty(sid)) { Debug.Fail("All prop must have symbolic identifier (SID)."); sid = "EmptyPropIcon"; } var propButton = new IconButton( _uiContentStorage.GetButtonTexture(), _uiContentStorage.GetPropIconLayers(sid).First(), buttonRect); propButton.OnClick += PropButton_OnClick; var uiItem = new InventoryUiItem(propButton, prop, lastIndex, buttonRect); currentInventoryItemList.Add(uiItem); } _currentInventoryItems = currentInventoryItemList.ToArray(); }
private void InitInventory(IPerson person, Rectangle rect) { var inventoryModule = person.GetModuleSafe <IInventoryModule>(); if (inventoryModule is null) { throw new InvalidOperationException( "Active person must be able to use equipment to shown in this dialog."); } var currentInventoryItemList = new List <InventoryUiItem>(); var inventoryItems = inventoryModule.CalcActualItems().ToArray(); for (var itemIndex = 0; itemIndex < inventoryItems.Length; itemIndex++) { var prop = inventoryItems[itemIndex]; if (prop is null) { continue; } var relativeY = itemIndex * (EQUIPMENT_ITEM_SIZE + EQUIPMENT_ITEM_SPACING); var buttonRect = new Rectangle( rect.Left, rect.Top + relativeY, EQUIPMENT_ITEM_SIZE, EQUIPMENT_ITEM_SIZE); var sid = prop.Scheme.Sid; if (string.IsNullOrEmpty(sid)) { Debug.Fail("All prop must have symbolic identifier (SID)."); sid = "EmptyPropIcon"; } var propButton = new IconButton( _uiContentStorage.GetButtonTexture(), _uiContentStorage.GetPropIconLayers(sid).First(), buttonRect); propButton.OnClick += PropButton_OnClick; var uiItem = new InventoryUiItem(propButton, prop, itemIndex, buttonRect); currentInventoryItemList.Add(uiItem); } _currentInventoryItems = currentInventoryItemList.ToArray(); }
private void InitContainerContent(IStaticObject container) { _container = container; var currentContainerItemList = new List <InventoryUiItem>(); var props = container.GetModule <IPropContainer>().Content.CalcActualItems().Take(8).ToArray(); for (var itemIndex = 0; itemIndex < props.Length; itemIndex++) { var prop = props[itemIndex]; var relativeY = itemIndex * (EQUIPMENT_ITEM_SIZE + EQUIPMENT_ITEM_SPACING); var buttonRect = new Rectangle( ContentRect.Left, ContentRect.Top + relativeY, EQUIPMENT_ITEM_SIZE, EQUIPMENT_ITEM_SIZE); var sid = prop.Scheme.Sid; if (string.IsNullOrEmpty(sid)) { Debug.Fail("All prop must have symbolic identifier (SID)."); sid = "EmptyPropIcon"; } var propButton = new IconButton( _uiContentStorage.GetButtonTexture(), _uiContentStorage.GetPropIconLayers(sid).First(), buttonRect); propButton.OnClick += ContainerPropButton_OnClick; var uiItem = new InventoryUiItem(propButton, prop, itemIndex, buttonRect); currentContainerItemList.Add(uiItem); } _currentContainerItems = currentContainerItemList.ToArray(); }