Exemplo n.º 1
0
        BuildingTile InterpretRaycastResult(RayQueryResult raycastResult)
        {
            BuildingTile buildingTile = raycastResult.Node.GetComponent <BuildingTile>();

            if (buildingTile == null)
            {
                buildingTile = raycastResult.Node.Parent.GetComponent <BuildingTile>();
            }

            return(buildingTile);
        }
Exemplo n.º 2
0
        private void OpenBuildingUpgradeMenu(Building building)
        {
            CloseBuildingUpgradeMenu();
            if (building == null)
            {
                return;
            }

            if (BuildingDetailsXML == null)
            {
                BuildingDetailsXML = ResourceCache.GetXmlFile("UI/BuildingDetails.xml");
            }

            BuildingUpgradeWindow = Helpers.CreateBuildingUpgradeUIFromBuilding(UI, BuildingDetailsXML, building);
            Debug.Assert(BuildingUpgradeWindow != null);

            UI.Root.AddChild(BuildingUpgradeWindow);

            var upgradeButton = BuildingUpgradeWindow.GetChild("UpgradeButton") as Button;

            if (upgradeButton != null)
            {
                upgradeButton.Pressed += (o) =>
                {
                    building.Level++;
                    GameManager.RemoveResourceValue(building.BuildingProperties.ResourceType, building.BuildingProperties.GetCostForLevel(building.Level));
                }
            }
            ;

            var deleteButton = BuildingUpgradeWindow.GetChild("DeleteButton") as Button;

            if (deleteButton != null)
            {
                deleteButton.Pressed += (o) =>
                {
                    m_CurrentSelectedTile.QueueDestroyBuilding();
                    if (building.Level == 1)
                    {
                        GameManager.AddResourceValue(building.BuildingProperties.ResourceType, building.BuildingProperties.Cost);
                    }
                    else
                    {
                        GameManager.AddResourceValue(building.BuildingProperties.ResourceType, building.BuildingProperties.GetCostForLevel(building.Level) / 2);
                    }
                    CloseBuildingUpgradeMenu();
                    m_CurrentSelectedTile.Selected = false;
                    m_lastSelectedTile             = null;
                }
            }
            ;
        }
Exemplo n.º 3
0
        public BuildingTile[] GetTileNeighbors(int x, int z)
        {
            List <BuildingTile> ret = new List <BuildingTile>();

            int[] xs = new int[] { -1, 0, 1, -1, 1, -1, 0, 1 };
            int[] zs = new int[] { -1, -1, -1, 0, 0, 1, 1, 1 };

            for (int i = 0; i < xs.Length; i++)
            {
                BuildingTile bt = GetTile(x + xs[i], z + zs[i]);
                if (bt != null)
                {
                    ret.Add(bt);
                }
            }

            return(ret.ToArray());
        }
Exemplo n.º 4
0
        protected void MoveCameraByTouches(float timeStep)
        {
            const float    touchSensitivity = 0.2f;
            RayQueryResult?raycastResult    = null;

            var input = Input;

            if (UIClicked || m_Loading)
            {
                return;
            }

            if (Input.MouseMove.LengthSquared > 0)
            {
                if (InputRaycastCollided(Input.MousePosition, out raycastResult))
                {
                    m_CurrentHoveredTile = InterpretRaycastResult(raycastResult.Value);
                    if (m_CurrentHoveredTile != m_lastHoveredTile)
                    {
                        if (m_CurrentHoveredTile != null)
                        {
                            m_CurrentHoveredTile.Hovered = true;
                            Debug.WriteLine("Hovered: " + m_CurrentHoveredTile.Node.Name);
                        }

                        if (m_lastHoveredTile != null)
                        {
                            m_lastHoveredTile.Hovered = false;
                        }

                        m_lastHoveredTile = m_CurrentHoveredTile;
                    }
                }
                else
                {
                    if (m_lastHoveredTile != null)
                    {
                        m_lastHoveredTile.Hovered = false;
                    }
                    m_CurrentHoveredTile = null;
                    m_lastHoveredTile    = null;
                }
            }

            if (Input.GetMouseButtonPress(MouseButton.Left))
            {
                if (InputRaycastCollided(Input.MousePosition, out raycastResult))
                {
                    m_CurrentSelectedTile = InterpretRaycastResult(raycastResult.Value);

                    if (m_CurrentSelectedTile != m_lastSelectedTile)
                    {
                        m_CurrentSelectedTile.Selected = true;
                        if (m_lastSelectedTile != null)
                        {
                            m_lastSelectedTile.Selected = false;
                        }
                        m_lastSelectedTile = m_CurrentSelectedTile;

                        CloseBuildingUpgradeMenu();
                        CloseBuildingSelectionMenu();

                        if (m_CurrentSelectedTile.HasBuildingBuilt())
                        {
                            OpenBuildingUpgradeMenu(m_CurrentSelectedTile.Building as Building);
                        }
                        else if (m_CurrentSelectedTile.IsBuildable)
                        {
                            OpenBuildingSelectionMenu();
                        }
                    }
                }
                else
                {
                    CloseBuildingUpgradeMenu();
                    CloseBuildingSelectionMenu();

                    if (m_CurrentSelectedTile != null)
                    {
                        m_CurrentSelectedTile.Selected = false;
                    }
                }
            }

            if (Input.GetMouseButtonDown(MouseButton.Right))
            {
                // TODO: screen to world sync move

                const float mouseSensitivity = .01f;
                var         mouseMove        = Input.MouseMove;
                float       cameraX          = -mouseSensitivity * mouseMove.X;
                float       cameraY          = mouseSensitivity * mouseMove.Y;

                cameraNode.Position = cameraNode.LocalToWorld(new Vector3(cameraX, cameraY, 0f));

                Debug.WriteLine("Camera " + cameraY + " " + cameraX);
            }
            if (input.NumTouches == 1)
            {
                TouchState state = input.GetTouch(0);
                if (state.Delta.X != 0 || state.Delta.Y != 0)
                {
                    var camera = cameraNode.GetComponent <Camera>();
                    if (camera == null)
                    {
                        return;
                    }

                    float cameraX = -TouchMovementFactor * state.Delta.X * DT;
                    float cameraY = TouchMovementFactor * state.Delta.Y * DT;

                    cameraNode.Position = cameraNode.LocalToWorld(new Vector3(cameraX, cameraY, 0f));
                    //cameraNode.Position = new Vector3(cameraNode.Position.X + cameraX, cameraNode.Position.Y + cameraY, cameraNode.Position.Z);

                    Debug.WriteLine("Camera " + cameraY + " " + cameraX);
                }
                else if (state.Delta == IntVector2.Zero && InputRaycastCollided(state.Position, out raycastResult))
                {
                    m_CurrentSelectedTile = InterpretRaycastResult(raycastResult.Value);

                    if (m_CurrentSelectedTile != m_lastSelectedTile)
                    {
                        m_CurrentSelectedTile.Selected = true;
                        if (m_lastSelectedTile != null)
                        {
                            m_lastSelectedTile.Selected = false;
                        }
                        m_lastSelectedTile = m_CurrentSelectedTile;

                        CloseBuildingUpgradeMenu();
                        CloseBuildingSelectionMenu();

                        if (m_CurrentSelectedTile.HasBuildingBuilt())
                        {
                            OpenBuildingUpgradeMenu(m_CurrentSelectedTile.Building as Building);
                        }
                        else if (m_CurrentSelectedTile.IsBuildable)
                        {
                            OpenBuildingSelectionMenu();
                        }
                    }
                }
                else
                {
                    CloseBuildingUpgradeMenu();
                    CloseBuildingSelectionMenu();

                    if (m_CurrentSelectedTile != null)
                    {
                        m_CurrentSelectedTile.Selected = false;
                    }
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Move camera for 3D samples
        /// </summary>
        protected void SimpleMoveCamera3D(float timeStep, float moveSpeed = 10.0f)
        {
            RayQueryResult?raycastResult = null;

            if (UIClicked || m_Loading)
            {
                return;
            }

            if (Input.MouseMove.LengthSquared > 0)
            {
                if (InputRaycastCollided(Input.MousePosition, out raycastResult))
                {
                    m_CurrentHoveredTile = InterpretRaycastResult(raycastResult.Value);
                    if (m_CurrentHoveredTile != m_lastHoveredTile)
                    {
                        if (m_CurrentHoveredTile != null)
                        {
                            m_CurrentHoveredTile.Hovered = true;
                            Debug.WriteLine("Hovered: " + m_CurrentHoveredTile.Node.Name);
                        }

                        if (m_lastHoveredTile != null)
                        {
                            m_lastHoveredTile.Hovered = false;
                        }

                        m_lastHoveredTile = m_CurrentHoveredTile;
                    }
                }
                else
                {
                    if (m_lastHoveredTile != null)
                    {
                        m_lastHoveredTile.Hovered = false;
                    }
                    m_CurrentHoveredTile = null;
                    m_lastHoveredTile    = null;
                }
            }

            if (Input.GetMouseButtonPress(MouseButton.Left))
            {
                if (InputRaycastCollided(Input.MousePosition, out raycastResult))
                {
                    m_CurrentSelectedTile = InterpretRaycastResult(raycastResult.Value);

                    if (m_CurrentSelectedTile != m_lastSelectedTile)
                    {
                        m_CurrentSelectedTile.Selected = true;
                        if (m_lastSelectedTile != null)
                        {
                            m_lastSelectedTile.Selected = false;
                        }
                        m_lastSelectedTile = m_CurrentSelectedTile;

                        CloseBuildingUpgradeMenu();
                        CloseBuildingSelectionMenu();

                        if (m_CurrentSelectedTile.HasBuildingBuilt())
                        {
                            OpenBuildingUpgradeMenu(m_CurrentSelectedTile.Building as Building);
                        }
                        else if (m_CurrentSelectedTile.IsBuildable)
                        {
                            OpenBuildingSelectionMenu();
                        }
                    }
                }
                else
                {
                    CloseBuildingUpgradeMenu();
                    CloseBuildingSelectionMenu();

                    if (m_CurrentSelectedTile != null)
                    {
                        m_CurrentSelectedTile.Selected = false;
                    }
                }
            }

            if (Input.GetMouseButtonDown(MouseButton.Right))
            {
                // TODO: screen to world sync move

                const float mouseSensitivity = .01f;
                var         mouseMove        = Input.MouseMove;
                float       cameraX          = -mouseSensitivity * mouseMove.X;
                float       cameraY          = mouseSensitivity * mouseMove.Y;

                cameraNode.Position = cameraNode.LocalToWorld(new Vector3(cameraX, cameraY, 0f));

                Debug.WriteLine("Camera " + cameraY + " " + cameraX);
            }

            if (Input.MouseMoveWheel != 0)
            {
                MainCamera.OrthoSize += Input.MouseMoveWheel;
                /*MainCamera.NearClip = -1000;*/ //TODO
            }
        }
Exemplo n.º 6
0
        public BuildingTile[] GetTileNeighbors(BuildingTile target)
        {
            var pos = GetStringPos(target.Node.Name);

            return(GetTileNeighbors(pos.X, pos.Y));
        }