/// <summary>
        /// Sets the position of the cursor to a specific character.
        /// </summary>
        /// <param name="posInLine">The position in the line.</param>
        /// <param name="posLine">The line of the text.</param>
        public void SetCaretPos(int posInLine, int posLine = 0)
        {
            caretBlinkMilliseconds = api.ElapsedMilliseconds;
            caretDisplayed         = true;

            caretPosLine   = GameMath.Clamp(posLine, 0, lines.Count - 1);
            caretPosInLine = GameMath.Clamp(posInLine, 0, lines[caretPosLine].Length);


            if (multilineMode)
            {
                caretX = Font.GetTextExtents(lines[caretPosLine].Substring(0, caretPosInLine)).XAdvance;
                caretY = Font.GetFontExtents().Height *caretPosLine;
            }
            else
            {
                string displayedText = lines[0];

                if (hideCharacters)
                {
                    displayedText = new StringBuilder(lines[0]).Insert(0, "•", displayedText.Length).ToString();
                }

                caretX = Font.GetTextExtents(displayedText.Substring(0, caretPosInLine)).XAdvance;
                caretY = 0;
            }

            OnCursorMoved?.Invoke(caretX, caretY);

            renderLeftOffset = Math.Max(0, caretX - Bounds.InnerWidth + rightSpacing);
        }
Exemplo n.º 2
0
 public override void OnGuiClosed()
 {
     if (!didSave)
     {
         OnCloseCancel?.Invoke();
     }
     base.OnGuiClosed();
 }
Exemplo n.º 3
0
        public override void OnMouseDownOnElement(ICoreClientAPI api, MouseEvent args)
        {
            base.OnMouseDownOnElement(api, args);

            On = !On;
            handler?.Invoke(On);
            api.Gui.PlaySound("toggleswitch");
        }
Exemplo n.º 4
0
        private void OnTextAreaChanged(string value)
        {
            GuiElementTextArea textArea = SingleComposer.GetTextArea("text");

            SingleComposer.GetScrollbar("scrollbar").SetNewTotalHeight((float)textArea.Bounds.fixedHeight);

            OnTextChanged?.Invoke(textArea.GetText());
        }
Exemplo n.º 5
0
        /// <summary>
        /// Runs given method
        /// </summary>
        /// <param name="method"></param>
        /// <returns></returns>
        public GuiComposer Execute(API.Common.Action method)
        {
            if (conditionalAdds.Count > 0 && !conditionalAdds.Peek())
            {
                return(this);
            }

            method.Invoke();
            return(this);
        }
Exemplo n.º 6
0
        public override void TeleportToDouble(double x, double y, double z, API.Common.Action onTeleported = null)
        {
            Teleporting = true;
            ICoreServerAPI sapi = this.World.Api as ICoreServerAPI;

            if (sapi != null)
            {
                sapi.WorldManager.LoadChunkColumnPriority((int)ServerPos.X / World.BlockAccessor.ChunkSize, (int)ServerPos.Z / World.BlockAccessor.ChunkSize, new ChunkLoadOptions()
                {
                    OnLoaded = () =>
                    {
                        Pos.SetPos(x, y, z);
                        ServerPos.SetPos(x, y, z);
                        PreviousServerPos.SetPos(-99, -99, -99);
                        PositionBeforeFalling.Set(x, y, z);
                        Pos.Motion.Set(0, 0, 0);
                        if (this is EntityPlayer)
                        {
                            sapi.Network.BroadcastEntityPacket(EntityId, 1, SerializerUtil.Serialize(ServerPos.XYZ));
                            IServerPlayer player          = this.Player as IServerPlayer;
                            int chunksize                 = World.BlockAccessor.ChunkSize;
                            player.CurrentChunkSentRadius = 0;

                            sapi.Event.RegisterCallback((bla) => {
                                if (player.ConnectionState == EnumClientState.Offline)
                                {
                                    return;
                                }

                                if (!sapi.WorldManager.HasChunk((int)x / chunksize, (int)y / chunksize, (int)z / chunksize, player))
                                {
                                    sapi.WorldManager.SendChunk((int)x / chunksize, (int)y / chunksize, (int)z / chunksize, player, false);
                                }

                                // Oherwise we get an endlessly looping exception spam and break the server
                                player.CurrentChunkSentRadius = 0;
                            }, 50);
                        }

                        WatchedAttributes.SetInt("positionVersionNumber", WatchedAttributes.GetInt("positionVersionNumber", 0) + 1);


                        onTeleported?.Invoke();

                        Teleporting = false;
                    },
                });
            }
        }
Exemplo n.º 7
0
        public virtual void SlotClick(ICoreClientAPI api, int slotId, EnumMouseButton mouseButton, bool shiftPressed, bool ctrlPressed, bool altPressed)
        {
            List <IInventory> inventories    = api.World.Player.InventoryManager.OpenedInventories;
            IInventory        mouseCursorInv = api.World.Player.InventoryManager.GetOwnInventory(GlobalConstants.mousecursorInvClassName);
            object            packet;

            EnumModifierKey modifiers =
                (shiftPressed ? EnumModifierKey.SHIFT : 0) |
                (ctrlPressed ? EnumModifierKey.CTRL : 0) |
                (altPressed ? EnumModifierKey.ALT : 0)
            ;

            ItemStackMoveOperation op = new ItemStackMoveOperation(api.World, mouseButton, modifiers, EnumMergePriority.AutoMerge);

            op.ActingPlayer = api.World.Player;

            if (shiftPressed)
            {
                ItemSlot sourceSlot = inventory[slotId];
                op.RequestedQuantity = sourceSlot.StackSize;
                packet = inventory.ActivateSlot(slotId, sourceSlot, ref op);
            }
            else
            {
                op.CurrentPriority = EnumMergePriority.DirectMerge;
                packet             = inventory.ActivateSlot(slotId, mouseCursorInv[0], ref op);
            }

            if (packet != null)
            {
                if (packet is object[] packets)
                {
                    for (int i = 0; i < packets.Length; i++)
                    {
                        SendPacketHandler(packets[i]);
                    }
                }
                else
                {
                    SendPacketHandler?.Invoke(packet);
                }
            }

            api.Input.TriggerOnMouseClickSlot(inventory[slotId]);
        }
Exemplo n.º 8
0
        public override void OnMouseUpOnElement(ICoreClientAPI api, MouseEvent args)
        {
            if (!Bounds.ParentBounds.PointInside(args.X, args.Y))
            {
                return;
            }
            if (!wasMouseDownOnElement)
            {
                return;
            }

            wasMouseDownOnElement = false;

            int i = 0;

            int    mx   = api.Input.MouseX;
            int    my   = api.Input.MouseY;
            double posY = insideBounds.absY;


            foreach (GuiHandbookPage element in Elements)
            {
                if (!element.Visible)
                {
                    i++;
                    continue;
                }

                float y = (float)(5 + Bounds.absY + posY);

                if (mx > Bounds.absX && mx <= Bounds.absX + Bounds.InnerWidth && my >= y - 8 && my <= y + scaled(unscaledCellHeight) - 8)
                {
                    api.Gui.PlaySound("menubutton_press");
                    onLeftClick?.Invoke(i);
                    args.Handled = true;
                    return;
                }

                posY += scaled(unscaledCellHeight + unscaledCellSpacing);
                i++;
            }
        }
Exemplo n.º 9
0
        private void OnTextChangedDlg(string text)
        {
            if (ignorechange)
            {
                return;
            }
            ignorechange = true;

            ImageSurface surface = new ImageSurface(Format.Argb32, 1, 1);
            Context      ctx     = new Context(surface);

            signPostFont.SetupContext(ctx);

            string[] textByCardinal = new string[8];
            for (int i = 0; i < 8; i++)
            {
                GuiElementTextInput texinput = SingleComposer.GetTextInput("text" + i);
                textByCardinal[i] = texinput.GetText();
                if (textByCardinal[i] == null)
                {
                    textByCardinal[i] = "";
                }

                int j = 0;
                while (ctx.TextExtents(textByCardinal[i]).Width > 185 && j++ < 100)
                {
                    textByCardinal[i] = textByCardinal[i].Substring(0, textByCardinal[i].Length - 1);
                }

                texinput.SetValue(textByCardinal[i]);
            }

            OnTextChanged?.Invoke(textByCardinal);

            ignorechange = false;

            surface.Dispose();
            ctx.Dispose();
        }
Exemplo n.º 10
0
        public void WalkMatchingBlocks(IWorldAccessor world, BlockPos centerPos, API.Common.Action <Block, BlockPos> onBlock)
        {
            if (TransformedOffsets == null)
            {
                throw new InvalidOperationException("call InitForUse() first");
            }

            BlockPos pos = new BlockPos();

            for (int i = 0; i < TransformedOffsets.Count; i++)
            {
                Vec4i offset = TransformedOffsets[i];

                pos.Set(centerPos.X + offset.X, centerPos.Y + offset.Y, centerPos.Z + offset.Z);
                Block block = world.BlockAccessor.GetBlock(pos);

                if (WildcardUtil.Match(BlockCodes[offset.W], block.Code))
                {
                    onBlock?.Invoke(block, pos);
                }
            }
        }
 internal virtual void TextChanged()
 {
     OnTextChanged?.Invoke(string.Join("\n", lines));
     RecomposeText();
 }
Exemplo n.º 12
0
 internal void UnFocusElements()
 {
     composerManager.UnfocusElements();
     OnFocusChanged?.Invoke(false);
 }
Exemplo n.º 13
0
 public override void LeaveNetwork()
 {
     base.LeaveNetwork();
     OnDisconnected?.Invoke();
 }
Exemplo n.º 14
0
 public override void JoinNetwork(MechanicalNetwork network)
 {
     base.JoinNetwork(network);
     OnConnected?.Invoke();
 }