コード例 #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>
    /// Opens a building tab on bottom menu
    /// </summary>
    /// <param name="tab"></param>
    public void Open_Tab(Building.UI_Category tab)
    {
        if (Game.Instance.State != Game.GameState.RUNNING)
        {
            //No building menu access if game is not running
            Show_Message("Start new game from menu: Game -> New");
            return;
        }
        if (tab == open_building_tab)
        {
            //Same tab -> hide menu
            bottom_menu_rectangle_transform.Translate(new Vector3(0.0f, -bottom_menu_height, 0.0f));
            tab_buttons[(Building.UI_Category)open_building_tab].GetComponent <Image>().color = Color.white;
            foreach (Building building in BuildingPrototypes.Get_By_Category((Building.UI_Category)open_building_tab))
            {
                building_buttons[building.Name].gameObject.SetActive(false);
            }
            open_building_tab = null;
            Hide_Building_Info();
            BuildingPrototypes.Currently_Selected = null;
            return;
        }
        else if (open_building_tab == null)
        {
            //Show menu
            bottom_menu_rectangle_transform.Translate(new Vector3(0.0f, bottom_menu_height, 0.0f));
        }

        if (open_building_tab != null)
        {
            //Hide buildings in old tab
            tab_buttons[(Building.UI_Category)open_building_tab].GetComponent <Image>().color = Color.white;
            foreach (Building building in BuildingPrototypes.Get_By_Category((Building.UI_Category)open_building_tab))
            {
                building_buttons[building.Name].gameObject.SetActive(false);
            }
        }
        open_building_tab = tab;
        //Show buildings in new tab
        foreach (Building building in BuildingPrototypes.Get_By_Category(tab))
        {
            building_buttons[building.Name].gameObject.SetActive(true);
        }
        tab_buttons[(Building.UI_Category)open_building_tab].GetComponent <Image>().color = Color.blue;
    }
コード例 #3
0
    public void Select_Building_At(int index)
    {
        if (Open_Building_Tab == null)
        {
            return;
        }
        List <Building> buildings_in_category = BuildingPrototypes.Get_By_Category(Open_Building_Tab.Value);

        if (index < 0 || index >= buildings_in_category.Count)
        {
            return;
        }
        if (BuildingPrototypes.Currently_Selected == buildings_in_category[index].Internal_Name)
        {
            BuildingPrototypes.Currently_Selected = null;
        }
        else
        {
            BuildingPrototypes.Currently_Selected = buildings_in_category[index].Internal_Name;
        }
    }
コード例 #4
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);
    }
コード例 #5
0
    // Use this for initialization
    private void Start()
    {
        if (Instance != null)
        {
            Logger.Instance.Error("Start called multiple times");
        }
        Instance             = this;
        show_alerts          = true;
        show_building_ranges = true;
        info_update_cooldown = 0;

        StorageSettingsPanel.SetActive(false);
        storage_settings_fields = new Dictionary <string, InputField>();
        StorageLinksPanel.SetActive(false);
        storage_links_inputs         = new Dictionary <string, InputField>();
        storage_links_buttons        = new Dictionary <string, Button>();
        storage_links_building_ids   = new Dictionary <string, int>();
        select_link_building_mode    = false;
        new_storage_link_building_id = -1;

        highlighted_road_tiles     = new List <Tile>();
        road_color                 = new Color(0.5f, 0.2f, 0.0f, 0.5f);
        highlighted_building_tiles = new List <Tile>();
        building_color             = new Color(0.2f, 0.5f, 0.0f, 0.5f);

        menu_is_open          = true;
        city_menu_is_open     = true;
        overlays_menu_is_open = true;
        tab_buttons           = new Dictionary <Building.UI_Category, Button>();
        building_buttons      = new Dictionary <string, Button>();
        open_building_tab     = null;
        Close_Menus();
        City_Menu_Enabled = false;

        //Initialize bottom menu
        int index = 0;

        //Resize
        bottom_menu_rectangle_transform           = Bottom_Menu.GetComponent <RectTransform>();
        bottom_menu_rectangle_transform.sizeDelta = new Vector2(Screen.width, bottom_menu_rectangle_transform.sizeDelta.y);
        //Calculate width & height of bottom menu
        Vector3[] bottom_menu_corners = new Vector3[4];
        bottom_menu_rectangle_transform.GetWorldCorners(bottom_menu_corners);
        bottom_menu_width  = bottom_menu_corners[2].x - bottom_menu_corners[0].x;
        bottom_menu_height = bottom_menu_corners[2].y - bottom_menu_corners[0].y;
        //Calculate width & height of buttons
        RectTransform button_rectangle_transform = Button_Prefab.GetComponent <RectTransform>();

        Vector3[] corners = new Vector3[4];
        button_rectangle_transform.GetWorldCorners(corners);
        float button_width  = corners[2].x - corners[0].x;
        float button_height = corners[2].y - corners[0].y;

        foreach (Building.UI_Category category in Enum.GetValues(typeof(Building.UI_Category)))
        {
            //Add button for category
            Button button = Instantiate(Button_Prefab);
            button.name = category.ToString() + "_tab_button";
            button.GetComponentInChildren <Text>().text = category.ToString();
            button.transform.SetParent(Bottom_Menu.transform);
            button.transform.position = new Vector3(Bottom_Menu.transform.position.x + (index * button_width) + (button_width / 2.0f) - (bottom_menu_width / 2.0f),
                                                    Bottom_Menu.transform.position.y + (bottom_menu_height / 2.0f) + (button_height / 2.0f));
            Button.ButtonClickedEvent on_click_event = new Button.ButtonClickedEvent();
            on_click_event.AddListener(new UnityEngine.Events.UnityAction(delegate() { Open_Tab(category); }));
            button.onClick = on_click_event;
            index++;

            tab_buttons.Add(category, button);

            //Create buttons for buildings
            int index_2 = 0;
            foreach (Building building in BuildingPrototypes.Get_By_Category(category))
            {
                Button building_button = Instantiate(Button_Prefab);
                building_button.GetComponentInChildren <Text>().text = building.Name;
                building_button.transform.SetParent(Bottom_Menu.transform);
                building_button.gameObject.SetActive(false);
                Image image = building_button.GetComponent <Image>();
                image.sprite = SpriteManager.Instance.Get_Sprite(building.Texture);
                image.rectTransform.sizeDelta      = new Vector2(image.rectTransform.sizeDelta.x / 2.0f, image.rectTransform.sizeDelta.y * 3.0f);
                building_button.transform.position = new Vector3(Bottom_Menu.transform.position.x + (index_2 * image.rectTransform.sizeDelta.x) + (image.rectTransform.sizeDelta.x / 2.0f) - (bottom_menu_width / 2.0f),
                                                                 Bottom_Menu.transform.position.y + (bottom_menu_height / 2.0f) - (image.rectTransform.sizeDelta.y / 2.0f));
                Button.ButtonClickedEvent building_on_click_event = new Button.ButtonClickedEvent();
                building_on_click_event.AddListener(new UnityEngine.Events.UnityAction(delegate() {
                    if (BuildingPrototypes.Currently_Selected == building.Internal_Name)
                    {
                        Hide_Building_Info();
                        BuildingPrototypes.Currently_Selected = null;
                    }
                    else
                    {
                        BuildingPrototypes.Currently_Selected = building.Internal_Name;
                    }
                }));
                building_button.onClick = building_on_click_event;

                building_buttons.Add(building.Name, building_button);
                index_2++;
            }
        }

        //Hide bottom menu
        bottom_menu_rectangle_transform.Translate(new Vector3(0.0f, -bottom_menu_height, 0.0f));

        //Hide message panel
        Message_Panel.SetActive(false);
        message_panel_open_time = 0.0f;

        //Initialize top menu
        top_menu_rectangle_transform           = Top_Menu.GetComponent <RectTransform>();
        top_menu_rectangle_transform.sizeDelta = new Vector2(Screen.width, top_menu_rectangle_transform.sizeDelta.y);

        //Right Menu
        RightPanel.SetActive(false);
        StorageSettingsButton.SetActive(false);
        StorageSettingsHeader.SetActive(false);
        StorageLinksButton.SetActive(false);
        selected_building = null;
    }