Ejemplo n.º 1
0
        public GuiDialogRenameTeleport(string DialogTitle, BlockPos blockEntityPos, ICoreClientAPI capi, CairoFont font)
            : base(DialogTitle, capi)
        {
            this.font           = font;
            this.blockEntityPos = blockEntityPos;

            if (blockEntityPos == null || TPNetManager.GetTeleport(blockEntityPos) == null)
            {
                capi.Logger.ModError("Unable to rename an unregistered teleport");
                Dispose();
                return;
            }

            ElementBounds elementBounds  = ElementBounds.Fixed(0.0, 0.0, 150.0, 20.0);
            ElementBounds elementBounds2 = ElementBounds.Fixed(0.0, 15.0, 150.0, 25.0);
            ElementBounds elementBounds3 = ElementBounds.Fill.WithFixedPadding(GuiStyle.ElementToDialogPadding);

            elementBounds3.BothSizing = ElementSizing.FitToChildren;
            ElementBounds bounds = ElementStdBounds.AutosizedMainDialog.WithAlignment(EnumDialogArea.CenterMiddle).WithFixedAlignmentOffset(60.0 + GuiStyle.DialogToScreenPadding, GuiStyle.DialogToScreenPadding);

            float num3 = 250f;

            base.SingleComposer = capi.Gui.CreateCompo("blockentitytexteditordialog", bounds).AddShadedDialogBG(elementBounds3).AddDialogTitleBar(DialogTitle, OnTitleBarClose)
                                  .BeginChildElements(elementBounds3)
                                  .AddTextInput(elementBounds2 = elementBounds2.BelowCopy().WithFixedWidth(num3), null, CairoFont.WhiteSmallText(), "text")
                                  .AddSmallButton(Lang.Get("Cancel"), OnButtonCancel, elementBounds2 = elementBounds2.BelowCopy(0.0, 20.0).WithFixedSize(100.0, 20.0).WithAlignment(EnumDialogArea.LeftFixed)
                                                                                                       .WithFixedPadding(10.0, 2.0))
                                  .AddSmallButton(Lang.Get("Save"), OnButtonSave, elementBounds2 = elementBounds2.FlatCopy().WithFixedSize(100.0, 20.0).WithAlignment(EnumDialogArea.RightFixed)
                                                                                                   .WithFixedPadding(10.0, 2.0))
                                  .EndChildElements()
                                  .Compose();

            base.SingleComposer.GetTextInput("text").SetValue(TPNetManager.GetTeleport(blockEntityPos).Name);
        }
Ejemplo n.º 2
0
        public override void GetBlockInfo(IPlayer forPlayer, StringBuilder dsc)
        {
            base.GetBlockInfo(forPlayer, dsc);

            if (Repaired)
            {
                dsc.AppendLine(TPNetManager.GetTeleport(Pos)?.Name);
            }
        }
Ejemplo n.º 3
0
        public override void OnBlockRemoved()
        {
            base.OnBlockRemoved();

            if (Api.Side == EnumAppSide.Server)
            {
                TPNetManager.RemoveTeleport(Pos);
            }
        }
Ejemplo n.º 4
0
        private bool OnButtonSave()
        {
            GuiElementTextInput textInput = base.SingleComposer.GetTextInput("text");

            TeleportData data = TPNetManager.GetTeleport(blockEntityPos);

            data.Name = textInput.GetText();
            TPNetManager.SetTeleport(blockEntityPos, data);

            didSave = true;
            TryClose();
            return(true);
        }
Ejemplo n.º 5
0
        public override bool DoPlaceBlock(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel, ItemStack byItemStack)
        {
            bool flag = base.DoPlaceBlock(world, byPlayer, blockSel, byItemStack);

            if (flag && byPlayer.WorldData.CurrentGameMode == EnumGameMode.Creative)
            {
                BlockEntityTeleport bet = api.World.BlockAccessor.GetBlockEntity(blockSel.Position) as BlockEntityTeleport;

                if (bet != null && bet.State == EnumTeleportState.Normal && api.Side == EnumAppSide.Server)
                {
                    TPNetManager.AddAvailableTeleport(byPlayer as IServerPlayer, blockSel.Position);
                }
            }

            return(flag);
        }
Ejemplo n.º 6
0
        public override void Initialize(ICoreAPI api)
        {
            base.Initialize(api);

            TPNetManager.TryCreateData(Pos, Repaired);

            if (api.Side == EnumAppSide.Client)
            {
                float rotY = Block.Shape.rotateY;
                animUtil?.InitializeAnimator(ConstantsCore.ModId + "-teleport", new Vec3f(0, rotY, 0));
            }

            ownBlock = Block as BlockTeleport;
            if (Repaired)
            {
                SetupGameTickers();
            }
        }
Ejemplo n.º 7
0
        public override bool OnBlockInteractStart(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel)
        {
            BlockEntityTeleport be = api.World.BlockAccessor.GetBlockEntity(blockSel.Position) as BlockEntityTeleport;

            if (be == null)
            {
                //api.World.BlockAccessor.SetBlock(BlockId, blockSel.Position);
                return(false);
            }

            if (be.Repaired && byPlayer.WorldData.EntityControls.Sneak)
            {
                be.OnShiftRightClick();
                return(true);
            }

            ItemSlot slot = byPlayer.InventoryManager.ActiveHotbarSlot;

            if (slot.Empty)
            {
                return(base.OnBlockInteractStart(world, byPlayer, blockSel));
            }

            if (!be.Repaired && slot.Itemstack.Collectible is ItemTemporalGear)
            {
                be.Repaired = true;

                if (byPlayer.WorldData.CurrentGameMode != EnumGameMode.Creative)
                {
                    slot.TakeOut(1);
                    slot.MarkDirty();
                }
                if (api.Side == EnumAppSide.Server)
                {
                    TPNetManager.AddAvailableTeleport(byPlayer as IServerPlayer, be.Pos);
                }

                world.PlaySoundAt(new AssetLocation("sounds/effect/latch"), blockSel.Position.X + 0.5, blockSel.Position.Y, blockSel.Position.Z + 0.5, byPlayer, true, 16);

                return(true);
            }

            return(false);
        }
        private bool OnClickItem(BlockPos targetPos)
        {
            var data = TPNetManager.GetTeleport(targetPos);

            if (data == null)
            {
                TryClose();
                return(false);
            }

            TPNetManager.TeleportTo(targetPos.ToVec3d(), blockEntityPos?.ToVec3d());

            double curr = capi.World.Player?.Entity?.WatchedAttributes.GetDouble("temporalStability") ?? 1;

            capi.World.Player?.Entity?.WatchedAttributes.SetDouble("temporalStability", Math.Max(0, (double)curr - 0.1));

            TryClose();

            return(true);
        }
Ejemplo n.º 9
0
        public override void StartClientSide(ICoreClientAPI api)
        {
            this.capi = api;

            api.RegisterCommand("csc", ConstantsCore.ModPrefix + "Clear shapes cache", "", (int groupId, CmdArgs args) =>
            {
                api.ObjectCache.RemoveAll((str, obj) => str.StartsWith(ConstantsCore.ModId));
            });

            // TODO Need move dialog to TPNetManager -.-
            api.RegisterCommand("tpdlg", ConstantsCore.ModPrefix + "Open teleport dialog", "", (int groupId, CmdArgs args) =>
            {
                if (capi.World.Player.WorldData.CurrentGameMode != EnumGameMode.Creative)
                {
                    return;
                }

                TPNetManager manager = api.ModLoader.GetModSystem <TPNetManager>();

                GuiDialogTeleport dialog = new GuiDialogTeleport(capi, null);
                dialog.TryOpen();
            });
        }
Ejemplo n.º 10
0
        private void OnGameTick(float dt)
        {
            if (animUtil?.animator?.ActiveAnimationCount == 0)
            {
                animUtil.StartAnimation(new AnimationMetaData()
                {
                    Animation      = "octagram",
                    Code           = "octagram",
                    AnimationSpeed = 0.5f,
                    EaseInSpeed    = 1f,
                    EaseOutSpeed   = 1f
                });
                animUtil.StartAnimation(new AnimationMetaData()
                {
                    Animation      = "gear",
                    Code           = "gear",
                    AnimationSpeed = 0.25f,
                    EaseInSpeed    = 1f,
                    EaseOutSpeed   = 1f
                });
            }

            if (!Active)
            {
                return;
            }

            toremove.Clear();

            float bestSecondsPassed = 0;

            foreach (var val in tpingPlayers)
            {
                if (val.Value.State == EnumTeleportingEntityState.None)
                {
                    if (Api.Side == EnumAppSide.Server)
                    {
                        IServerPlayer player = Api.World.PlayerByUid(val.Key) as IServerPlayer;
                        TPNetManager.AddAvailableTeleport(player, Pos);
                    }
                    val.Value.State = EnumTeleportingEntityState.Teleporting;
                }

                val.Value.SecondsPassed += Math.Min(0.5f, dt);

                if (Api.World.ElapsedMilliseconds - val.Value.LastCollideMs > 300)
                {
                    toremove.Add(val.Key);
                    continue;
                }

                if (val.Value.SecondsPassed > 3 && val.Value.State == EnumTeleportingEntityState.Teleporting)
                {
                    val.Value.State = EnumTeleportingEntityState.UI;

                    if (Api.Side == EnumAppSide.Client && teleportDlg?.IsOpened() != true)
                    {
                        if (teleportDlg != null)
                        {
                            teleportDlg.Dispose();
                        }

                        teleportDlg = new GuiDialogTeleport(Api as ICoreClientAPI, Pos);
                        teleportDlg.TryOpen();
                    }
                }

                bestSecondsPassed = Math.Max(val.Value.SecondsPassed, bestSecondsPassed);
            }

            foreach (var playerUID in toremove)
            {
                tpingPlayers.Remove(playerUID);

                if (Api.Side == EnumAppSide.Client)
                {
                    teleportDlg?.TryClose();
                }
            }

            Active = tpingPlayers.Count > 0;

            if (Api.Side == EnumAppSide.Server)
            {
                for (int i = 0; i < 10; i++)
                {
                    props.MinPos.Set(RandomParticleInCirclePos());
                    Api.World.SpawnParticles(props);
                }
            }

            if (Api.Side == EnumAppSide.Client)
            {
                bestSecondsPassed = Math.Min(bestSecondsPassed, 3);
                animUtil.activeAnimationsByAnimCode["octagram"].AnimationSpeed = (float)(0.5f * (1 + Math.Exp(bestSecondsPassed) * 0.3f));
            }
        }
        private void SetupDialog()
        {
            var availableTeleports = TPNetManager.GetAvailableTeleports(capi.World.Player);

            ElementBounds[] buttons = new ElementBounds[availableTeleports?.Count() > 0 ? availableTeleports.Count() : 1];

            buttons[0] = ElementBounds.Fixed(0, 0, 300, 40);
            for (int i = 1; i < buttons.Length; i++)
            {
                buttons[i] = buttons[i - 1].BelowCopy(0, 1);
            }


            ElementBounds listBounds = ElementBounds.Fixed(0, 0, 302, 400).WithFixedPadding(1);

            listBounds.BothSizing = ElementSizing.Fixed;

            ElementBounds clipBounds  = listBounds.ForkBoundingParent();
            ElementBounds insetBounds = listBounds.FlatCopy().FixedGrow(6).WithFixedOffset(-3, -3);

            ElementBounds scrollbarBounds = ElementStdBounds.VerticalScrollbar(insetBounds);


            ElementBounds bgBounds = ElementBounds.Fill.WithFixedPadding(GuiStyle.ElementToDialogPadding).WithFixedOffset(0, GuiStyle.TitleBarHeight);

            bgBounds.BothSizing = ElementSizing.FitToChildren;
            bgBounds.WithChildren(insetBounds, scrollbarBounds);


            ElementBounds dialogBounds = ElementStdBounds.AutosizedMainDialog;


            SingleComposer = capi.Gui
                             .CreateCompo("teleport-dialog", dialogBounds)
                             .AddDialogTitleBar(DialogTitle, CloseIconPressed)
                             .AddDialogBG(bgBounds, false)
                             .BeginChildElements(bgBounds)
            ;

            if (availableTeleports == null || availableTeleports.Count() == 0)
            {
                SingleComposer
                .AddStaticText(
                    Lang.Get("No available teleports"),
                    CairoFont.WhiteSmallText(),
                    buttons[0])
                .EndChildElements()
                .Compose()
                ;
                return;
            }

            SingleComposer
            .BeginClip(clipBounds)
            .AddInset(insetBounds, 3)
            .AddContainer(listBounds, "stacklist")
            .EndClip()
            .AddHoverText("", CairoFont.WhiteDetailText(), 300, listBounds.FlatCopy(), "hovertext")
            .AddVerticalScrollbar(OnNewScrollbarValue, scrollbarBounds, "scrollbar")
            .EndChildElements()
            ;

            var hoverTextElem = SingleComposer.GetHoverText("hovertext");

            hoverTextElem.SetAutoWidth(true);

            var stacklist = SingleComposer.GetContainer("stacklist");

            for (int i = 0; i < buttons.Length; i++)
            {
                var tp = availableTeleports.ElementAt(i);
                if (tp.Value.Name == null)
                {
                    tp.Value.Name = "null";
                }

                bool playerLowStability = capi.World.Player?.Entity?.GetBehavior <EntityBehaviorTemporalStabilityAffected>()?.OwnStability < 0.2;
                bool nowStormActive     = capi.ModLoader.GetModSystem <SystemTemporalStability>().StormData.nowStormActive;

                var font = CairoFont.WhiteSmallText();

                stacklist.Add(new GuiElementTextButtonExt(capi,
                                                          (nowStormActive || playerLowStability) ? tp.Value.Name.Shuffle() : tp.Value.Name,
                                                          tp.Key,
                                                          tp.Value.Available ? font : font.WithColor(ColorUtil.Hex2Doubles("#c91a1a")),
                                                          CairoFont.WhiteSmallText(),
                                                          () => OnClickItem(tp.Key),
                                                          buttons[i],
                                                          EnumButtonStyle.Normal
                                                          ));

                if (tp.Key == blockEntityPos)
                {
                    (stacklist.Elements.Last() as GuiElementTextButtonExt).Enabled = false;
                }
            }

            SingleComposer.GetScrollbar("scrollbar").SetHeights(
                (float)Math.Min(listBounds.fixedHeight, (buttons.Last().fixedHeight + buttons.Last().fixedY)),
                (float)(buttons.Last().fixedHeight + buttons.Last().fixedY)
                );
            //SingleComposer.GetScrollbar("scrollbar").ScrollToBottom();
            //SingleComposer.GetScrollbar("scrollbar").CurrentYPosition = 0;
            SingleComposer.Compose();
        }