Ejemplo n.º 1
0
        /// <summary>
        /// Creates a new GUI Element List Menu
        /// </summary>
        /// <param name="capi">The Client API.</param>
        /// <param name="values">The values of the list.</param>
        /// <param name="names">The names for each of the values.</param>
        /// <param name="selectedIndex">The default selected index.</param>
        /// <param name="onSelectionChanged">The event fired when the selection is changed.</param>
        /// <param name="bounds">The bounds of the GUI element.</param>
        public GuiElementListMenu(ICoreClientAPI capi, string[] values, string[] names, int selectedIndex, SelectionChangedDelegate onSelectionChanged, ElementBounds bounds, CairoFont font, bool multiSelect) : base(capi, "", font, bounds)
        {
            if (values.Length != names.Length)
            {
                throw new ArgumentException("Values and Names arrays must be of the same length!");
            }

            hoverTexture     = new LoadedTexture(capi);
            dropDownTexture  = new LoadedTexture(capi);
            scrollbarTexture = new LoadedTexture(capi);

            this.Values             = values;
            this.Names              = names;
            this.SelectedIndex      = selectedIndex;
            this.multiSelect        = multiSelect;
            this.onSelectionChanged = onSelectionChanged;
            HoveredIndex            = selectedIndex;

            ElementBounds scrollbarBounds = ElementBounds.Fixed(0, 0, 0, 0).WithEmptyParent();

            scrollbar = new GuiElementCompactScrollbar(api, OnNewScrollbarValue, scrollbarBounds);



            richtTextElem = new GuiElementRichtext[values.Length];
            for (int i = 0; i < values.Length; i++)
            {
                ElementBounds textBounds = ElementBounds.Fixed(0, 0, 700, 100).WithEmptyParent();
                richtTextElem[i] = new GuiElementRichtext(capi, new RichTextComponentBase[0], textBounds);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Constructor for the button
        /// </summary>
        /// <param name="capi">The core client API.</param>
        /// <param name="color"></param>
        /// <param name="OnToggled">The action that happens when the button is toggled.</param>
        /// <param name="bounds">The bounding box of the button.</param>
        public GuiElementColorListPicker(ICoreClientAPI capi, int color, Common.Action <bool> OnToggled, ElementBounds bounds) : base(capi, bounds)
        {
            activeTexture = new LoadedTexture(capi);

            this.color = color;
            handler    = OnToggled;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates an ItemStackInfo element.
        /// </summary>
        /// <param name="capi">The client API</param>
        /// <param name="bounds">The bounds of the object.</param>
        /// <param name="OnRequireInfoText">The function that is called when an item information is called.</param>
        public GuiElementItemstackInfo(ICoreClientAPI capi, ElementBounds bounds, InfoTextDelegate OnRequireInfoText) : base(capi, "", CairoFont.WhiteSmallText(), bounds)
        {
            this.OnRequireInfoText = OnRequireInfoText;

            texture = new LoadedTexture(capi);

            ElementBounds textBounds = bounds.CopyOnlySize();
            ElementBounds descBounds = textBounds.CopyOffsetedSibling(ItemStackSize + 50, MarginTop, -ItemStackSize - 50, 0);

            descBounds.WithParent(bounds);
            textBounds.WithParent(bounds);

            descriptionElement = new GuiElementRichtext(capi, new RichTextComponentBase[0], descBounds);
            //new GuiElementStaticText(capi, "", EnumTextOrientation.Left, textBounds.CopyOffsetedSibling(ItemStackSize + 50, MarginTop, -ItemStackSize - 50, 0), Font);
            descriptionElement.zPos = 1001;


            titleFont            = Font.Clone();
            titleFont.FontWeight = FontWeight.Bold;

            titleElement      = new GuiElementRichtext(capi, new RichTextComponentBase[0], textBounds);
            titleElement.zPos = 1001;

            maxWidth = bounds.fixedWidth;
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Creates a new text area.
 /// </summary>
 /// <param name="capi">The client API</param>
 /// <param name="bounds">The bounds of the text area.</param>
 /// <param name="OnTextChanged">The event fired when the text is changed.</param>
 /// <param name="font">The font of the text.</param>
 public GuiElementTextArea(ICoreClientAPI capi, ElementBounds bounds, Action <string> OnTextChanged, CairoFont font) : base(capi, font, bounds)
 {
     highlightTexture   = new LoadedTexture(capi);
     multilineMode      = true;
     minHeight          = bounds.fixedHeight;
     this.OnTextChanged = OnTextChanged;
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Adds a chat input element to the UI.
 /// </summary>
 /// <param name="capi">The client API</param>
 /// <param name="bounds">The bounds of the chat input.</param>
 /// <param name="OnTextChanged">The event fired when the text is altered.</param>
 public GuiElementChatInput(ICoreClientAPI capi, ElementBounds bounds, API.Common.Action <string> OnTextChanged) : base(capi, null, bounds)
 {
     highlightTexture   = new LoadedTexture(capi);
     this.OnTextChanged = OnTextChanged;
     this.caretColor    = new float[] { 1, 1, 1, 1 };
     this.Font          = CairoFont.WhiteSmallText();
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Creates a new title bar.
        /// </summary>
        /// <param name="capi">The Client API.</param>
        /// <param name="text">The text on the title bar.</param>
        /// <param name="composer">The GuiComposer for the title bar.</param>
        /// <param name="OnClose">The event fired when the title bar is closed.</param>
        /// <param name="font">The font of the title bar.</param>
        /// <param name="bounds">The bounds of the title bar.</param>
        public GuiElementDialogTitleBar(ICoreClientAPI capi, string text, GuiComposer composer, Action OnClose = null, CairoFont font = null, ElementBounds bounds = null) : base(capi, text, font, bounds)
        {
            closeIconHoverTexture = new LoadedTexture(capi);
            menuIconHoverTexture  = new LoadedTexture(capi);

            if (bounds == null)
            {
                this.Bounds = ElementStdBounds.TitleBar();
            }
            if (font == null)
            {
                this.Font = CairoFont.WhiteSmallText();
            }
            this.OnClose = OnClose;

            ElementBounds dropDownBounds = ElementBounds.Fixed(0, 0, 100, 25);

            this.Bounds.WithChild(dropDownBounds);

            listMenu = new GuiElementListMenu(capi, new string[] { "auto", "manual" }, new string[] { Lang.Get("Fixed"), Lang.Get("Movable") }, 0, onSelectionChanged, dropDownBounds, CairoFont.WhiteSmallText(), false)
            {
                HoveredIndex = 0
            };

            baseComposer = composer;
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Takes a string of text and applies a texture to it.
        /// </summary>
        /// <param name="text">The text to texture.</param>
        /// <param name="font">The font of the text.</param>
        /// <param name="background">The background of the text. (default: none/null)</param>
        /// <returns>The texturized text.</returns>
        public LoadedTexture GenTextTexture(string text, CairoFont font, TextBackground background = null)
        {
            LoadedTexture tex = new LoadedTexture(capi);

            GenOrUpdateTextTexture(text, font, ref tex, background);
            return(tex);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Takes a string of text and applies a texture to it.
        /// </summary>
        /// <param name="text">The text to texture.</param>
        /// <param name="font">The font of the text.</param>
        /// <param name="width">The width of the text.</param>
        /// <param name="height">The height of the text.</param>
        /// <param name="background">The background of the text. (default: none/null)</param>
        /// <param name="orientation">The orientation of the text. (default: left)</param>
        /// <returns>The texturized text.</returns>
        public LoadedTexture GenTextTexture(string text, CairoFont font, int width, int height, TextBackground background = null, EnumTextOrientation orientation = EnumTextOrientation.Left, bool demulAlpha = false)
        {
            LoadedTexture tex = new LoadedTexture(capi);

            GenOrUpdateTextTexture(text, font, width, height, ref tex, background, orientation);
            return(tex);
        }
Ejemplo n.º 9
0
        public void Recompose(ICoreClientAPI capi)
        {
            Texture?.Dispose();
            Texture = new TextTextureUtil(capi).GenTextTexture(Stack.GetName(), CairoFont.WhiteSmallText());

            scissorBounds = ElementBounds.FixedSize(50, 50);
            scissorBounds.ParentBounds = capi.Gui.WindowBounds;
        }
Ejemplo n.º 10
0
 internal GuiComposer(ICoreClientAPI api, ElementBounds bounds, string dialogName)
 {
     staticElementsTexture = new LoadedTexture(api);
     this.dialogName       = dialogName;
     this.bounds           = bounds;
     this.Api = api;
     parentBoundsForNextElement.Push(bounds);
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Builds a slider.  A horizontal customizeable slider.
        /// </summary>
        /// <param name="capi">The Client API</param>
        /// <param name="onNewSliderValue">The event that's fired when the slider changed.</param>
        /// <param name="bounds">the bounds of the object.</param>
        public GuiElementSlider(ICoreClientAPI capi, ActionConsumable <int> onNewSliderValue, ElementBounds bounds) : base(capi, bounds)
        {
            handleTexture     = new LoadedTexture(capi);
            hoverTextTexture  = new LoadedTexture(capi);
            waterTexture      = new LoadedTexture(capi);
            alarmValueTexture = new LoadedTexture(capi);

            this.onNewSliderValue = onNewSliderValue;
        }
Ejemplo n.º 12
0
        public SkillItem WithIcon(ICoreClientAPI capi, DrawSkillIconDelegate onDrawIcon)
        {
            Texture = capi.Gui.Icons.GenTexture(48, 48, (ctx, surface) =>
            {
                onDrawIcon(ctx, 5, 5, 38, 38, ColorUtil.WhiteArgbDouble);
            });

            return(this);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// A text component with an embedded link.
        /// </summary>
        /// <param name="displayText">The text of the Text.</param>
        /// <param name="url">The link in the text.</param>
        public LinkTextComponent(ICoreClientAPI api, string displayText, CairoFont font, Common.Action <LinkTextComponent> onLinkClicked) : base(api, displayText, font)
        {
            this.onLinkClicked = onLinkClicked;
            MouseOverCursor    = "linkselect";

            this.font = this.font.Clone().WithColor(GuiStyle.ActiveButtonTextColor);

            hoverText  = new LoadedTexture(api);
            normalText = new LoadedTexture(api);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Constructor for the button
        /// </summary>
        /// <param name="capi">The core client API.</param>
        /// <param name="icon">The icon name</param>
        /// <param name="text">The text for the button.</param>
        /// <param name="font">The font of the text.</param>
        /// <param name="OnToggled">The action that happens when the button is toggled.</param>
        /// <param name="bounds">The bounding box of the button.</param>
        /// <param name="toggleable">Can the button be toggled on or off?</param>
        public GuiElementToggleButton(ICoreClientAPI capi, string icon, string text, CairoFont font, Common.Action <bool> OnToggled, ElementBounds bounds, bool toggleable = false) : base(capi, text, font, bounds)
        {
            releasedTexture = new LoadedTexture(capi);
            pressedTexture  = new LoadedTexture(capi);
            hoverTexture    = new LoadedTexture(capi);

            handler    = OnToggled;
            Toggleable = toggleable;
            this.icon  = icon;
        }
        /// <summary>
        /// Initializes the text component.
        /// </summary>
        /// <param name="capi">The Client API</param>
        /// <param name="font">The font of the text.</param>
        /// <param name="bounds">The bounds of the component.</param>
        public GuiElementEditableTextBase(ICoreClientAPI capi, CairoFont font, ElementBounds bounds) : base(capi, "", font, bounds)
        {
            caretTexture = new LoadedTexture(capi);
            textTexture  = new LoadedTexture(capi);

            lines = new List <string>
            {
                ""
            };
        }
Ejemplo n.º 16
0
        public void SetPlaceHolderText(string text)
        {
            TextTextureUtil util = new TextTextureUtil(this.api);

            placeHolderTextTexture?.Dispose();
            CairoFont font = Font.Clone();

            font.Color[3]         *= 0.5;
            placeHolderTextTexture = util.GenTextTexture(text, font);
        }
Ejemplo n.º 17
0
        public void SetRotOverlay(ICoreClientAPI capi, float opacity)
        {
            if (OverlayTexture == null)
            {
                OverlayTexture = new LoadedTexture(capi);
            }

            capi.Render.GetOrLoadTexture(new AssetLocation("textures/gui/rot.png"), ref OverlayTexture);

            this.OverlayOpacity = opacity;
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Creates a new stat bar for the GUI.
        /// </summary>
        /// <param name="capi">The client API</param>
        /// <param name="bounds">The bounds of the stat bar.</param>
        /// <param name="color">The color of the stat bar.</param>
        /// <param name="rightToLeft">Determines the direction that the bar fills.</param>
        public GuiElementStatbar(ICoreClientAPI capi, ElementBounds bounds, double[] color, bool rightToLeft) : base(capi, "", CairoFont.WhiteDetailText(), bounds)
        {
            barTexture   = new LoadedTexture(capi);
            flashTexture = new LoadedTexture(capi);
            valueTexture = new LoadedTexture(capi);

            this.color       = color;
            this.rightToLeft = rightToLeft;

            onGetStatbarValue = () => { return((float)Math.Round((float)value, 1) + " / " + (int)this.maxValue); };
        }
Ejemplo n.º 19
0
 public void WithAlarmTabs(CairoFont notifyFont)
 {
     this.notifyFont = notifyFont;
     notifyTextures  = new LoadedTexture[tabs.Length];
     for (int i = 0; i < tabs.Length; i++)
     {
         notifyTextures[i] = new LoadedTexture(this.api);
     }
     AlarmTabs = true;
     ComposeOverlays(true);
 }
Ejemplo n.º 20
0
        /// <summary>
        /// Creates a new dropdown configuration list.
        /// </summary>
        /// <param name="capi">The Client API</param>
        /// <param name="items">The list of items in the configuration.</param>
        /// <param name="OnItemClick">The event fired when the particular item is clicked.</param>
        /// <param name="font">The font of the text.</param>
        /// <param name="bounds">the bounds of the element.</param>
        public GuiElementConfigList(ICoreClientAPI capi, List <ConfigItem> items, ConfigItemClickDelegate OnItemClick, CairoFont font, ElementBounds bounds) : base(capi, "", font, bounds)
        {
            hoverTexture = new LoadedTexture(capi);

            this.items              = items;
            this.OnItemClick        = OnItemClick;
            this.errorFont          = font.Clone();
            this.stdFont            = font;
            this.titleFont          = font.Clone().WithWeight(FontWeight.Bold);
            this.titleFont.Color[3] = 0.6;
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Creates a Skill Item Grid.
        /// </summary>
        /// <param name="capi">The Client API</param>
        /// <param name="skillItems">The items with skills.</param>
        /// <param name="columns">The columns of the Item Grid</param>
        /// <param name="rows">The Rows of the Item Grid.</param>
        /// <param name="OnSlotClick">The event fired when the slot is clicked.</param>
        /// <param name="bounds">The bounds of the Item Grid.</param>
        public GuiElementSkillItemGrid(ICoreClientAPI capi, List <SkillItem> skillItems, int columns, int rows, Action <int> OnSlotClick, ElementBounds bounds) : base(capi, bounds)
        {
            hoverTexture = new LoadedTexture(capi);

            this.skillItems  = skillItems;
            this.cols        = columns;
            this.rows        = rows;
            this.OnSlotClick = OnSlotClick;

            this.Bounds.fixedHeight = rows * (GuiElementItemSlotGrid.unscaledSlotPadding + GuiElementPassiveItemSlot.unscaledSlotSize);
            this.Bounds.fixedWidth  = columns * (GuiElementItemSlotGrid.unscaledSlotPadding + GuiElementPassiveItemSlot.unscaledSlotSize);
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Creates a switch which can be toggled.
        /// </summary>
        /// <param name="capi">The Client API</param>
        /// <param name="OnToggled">The event that happens when the switch is flipped.</param>
        /// <param name="bounds">The bounds of the element.</param>
        /// <param name="size">The size of the switch. (Default: 30)</param>
        /// <param name="padding">The padding on the outside of the switch (Default: 5)</param>
        public GuiElementSwitch(ICoreClientAPI capi, Action <bool> OnToggled, ElementBounds bounds, double size = 30, double padding = 4) : base(capi, bounds)
        {
            onTexture = new LoadedTexture(capi);

            bounds.fixedWidth  = size;
            bounds.fixedHeight = size;

            this.unscaledPadding = padding;
            this.unscaledSize    = size;

            this.handler = OnToggled;
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Creates a new stat bar for the GUI.
        /// </summary>
        /// <param name="capi">The client API</param>
        /// <param name="bounds">The bounds of the stat bar.</param>
        /// <param name="color">The color of the stat bar.</param>
        /// <param name="rightToLeft">Determines the direction that the bar fills.</param>
        public GuiElementStatbar(ICoreClientAPI capi, ElementBounds bounds, double[] color, bool rightToLeft) : base(capi, "", CairoFont.WhiteDetailText(), bounds)
        {
            barTexture   = new LoadedTexture(capi);
            flashTexture = new LoadedTexture(capi);
            valueTexture = new LoadedTexture(capi);

            this.color       = color;
            this.rightToLeft = rightToLeft;
            //value = new Random(Guid.NewGuid().GetHashCode()).Next(100);

            onGetStatbarValue = () => { return((int)value + " / " + (int)this.maxValue); };
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Constructor for the button
        /// </summary>
        /// <param name="capi">The core client API.</param>
        /// <param name="color"></param>
        /// <param name="OnToggled">The action that happens when the button is toggled.</param>
        /// <param name="bounds">The bounding box of the button.</param>
        public GuiElementColorListPicker(ICoreClientAPI capi, int color, Action <bool> OnToggled, ElementBounds bounds) : base(capi, bounds)
        {
            activeTexture = new LoadedTexture(capi);

            this.color = color;
            handler    = OnToggled;

            hoverText = new GuiElementHoverText(capi, "", CairoFont.WhiteSmallText(), 200, Bounds.CopyOnlySize());
            hoverText.Bounds.ParentBounds = bounds;
            hoverText.SetAutoWidth(true);
            bounds.ChildBounds.Add(hoverText.Bounds);
        }
Ejemplo n.º 25
0
        public SkillItem WithIcon(ICoreClientAPI capi, string iconCode)
        {
            if (capi == null)
            {
                return(this);
            }

            Texture = capi.Gui.Icons.GenTexture(48, 48, (ctx, surface) =>
            {
                capi.Gui.Icons.DrawIcon(ctx, iconCode, 5, 5, 38, 38, ColorUtil.WhiteArgbDouble);
            });

            return(this);
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Creates a new vertical tab group.
        /// </summary>
        /// <param name="capi">The Client API</param>
        /// <param name="tabs">The collection of individual tabs.</param>
        /// <param name="font">The font for the group of them all.</param>
        /// <param name="bounds">The bounds of the tabs.</param>
        /// <param name="onTabClicked">The event fired when the tab is clicked.</param>
        public GuiElementVerticalTabs(ICoreClientAPI capi, GuiTab[] tabs, CairoFont font, CairoFont selectedFont, ElementBounds bounds, Action <int, GuiTab> onTabClicked) : base(capi, "", font, bounds)
        {
            this.selectedFont = selectedFont;
            this.tabs         = tabs;
            handler           = onTabClicked;
            hoverTextures     = new LoadedTexture[tabs.Length];
            for (int i = 0; i < tabs.Length; i++)
            {
                hoverTextures[i] = new LoadedTexture(capi);
            }
            baseTexture = new LoadedTexture(capi);

            tabWidths = new int[tabs.Length];
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Creates a button with text.
        /// </summary>
        /// <param name="capi">The Client API</param>
        /// <param name="text">The text of the button.</param>
        /// <param name="font">The font of the text.</param>
        /// <param name="hoverFont">The font of the text when the player is hovering over the button.</param>
        /// <param name="onClick">The event fired when the button is clicked.</param>
        /// <param name="bounds">The bounds of the button.</param>
        /// <param name="style">The style of the button.</param>
        public GuiElementTextButton(ICoreClientAPI capi, string text, CairoFont font, CairoFont hoverFont, ActionConsumable onClick, ElementBounds bounds, EnumButtonStyle style = EnumButtonStyle.Normal) : base(capi, bounds)
        {
            hoverTexture     = new LoadedTexture(capi);
            disabledTexture  = new LoadedTexture(capi);
            this.buttonStyle = style;

            normalText = new GuiElementStaticText(capi, text, EnumTextOrientation.Center, bounds, font);
            normalText.AutoBoxSize(true);

            pressedText = new GuiElementStaticText(capi, text, EnumTextOrientation.Center, bounds.CopyOnlySize(), hoverFont);
            bounds      = normalText.Bounds;

            this.onClick = onClick;
        }
Ejemplo n.º 28
0
        public GuiElementHandbookList(ICoreClientAPI capi, ElementBounds bounds, API.Common.Action <int> onLeftClick, List <GuiHandbookPage> elements = null) : base(capi, bounds)
        {
            hoverOverlayTexture = new LoadedTexture(capi);

            insideBounds = new ElementBounds().WithFixedPadding(unscaledCellSpacing).WithEmptyParent();
            insideBounds.CalcWorldBounds();

            this.onLeftClick = onLeftClick;
            if (elements != null)
            {
                Elements = elements;
            }

            CalcTotalHeight();
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Creates a new instance of this class.
        /// </summary>
        /// <param name="capi">The client API</param>
        /// <param name="inventory">The attached inventory</param>
        /// <param name="SendPacket">A handler that should send supplied network packet to the server, if the inventory modifications should be synced</param>
        /// <param name="columns">The number of columns in the GUI.</param>
        /// <param name="bounds">The bounds of the slot grid.</param>
        public GuiElementItemSlotGridBase(ICoreClientAPI capi, IInventory inventory, API.Common.Action <object> SendPacket, int columns, ElementBounds bounds) : base(capi, bounds)
        {
            slotTexture          = new LoadedTexture(capi);
            highlightSlotTexture = new LoadedTexture(capi);
            crossedOutTexture    = new LoadedTexture(capi);

            prevSlotQuantity  = inventory.Count;
            this.inventory    = inventory;
            cols              = columns;
            SendPacketHandler = SendPacket;

            inventory.SlotNotified += OnSlotNotified;

            DrawIconHandler = (cr, type, x, y, w, h, rgba) => api.Gui.Icons.DrawIconInt(cr, type, x, y, w, h, rgba);
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Adds a mod cell to the table.
        /// </summary>
        /// <param name="capi">The client API</param>
        /// <param name="cell">The table cell to add.</param>
        /// <param name="assetManager">The asset manager for the mod</param>
        /// <param name="bounds">The bounds of the cell</param>
        public GuiElementModCell(ICoreClientAPI capi, ListCellEntry cell, IAssetManager assetManager, ElementBounds bounds) : base(capi, "", null, bounds)
        {
            this.cell         = cell;
            this.assetManager = assetManager;

            if (cell.TitleFont == null)
            {
                cell.TitleFont = CairoFont.WhiteSmallishText();
            }

            if (cell.DetailTextFont == null)
            {
                cell.DetailTextFont           = CairoFont.WhiteSmallText();
                cell.DetailTextFont.Color[3] *= 0.6;
            }

            modcellTexture = new LoadedTexture(capi);
        }