/// <summary>
        /// Adds multiple tabs to a group of vertical tabs.
        /// </summary>
        /// <param name="tabs">The tabs being added.</param>
        /// <param name="bounds">The boundaries of the tab group.</param>
        /// <param name="OnTabClicked">The event fired when any of the tabs are clicked.</param>
        /// <param name="key">The name of this tab group.</param>
        public static GuiComposer AddVerticalTabs(this GuiComposer composer, GuiTab[] tabs, ElementBounds bounds, Action <int, GuiTab> OnTabClicked, string key = null)
        {
            if (!composer.Composed)
            {
                CairoFont font         = CairoFont.WhiteDetailText().WithFontSize(17);
                CairoFont selectedFont = CairoFont.WhiteDetailText().WithFontSize(17).WithColor(GuiStyle.ActiveButtonTextColor);
                composer.AddInteractiveElement(new GuiElementVerticalTabs(composer.Api, tabs, font, selectedFont, bounds, OnTabClicked), key);
            }

            return(composer);
        }
Example #2
0
 /// <summary>
 /// Adds an icon button.
 /// </summary>
 /// <param name="icon">The name of the icon.</param>
 /// <param name="onToggle">The event that happens once the button is toggled.</param>
 /// <param name="bounds">The bounding box of the button.</param>
 /// <param name="key">The name of the button for easy access.</param>
 public static GuiComposer AddIconButton(this GuiComposer composer, string icon, API.Common.Action <bool> onToggle, ElementBounds bounds, string key = null)
 {
     if (!composer.composed)
     {
         composer.AddInteractiveElement(new GuiElementToggleButton(composer.Api, icon, "", CairoFont.WhiteDetailText(), onToggle, bounds, false), key);
     }
     return(composer);
 }
Example #3
0
 public ClearFloatTextComponent(ICoreClientAPI api, float unScaleMarginTop = 0) : base(api, "", CairoFont.WhiteDetailText())
 {
     this.Float        = EnumFloat.None;
     UnscaledMarginTop = unScaleMarginTop;
 }
Example #4
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); };
        }
Example #5
0
        /// <summary>
        /// Flips through given array of grid recipes every second
        /// </summary>
        /// <param name="capi"></param>
        /// <param name="gridrecipes"></param>
        /// <param name="size"></param>
        /// <param name="floatType"></param>
        /// <param name="onStackClicked"></param>
        /// <param name="allStacks">If set, will resolve wildcards based on this list, otherwise will search all available blocks/items</param>
        public SlideshowGridRecipeTextComponent(ICoreClientAPI capi, GridRecipe[] gridrecipes, double size, EnumFloat floatType, Action <ItemStack> onStackClicked = null, ItemStack[] allStacks = null) : base(capi)
        {
            size = GuiElement.scaled(size);

            this.onStackClicked = onStackClicked;
            this.Float          = floatType;
            this.BoundsPerLine  = new LineRectangled[] { new LineRectangled(0, 0, 3 * (size + 3), 3 * (size + 3)) };
            this.size           = size;

            Random fixedRand = new Random(123);

            // Expand wild cards
            List <GridRecipeAndUnnamedIngredients> resolvedGridRecipes = new List <GridRecipeAndUnnamedIngredients>();
            Queue <GridRecipe> halfResolvedRecipes = new Queue <GridRecipe>(gridrecipes);

            bool allResolved = false;

            while (!allResolved)
            {
                allResolved = true;

                int cnt = halfResolvedRecipes.Count;

                while (cnt-- > 0)
                {
                    GridRecipe toTestRecipe = halfResolvedRecipes.Dequeue();
                    Dictionary <int, ItemStack[]> unnamedIngredients = null;

                    bool thisResolved = true;

                    for (int j = 0; j < toTestRecipe.resolvedIngredients.Length; j++)
                    {
                        CraftingRecipeIngredient ingred = toTestRecipe.resolvedIngredients[j];

                        if (ingred != null && ingred.IsWildCard)
                        {
                            allResolved  = false;
                            thisResolved = false;
                            ItemStack[] stacks = ResolveWildCard(capi.World, ingred, allStacks);

                            if (ingred.Name == null)
                            {
                                if (unnamedIngredients == null)
                                {
                                    unnamedIngredients = new Dictionary <int, ItemStack[]>();
                                }
                                unnamedIngredients[j] = ((ItemStack[])stacks.Clone()).Shuffle(fixedRand);
                                thisResolved          = true;
                                continue;
                            }

                            if (stacks.Length == 0)
                            {
                                throw new ArgumentException("Attempted to resolve the recipe ingredient wildcard " + ingred.Type + " " + ingred.Code + " but there are no such items/blocks!");
                            }

                            for (int k = 0; k < stacks.Length; k++)
                            {
                                GridRecipe cloned = toTestRecipe.Clone();

                                for (int m = 0; m < cloned.resolvedIngredients.Length; m++)
                                {
                                    CraftingRecipeIngredient clonedingred = cloned.resolvedIngredients[m];
                                    if (clonedingred != null && clonedingred.Code.Equals(ingred.Code))
                                    {
                                        clonedingred.Code              = stacks[k].Collectible.Code;
                                        clonedingred.IsWildCard        = false;
                                        clonedingred.ResolvedItemstack = stacks[k];
                                    }
                                }

                                halfResolvedRecipes.Enqueue(cloned);
                            }

                            break;
                        }
                    }

                    if (thisResolved)
                    {
                        resolvedGridRecipes.Add(new GridRecipeAndUnnamedIngredients()
                        {
                            Recipe = toTestRecipe, unnamedIngredients = unnamedIngredients
                        });
                    }
                }
            }

            resolveCache.Clear();
            this.GridRecipesAndUnIn = resolvedGridRecipes.ToArray();


            this.GridRecipesAndUnIn.Shuffle(fixedRand);

            for (int i = 0; i < GridRecipesAndUnIn.Length; i++)
            {
                string trait = GridRecipesAndUnIn[i].Recipe.RequiresTrait;
                if (trait != null)
                {
                    extraTexts[i] = capi.Gui.TextTexture.GenTextTexture(Lang.Get("* Requires {0} trait", trait), CairoFont.WhiteDetailText());
                }
            }

            if (GridRecipesAndUnIn.Length == 0)
            {
                throw new ArgumentException("Could not resolve any of the supplied grid recipes?");
            }
        }
Example #6
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); };
        }