コード例 #1
0
        public void OpenDialog(IClientWorldAccessor world, BlockPos pos, ItemStack baseMaterial)
        {
            List <KnappingRecipe> recipes = Api.GetKnappingRecipes()
                                            .Where(r => r.Ingredient.SatisfiesAsIngredient(baseMaterial))
                                            .OrderBy(r => r.Output.ResolvedItemstack.Collectible.Code) // Cannot sort by name, thats language dependent!
                                            .ToList()
            ;

            List <ItemStack> stacks = recipes
                                      .Select(r => r.Output.ResolvedItemstack)
                                      .ToList()
            ;

            ICoreClientAPI capi = Api as ICoreClientAPI;

            dlg?.Dispose();
            dlg = new GuiDialogBlockEntityRecipeSelector(
                Lang.Get("Select recipe"),
                stacks.ToArray(),
                (selectedIndex) => {
                selectedRecipeId = recipes[selectedIndex].RecipeId;
                capi.Network.SendBlockEntityPacket(pos.X, pos.Y, pos.Z, (int)EnumClayFormingPacket.SelectRecipe, SerializerUtil.Serialize(recipes[selectedIndex].RecipeId));
            },
                () => {
                capi.Network.SendBlockEntityPacket(pos.X, pos.Y, pos.Z, (int)EnumClayFormingPacket.CancelSelect);
            },
                pos,
                Api as ICoreClientAPI
                );

            dlg.TryOpen();
        }
コード例 #2
0
        internal void OpenDialog(ItemStack ingredient)
        {
            List <SmithingRecipe> recipes = (ingredient.Collectible as IAnvilWorkable).GetMatchingRecipes(ingredient);

            List <ItemStack> stacks = recipes
                                      .Select(r => r.Output.ResolvedItemstack)
                                      .ToList()
            ;

            IClientWorldAccessor clientWorld = (IClientWorldAccessor)Api.World;
            ICoreClientAPI       capi        = Api as ICoreClientAPI;

            dlg?.Dispose();
            dlg = new GuiDialogBlockEntityRecipeSelector(
                Lang.Get("Select smithing recipe"),
                stacks.ToArray(),
                (selectedIndex) => {
                SelectedRecipeId = recipes[selectedIndex].RecipeId;
                capi.Network.SendBlockEntityPacket(Pos.X, Pos.Y, Pos.Z, (int)EnumAnvilPacket.SelectRecipe, SerializerUtil.Serialize(recipes[selectedIndex].RecipeId));
            },
                () => {
                capi.Network.SendBlockEntityPacket(Pos.X, Pos.Y, Pos.Z, (int)EnumAnvilPacket.CancelSelect);
            },
                Pos,
                Api as ICoreClientAPI
                );

            dlg.TryOpen();
        }
コード例 #3
0
        public override void StartClientSide(ICoreClientAPI api)
        {
            ClientAPI = api;
            EventAPI  = ClientAPI.Event;
            Logger    = ClientAPI.Logger;

            LoadConfig();

            AliasCommler = new AliasCommandler(this);
            ClientAPI.RegisterCommand(AliasCommler);


            Editor = new GuiDialogAliasEditor(ClientAPI);
            ClientAPI.Gui.RegisterDialog(Editor);

            // ClientAPI.Input.RegisterHotKey("opencmeditor", "Open CommandMacro editor", GlKeys.O);
            // ClientAPI.Input.SetHotKeyHandler("opencmeditor", combo => {
            //  Editor.TryOpen();
            //  return true;
            // });

            Logger.Debug("Initializing aliases!");
            Player = ClientAPI.World.Player;
            AliasMan.InitAllAliases(ClientAPI);

            EventAPI.LeaveWorld += SaveConfig;
        }
コード例 #4
0
 /// <summary>
 /// Zobrazí daný dialog a vrátí odpověď.
 /// </summary>
 /// <param name="dialog">Data pro dialog</param>
 /// <returns></returns>
 public GuiDialogButtons ShowDialog(GuiDialog dialog)
 {
     if (dialog == null || dialog.IsEmpty)
     {
         return(GuiDialogButtons.None);
     }
     return(this.ShowDialog(dialog.Message, dialog.Title, dialog.Buttons, dialog.Icon));
 }
コード例 #5
0
        public override void OnInteract(EntityAgent byEntity, ItemSlot slot, Vec3d hitPosition, EnumInteractMode mode)
        {
            if (mode != EnumInteractMode.Interact || !(byEntity is EntityPlayer))
            {
                base.OnInteract(byEntity, slot, hitPosition, mode);
                return;
            }

            if (!Alive)
            {
                return;
            }

            EntityPlayer entityplr = byEntity as EntityPlayer;
            IPlayer      player    = World.PlayerByUid(entityplr.PlayerUID);

            player.InventoryManager.OpenInventory(Inventory);

            tradingWith = entityplr;


            if (World.Side == EnumAppSide.Client)
            {
                if (tradingWith.Pos.SquareDistanceTo(this.Pos) <= 5 && dlg?.IsOpened() != true)
                {
                    dlg = new GuiDialogTrader(Inventory, this, World.Api as ICoreClientAPI);
                    dlg.TryOpen();
                    dlg.OnClosed += () => tradingWith = null;
                }

                talkUtil.Talk(EnumTalkType.Meet);
            }

            if (World.Side == EnumAppSide.Server)
            {
                // Make the trader walk towards the player
                AiTaskManager tmgr = GetBehavior <EntityBehaviorTaskAI>().taskManager;
                tmgr.StopTask(typeof(AiTaskWander));

                AiTaskGotoEntity task = new AiTaskGotoEntity(this, entityplr);
                if (task.TargetReached())
                {
                    tmgr.ExecuteTask(new AiTaskLookAtEntity(this, entityplr), 1);
                }
                else
                {
                    tmgr.ExecuteTask(task, 1);
                }

                AnimManager.StopAnimation("idle");
                AnimManager.StartAnimation(new AnimationMetaData()
                {
                    Animation = "welcome", Code = "welcome", Weight = 10, EaseOutSpeed = 10000, EaseInSpeed = 10000
                });
            }
        }
コード例 #6
0
        public override void StartClientSide(ICoreClientAPI api)
        {
            base.StartClientSide(api);

            dialog = new SampleGuiDialog(api);

            capi = api;
            capi.Input.RegisterHotKey("samplePopUp", "Pop up window with text", GlKeys.O, HotkeyType.GUIOrOtherControls);
            capi.Input.SetHotKeyHandler("samplePopUp", ToggleGui);
        }
コード例 #7
0
        public override void StartClientSide(ICoreClientAPI capi)
        {
            dialog = new GuiSvgSamples(capi);

            // Register UI hotkeys
            capi.Input.RegisterHotKey("svgtoggle", "svgtoggle", GlKeys.U, HotkeyType.GUIOrOtherControls);
            capi.Input.SetHotKeyHandler("svgtoggle", OpenGui);

            capi.Event.IsPlayerReady += Event_IsPlayerReady;
        }
コード例 #8
0
        public override void StartClientSide(ICoreClientAPI api)
        {
            base.StartClientSide(api);

            dialog = new GuiDialogAnnoyingText(api);

            capi = api;
            capi.Input.RegisterHotKey("annoyingtextgui", "Annoys you with annoyingly centered text", GlKeys.U, HotkeyType.GUIOrOtherControls);
            capi.Input.SetHotKeyHandler("annoyingtextgui", ToggleGui);
        }
コード例 #9
0
ファイル: AlchemyMod.cs プロジェクト: Llama3013/vsmod-Alchemy
        public override void StartClientSide(ICoreClientAPI api)
        {
            base.StartClientSide(api);

            dialog = new HudPotion(api);
            dialog.TryOpen();

            capi = api;
            api.Input.RegisterHotKey("potionhud", "Toggle potion hud", GlKeys.LBracket, HotkeyType.GUIOrOtherControls);
            api.Input.SetHotKeyHandler("potionhud", ToggleGui);
        }
コード例 #10
0
        private void ShowDialog()
        {
            if (!clientEnabled)
            {
                logEntries.Clear();
                return;
            }

            dialog = new GuiDialogLogViewer(string.Join("\n", logEntries), capi);
            dialog.TryOpen();
        }
コード例 #11
0
        /// <summary>
        /// Metoda je volána POUZE PO PRVNÍM vykreslení obsahu
        /// </summary>
        protected override void OnFirstDrawAfter()
        {
            base.OnFirstDrawAfter();
            GuiDialog initialDialog = this.InitialDialog;

            if (initialDialog != null)
            {
                this.ShowDialog(initialDialog);
            }
            this.InitialDialog = null;
        }
コード例 #12
0
        public override void OnInteract(EntityAgent byEntity, IItemSlot slot, Vec3d hitPosition, int mode)
        {
            if (mode != 1 || !(byEntity is EntityPlayer))
            {
                base.OnInteract(byEntity, slot, hitPosition, mode);
                return;
            }

            EntityPlayer entityplr = byEntity as EntityPlayer;
            IPlayer      player    = World.PlayerByUid(entityplr.PlayerUID);

            player.InventoryManager.OpenInventory(Inventory);

            tradingWith = entityplr;


            if (World.Side == EnumAppSide.Client)
            {
                if (tradingWith.Pos.SquareDistanceTo(this.Pos) <= 5)
                {
                    dlg = new GuiDialogTrader(Inventory, this, World.Api as ICoreClientAPI);
                    dlg.TryOpen();
                    dlg.OnClosed += () => tradingWith = null;
                }

                talkUtil.Talk(EnumTalkType.Meet);
            }

            if (World.Side == EnumAppSide.Server)
            {
                // Make the trader walk towards the player
                AiTaskManager tmgr = GetBehavior <EntityBehaviorTaskAI>().taskManager;
                tmgr.StopTask(typeof(AiTaskWander));

                AiTaskGotoEntity task = new AiTaskGotoEntity(this, entityplr);
                if (task.TargetReached())
                {
                    tmgr.ExecuteTask(new AiTaskLookAtEntity(this, entityplr), 1);
                }
                else
                {
                    tmgr.ExecuteTask(task, 1);
                }
            }
        }
コード例 #13
0
        private void ShowDialog()
        {
            if (!clientEnabled)
            {
                logEntries.Clear();
                return;
            }

            List <string> printedEntries = logEntries;

            if (logEntries.Count > 180)
            {
                printedEntries = logEntries.Take(140).ToList();
                printedEntries.Add(string.Format("...{0} more", logEntries.Count - 0));
            }

            dialog = new GuiDialogLogViewer(string.Join("\n", printedEntries), capi);
            dialog.TryOpen();
        }
コード例 #14
0
        public void OpenDialog(IClientWorldAccessor world, BlockPos pos, ItemStack ingredient)
        {
            if (ingredient.Collectible is ItemWorkItem)
            {
                ingredient = new ItemStack(world.GetItem(new AssetLocation("clay-" + ingredient.Collectible.LastCodePart())));
            }

            List <ClayFormingRecipe> recipes = world.ClayFormingRecipes
                                               .Where(r => r.Ingredient.SatisfiesAsIngredient(ingredient))
                                               .OrderBy(r => r.Output.ResolvedItemstack.Collectible.Code) // Cannot sort by name, thats language dependent!
                                               .ToList();

            ;


            List <ItemStack> stacks = recipes
                                      .Select(r => r.Output.ResolvedItemstack)
                                      .ToList()
            ;

            ICoreClientAPI capi = Api as ICoreClientAPI;

            dlg = new GuiDialogBlockEntityRecipeSelector(
                Lang.Get("Select recipe"),
                stacks.ToArray(),
                (selectedIndex) => {
                capi.Logger.VerboseDebug("Select clay from recipe {0}, have {1} recipes.", selectedIndex, recipes.Count);

                selectedRecipeId = recipes[selectedIndex].RecipeId;
                capi.Network.SendBlockEntityPacket(pos.X, pos.Y, pos.Z, (int)EnumClayFormingPacket.SelectRecipe, SerializerUtil.Serialize(recipes[selectedIndex].RecipeId));
            },
                () => {
                capi.Network.SendBlockEntityPacket(pos.X, pos.Y, pos.Z, (int)EnumClayFormingPacket.CancelSelect);
            },
                pos,
                Api as ICoreClientAPI
                );

            dlg.OnClosed += dlg.Dispose;
            dlg.TryOpen();
        }
コード例 #15
0
        public override void OnInteract(EntityAgent byEntity, ItemSlot slot, Vec3d hitPosition, EnumInteractMode mode)
        {
            if (mode != EnumInteractMode.Interact || !(byEntity is EntityPlayer))
            {
                base.OnInteract(byEntity, slot, hitPosition, mode);
                return;
            }

            if (!Alive)
            {
                return;
            }

            EntityPlayer entityplr = byEntity as EntityPlayer;
            IPlayer      player    = World.PlayerByUid(entityplr.PlayerUID);


            tradingWith = entityplr;


            if (World.Side == EnumAppSide.Client)
            {
                ICoreClientAPI capi = (ICoreClientAPI)Api;

                if (tradingWith.Pos.SquareDistanceTo(this.Pos) <= 5 && dlg?.IsOpened() != true)
                {
                    // Will break all kinds of things if we allow multiple concurrent of these dialogs
                    if (capi.Gui.OpenedGuis.FirstOrDefault(dlg => dlg is GuiDialogTrader && dlg.IsOpened()) == null)
                    {
                        capi.Network.SendEntityPacket(this.EntityId, 1001);
                        player.InventoryManager.OpenInventory(Inventory);

                        dlg = new GuiDialogTrader(Inventory, this, World.Api as ICoreClientAPI);
                        dlg.TryOpen();
                    }
                    else
                    {
                        capi.TriggerIngameError(this, "onlyonedialog", Lang.Get("Can only trade with one trader at a time"));
                    }
                }
                else
                {
                    // Ensure inventory promptly closed server-side if the client didn't open the GUI

                    capi.Network.SendPacketClient(capi.World.Player.InventoryManager.CloseInventory(Inventory));
                }

                talkUtil.Talk(EnumTalkType.Meet);
            }

            if (World.Side == EnumAppSide.Server)
            {
                // Make the trader walk towards the player
                AiTaskManager tmgr = GetBehavior <EntityBehaviorTaskAI>().TaskManager;
                tmgr.StopTask(typeof(AiTaskWander));

                AiTaskGotoEntity task = new AiTaskGotoEntity(this, entityplr);
                if (task.TargetReached())
                {
                    tmgr.ExecuteTask(new AiTaskLookAtEntity(this, entityplr), 1);
                }
                else
                {
                    tmgr.ExecuteTask(task, 1);
                }

                AnimManager.StartAnimation(new AnimationMetaData()
                {
                    Animation = "welcome", Code = "welcome", Weight = 10, EaseOutSpeed = 10000, EaseInSpeed = 10000
                });
                AnimManager.StopAnimation("idle");
            }
        }