Exemplo n.º 1
0
    protected void Start()
    {
        switch (myControllerInput.inputType)
        {
        case InputType.KEYBOARD:
            DownPlatformButton  = "E";
            RightPlatformButton = "F";
            break;

        case InputType.PS4_CONTROLLER:
            DownPlatformButton  = "X";
            RightPlatformButton = "O";
            break;

        case InputType.XBOX_CONTROLLER:
            DownPlatformButton  = "A";
            RightPlatformButton = "B";
            break;
        }
        CameraOriginalPosition = myCamera.orthographicSize;
        Stats               = GetComponent <Stats>();
        feetAnimation       = transform.Find("Feet").GetComponent <Animator>();
        rb                  = GetComponent <Rigidbody2D>();
        InventoryHandler    = GetComponent <InventoryHandler>();
        reviveBarHandler    = transform.Find("PlayerDownCanvas").GetComponent <ReviveBarHandler>();
        PlayerOriginalImage = GetComponent <SpriteRenderer>().sprite;
        LootBagHandler      = GetComponent <LootBagHandler>();
        InteractionPanel    = transform.Find("InteractionCollider").GetComponent <InteractionHandler>();
        InteractionPanel.InitInteraction(MyHUD);
    }
Exemplo n.º 2
0
    public void CreateItemSelectPanel(InteractionPanel interactionPanel, Action targetAction)
    {
        GameObject obj = Instantiate(itemSelectPanelPrefab, transform);

        obj.transform.SetParent(transform);
        obj.transform.position = Input.mousePosition;
        ItemSelectPanel itemSelectPanel = obj.GetComponent <ItemSelectPanel>();

        // Set this panel to close on the close button click
        itemSelectPanel.closeButton.onClick.AddListener(() => { Destroy(obj); });
        // Set parent panel to close select panel on close
        interactionPanel.closeButton.onClick.AddListener(() => { Destroy(obj); });

        // Add the item icons
        List <WorldItem> availableItems = new List <WorldItem> {
            new WorldItem(ItemDatabase.items.resources.Gold, 1), new WorldItem(ItemDatabase.items.resources.Wood, 1), new WorldItem(ItemDatabase.items.resources.Stone, 1)
        };

        foreach (WorldItem item in availableItems)
        {
            Button itemIcon = Instantiate(itemSelectPanel.itemIconButton, transform);
            itemIcon.transform.SetParent(itemSelectPanel.itemIconGridLayout.transform);
            itemIcon.image.sprite = item.itemDefinition.icon;
            // Add function to the icon, adds the world item to the action's effects
            itemIcon.onClick.AddListener(() => { targetAction.AddEffect(item); });
        }
    }
Exemplo n.º 3
0
    private static void panelCreator(NetworkMessage message)
    {
        CreatePanelMessage panelMessage = message.ReadMessage <CreatePanelMessage>();

        InteractionPanel newPanel = Instantiate <InteractionPanel>(_instance.panelPrefabs[panelMessage.prefabIndex]);
        Vector3          pos      = Vector3.zero;
        Quaternion       rot      = Quaternion.identity;

        getCellCenter(panelMessage.x, panelMessage.y, newPanel.dimensionX, newPanel.dimensionY, out pos, out rot);
        newPanel.transform.position = pos + Vector3.up * MoveDownUp.HEIGHT;
        newPanel.transform.rotation = rot;

        newPanel.setActionSet(panelMessage.actionSet);
    }
Exemplo n.º 4
0
    // TODO - maybe UI panels should have base and subclasses that implement their own creation methods
    public void CreateInteractionPanel(WorldObject.InformationStruct informationStruct)
    {
        GameObject obj = Instantiate(interactionPanelPrefab, transform);

        obj.transform.SetParent(transform);
        obj.transform.position = Input.mousePosition;
        InteractionPanel interactionPanel = obj.GetComponent <InteractionPanel>();

        // Set the title as the object name
        interactionPanel.objectNameText.text = informationStruct.objectName;

        // Set this panel to close on the close button click
        interactionPanel.closeButton.onClick.AddListener(() => { Destroy(obj); });

        // Update the actions panel
        foreach (Action action in informationStruct.actions)
        {
            ActionIndicator actionIndicator = Instantiate(interactionPanel.actionEntryPrefab, transform);
            actionIndicator.transform.SetParent(interactionPanel.actionListPanel.transform);

            // Link the add item button
            actionIndicator.addItemButton.onClick.AddListener(() => { CreateItemSelectPanel(interactionPanel, action); });

            // Add the action title
            actionIndicator.actionNameText.text = action.description;

            // Add precondition icons
            foreach (WorldItem precondition in action.preconditions)
            {
                Image itemIcon = Instantiate(actionIndicator.itemIcon, transform);
                itemIcon.transform.SetParent(actionIndicator.preconditionGridLayout.transform);
                itemIcon.sprite = precondition.itemDefinition.icon;
            }

            // Add effect icons
            foreach (WorldItem effect in action.effects)
            {
                Image itemIcon = Instantiate(actionIndicator.itemIcon, transform);
                itemIcon.transform.SetParent(actionIndicator.effectGridLayout.transform);
                itemIcon.sprite = effect.itemDefinition.icon;
            }
        }
    }
Exemplo n.º 5
0
    private static CreatePanelMessage createRandomPanel()
    {
        InteractionPanel chosenPanel = null;
        int chosenX, chosenY;
        PanelActionSetBase chosenActionSet;

        while (true)
        {
            float totalWeight = 0.0f;
            foreach (InteractionPanel panel in _panelsToChooseFrom)
            {
                totalWeight += panel.spawnWeight;
            }

            float r = Random.value * totalWeight;
            foreach (InteractionPanel panel in _panelsToChooseFrom)
            {
                if (panel.spawnWeight > r)
                {
                    chosenPanel = panel;
                    break;
                }
                else
                {
                    r -= panel.spawnWeight;
                }
            }

            List <int> availableCellLocationsX = new List <int>();
            List <int> availableCellLocationsY = new List <int>();
            for (int x = 0; x < CELLS_X - chosenPanel.dimensionX + 1; x++)
            {
                for (int y = 0; y < CELLS_Y - chosenPanel.dimensionY + 1; y++)
                {
                    bool isAnyCellFilled = false;
                    for (int dx = 0; dx < chosenPanel.dimensionX; dx++)
                    {
                        for (int dy = 0; dy < chosenPanel.dimensionY; dy++)
                        {
                            if (_isCellFilled[x + dx, y + dy])
                            {
                                isAnyCellFilled = true;
                                break;
                            }
                        }

                        if (isAnyCellFilled)
                        {
                            break;
                        }
                    }

                    if (!isAnyCellFilled)
                    {
                        availableCellLocationsX.Add(x);
                        availableCellLocationsY.Add(y);
                    }
                }
            }

            if (availableCellLocationsX.Count == 0)
            {
                _panelsToChooseFrom.Remove(chosenPanel);

                if (_panelsToChooseFrom.Count == 0)
                {
                    throw new System.Exception("Cannot fit any more panels!");
                }
                continue;
            }

            int chosenCellIndex = Random.Range(0, availableCellLocationsX.Count);
            chosenX         = availableCellLocationsX[chosenCellIndex];
            chosenY         = availableCellLocationsY[chosenCellIndex];
            chosenActionSet = chosenPanel.createViableActionSet(_createdPanels);
            break;
        }
        ;

        emptyCells -= chosenPanel.dimensionY * chosenPanel.dimensionX;
        _createdPanels.Add(chosenActionSet.panelLabel);

        for (int dx = 0; dx < chosenPanel.dimensionX; dx++)
        {
            for (int dy = 0; dy < chosenPanel.dimensionY; dy++)
            {
                _isCellFilled[chosenX + dx, chosenY + dy] = true;
            }
        }

        chosenActionSet.currentVariantIndex = Random.Range(0, chosenActionSet.getVariantCount());

        CreatePanelMessage creationMessage = new CreatePanelMessage(chosenActionSet, chosenX, chosenY, _instance.panelPrefabs.IndexOf(chosenPanel));

        return(creationMessage);
    }
Exemplo n.º 6
0
 private void Awake()
 {
     SharedInstance = this;
     gameObject.SetActive(false);
 }