예제 #1
0
    /// <summary>
    /// Shows info about building that is selected to be built
    /// </summary>
    public void Show_Building_Info()
    {
        if (BuildingPrototypes.Currently_Selected == null)
        {
            return;
        }
        Unselect_Building();
        RightPanel.SetActive(true);

        //Collect data
        StringBuilder data  = new StringBuilder();
        Building      proto = BuildingPrototypes.Get();

        RightPanel.transform.Find("NameText").gameObject.GetComponent <Text>().text = proto.Name;

        data.Append("\nCost\n");
        bool has_cost = false;

        foreach (KeyValuePair <string, float> cost in proto.Cost)
        {
            data.Append(Helper.Parse_To_Human_Readable(cost.Key));
            data.Append(": ");
            data.Append(cost.Value);
            data.Append("\n");
            has_cost = true;
        }
        if (!has_cost)
        {
            data.Append("free\n");
        }

        data.Append("\nBuilding time: ");
        data.Append(proto.Construction_Time);
        data.Append("\nUpkeep: ");
        data.Append(proto.Upkeep);

        if (proto.Appeal_Effect != 0.0f)
        {
            float actual_effect = proto.Appeal_Effect * (proto.Width * proto.Height);
            data.Append("\n\nAppeal effect: ");
            data.Append(Math.Round(actual_effect, 2));
            data.Append("\nAppeal range: ");
            data.Append(proto.Appeal_Range);
        }

        data.Append("\nStorage: ");
        data.Append(proto.Max_Storage);
        if (proto.Range != 0 && proto.Transport_Speed != 0)
        {
            data.Append("\nTransport range: ");
            data.Append(proto.Range);
            data.Append("\nTransport speed: ");
            data.Append(proto.Transport_Speed);
        }

        //Render
        RightPanel.transform.Find("DataText").gameObject.GetComponent <Text>().text = data.ToString();
    }
예제 #2
0
    /// <summary>
    /// Per frame update
    /// </summary>
    private void Update()
    {
        Vector3 current_position = CameraManager.Instance.Camera.ScreenToWorldPoint(Input.mousePosition);

        if (Input.GetMouseButton(1) || Input.GetMouseButton(2))
        {
            //Camera
            Vector3 difference = last_position - current_position;
            CameraManager.Instance.Move_Camera(difference);
            //Hide message
            MenuManager.Instance.Hide_Message();
            MenuManager.Instance.Close_Menus();
        }
        if (Input.GetMouseButtonDown(0))
        {
            //Hide message
            MenuManager.Instance.Hide_Message();
            if (!EventSystem.current.IsPointerOverGameObject())
            {
                MenuManager.Instance.Close_Menus();
            }

            //Right click
            if (Game.Instance.State == Game.GameState.RUNNING && !EventSystem.current.IsPointerOverGameObject())
            {
                Tile tile = Get_Tile_At_Mouse();
                if (tile != null)
                {
                    if (BuildingPrototypes.Currently_Selected != null)
                    {
                        if (!City.Instance.Build(BuildingPrototypes.Get(), tile))
                        {
                            MenuManager.Instance.Show_Message(City.Instance.Error_Message);
                        }
                        else if (!Input.GetButton("Build Multiple"))
                        {
                            BuildingPrototypes.Currently_Selected = null;
                        }
                    }
                    else
                    {
                        if (tile.Building != null && !ConsoleManager.Instance.Is_Open())
                        {
                            MenuManager.Instance.Select_Building(tile.Building);
                        }
                        else if (!EventSystem.current.IsPointerOverGameObject())
                        {
                            MenuManager.Instance.Unselect_Building();
                        }
                    }
                }
            }
        }

        //Zoom
        if (Input.GetAxis("Mouse ScrollWheel") > 0.0f)
        {
            CameraManager.Instance.Zoom_Camera(CameraManager.Zoom.Out);
        }
        else if (Input.GetAxis("Mouse ScrollWheel") < 0.0f)
        {
            CameraManager.Instance.Zoom_Camera(CameraManager.Zoom.In);
        }

        //Transparent building
        if (Transparent_Building.activeSelf)
        {
            Tile tile = Get_Tile_At_Mouse();
            if (tile != null)
            {
                Transparent_Building.transform.position = tile.Position;
                if (tile != tile_under_cursor)
                {
                    //Highlight tiles
                    if (BuildingPrototypes.Get().Attribute("highlight_tiles_during_build") != 0.0f)
                    {
                        //Circle
                        foreach (Tile t in highlighted_tiles)
                        {
                            t.Highlight = highlight_color;
                        }
                        int y_fix = 0; //TODO: fix this
                        if (BuildingPrototypes.Get().Height % 2 != 0)
                        {
                            y_fix = 1;
                        }
                        highlighted_tiles = tile.Map.Get_Tiles_In_Circle(tile.X, tile.Y + y_fix, BuildingPrototypes.Get().Attribute("highlight_tiles_during_build"),
                                                                         BuildingPrototypes.Get().Width % 2 == 0, BuildingPrototypes.Get().Height % 2 == 0);
                        foreach (Tile t in highlighted_tiles)
                        {
                            t.Highlight = highlight_color;
                        }
                    }
                    if (BuildingPrototypes.Get().Range != 0)
                    {
                        //Connected buildings
                        foreach (Tile t in highlighted_connected_building_tiles)
                        {
                            t.Highlight = highlight_connected_color;
                            if (t.Building != null)
                            {
                                t.Building.Clear_Range_Marker();
                            }
                        }
                        List <Building> connected_buildings = BuildingPrototypes.Get().Get_Connected_Buildings(BuildingPrototypes.Get().Range, 0, tile, true);
                        highlighted_connected_building_tiles.Clear();
                        foreach (Building connected_building in connected_buildings)
                        {
                            foreach (Tile t in connected_building.Tiles)
                            {
                                highlighted_connected_building_tiles.Add(t);
                            }
                        }
                        foreach (Tile t in highlighted_connected_building_tiles)
                        {
                            t.Highlight = highlight_connected_color;
                        }
                    }
                }
                tile_under_cursor = tile;
            }
            else
            {
                Transparent_Building.transform.position = Get_Mouse_Point();
            }
        }

        if ((!Transparent_Building.activeSelf || BuildingPrototypes.Get().Attribute("highlight_tiles_during_build") == 0.0f) && highlighted_tiles.Count != 0)
        {
            //Clear circle highlights
            foreach (Tile t in highlighted_tiles)
            {
                t.Highlight = highlight_color;
            }
            highlighted_tiles.Clear();
        }
        if ((!Transparent_Building.activeSelf || BuildingPrototypes.Get().Range == 0) && highlighted_connected_building_tiles.Count != 0)
        {
            //Clear connected building highlights
            foreach (Tile t in highlighted_connected_building_tiles)
            {
                t.Highlight = highlight_connected_color;
                if (t.Building != null)
                {
                    t.Building.Clear_Range_Marker();
                }
            }
            highlighted_connected_building_tiles.Clear();
        }

        last_position = CameraManager.Instance.Camera.ScreenToWorldPoint(Input.mousePosition);
    }