Exemplo n.º 1
0
 public void ShowPassengers(List <PassengerMetadata> passengers)
 {
     if (passengers == null || passengers.Count < 1)
     {
         _window.ShowAlert(_labels.NoKerbalsToBoardMessage);
     }
     else
     {
         if (_passengers.Count < 1)
         {
             for (int i = 0; i < passengers.Count; i++)
             {
                 var passenger = passengers[i];
                 var panel     = _prefabInstantiator
                                 .InstantiatePrefab <KerbalSelector>(PassengersList);
                 panel.Initialize(this, passenger);
                 panel.Toggle.interactable = _flight.Status != FlightStatus.Enroute;
                 _passengers.Add(passenger.Name, panel);
             }
         }
         else
         {
             var passengerNames = passengers.Select(p => p.Name);
             var kerbals        = _passengers.Keys.ToArray();
             for (int i = 0; i < kerbals.Length; i++)
             {
                 var kerbal = kerbals[i];
                 if (!passengerNames.Contains(kerbal))
                 {
                     var panel = _passengers[kerbal];
                     _passengers.Remove(kerbal);
                     Destroy(panel);
                 }
             }
             for (int i = 0; i < passengers.Count; i++)
             {
                 var passenger = passengers[i];
                 if (!_passengers.ContainsKey(passenger.Name))
                 {
                     var panel = _prefabInstantiator
                                 .InstantiatePrefab <KerbalSelector>(PassengersList);
                     panel.Initialize(this, passenger);
                     panel.Toggle.interactable = _flight.Status != FlightStatus.Enroute;
                     _passengers.Add(passenger.Name, panel);
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
        public void ShowWarnings(List <WarningMetadata> warnings)
        {
            if ((warnings == null || warnings.Count < 1) && _warnings.Count > 0)
            {
                foreach (var warning in _warnings)
                {
                    if (warning.Value.gameObject.activeSelf)
                    {
                        warning.Value.gameObject.SetActive(false);
                    }
                }
                DisembarkButton.interactable = true;
            }
            else
            {
                // We'll cache warning prefabs so we don't have to reinstantiate them
                //  which means we need to do some extra checks to turn on/off previously
                //  instantiated warnings and create new prefabs if necessary
                var preventAction = false;
                foreach (var warning in warnings)
                {
                    preventAction |= warning.PreventsAction;
                    if (_warnings.ContainsKey(warning.Message))
                    {
                        if (!_warnings[warning.Message].gameObject.activeSelf)
                        {
                            _warnings[warning.Message].gameObject.SetActive(true);
                        }
                    }
                    else
                    {
                        var panel = _prefabInstantiator
                                    .InstantiatePrefab <WarningPanel>(WarningsList);
                        panel.Initialize(warning);
                        _warnings.Add(warning.Message, panel);
                    }
                }

                DisembarkButton.interactable = !preventAction;

                // Disable warnings that should no longer be displayed
                var warningMessages = warnings.Select(w => w.Message);
                foreach (var warning in _warnings)
                {
                    if (!warningMessages.Contains(warning.Key) &&
                        warning.Value.gameObject.activeSelf)
                    {
                        warning.Value.gameObject.SetActive(false);
                    }
                }
            }
        }
 public void UpdateResources()
 {
     if (_shipMetadata == null || _prefabInstantiator == null)
     {
         return;
     }
     for (int i = 0; i < _shipMetadata.KonstructorMetadata.Resources.Count; i++)
     {
         var resource = _shipMetadata.KonstructorMetadata.Resources[i];
         if (!_resourcePanels.ContainsKey(resource.Name))
         {
             var prefab = _prefabInstantiator
                          .InstantiatePrefab <RequiredResourcePanel>(ResourcesPanel.transform);
             _resourcePanels.Add(resource.Name, prefab);
         }
         var panel = _resourcePanels[resource.Name];
         panel.SetValues(resource);
     }
 }
Exemplo n.º 4
0
        public void ShowFlights(List <FlightMetadata> flights)
        {
            if (flights != null && flights.Count > 0)
            {
                // Setup filtering dropdowns
                foreach (var flight in flights)
                {
                    if (_departures.ContainsKey(flight.DepartureBody))
                    {
                        var departureBiomes = _departures[flight.DepartureBody];
                        if (!departureBiomes.Contains(flight.DepartureBiome))
                        {
                            departureBiomes.Add(flight.DepartureBiome);
                        }
                    }
                    else
                    {
                        var departureBiomes = new List <string> {
                            flight.DepartureBiome
                        };
                        _departures.Add(flight.DepartureBody, departureBiomes);
                    }
                    if (_arrivals.ContainsKey(flight.ArrivalBody))
                    {
                        var arrivalBiomes = _arrivals[flight.ArrivalBody];
                        if (!arrivalBiomes.Contains(flight.ArrivalBiome))
                        {
                            arrivalBiomes.Add(flight.ArrivalBiome);
                        }
                    }
                    else
                    {
                        var arrivalBiomes = new List <string> {
                            flight.ArrivalBiome
                        };
                        _arrivals.Add(flight.ArrivalBody, arrivalBiomes);
                    }
                }
                UpdateDropdowns();

                // Create UI panels for each flight
                if (_flights.Count < 1)
                {
                    for (int i = 0; i < flights.Count; i++)
                    {
                        var flight = flights[i];
                        var panel  = _prefabInstantiator
                                     .InstantiatePrefab <FlightSelector>(FlightsList);
                        panel.Initialize(this, _controller.FlightSelectorLabels);
                        panel.ShowFlight(flight);
                        _flights.Add(flight.UniqueId, panel);
                    }
                }
                else
                {
                    var existingFlightIds = _flights.Keys.ToArray();
                    var incomingFlightIds = flights.Select(f => f.UniqueId);
                    for (int i = 0; i < existingFlightIds.Length; i++)
                    {
                        var flightId = existingFlightIds[i];
                        if (!incomingFlightIds.Contains(flightId))
                        {
                            var panel = _flights[flightId];
                            _flights.Remove(flightId);
                            Destroy(panel);
                        }
                    }
                    for (int i = 0; i < flights.Count; i++)
                    {
                        var flight = flights[i];
                        if (!_flights.ContainsKey(flight.UniqueId))
                        {
                            var panel = _prefabInstantiator
                                        .InstantiatePrefab <FlightSelector>(FlightsList);
                            panel.Initialize(this, _controller.FlightSelectorLabels);
                            panel.ShowFlight(flight);
                            _flights.Add(flight.UniqueId, panel);
                        }
                        else
                        {
                            var panel = _flights[flight.UniqueId];
                            panel.ShowFlight(flight);
                            if (_selectedFlight != null && _selectedFlight.UniqueId == flight.UniqueId)
                            {
                                if (_selectedFlight.Status != flight.Status)
                                {
                                    // Status changed since the last update, so refresh the panels
                                    FlightSelected(flight, true);
                                }
                                SelectedFlightPanel.ShowFlight(flight);
                                if (flight.Status == FlightStatus.Enroute)
                                {
                                    EnroutePanel.ShowArrivalTime(flight.Duration);
                                }
                            }
                        }
                    }
                }
                // Toggle panels based on filtering options
                foreach (var panel in _flights.Values)
                {
                    var isArrivalBody = string.IsNullOrEmpty(_filterArrivalBody) ||
                                        panel.Flight.ArrivalBody == _filterArrivalBody;
                    var isArrivalBiome = string.IsNullOrEmpty(_filterArrivalBiome) ||
                                         panel.Flight.ArrivalBiome == _filterArrivalBiome;
                    var isDepartureBody = string.IsNullOrEmpty(_filterDepartureBody) ||
                                          panel.Flight.DepartureBody == _filterDepartureBody;
                    var isDepartureBiome = string.IsNullOrEmpty(_filterDepartureBiome) ||
                                           panel.Flight.DepartureBiome == _filterDepartureBiome;
                    var isOn = isArrivalBody && isArrivalBiome && isDepartureBody && isDepartureBiome;
                    if (_selectedFlight != null && _selectedFlight.UniqueId == panel.Flight.UniqueId && !isOn)
                    {
                        FlightSelected(_selectedFlight, false);
                    }
                    ToggleFlightPanel(panel, isOn);
                }
            }
        }
        private void UpdateResources(float deltaTime = 0f, bool targetChanged = true)
        {
            if (_transferTargetA == null || _transferTargetB == null)
            {
                HideRow(Row2);
            }
            else if (_transferTargetA.Id == _transferTargetB.Id)
            {
                HideRow(Row2);
                ShowAlert(_transferTargetsController.SameVesselSelectedMessage);
            }
            else
            {
                ShowRow(Row2);
                var transferControllers = _transferTargetsController
                                          .GetResourceTransferControllers(_transferTargetA, _transferTargetB);

                if (targetChanged)
                {
                    HideAlert();
                    ClearResourcePanels();
                    _transferControllers = transferControllers;

                    foreach (var controller in transferControllers)
                    {
                        var panel = _prefabInstantiator
                                    .InstantiatePrefab <ResourceTransferPanel>(ResourcesPanel.transform);
                        controller.Value.SetPanel(panel);
                        panel.Initialize(controller.Value);
                        _resourcePanels.Add(controller.Key, panel);
                    }
                }
                else
                {
                    // Kill off any resource controllers that no longer exist
                    var newResources = transferControllers.Keys;
                    foreach (var controller in _transferControllers)
                    {
                        if (!newResources.Contains(controller.Key))
                        {
                            _transferControllers.Remove(controller.Key);
                            Destroy(_resourcePanels[controller.Key].gameObject);
                            _resourcePanels.Remove(controller.Key);
                        }
                    }
                    // Update resource displays and transfers and add any new controllers
                    var existingResources = _transferControllers.Keys;
                    foreach (var controller in transferControllers)
                    {
                        if (existingResources.Contains(controller.Key))
                        {
                            _transferControllers[controller.Key].Update(deltaTime);
                        }
                        else
                        {
                            var panel = _prefabInstantiator
                                        .InstantiatePrefab <ResourceTransferPanel>(ResourcesPanel.transform);
                            controller.Value.SetPanel(panel);
                            panel.Initialize(controller.Value);
                            _resourcePanels.Add(controller.Key, panel);
                            _transferControllers.Add(controller.Key, controller.Value);
                        }
                    }
                }
            }
        }