예제 #1
0
    private void InitializeSelectedTroopsScrollview()
    {
        UnitsScrollview sv = selectedTroopsScrollviewPrefab.GetComponent <UnitsScrollview>();

        sv.AddTitle("Selected units");
        sv.SetContent(this.selectedUnits, (Unit u) => { DeselectUnit(u); UpdateScrollviews(); });
    }
예제 #2
0
    /// <summary>
    /// Moves a unit from one scrollview to the next.
    /// </summary>
    private void CycleUnit(Unit unit)
    {
        for (int i = 0; i < scrollviewCityPairs.Count; i++)
        {
            UnitsScrollview currentScrollview = scrollviewCityPairs[i].scrollview;
            UnitsScrollview nextScrollview    = null;

            // Wraps to front of list if we're dealing with the last scrollview

            if (i + 1 == scrollviewCityPairs.Count)
            {
                nextScrollview = scrollviewCityPairs[0].scrollview;
            }
            else
            {
                nextScrollview = scrollviewCityPairs[i + 1].scrollview;
            }

            if (currentScrollview.GetUnits().Contains(unit))
            {
                // Remove the unit from the current scrollview
                List <Unit> currentSvUnits = new List <Unit>(currentScrollview.GetUnits());
                currentSvUnits.Remove(unit);
                currentScrollview.SetContent(currentSvUnits, CycleUnit);

                // Add the unit to the next scrollview
                List <Unit> nextSvUnits = new List <Unit>(nextScrollview.GetUnits());
                nextSvUnits.Add(unit);
                nextScrollview.SetContent(nextSvUnits, CycleUnit);

                break;
            }
        }
    }
예제 #3
0
    private void InitializeAvailableTroopsScrollview()
    {
        UnitsScrollview sv = availableTroopsScrollviewPrefab.GetComponent <UnitsScrollview>();

        sv.AddTitle("Available units");
        sv.SetContent(this.availableUnits, (Unit u) => { SelectUnit(u); UpdateScrollviews(); });
    }
예제 #4
0
    /// <summary>
    /// Creates one scrollview for the selected city and one for each of the selected
    /// city's neighbors. Players will then be able to assign the units from the selected city
    /// to a neighboring city.
    /// </summary>
    void CreateAttackFromCityScrollviews(City selectedCity)
    {
        DestroyAllScrollviews();

        // Get all the roads into the city
        List <Road> connectedRoads = selectedCity.GetConnectedRoads();

        // Create a scrollview of the units in the selected city
        UnitsScrollview selectedCitySv = UnitsScrollview.Instantiate <UnitsScrollview>(unitsScrollviewPrefab);

        selectedCitySv.AddTitle(selectedCity.placeName);
        selectedCitySv.transform.SetParent(unitsScrollviewLayout.transform);

        // Populate the selected city scrollview with the current units
        selectedCitySv.SetContent(new List <Unit>(selectedCity.occupyingUnits), CycleUnit);
        scrollviewPairs.Add(new ScrollviewPair(selectedCity, selectedCitySv));

        // Create scrollviews from the neighboring roads that have
        // enemy units camped within them
        foreach (Road road in connectedRoads)
        {
            UnitsScrollview unitsScrollviewCopy = UnitsScrollview.Instantiate <UnitsScrollview>(unitsScrollviewPrefab);
            unitsScrollviewCopy.AddTitle("Camp on Via " + road.placeName);
            unitsScrollviewCopy.transform.SetParent(unitsScrollviewLayout.transform);
            unitsScrollviewCopy.SetContent(new List <Unit>(), CycleUnit);
            scrollviewPairs.Add(new ScrollviewPair(road, unitsScrollviewCopy));
        }
    }
예제 #5
0
    /// <summary>
    /// Creates one scrollview for the selected city and one for each of the selected
    /// city's neighbors. Players will then be able to assign the units from the selected city
    /// to a neighboring city.
    /// </summary>
    void AddNeighboringCityScrollviews(City selectedCity)
    {
        DestroyAllScrollviews();

        // City selectedCity = (City) GameManager.instance.placeSelection;

        List <City> neighboringCities = selectedCity.GetNeighbors();

        UnitsScrollview selectedCitySv = UnitsScrollview.Instantiate <UnitsScrollview>(unitsScrollviewPrefab);

        selectedCitySv.AddTitle(selectedCity.placeName);
        selectedCitySv.transform.SetParent(unitsScrollviewLayout.transform);

        // Create a new list here to prevent overriding values
        selectedCitySv.SetContent(new List <Unit>(selectedCity.occupyingUnits), CycleUnit);

        scrollviewCityPairs.Add(new ScrollviewCityPair(selectedCity, selectedCitySv));

        foreach (City neighboringCity in neighboringCities)
        {
            UnitsScrollview unitsScrollviewCopy = UnitsScrollview.Instantiate <UnitsScrollview>(unitsScrollviewPrefab);
            unitsScrollviewCopy.AddTitle("To " + neighboringCity.placeName);
            unitsScrollviewCopy.transform.SetParent(unitsScrollviewLayout.transform);
            unitsScrollviewCopy.SetContent(new List <Unit>(), CycleUnit);
            scrollviewCityPairs.Add(new ScrollviewCityPair(neighboringCity, unitsScrollviewCopy));
        }
    }
예제 #6
0
    /// <summary>
    /// Creates two scrollviews, one for each camp on the city.
    /// Creates two other scrollviews for the cities the road connects.
    /// </summary>
    void CreateAttackFromRoadScrollviews(Road selectedRoad)
    {
        print("City1: " + selectedRoad.city1.placeName);
        print("City2: " + selectedRoad.city2.placeName);

        /// Clear any existing scrollviews
        DestroyAllScrollviews();

        /// Creates a scrollview for the units camped near the first city

        UnitsScrollview city1CampSv = UnitsScrollview.Instantiate <UnitsScrollview>(unitsScrollviewPrefab);

        city1CampSv.AddTitle("Camp near " + selectedRoad.city1.placeName);
        city1CampSv.transform.SetParent(unitsScrollviewLayout.transform);

        // Fill the city 1 camp scrollview
        // Copy units to a new list to prevent overriding values
        // TODO: Create "CycleRoadUnit" method instead of basic "CycleUnit" method.
        city1CampSv.SetContent(new List <Unit>(selectedRoad.GetEncampedUnits(selectedRoad.city1)), CycleRoadUnit);
        scrollviewPairs.Add(new ScrollviewPair(selectedRoad.city1, city1CampSv));

        // Create empty scrollviews for the first city
        // Units chosen to attack will populate the scrollview
        UnitsScrollview city1AttackingUnitsSv = UnitsScrollview.Instantiate <UnitsScrollview>(unitsScrollviewPrefab);

        city1AttackingUnitsSv.AddTitle("Attack " + selectedRoad.city1.placeName);
        city1AttackingUnitsSv.transform.SetParent(unitsScrollviewLayout.transform);
        city1AttackingUnitsSv.SetContent(new List <Unit>(), CycleRoadUnit);
        scrollviewPairs.Add(new ScrollviewPair(selectedRoad.city1, city1AttackingUnitsSv));

        // Repeat process for the second city
        // This ensures the "camp" and "attacking" scrollviews will be next to each other
        UnitsScrollview city2CampSv = UnitsScrollview.Instantiate <UnitsScrollview>(unitsScrollviewPrefab);

        city2CampSv.AddTitle("Camp near " + selectedRoad.city2.placeName);
        city2CampSv.transform.SetParent(unitsScrollviewLayout.transform);
        city2CampSv.SetContent(new List <Unit>(selectedRoad.GetEncampedUnits(selectedRoad.city2)), CycleRoadUnit);
        scrollviewPairs.Add(new ScrollviewPair(selectedRoad.city2, city2CampSv));

        UnitsScrollview city2AttackingUnitsSv = UnitsScrollview.Instantiate <UnitsScrollview>(unitsScrollviewPrefab);

        city2AttackingUnitsSv.AddTitle("Attack " + selectedRoad.city2.placeName);
        city2AttackingUnitsSv.transform.SetParent(unitsScrollviewLayout.transform);
        city2AttackingUnitsSv.SetContent(new List <Unit>(), CycleRoadUnit);
        scrollviewPairs.Add(new ScrollviewPair(selectedRoad.city2, city2AttackingUnitsSv));

        // Pair the scrollviews
        city1ScrollviewPair = new RoadScrollviewPair(city1AttackingUnitsSv, city1CampSv);
        city2ScrollviewPair = new RoadScrollviewPair(city2AttackingUnitsSv, city2CampSv);
    }
예제 #7
0
    private void InitializeFriendlyUnitList(City city)
    {
        /// Instantiate a new UnitScrollview widget
        UnitsScrollview scrollview = friendlyUnitsList.GetComponent <UnitsScrollview>();

        /// Set the unit scrollview title.
        scrollview.AddTitle("Occupying Units");

        /// Add the units and provide logic for what should be done whenever the
        /// individual unit is clicked.
        scrollview.SetContent(city.occupyingUnits, (Unit u) =>
        {
            GameManager.instance.SelectUnit(u);
        });
    }
예제 #8
0
 public ScrollviewCityPair(City city, UnitsScrollview scrollview)
 {
     this.city       = city;
     this.scrollview = scrollview;
 }
예제 #9
0
 public RoadScrollviewPair(UnitsScrollview attackingUnitsScrollview, UnitsScrollview campScrollview)
 {
     this.attackingUnitsScrollview = attackingUnitsScrollview;
     this.campScrollview           = campScrollview;
 }
예제 #10
0
 public ScrollviewPair(Place city, UnitsScrollview scrollview)
 {
     this.place      = city;
     this.scrollview = scrollview;
 }