Exemple #1
0
 /// <summary>
 /// Adds a slider to the current GUI.
 /// </summary>
 /// <param name="onNewSliderValue">The event that fires when the slider's value is changed.</param>
 /// <param name="bounds">The bounds of the slider.</param>
 /// <param name="key">the internal name of the slider.</param>
 public static GuiComposer AddSlider(this GuiComposer composer, ActionConsumable <int> onNewSliderValue, ElementBounds bounds, string key = null)
 {
     if (!composer.composed)
     {
         composer.AddInteractiveElement(new GuiElementSlider(composer.Api, onNewSliderValue, bounds), key);
     }
     return(composer);
 }
Exemple #2
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;
        }
Exemple #3
0
 /// <summary>
 /// Creates a button for the current GUI.
 /// </summary>
 /// <param name="text">The text on 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. (Default: Normal)</param>
 /// <param name="orientation">The orientation of the text. (Default: center)</param>
 /// <param name="key">The internal name of the button.</param>
 public static GuiComposer AddButton(this GuiComposer composer, string text, ActionConsumable onClick, ElementBounds bounds, EnumButtonStyle style = EnumButtonStyle.Normal, EnumTextOrientation orientation = EnumTextOrientation.Center, string key = null)
 {
     if (!composer.composed)
     {
         GuiElementTextButton elem = new GuiElementTextButton(composer.Api, text, CairoFont.ButtonText(), CairoFont.ButtonPressedText(), onClick, bounds, style);
         elem.SetOrientation(orientation);
         composer.AddInteractiveElement(elem, key);
     }
     return(composer);
 }
 /// <summary>
 /// This performs a entity search inside a spacially partioned search grid thats refreshed every 16ms.
 /// This can be a lot faster for when there are thousands of entities on a small space. It is used by EntityBehaviorRepulseAgents to improve performance, because otherwise when spawning 1000 creatures nearby, it has to do 1000x1000 = 1mil search operations every frame
 /// A small search grid allows us to ignore most of those during the search.  Return false to stop the walk.
 /// </summary>
 /// <param name="centerPos"></param>
 /// <param name="radius"></param>
 /// <param name="callback">Return false to stop the walk</param>
 public void WalkEntities(Vec3d centerPos, double radius, ActionConsumable <Entity> callback)
 {
     if (api.Side == EnumAppSide.Client)
     {
         WalkEntities(centerPos, radius, callback, onIsInRangeClient);
     }
     else
     {
         WalkEntities(centerPos, radius, callback, onIsInRangeServer);
     }
 }
Exemple #5
0
 /// <summary>
 /// Creates a button for the current GUI.
 /// </summary>
 /// <param name="text">The text on 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="buttonFont">The font of the button.</param>
 /// <param name="style">The style of the button. (Default: Normal)</param>
 /// <param name="orientation">The orientation of the text. (Default: center)</param>
 /// <param name="key">The internal name of the button.</param>
 public static GuiComposer AddButton(this GuiComposer composer, string text, ActionConsumable onClick, ElementBounds bounds, CairoFont buttonFont, EnumButtonStyle style = EnumButtonStyle.Normal, EnumTextOrientation orientation = EnumTextOrientation.Center, string key = null)
 {
     if (!composer.composed)
     {
         CairoFont            hoverFont = buttonFont.Clone().WithColor(GuiStyle.ActiveButtonTextColor);
         GuiElementTextButton elem      = new GuiElementTextButton(composer.Api, text, buttonFont, hoverFont, onClick, bounds, style);
         elem.SetOrientation(orientation);
         composer.AddInteractiveElement(elem, key);
     }
     return(composer);
 }
Exemple #6
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;
        }
        public Entity GetNearestEntity(Vec3d position, double radius, ActionConsumable <Entity> matches = null)
        {
            Entity nearestEntity   = null;
            double nearestDistance = 999999;

            WalkEntities(position, radius, (e) =>
            {
                double dist = e.SidedPos.SquareDistanceTo(position);

                if (dist < nearestDistance && matches(e))
                {
                    nearestDistance = dist;
                    nearestEntity   = e;
                }

                return(true);
            });

            return(nearestEntity);
        }
        public Entity GetNearestEntity(Vec3d position, double radius, ActionConsumable <Entity> matches = null)
        {
            Entity nearestEntity     = null;
            double radiusSq          = radius * radius;
            double nearestDistanceSq = radiusSq;

            if (api.Side == EnumAppSide.Client)
            {
                WalkEntityPartitions(position, radius, (e) =>
                {
                    double distSq = e.Pos.SquareDistanceTo(position);

                    if (distSq < nearestDistanceSq && matches(e))
                    {
                        nearestDistanceSq = distSq;
                        nearestEntity     = e;
                    }

                    return(true);
                });
            }
            else
            {
                WalkEntityPartitions(position, radius, (e) =>
                {
                    double distSq = e.ServerPos.SquareDistanceTo(position);

                    if (distSq < nearestDistanceSq && matches(e))
                    {
                        nearestDistanceSq = distSq;
                        nearestEntity     = e;
                    }

                    return(true);
                });
            }



            return(nearestEntity);
        }
Exemple #9
0
        public void IterateOverEach(BlockPos controllerPos, ActionConsumable <BlockPos> onBlock)
        {
            int      x      = controllerPos.X - ControllerPositionRel.X;
            int      y      = controllerPos.Y - ControllerPositionRel.Y;
            int      z      = controllerPos.Z - ControllerPositionRel.Z;
            BlockPos tmpPos = new BlockPos();

            for (int dx = 0; dx < SizeX; dx++)
            {
                for (int dy = 0; dy < SizeY; dy++)
                {
                    for (int dz = 0; dz < SizeZ; dz++)
                    {
                        tmpPos.Set(x + dx, y + dy, z + dz);
                        if (!onBlock(tmpPos))
                        {
                            return;
                        }
                    }
                }
            }
        }
        /// <summary>
        /// This performs a entity search inside a spacially partioned search grid thats refreshed every 16ms.
        /// This can be a lot faster for when there are thousands of entities on a small space. It is used by EntityBehaviorRepulseAgents to improve performance, because otherwise when spawning 1000 creatures nearby, it has to do 1000x1000 = 1mil search operations every frame
        /// A small search grid allows us to ignore most of those during the search.
        /// </summary>
        /// <param name="centerPos"></param>
        /// <param name="radius"></param>
        /// <param name="callback">Return false to stop the walk</param>
        public void WalkEntities(Vec3d centerPos, double radius, ActionConsumable <Entity> callback)
        {
            int mingx = (int)((centerPos.X - radius) / gridSizeInBlocks);
            int maxgx = (int)((centerPos.X + radius) / gridSizeInBlocks);
            //int mingy = (int)((centerPos.Y - radius) / gridSizeInBlocks);
            //int maxgy = (int)((centerPos.Y + radius) / gridSizeInBlocks);

            int mincy = (int)((centerPos.Y - radius) / chunkSize);
            int maxcy = (int)((centerPos.Y + radius) / chunkSize);

            int mingz = (int)((centerPos.Z - radius) / gridSizeInBlocks);
            int maxgz = (int)((centerPos.Z + radius) / gridSizeInBlocks);

            double radiusSq = radius * radius;

            long                 indexBefore    = -1;
            IWorldChunk          chunk          = null;
            EntityPartitionChunk partitionChunk = null;

            int gridXMax = api.World.BlockAccessor.MapSizeX / gridSizeInBlocks;
            //int gridYMax = api.World.BlockAccessor.MapSizeY / gridSizeInBlocks;
            int gridZMax = api.World.BlockAccessor.MapSizeZ / gridSizeInBlocks;

            int cyTop = api.World.BlockAccessor.MapSizeY / chunkSize;

            for (int gridX = mingx; gridX <= maxgx; gridX++)
            {
                //for (int gridY = mingy; gridY <= maxgy; gridY++)
                for (int cy = mincy; cy <= maxcy; cy++)
                {
                    for (int gridZ = mingz; gridZ <= maxgz; gridZ++)
                    {
                        if (gridX < 0 || cy < 0 || gridZ < 0 || gridX >= gridXMax || cy >= cyTop || gridZ >= gridZMax)
                        {
                            continue;
                        }

                        int cx = gridX * gridSizeInBlocks / chunkSize;
                        //int cy = gridY * gridSizeInBlocks / chunkSize;
                        int cz = gridZ * gridSizeInBlocks / chunkSize;

                        long index3d = MapUtil.Index3dL(cx, cy, cz, chunkMapSizeX, chunkMapSizeZ);

                        if (index3d != indexBefore)
                        {
                            chunk = api.World.BlockAccessor.GetChunk(cx, cy, cz);
                            Partitions.TryGetValue(index3d, out partitionChunk);
                            indexBefore = index3d;
                        }

                        if (chunk == null || chunk.Entities == null || partitionChunk == null)
                        {
                            continue;
                        }

                        int lgx = gridX % partitionsLength;
                        int lgz = gridZ % partitionsLength;

                        List <Entity> entities = partitionChunk.Entities[lgz * partitionsLength + lgx];

                        for (int i = 0; i < entities.Count; i++)
                        {
                            double distSq = entities[i].SidedPos.SquareDistanceTo(centerPos);
                            if (distSq <= radiusSq && !callback(entities[i]))
                            {
                                return;
                            }
                        }
                    }
                }
            }
        }
 /// <summary>
 /// Same as <see cref="WalkEntities(Vec3d, double, Action{Entity})"/> but does no exact radius distance check, walks all entities that it finds in the grid
 /// </summary>
 /// <param name="centerPos"></param>
 /// <param name="radius"></param>
 /// <param name="callback"></param>
 public void WalkEntityPartitions(Vec3d centerPos, double radius, ActionConsumable <Entity> callback)
 {
     WalkEntities(centerPos, radius, callback, onIsInRangePartition);
 }
Exemple #12
0
 public Entity[] GetEntitiesAround(Vec3d position, float horRange, float vertRange, ActionConsumable <Entity> matches = null)
 {
     return(new Entity[0]);
 }
Exemple #13
0
 public override RichTextComponentBase[] GetPageText(ICoreClientAPI capi, ItemStack[] allStacks, ActionConsumable <string> openDetailPageFor)
 {
     return(Stack.Collectible.GetBehavior <CollectibleBehaviorHandbookTextAndExtraInfo>()?.GetHandbookInfo(dummySlot, capi, allStacks, openDetailPageFor) ?? new RichTextComponentBase[0]);
 }
 public BlockConditon(ActionConsumable <Block> matcher)
 {
     this.matcher = matcher;
 }
        private void WalkEntities(Vec3d centerPos, double radius, ActionConsumable <Entity> callback, RangeTestDelegate onRangeTest)
        {
            int gridXMax = api.World.BlockAccessor.MapSizeX / gridSizeInBlocks - 1;
            int cyTop    = api.World.BlockAccessor.MapSizeY / chunkSize - 1;
            int gridZMax = api.World.BlockAccessor.MapSizeZ / gridSizeInBlocks - 1;

            int mingx = (int)GameMath.Clamp((centerPos.X - radius) / gridSizeInBlocks, 0, gridXMax);
            int maxgx = (int)GameMath.Clamp((centerPos.X + radius) / gridSizeInBlocks, 0, gridXMax);

            int mincy = (int)GameMath.Clamp((centerPos.Y - radius) / chunkSize, 0, cyTop);
            int maxcy = (int)GameMath.Clamp((centerPos.Y + radius) / chunkSize, 0, cyTop);

            int mingz = (int)GameMath.Clamp((centerPos.Z - radius) / gridSizeInBlocks, 0, gridZMax);
            int maxgz = (int)GameMath.Clamp((centerPos.Z + radius) / gridSizeInBlocks, 0, gridZMax);

            double radiusSq = radius * radius;

            long                 indexBefore    = -1;
            IWorldChunk          chunk          = null;
            EntityPartitionChunk partitionChunk = null;

            for (int gridX = mingx; gridX <= maxgx; gridX++)
            {
                int cx  = gridX * gridSizeInBlocks / chunkSize;
                int lgx = gridX % partitionsLength;

                for (int gridZ = mingz; gridZ <= maxgz; gridZ++)
                {
                    int cz  = gridZ * gridSizeInBlocks / chunkSize;
                    int lgz = gridZ % partitionsLength;
                    lgz = lgz * partitionsLength + lgx;

                    for (int cy = mincy; cy <= maxcy; cy++)
                    {
                        long index3d = MapUtil.Index3dL(cx, cy, cz, chunkMapSizeX, chunkMapSizeZ);

                        if (index3d != indexBefore)
                        {
                            indexBefore = index3d;
                            chunk       = api.World.BlockAccessor.GetChunk(cx, cy, cz);
                            if (chunk == null || chunk.Entities == null)
                            {
                                continue;
                            }
                            Partitions.TryGetValue(index3d, out partitionChunk);
                        }
                        else if (chunk == null || chunk.Entities == null)
                        {
                            continue;
                        }

                        if (partitionChunk == null)
                        {
                            continue;
                        }

                        List <Entity> entities = partitionChunk.Entities[lgz];

                        for (int i = 0; i < entities.Count; i++)
                        {
                            if (onRangeTest(entities[i], centerPos, radiusSq) && !callback(entities[i]))
                            {
                                return;
                            }
                        }
                    }
                }
            }
        }
Exemple #16
0
        /// <summary>
        /// Creates a small button for the current GUI.
        /// </summary>
        /// <param name="text">The text on 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. (Default: Normal)</param>
        /// <param name="orientation">The orientation of the text. (Default: center)</param>
        /// <param name="key">The internal name of the button.</param>
        public static GuiComposer AddSmallButton(this GuiComposer composer, string text, ActionConsumable onClick, ElementBounds bounds, EnumButtonStyle style = EnumButtonStyle.Normal, EnumTextOrientation orientation = EnumTextOrientation.Center, string key = null)
        {
            if (!composer.composed)
            {
                CairoFont font1 = CairoFont.ButtonText();
                CairoFont font2 = CairoFont.ButtonPressedText();
                font1.Fontname         = GuiStyle.StandardFontName;
                font2.Fontname         = GuiStyle.StandardFontName;
                font1.FontWeight       = FontWeight.Bold;
                font2.FontWeight       = FontWeight.Bold;
                font1.UnscaledFontsize = GuiStyle.SmallFontSize;
                font2.UnscaledFontsize = GuiStyle.SmallFontSize;

                GuiElementTextButton elem = new GuiElementTextButton(composer.Api, text, font1, font2, onClick, bounds, style);
                elem.SetOrientation(orientation);
                composer.AddInteractiveElement(elem, key);
            }
            return(composer);
        }
Exemple #17
0
 public override RichTextComponentBase[] GetPageText(ICoreClientAPI capi, ItemStack[] allStacks, ActionConsumable <string> openDetailPageFor)
 {
     return(comps);
 }
Exemple #18
0
 public GuiElementSliderOld(ICoreClientAPI capi, ActionConsumable <int> onNewSliderValue, ElementBounds bounds) : base(capi, bounds)
 {
     this.onNewSliderValue = onNewSliderValue;
 }
Exemple #19
0
 public GuiElementTextButtonExt(ICoreClientAPI capi, string text, BlockPos teleportPos, CairoFont font, CairoFont hoverFont, ActionConsumable onClick, ElementBounds bounds, EnumButtonStyle style = EnumButtonStyle.Normal) : base(capi, text, font, hoverFont, onClick, bounds, style)
 {
     this.TeleportPos = teleportPos;
 }
Exemple #20
0
 public abstract RichTextComponentBase[] GetPageText(ICoreClientAPI capi, ItemStack[] allStacks, ActionConsumable <string> openDetailPageFor);