Exemple #1
0
 public void CancelSelection()
 {
     EquipBar.Get().CancelSelection();
     CraftBar.Get().CancelSelection();
     InventoryBar.Get().CancelSelection();
     PlayerCharacter.Get().CancelConstruction();
 }
Exemple #2
0
    //When the character interact with this selectable, check all the actions and see if any should be triggered.
    public void Use(PlayerCharacter character)
    {
        if (enabled)
        {
            ItemSlot islot   = InventoryBar.Get().GetSelectedSlot();
            ItemSlot eslot   = EquipBar.Get().GetSelectedSlot();
            ItemSlot slot    = eslot != null ? eslot : islot;
            MAction  maction = slot != null && slot.GetItem() != null?slot.GetItem().FindMergeAction(this) : null;

            AAction aaction = FindAutoAction();
            if (maction != null && maction.CanDoAction(character, this))
            {
                maction.DoAction(character, slot, this);
                TheUI.Get().CancelSelection();
            }
            else if (aaction != null && aaction.CanDoAction(character, this))
            {
                aaction.DoAction(character, this);
            }
            else if (actions.Length > 0)
            {
                ActionSelector.Get().Show(character, this);
            }

            if (onUse != null)
            {
                onUse.Invoke(character);
            }
        }
    }
Exemple #3
0
        void InitializeUI()
        {
            SpeedMeter.AttachTo(Camera.Main);
            SpeedMeter.RelativeZ = -40; // so that it's "in front" of the camera
            SpeedMeter.RelativeX = Camera.Main.OrthogonalWidth / 2.0f - (32 + SpeedMeter.mSpriteInstance.Width / 2);
            SpeedMeter.RelativeY = -(Camera.Main.OrthogonalHeight / 2.0f - (32 + SpeedMeter.mSpriteInstance.Height / 2));

            SpeedMeter.SetCaseScale(5, -1, 3, 0);
            SpeedMeter.SetState(PlayerBoat.SpeedScale);


            ButtonPistolClick += (x) =>
            {
                PlayerInstance.EquipItem(Weapon.ExistingWeapons.First(w => w.ItemName == "Pistol"));
            };
            ButtonShotgunClick += (x) =>
            {
                PlayerInstance.AddItemToInventory(Item.ExistingItems.First(y => y.ItemName == "Pistol"));
                PlayerInstance.AddItemToInventory(Item.ExistingItems.First(y => y.ItemName == "Sword"));
            };

            FlatRedBallServices.IsWindowsCursorVisible = true;

            (InventoryGui.GetGraphicalUiElementByName("TextPlayerName") as GumRuntimes.TextRuntime).Text = PlayerInstance.PlayerName;

            InventoryGui.PlaceCasesInInventoryPanel(PlayerInstance.PlayerInventory.Length, 8);

            InventoryGui.OnItemMovedCase += InventoryGuiOnItemMoved;

            foreach (var box in InventoryBar.GetInventoryBoxList())
            {
                box.Click += InventoryBarOnBoxClicked;
            }
        }
Exemple #4
0
    private void OnClickSlot(int slot, CraftData item)
    {
        PlayerControlsMouse controls = PlayerControlsMouse.Get();

        ItemSlot islot = InventoryBar.Get().GetSelectedSlot();
        ItemSlot eslot = GetSlot(slot);

        selected_right_slot = -1;

        //Merge items
        if (eslot != null && islot != null)
        {
            ItemSlot slot1   = eslot;
            ItemSlot slot2   = islot;
            ItemData item1   = slot1.GetItem();
            ItemData item2   = slot2.GetItem();
            MAction  action1 = item1 != null?item1.FindMergeAction(item2) : null;

            MAction action2 = item2 != null?item2.FindMergeAction(item1) : null;

            if (action1 != null && action1.CanDoAction(PlayerCharacter.Get(), slot2))
            {
                action1.DoAction(PlayerCharacter.Get(), slot1, slot2);
                TheUI.Get().CancelSelection();
                return;
            }

            else if (action2 != null && action2.CanDoAction(PlayerCharacter.Get(), slot1))
            {
                action2.DoAction(PlayerCharacter.Get(), slot2, slot1);
                TheUI.Get().CancelSelection();
                return;
            }
        }

        if (islot != null)
        {
            ItemData idata = islot.GetItem();
            if (idata != null && idata.type == ItemType.Equipment)
            {
                PlayerData.Get().EquipItemTo(islot.slot_index, ItemData.GetEquipIndex(idata.equip_slot));
                TheUI.Get().CancelSelection();
            }
        }
        else if (item != null && slot != selected_slot)
        {
            TheUI.Get().CancelSelection();
            selected_slot = slot;
        }
        else
        {
            CancelSelection();
        }

        if (onClickSlot != null && eslot != null)
        {
            onClickSlot.Invoke(eslot);
        }
    }
 public int GetInventorySelectedSlotIndex()
 {
     if (InventoryBar.Get())
     {
         return(InventoryBar.Get().GetSelectedSlotIndex());
     }
     return(-1);
 }
Exemple #6
0
        private void ToggleInventory()
        {
            InventoryGui.SetVisibility(!InventoryGui.GetVisibility());
            InventoryBar.SetVisibility(!InventoryGui.GetVisibility());

            IsInventoryOpened = InventoryGui.GetVisibility();
            InventoryGui.DisplayItemsOnUI(PlayerInstance.PlayerInventory);
            InventoryBar.SetAllItems(InventoryGui.GetInventoryBar().GetAllItems());
        }
Exemple #7
0
        protected override void Initialize()
        {
            Map          = new Map(200, 1000);
            Player       = new Player(50, 0, new InputComponent(), new PhysicsComponent());
            camera       = new Camera(GraphicsDevice.Viewport);
            inventoryBar = new InventoryBar(camera);
            inventory    = new Inventory(camera);
            background   = new Background();

            base.Initialize();
        }
        private void AffectEvents()
        {
            foreach (InventoryBoxRuntime c in ContainerItems.Children.Where(x => x.GetType() == typeof(InventoryBoxRuntime)))
            {
                c.Click += InventoryBoxOnClick;
            }

            foreach (InventoryBoxRuntime t in InventoryBar.GetInventoryBoxList())
            {
                t.Click += IntenvoryBarBoxOnClick;
                t.Click += (x) => { Console.WriteLine("DEBUG : " + "(inventoryguiruntime.cs 67)"); };
            }
        }
Exemple #9
0
    void Awake()
    {
        _instance = this;

        for (int i = 0; i < slots.Length; i++)
        {
            int index = i; //Important to copy so not overwritten in loop
            slots[i].slot_index    = index;
            slots[i].onClick      += (CraftData item) => { OnClickSlot(index, item); };
            slots[i].onClickRight += (CraftData item) => { OnClickSlotRight(index, item); };
            slots[i].onClickLong  += (CraftData item) => { OnClickSlotRight(index, item); };
        }
    }
Exemple #10
0
 private void InventoryBarControls()
 {
     if (InputManager.Keyboard.KeyPushed(Keys.D1))
     {
         InventoryBar.SetSelectedItemCase(0);
         PlayerInstance.EquipItem(InventoryBar.GetSelectedItem());
     }
     else if (InputManager.Keyboard.KeyPushed(Keys.D2))
     {
         InventoryBar.SetSelectedItemCase(1);
         PlayerInstance.EquipItem(InventoryBar.GetSelectedItem());
     }
     else if (InputManager.Keyboard.KeyPushed(Keys.D3))
     {
         InventoryBar.SetSelectedItemCase(2);
         PlayerInstance.EquipItem(InventoryBar.GetSelectedItem());
     }
     else if (InputManager.Keyboard.KeyPushed(Keys.D4))
     {
         InventoryBar.SetSelectedItemCase(3);
         PlayerInstance.EquipItem(InventoryBar.GetSelectedItem());
     }
 }
Exemple #11
0
    public void OpenInventory()
    {
        if (interfaceOpen == true)
        {
            interfaceOpen = false;

            GameObject  player    = GameObject.FindGameObjectWithTag("Player"); // finding the player
            List <Item> inventory = player.GetComponent <scr_player>().InventoryList;
        }
        else
        {
            interfaceOpen = true;
            GameObject  player    = GameObject.FindGameObjectWithTag("Player");         // finding the player
            List <Item> inventory = player.GetComponent <scr_player>().InventoryList;

            if (inventory.Count != 0)
            {
                foreach (Item item in inventory)    // finding the player's Inventory
                {
                    tmpPanelItem = Instantiate(panelItemPrefab) as GameObject;
                    InventoryBar tmpInventoryBar = tmpPanelItem.GetComponent <InventoryBar>() as InventoryBar;

                    if (tmpInventoryBar != null)
                    {
                        tmpInventoryBar.item          = item;
                        tmpInventoryBar.itemName.text = item.itemName;
                        tmpInventoryBar.description   = item.itemDesc;
                        tmpInventoryBar.gObject       = item.gItem;
                    }



                    tmpPanelItem.transform.SetParent(player.GetComponent <scr_player>().inventoryUI.transform.FindChild("Inventory").transform.FindChild("Left Side").transform.FindChild("InventoryList").transform.FindChild("Width"));
                }
            }
        }
    }
Exemple #12
0
    void Update()
    {
        Vector3 wPos = InventoryBar.Get().GetSlotWorldPosition(slot_target);

        Vector3 dir   = wPos - transform.position;
        Vector3 tDir  = wPos - start_pos;
        float   mdist = Mathf.Min(fx_speed * Time.deltaTime, dir.magnitude);
        float   scale = dir.magnitude / tDir.magnitude;

        transform.position  += dir.normalized * mdist;
        transform.localScale = start_scale * scale;
        transform.rotation   = Quaternion.LookRotation(TheCamera.Get().transform.forward, Vector3.up);

        if (dir.magnitude < 0.1f)
        {
            Destroy(gameObject);
        }

        timer += Time.deltaTime;
        if (timer > 2f)
        {
            Destroy(gameObject);
        }
    }
Exemple #13
0
    void Update()
    {
        transform.position = PlayerControlsMouse.Get().GetPointingPos();
        transform.rotation = Quaternion.LookRotation(TheCamera.Get().transform.forward, Vector3.up);

        ItemSlot   islot   = InventoryBar.Get().GetSelectedSlot();
        ItemSlot   eslot   = EquipBar.Get().GetSelectedSlot();
        ItemSlot   slot    = eslot != null ? eslot : islot;
        Selectable select  = Selectable.GetNearestHover(transform.position);
        MAction    maction = slot != null && slot.GetItem() != null?slot.GetItem().FindMergeAction(select) : null;

        title.enabled = maction != null;
        title.text    = maction != null ? maction.title : "";

        if ((slot != null) != icon_group.activeSelf)
        {
            icon_group.SetActive(slot != null);
        }

        if (slot != null && slot.GetItem())
        {
            icon.sprite = slot.GetItem().icon;
        }
    }
Exemple #14
0
 private void InventoryBarOnBoxClicked(FlatRedBall.Gui.IWindow sender)
 {
     InventoryBar.SetSelectedItemCase((InventoryBoxRuntime)sender);
 }