private void Init() { m_windowIsMovable = false; m_enableBackgroundFade = true; m_size = new Vector2(0.45f, 0.875f); AddCaption(new Vector2(0, -0.005f)); AddActivatedCheckbox(GetControlsOriginLeftFromScreenSize() + new Vector2(0.05f, 0.01f), PrefabSecurityControlHUB.Activated); m_activatedCheckbox.OnCheck = OnActivateClick; m_connectedPrefabIdsListbox = new MyGuiControlListbox(this, new Vector2(0, -0.02f), new Vector2(0.2f, 0.07f), MyGuiConstants.LISTBOX_BACKGROUND_COLOR, MyTextsWrapper.Get(MyTextsWrapperEnum.ConnectedPrefabIds), MyGuiConstants.LABEL_TEXT_SCALE, 1, 7, 1, false, true, false); foreach (IMyUseableEntity connectedEntity in PrefabSecurityControlHUB.ConnectedEntities) { MyEntity entity = connectedEntity as MyEntity; Debug.Assert(entity.EntityId != null); uint entityId = entity.EntityId.Value.NumericValue; m_connectedPrefabIdsListbox.AddItem((int)entityId, new StringBuilder(entityId.ToString())); } Controls.Add(m_connectedPrefabIdsListbox); Vector2 buttonPosition = m_connectedPrefabIdsListbox.GetPosition() + new Vector2(-m_connectedPrefabIdsListbox.GetSize().Value.X / 2f, m_connectedPrefabIdsListbox.GetSize().Value.Y / 2f) + new Vector2(-0.05f, 0.09f); Controls.Add(new MyGuiControlButton(this, buttonPosition, MyGuiConstants.MESSAGE_BOX_BUTTON_SIZE, MyGuiConstants.BUTTON_BACKGROUND_COLOR, MyTextsWrapperEnum.Add, MyGuiConstants.BUTTON_TEXT_COLOR, MyGuiConstants.BUTTON_TEXT_SCALE, OnAddClick, MyGuiControlButtonTextAlignment.CENTERED, true, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER, true)); buttonPosition += new Vector2(0.18f, 0f); Controls.Add(new MyGuiControlButton(this, buttonPosition, MyGuiConstants.MESSAGE_BOX_BUTTON_SIZE, MyGuiConstants.BUTTON_BACKGROUND_COLOR, MyTextsWrapperEnum.Delete, MyGuiConstants.BUTTON_TEXT_COLOR, MyGuiConstants.BUTTON_TEXT_SCALE, OnDeleteClick, MyGuiControlButtonTextAlignment.CENTERED, true, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER, true)); }
private void DropItem(MyGuiControlListbox listbox, MyGuiControlListboxItem item, int rowIndex, int itemIndex) { // in god editor and other side listbox, we don't want put this item to this listbox, so we remove it if (m_inventoryScreenType == MyGuiScreenInventoryType.GodEditor && listbox == m_otherSideInventoryListBox) { m_itemsRepository.RemoveItem(item.Key); } else { if (listbox.GetItem(rowIndex, itemIndex) != null || listbox.GetRowsCount() <= rowIndex) { listbox.AddItem(item); } else { listbox.AddItem(item, rowIndex, itemIndex); } // if there are no empty row, we try add new row if (listbox.GetEmptyRowsCount() == 0) { AddFreeRowsIfCan(listbox, 1); } } StopDragging(); }
private void MoveItemBetweenListboxes(MyGuiControlListbox listboxFrom, MyGuiControlListbox listboxTo, bool copyItem, bool deleteItem) { bool moved = false; MyGuiControlListboxItem selectedItem = listboxFrom.GetSelectedItem(); if (selectedItem != null) { System.Diagnostics.Debug.Assert(m_itemsRepository.Contains(selectedItem.Key)); if (!IsListboxFull(listboxTo) && m_itemsRepository.Contains(selectedItem.Key)) { MyInventoryItem item = m_itemsRepository.GetItem(selectedItem.Key); if (!CanDropItem(item, listboxFrom, listboxTo)) { return; } if (m_tradeForMoney) { selectedItem.ToolTip = GetListboxItemTooltip(listboxTo, selectedItem.Key); bool tradeForMoneyResult = HandleTradeForMoney(listboxFrom, listboxTo, item); if (!tradeForMoneyResult) { return; } } if (NeedHandleSmallShipDrop(item)) { HandleSmallShipDrop(listboxFrom, listboxTo, item); } // we make copy of moved item if (copyItem) { listboxTo.AddItem(CreateCopyOfListboxItem(selectedItem)); } else { listboxFrom.RemoveItem(selectedItem.Key, false); // if we don't want delete moved item if (!deleteItem) { listboxTo.AddItem(selectedItem); } } moved = true; m_wasAnythingTrasfered = true; if (m_tradeForMoney) { UpdateOtherSideInventoryListboxForTrading(); } } else { MyAudio.AddCue2D(MySoundCuesEnum.HudInventoryFullWarning); } } if (moved && listboxTo.GetEmptyRowsCount() == 0) { AddFreeRowsIfCan(listboxTo, 1); } }
private void FillListBoxFromID(MyGuiControlListbox listbox, int id, bool canBeMoved = true) { MyInventoryItem inventoryItem = m_itemsRepository.GetItem(id); StringBuilder description = null; if (inventoryItem.Icon == null) { description = inventoryItem.MultiLineDescription; } MyGuiControlListboxItem listboxItem = new MyGuiControlListboxItem(id, description, inventoryItem.Icon, GetListboxItemTooltip(listbox, id), MyGuiConstants.LABEL_TEXT_SCALE); listboxItem.IconTexts = new MyIconTexts(); // add amount icon's text if (inventoryItem.Amount != 0f || inventoryItem.Amount != inventoryItem.MaxAmount) { StringBuilder amount = new StringBuilder(); if (inventoryItem.Amount > (int)inventoryItem.Amount) { float fixedAmount = Math.Max(0.01f, inventoryItem.Amount); // prevent items with zero amount, for visualization 0.01 is the minimum value amount.AppendDecimal(fixedAmount, 2); } else { amount.AppendInt32((int)inventoryItem.Amount); } //amount.Append(inventoryItem.Amount.ToString()); MyGuiDrawAlignEnum align; Vector2 offset; //All amounts alignet to right bottom position from now /* if (inventoryItem.AmountTextAlign == MyInventoryAmountTextAlign.MiddleRight) { align = MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_CENTER; offset = new Vector2(-0.004f, 0.0038f); } else if (inventoryItem.AmountTextAlign == MyInventoryAmountTextAlign.BottomRight) { * */ align = MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_BOTTOM; offset = new Vector2(-0.013f, -0.01f); /*} else { throw new MyMwcExceptionApplicationShouldNotGetHere(); } * */ listboxItem.IconTexts[align] = new MyColoredText(amount, Color.White, Color.White, MyGuiManager.GetFontMinerWarsBlue(), 0.6f, offset); } bool enabled = inventoryItem.CanBeMoved && canBeMoved; if (m_tradeForMoney) { enabled &= inventoryItem.CanBeTraded; } listboxItem.Enabled = enabled; //if (!inventoryItem.CanBeMoved) //{ // listboxItem.Enabled = false; //} listbox.AddItem(listboxItem); }
private void RecreateControls() { Controls.Clear(); m_size = new Vector2(1100f / 1600f, 1200 / 1200f); Vector2 controlsOriginLeft = new Vector2(-m_size.Value.X / 2.0f + 0.07f, -m_size.Value.Y / 2.0f + 0.2f - 0.0360f); Vector2 controlsOriginRight = new Vector2(-m_size.Value.X / 2.0f + 0.07f + 0.355f, -m_size.Value.Y / 2.0f + 0.2f - 0.0360f); AddCaption(MyTextsWrapperEnum.TemporarySectorMap, new Vector2(0, 0.035f)); //Controls.Add(new MyGuiControlLabel(this, controlsOriginLeft, null, MyTextsWrapperEnum.Map, MyGuiConstants.LABEL_TEXT_COLOR, // MyGuiConstants.LABEL_TEXT_SCALE, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER)); if (m_sectors != null && m_sectors.Count > 0) { // When editing global story sectors, add some unused sector AddUnusedSector(); int selectedIndex = 0; /*m_sectorsCombobox = new MyGuiControlCombobox(this, new Vector2(0, -0.17f), MyGuiControlPreDefinedSize.LONGMEDIUM, MyGuiConstants.COMBOBOX_BACKGROUND_COLOR, MyGuiConstants.COMBOBOX_TEXT_SCALE, 6, true, false, true); for (int i = 0; i < m_sectors.Count; i++) { MyMwcSectorIdentifier sectorIdentifier = m_sectors[i]; if (m_lastSandboxSector.HasValue && sectorIdentifier.Position.Equals(m_lastSandboxSector.Value)) { selectedIndex = i; } if (string.IsNullOrEmpty(sectorIdentifier.SectorName)) { m_sectorsCombobox.AddItem(i, GetSectorScreenshot(sectorIdentifier), new StringBuilder(string.Format("{0}", sectorIdentifier.Position.ToString()))); } else { m_sectorsCombobox.AddItem(i, GetSectorScreenshot(sectorIdentifier), new StringBuilder(string.Format("{0} ({1})", sectorIdentifier.SectorName, sectorIdentifier.Position.ToString()))); } } SortSectors(); m_sectorsCombobox.SelectItemByKey(selectedIndex); m_sectorsCombobox.OnSelectItemDoubleClick += OnItemDoubleClick; Controls.Add(m_sectorsCombobox);*/ //Listbox m_sectorsListbox = new MyGuiControlListbox(this, new Vector2(0, -0.025f), new Vector2(0.43f, 0.1f), MyGuiConstants.LISTBOX_BACKGROUND_COLOR, null, MyGuiConstants.LABEL_TEXT_SCALE, 1, 6, 1, true, true, false, null, null, MyGuiManager.GetScrollbarSlider(), MyGuiManager.GetHorizontalScrollbarSlider(), 1, 0, MyGuiConstants.LISTBOX_BACKGROUND_COLOR_BLUE, 0f, 0f, 0f, 0f, 0, 0f, -0.01f, -0.01f, -0.02f, 0.02f) { IconScale = new Vector2(0.97f) }; for (int i = 0; i < m_sectors.Count; i++) { MyMwcSectorIdentifier sectorIdentifier = m_sectors[i]; if (m_lastSandboxSector.HasValue && sectorIdentifier.Position.Equals(m_lastSandboxSector.Value)) { selectedIndex = i; } if (string.IsNullOrEmpty(sectorIdentifier.SectorName)) { m_sectorsListbox.AddItem(i, new StringBuilder(string.Format("{0}", sectorIdentifier.Position.ToString())), GetSectorScreenshot(sectorIdentifier)); } else { m_sectorsListbox.AddItem(i, new StringBuilder(string.Format("{0} ({1})", sectorIdentifier.SectorName, sectorIdentifier.Position.ToString())), GetSectorScreenshot(sectorIdentifier)); } } SortSectors(); m_sectorsListbox.SetSelectedItem(selectedIndex); m_sectorsListbox.ItemDoubleClick += OnItemDoubleClick; Controls.Add(m_sectorsListbox); } else { var text = m_loadingSectors.HasValue ? MyTextsWrapperEnum.LoadingPleaseWait : MyTextsWrapperEnum.NoSectorsAvailable; Controls.Add(new MyGuiControlLabel(this, new Vector2(0, -0.03f), null, text, MyGuiConstants.LABEL_TEXT_COLOR, MyGuiConstants.LABEL_TEXT_SCALE, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER)); } // Buttons OK and CANCEL var m_okButton = new MyGuiControlButton(this, new Vector2(-0.0879f, 0.35f), MyGuiConstants.OK_BUTTON_SIZE * 0.75f, MyGuiConstants.BUTTON_BACKGROUND_COLOR, MyGuiManager.GetInventoryScreenButtonTexture(), null, null, MyTextsWrapperEnum.Ok, MyGuiConstants.BUTTON_TEXT_COLOR, MyGuiConstants.BUTTON_TEXT_SCALE, MyGuiControlButtonTextAlignment.CENTERED, OnOkClick, true, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, true, true); Controls.Add(m_okButton); var m_cancelButton = new MyGuiControlButton(this, new Vector2(0.0879f, 0.35f), MyGuiConstants.OK_BUTTON_SIZE * 0.75f, MyGuiConstants.BUTTON_BACKGROUND_COLOR, MyGuiManager.GetInventoryScreenButtonTexture(), null, null, MyTextsWrapperEnum.Cancel, MyGuiConstants.BUTTON_TEXT_COLOR, MyGuiConstants.BUTTON_TEXT_SCALE, MyGuiControlButtonTextAlignment.CENTERED, OnCancelClick, true, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, true, true); Controls.Add(m_cancelButton); }
private void RecreateControls() { m_size = new Vector2(1100f / 1600f, 1200 / 1200f); Controls.Clear(); string prevName = MyConfig.LastFriendName; if (m_findPlayerName != null && m_findPlayerName.Text != null) { prevName = m_findPlayerName.Text; } AddCaption(MyTextsWrapperEnum.FriendsSectorMap, new Vector2(0, 0.04f)); Vector2 controlsOriginLeft = new Vector2(-m_size.Value.X / 2.0f + 0.1f, -m_size.Value.Y / 2.0f + 0.1f); Vector2 controlsDelta = new Vector2(0, 0.0525f); // controls for typing friend name to search Controls.Add(new MyGuiControlLabel(this, controlsOriginLeft + 1f * controlsDelta, null, MyTextsWrapperEnum.FriendName, MyGuiConstants.LABEL_TEXT_COLOR, MyGuiConstants.LABEL_TEXT_SCALE, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER)); m_findPlayerName = new MyGuiControlTextbox(this, controlsOriginLeft + 1f * controlsDelta + new Vector2(MyGuiConstants.TEXTBOX_MEDIUM_SIZE.X / 2.0f + 0.15f, 0), MyGuiControlPreDefinedSize.MEDIUM, prevName, 20, MyGuiConstants.TEXTBOX_BACKGROUND_COLOR, MyGuiConstants.LABEL_TEXT_SCALE, MyGuiControlTextboxType.NORMAL); Controls.Add(m_findPlayerName); var searchButton = new MyGuiControlButton(this, m_findPlayerName.GetPosition() + new Vector2(MyGuiConstants.TEXTBOX_MEDIUM_SIZE.X / 2.0f - 0.0208f, 0), MyGuiConstants.SEARCH_BUTTON_SIZE, MyGuiConstants.BUTTON_BACKGROUND_COLOR, MyGuiManager.GetButtonSearchTexture(), null, null, MyTextsWrapperEnum.Search, MyGuiConstants.BUTTON_TEXT_COLOR, MyGuiConstants.BUTTON_TEXT_SCALE * 0.8f, MyGuiControlButtonTextAlignment.CENTERED, OnSearchClick, true, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER, true, true); Controls.Add(searchButton); // friend maps available for selection //Controls.Add(new MyGuiControlLabel(this, controlsOriginLeft + 3* controlsDelta, null, MyTextsWrapperEnum.Map, MyGuiConstants.LABEL_TEXT_COLOR, // MyGuiConstants.LABEL_TEXT_SCALE, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER)); if (m_sectorIdentifiers != null && m_userDetails != null && m_sectorIdentifiers.Count > 0) { m_mapsCombobox = new MyGuiControlListbox(this, new Vector2(0, -0.010f), new Vector2(0.43f, 0.1f), MyGuiConstants.LISTBOX_BACKGROUND_COLOR, null, MyGuiConstants.LABEL_TEXT_SCALE, 1, 6, 1, true, true, false, null, null, MyGuiManager.GetScrollbarSlider(), MyGuiManager.GetHorizontalScrollbarSlider(), 1, 0, MyGuiConstants.LISTBOX_BACKGROUND_COLOR_BLUE, 0f, 0f, 0f, 0f, 0, 0f, -0.01f, -0.01f, -0.02f, 0.02f); for (int i = 0; i < m_sectorIdentifiers.Count; i++) { MyMwcSectorIdentifier sectorIdentifier = m_sectorIdentifiers[i]; foreach (MyMwcUserDetail userDetail in m_userDetails) { if (sectorIdentifier.UserId.HasValue && sectorIdentifier.UserId.Value == userDetail.UserId) { if (string.IsNullOrEmpty(sectorIdentifier.SectorName)) { m_mapsCombobox.AddItem(i, new StringBuilder(string.Format("{0} - {1}", userDetail.DisplayName, sectorIdentifier.Position.ToString())), null); } else { m_mapsCombobox.AddItem(i, new StringBuilder(string.Format("{0} - {1} ({2})", userDetail.DisplayName, sectorIdentifier.SectorName, sectorIdentifier.Position.ToString())), null); } } } } SortSectors(); m_mapsCombobox.ItemDoubleClick += OnItemDoubleClick; Controls.Add(m_mapsCombobox); } else { Controls.Add(new MyGuiControlLabel(this, controlsOriginLeft + 3 * controlsDelta + new Vector2(0.21f, 0), null, MyTextsWrapperEnum.NoSectorsAvailable, MyGuiConstants.LABEL_TEXT_COLOR, MyGuiConstants.LABEL_TEXT_SCALE, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER)); } // Buttons OK and CANCEL var m_okButton = new MyGuiControlButton(this, new Vector2(-0.0879f, 0.35f), MyGuiConstants.OK_BUTTON_SIZE * 0.75f, MyGuiConstants.BUTTON_BACKGROUND_COLOR, MyGuiManager.GetInventoryScreenButtonTexture(), null, null, MyTextsWrapperEnum.Ok, MyGuiConstants.BUTTON_TEXT_COLOR, MyGuiConstants.BUTTON_TEXT_SCALE, MyGuiControlButtonTextAlignment.CENTERED, OnOkClick, true, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, true, true); Controls.Add(m_okButton); var m_cancelButton = new MyGuiControlButton(this, new Vector2(0.0879f, 0.35f), MyGuiConstants.OK_BUTTON_SIZE * 0.75f, MyGuiConstants.BUTTON_BACKGROUND_COLOR, MyGuiManager.GetInventoryScreenButtonTexture(), null, null, MyTextsWrapperEnum.Cancel, MyGuiConstants.BUTTON_TEXT_COLOR, MyGuiConstants.BUTTON_TEXT_SCALE, MyGuiControlButtonTextAlignment.CENTERED, OnCancelClick, true, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, true, true); Controls.Add(m_cancelButton); m_findPlayerName.MoveCartrigeToEnd(); this.SetControlIndex(Controls.IndexOf(m_findPlayerName)); }
private void MoveItemToListbox(MyGuiControlListbox moveTo, MyGuiControlListboxItem item, int? rowIndex = null, int? itemIndex = null) { if (moveTo == m_allItemsInventoryListbox) { RemoveCopy(item.Key); } else { if (rowIndex != null && itemIndex != null) { moveTo.AddItem(item, rowIndex.Value, itemIndex.Value); } else { moveTo.AddItem(item); } } }
private void AddInventoryListbox(MyGuiControlListbox listbox, MyInventory inventory, ref List<MyGuiControlListbox> listboxesToDragAndDrop) { Controls.Add(listbox); listboxesToDragAndDrop.Add(listbox); listbox.ItemDrag += ListboxItemDrag; listbox.ItemDoubleClick += ListboxItemDoubleClick; foreach (MyInventoryItem inventoryItem in inventory.GetInventoryItems()) { listbox.AddItem(CreateListboxItemAndAddToRepository(inventoryItem)); } }