Esempio n. 1
0
        public override void OnPointerUp(PointerEventData eventData)
        {
            base.OnPointerUp(eventData);

            List <ButtonArgument> buttons = new List <ButtonArgument>();
            ButtonArgument        arg     = new ButtonArgument("Buy");

            if (!SellMode)
            {
                arg.onClickCallback.Add(() => ShopUI.current.BuyItem(stack));
                ShopUI.current.TextBox.Type("Is this what you want?");
            }
            else
            {
                arg.Title = "Sell";
                arg.onClickCallback.Add(() => ShopUI.current.SellItem(stack));
                ShopUI.current.TextBox.Type("I can buy this from you");
            }

            arg.onClickCallback.Add(() => ShopUI.current.Refresh());

            if (stack.amount == 1)
            {
                arg.onClickCallback.Add(() => ShopUI.current.infoDisplayer.Clear());
            }

            buttons.Add(arg);

            ShopUI.current.menu.Initialize(buttons, () => ShopUI.current.TextBox.Type("Anything else?"));
            ShopUI.current.menu.Show(eventData.pressPosition);
        }
        public void SetData(ItemStack stack, ButtonArgument arg = null)
        {
            this.stack = stack;
            onPointerEvent.RemoveAllListeners();
            CommonAttributes atr = stack.item.GetAttribute <CommonAttributes>();

            if (atr)
            {
                this.InventorySprite.sprite = atr.GetSprite();
                this.Amounttext.text        = this.stack.amount.ToString();
                if (this.Amounttext.text == "1")
                {
                    this.Amounttext.enabled = false;
                }
                else
                {
                    this.Amounttext.enabled = true;
                }
            }


            if (arg != null)
            {
                foreach (UnityAction argument in arg.onClickCallback)
                {
                    onPointerEvent.AddListener(argument);
                }
            }
        }
Esempio n. 3
0
        private void OpenMiniMenuStats(IntMessage msg)
        {
            NewItem itm = gear.items[msg.i];

            if (itm)
            {
                onCancelActions.Remove(DropDownMenu.Hide);
                onCancelActions.Add(DropDownMenu.Hide);

                ButtonArgument Argument = new ButtonArgument("Unequip");
                Argument.onClickCallback.Add(() => DropDownMenu.Hide());
                Argument.onClickCallback.Add(() => gear.Unequip(msg.i, inventory));
                Argument.onClickCallback.Add(() => GenerateUI());
                Argument.onClickCallback.Add(() => UpdateStatLabels());

                DropDownMenu.Initialize(new List <ButtonArgument>()
                {
                    Argument
                }, null);
            }
            else
            {
                Debug.Log("No Item : " + msg.i.ToString());
            }
        }
Esempio n. 4
0
        private void OpenMiniMenuInventory(NewItem itm)
        {
            List <ButtonArgument> buttonArguments = new List <ButtonArgument>();

            onCancelActions.Remove(DropDownMenu.Hide);
            onCancelActions.Add(DropDownMenu.Hide);
            if (itm.GetAttribute <UseAttribute>() != null)
            {
                ButtonArgument UseArgument = new ButtonArgument("Use");


                UseArgument.onClickCallback.Add(() => DropDownMenu.Hide());
                UseArgument.onClickCallback.Add(() => itm.GetAttribute <UseAttribute>().Use(TurnManager.currentCharacter));

                if (itm.GetAttribute <UseAttribute>().destoryOnUse)
                {
                    UseArgument.onClickCallback.Add(() => inventory.DepleteItem(itm));
                }

                UseArgument.onClickCallback.Add(() => GenerateUI());
                UseArgument.onClickCallback.Add(() => UpdateStatLabels());


                buttonArguments.Add(UseArgument);
            }

            if (itm.GetAttribute <GearSlotAttribute>() != null)
            {
                ButtonArgument GearArgument = new ButtonArgument("Equip");

                WeaponAttribute weaponAttr = itm.GetAttribute <WeaponAttribute>();
                if (weaponAttr)
                {
                    GearArgument.Interactable = TurnManager.currentCharacter.stats.CanEquipWeapons.Contains((int)weaponAttr.WeaponType) ? true : false;
                }

                GearArgument.onClickCallback.Add(() => DropDownMenu.Hide());
                GearArgument.onClickCallback.Add(() => gear.Equip(itm, inventory));
                GearArgument.onClickCallback.Add(() => UpdateStatLabels());
                GearArgument.onClickCallback.Add(() => GenerateUI());

                buttonArguments.Add(GearArgument);
            }


            ButtonArgument DropArgument = new ButtonArgument("Drop");

            DropArgument.onClickCallback.Add(() => DropDownMenu.Hide());
            DropArgument.onClickCallback.Add(() => inventory.DepleteItem(itm));
            DropArgument.onClickCallback.Add(() => GenerateUI());

            buttonArguments.Add(DropArgument);


            DropDownMenu.Initialize(buttonArguments, null);
        }
Esempio n. 5
0
        private void GenerateUI()
        {
            DestroyChildren(buttonContainer.transform);

            int _i = 0;

            for (int i = 0; i < inventory.Items.Count; i++)
            {
                _i = i;
                Inventory_ItemList_Button btn       = GameObject.Instantiate <Inventory_ItemList_Button>(InventorybuttonPrefab);
                RectTransform             transform = btn.GetComponent <RectTransform>();
                btn.transform.SetParent(buttonContainer.transform, false);
                btn.GetComponent <RectTransform>().localScale = new Vector3(1, 1, 1);
                btn.onClick.RemoveAllListeners();

                ButtonArgument equipArgument = new ButtonArgument("Equip");
                NewItem        itm           = inventory.Items[_i].item;
                equipArgument.onClickCallback.Add(() => OpenMiniMenuInventory(itm));
                btn.SetData(inventory.Items[_i], equipArgument);
            }


            for (int q = 0; q < gear.items.Length; q++)
            {
                int _q = q;
                gearInfo.buttons[q].onClick.RemoveAllListeners();
                if (gear.items[q])
                {
                    gearInfo.buttons[q].interactable = true;
                    ButtonArgument unequipArgument = new ButtonArgument("Unequip");
                    unequipArgument.onClickCallback.Add(() => OpenMiniMenuStats(new IntMessage(_q)));
                    NewItem itm = gear.items[q];

                    gearInfo.buttons[q].SetData(itm, unequipArgument);
                }
                else
                {
                    gearInfo.buttons[q].Clear();
                    gearInfo.buttons[q].interactable = false;

                    if (gear.Names[q])
                    {
                        if (gear.Names[q].GetAttribute <CommonAttributes>())
                        {
                            gearInfo.buttons[q].InventorySprite.sprite = gear.Names[q].GetAttribute <CommonAttributes>().GetSprite();
                        }
                    }
                    else
                    {
                        gearInfo.buttons[q].InventorySprite.sprite = null;
                    }
                }
            }
        }
Esempio n. 6
0
        public void SetData(NewItem stack, ButtonArgument arg = null)
        {
            this.stack = stack;
            onPointerEvent.RemoveAllListeners();
            CommonAttributes atr = stack.GetAttribute <CommonAttributes>();

            if (atr)
            {
                this.image.sprite = atr.GetSprite();
            }


            if (arg != null)
            {
                foreach (UnityAction argument in arg.onClickCallback)
                {
                    onPointerEvent.AddListener(argument);
                }
            }
        }