private void SetGridItemAt(int slot, MyToolbarItem item, string icon, string subicon, String tooltip, Sandbox.Graphics.GUI.MyGuiControlGrid.ColoredIcon?symbol = null)
        {
            var gridItem = m_toolbarItemsGrid.GetItemAt(slot);

            if (gridItem == null)
            {
                gridItem = new MyGuiControlGrid.Item(
                    icon: icon,
                    subicon: subicon,
                    toolTip: tooltip,
                    userData: item);
                if (DrawNumbers)
                {
                    gridItem.AddText(MyToolbarComponent.GetSlotControlText(slot));
                }
                //Ammo amount in toolbar
                if (item != null)
                {
                    gridItem.AddText(item.IconText, MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_BOTTOM);
                }
                else
                {
                    gridItem.ClearText(MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_BOTTOM);
                }
                gridItem.Enabled = (item != null) ? item.Enabled : true;
                if (symbol.HasValue)
                {
                    gridItem.AddIcon(symbol.Value, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP);
                }
                m_toolbarItemsGrid.SetItemAt(slot, gridItem);
            }
            else
            {
                gridItem.UserData = item;
                gridItem.Icon     = icon;
                gridItem.SubIcon  = subicon;
                if (gridItem.ToolTip == null)
                {
                    gridItem.ToolTip = new MyToolTips();
                }
                gridItem.ToolTip.ToolTips.Clear();
                gridItem.ToolTip.AddToolTip(tooltip);
                //Ammo amount in toolbar
                if (item != null)
                {
                    gridItem.AddText(item.IconText, MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_BOTTOM);
                }
                else
                {
                    gridItem.ClearText(MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_BOTTOM);
                }
                gridItem.Enabled = (item != null) ? item.Enabled : true;
                if (symbol.HasValue)
                {
                    gridItem.AddIcon(symbol.Value, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP);
                }
            }
        }
Example #2
0
        protected virtual void SetGridItemAt(int slot, MyToolbarItem item, string[] icons, string subicon, String tooltip, Sandbox.Graphics.GUI.MyGuiControlGrid.ColoredIcon?symbol = null)
        {
            var gridItem = m_toolbarItemsGrid.GetItemAt(slot);

            if (gridItem == null)
            {
                gridItem = new MyGuiControlGrid.Item(
                    icons: icons,
                    subicon: subicon,
                    toolTip: tooltip,
                    userData: item);
                if (DrawNumbers)
                {
                    gridItem.AddText(MyToolbarComponent.GetSlotControlText(slot));
                }
                //By Gregory: Changed to IconText for weapon check MyToolbarItemWeapon IconText override
                if (item != null)
                {
                    gridItem.AddText(item.IconText, MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_BOTTOM);
                }
                else
                {
                    gridItem.ClearText(MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_BOTTOM);
                }
                gridItem.Enabled = (item != null) ? item.Enabled : true;
                if (symbol.HasValue)
                {
                    gridItem.AddIcon(symbol.Value, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP);
                }
                m_toolbarItemsGrid.SetItemAt(slot, gridItem);
            }
            else
            {
                gridItem.UserData = item;
                gridItem.Icons    = icons;
                gridItem.SubIcon  = subicon;
                if (gridItem.ToolTip == null)
                {
                    gridItem.ToolTip = new MyToolTips();
                }
                gridItem.ToolTip.ToolTips.Clear();
                gridItem.ToolTip.AddToolTip(tooltip);
                //By Gregory: Changed to IconText for weapon check MyToolbarItemWeapon IconText override
                if (item != null)
                {
                    gridItem.AddText(item.IconText, MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_BOTTOM);
                }
                else
                {
                    gridItem.ClearText(MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_BOTTOM);
                }
                gridItem.Enabled = (item != null) ? item.Enabled : true;
                if (symbol.HasValue)
                {
                    gridItem.AddIcon(symbol.Value, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP);
                }
            }
        }
Example #3
0
 protected override void UnloadData()
 {
     m_instance = null;
     base.UnloadData();
 }
Example #4
0
 public override void LoadData()
 {
     m_instance = this;
     base.LoadData();
 }
Example #5
0
        public void ShowToolbar(MyToolbar toolbar)
        {
            if (m_shownToolbar != null)
            {
                m_shownToolbar.ItemChanged         -= Toolbar_ItemChanged;
                m_shownToolbar.ItemUpdated         -= Toolbar_ItemUpdated;
                m_shownToolbar.SelectedSlotChanged -= Toolbar_SelectedSlotChanged;
                m_shownToolbar.SlotActivated       -= Toolbar_SlotActivated;
                m_shownToolbar.ItemEnabledChanged  -= Toolbar_ItemEnabledChanged;
                m_shownToolbar.CurrentPageChanged  -= Toolbar_CurrentPageChanged;

                foreach (var label in m_pageLabelList)
                {
                    Elements.Remove(label);
                }
                m_pageLabelList.Clear();
            }

            m_shownToolbar = toolbar;

            if (m_shownToolbar == null) // Toolbar can be null in the passenger seat
            {
                m_toolbarItemsGrid.Enabled = false;
                m_toolbarItemsGrid.Visible = false;
            }
            else
            {
                var slotCount = toolbar.SlotCount;
                m_toolbarItemsGrid.ColumnsCount = slotCount + (toolbar.ShowHolsterSlot ? 1 : 0);
                for (int i = 0; i < slotCount; ++i)
                {
                    SetGridItemAt(i, toolbar.GetSlotItem(i), clear: true);
                }
                m_selectedItemLabel.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_BOTTOM;
                m_colorVariantPanel.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_BOTTOM;
                m_colorVariantPanel.Visible     = MyFakes.ENABLE_BLOCK_COLORING; // character != null;

                if (toolbar.ShowHolsterSlot)
                {
                    SetGridItemAt(slotCount, new MyToolbarItemEmpty(), new string[] { @"Textures\GUI\Icons\HideWeapon.dds" }, null, MyTexts.GetString(MyCommonTexts.HideWeapon));
                }

                if (toolbar.PageCount > 1)
                {
                    for (int i = 0; i < toolbar.PageCount; ++i)
                    {
                        m_textCache.Clear();
                        m_textCache.AppendInt32(i + 1);

                        MyGuiControlLabel pageLabel = new MyGuiControlLabel(text: MyToolbarComponent.GetSlotControlText(i).ToString() ?? m_textCache.ToString());
                        pageLabel.BackgroundTexture = MyGuiConstants.TEXTURE_TOOLBAR_TAB;
                        pageLabel.TextScale         = 0.7f;
                        pageLabel.Size        = m_toolbarItemsGrid.ItemSize * new Vector2(0.5f, 0.35f);
                        pageLabel.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER;

                        m_pageLabelList.Add(pageLabel);
                        Elements.Add(pageLabel);
                    }
                }

                RepositionControls();

                HighlightCurrentPageLabel();
                RefreshSelectedItem(toolbar);

                m_shownToolbar.ItemChanged         -= Toolbar_ItemChanged;
                m_shownToolbar.ItemChanged         += Toolbar_ItemChanged;
                m_shownToolbar.ItemUpdated         -= Toolbar_ItemUpdated;
                m_shownToolbar.ItemUpdated         += Toolbar_ItemUpdated;
                m_shownToolbar.SelectedSlotChanged -= Toolbar_SelectedSlotChanged;
                m_shownToolbar.SelectedSlotChanged += Toolbar_SelectedSlotChanged;
                m_shownToolbar.SlotActivated       -= Toolbar_SlotActivated;
                m_shownToolbar.SlotActivated       += Toolbar_SlotActivated;
                m_shownToolbar.ItemEnabledChanged  -= Toolbar_ItemEnabledChanged;
                m_shownToolbar.ItemEnabledChanged  += Toolbar_ItemEnabledChanged;
                m_shownToolbar.CurrentPageChanged  -= Toolbar_CurrentPageChanged;
                m_shownToolbar.CurrentPageChanged  += Toolbar_CurrentPageChanged;

                MaxSize = MinSize = new Vector2(m_toolbarItemsGrid.Size.X, m_toolbarItemsGrid.Size.Y + m_selectedItemLabel.Size.Y + m_colorVariantPanel.Size.Y);

                m_toolbarItemsGrid.Enabled = true;
                m_toolbarItemsGrid.Visible = true;
            }
        }
 protected override void UnloadData()
 {
     m_instance = null;
     base.UnloadData();
 }
 public override void LoadData()
 {
     m_instance = this;
     base.LoadData();
 }