Exemplo n.º 1
0
 public void OnTerminalSelected(int index)
 {
     if (index < 1)
     {
         _window.ArrivalTerminalSelected(null);
         _selectedTerminal = null;
         VesselLabel.text  = "-";
         SeatsLabel.text   = "0 / 0";
     }
     else
     {
         var option   = TerminalsDropdown.options[index] as DropdownOptionWithId;
         var terminal = _terminals[option.Id];
         _selectedTerminal = terminal;
         _window.ArrivalTerminalSelected(terminal);
     }
 }
Exemplo n.º 2
0
        public void ShowTerminals(List <ArrivalMetadata> terminals)
        {
            var dropdownOptions = new List <Dropdown.OptionData>
            {
                new DropdownOptionWithId
                {
                    text = "Select a terminal...",
                    Id   = "0",
                },
            };

            if (_terminals.Count > 0 && (terminals == null || terminals.Count < 1))
            {
                // Terminals no longer in range, so reset everything
                TerminalsDropdown.ClearOptions();
                TerminalsDropdown.AddOptions(dropdownOptions);
                TerminalsDropdown.SetValueWithoutNotify(0);
                TerminalsDropdown.RefreshShownValue();
                _selectedTerminal = null;
                VesselLabel.text  = "-";
                SeatsLabel.text   = "0 / 0";
                _terminals.Clear();
            }
            else if (_terminals.Count < 1)
            {
                // First time setup for the terminal dropdown
                foreach (var terminal in terminals)
                {
                    dropdownOptions.Add(new DropdownOptionWithId
                    {
                        text = $"{terminal.VesselName} ({terminal.TerminalId.Substring(0, 6)})",
                        Id   = terminal.TerminalId,
                    });
                    _terminals.Add(terminal.TerminalId, terminal);
                }
                TerminalsDropdown.ClearOptions();
                TerminalsDropdown.AddOptions(dropdownOptions);
                TerminalsDropdown.RefreshShownValue();
            }
            else
            {
                // Add new terminals to the dropdown if there are any
                dropdownOptions.Clear();
                foreach (var terminal in terminals)
                {
                    if (!_terminals.ContainsKey(terminal.TerminalId))
                    {
                        dropdownOptions.Add(new DropdownOptionWithId
                        {
                            text = $"{terminal.VesselName} ({terminal.TerminalId.Substring(0, 6)})",
                            Id   = terminal.TerminalId,
                        });
                        _terminals.Add(terminal.TerminalId, terminal);
                    }
                    else
                    {
                        _terminals[terminal.TerminalId] = terminal;
                    }
                }
                if (dropdownOptions.Count > 0)
                {
                    TerminalsDropdown.AddOptions(dropdownOptions);
                    if (_selectedTerminal != null)
                    {
                        var terminalId = _selectedTerminal.TerminalId;
                        var idx        = TerminalsDropdown.options
                                         .FindIndex(t => (t as DropdownOptionWithId).Id == terminalId);
                        if (idx < 1)
                        {
                            _selectedTerminal = null;
                            TerminalsDropdown.SetValueWithoutNotify(0);
                            VesselLabel.text = "-";
                            SeatsLabel.text  = "0 / 0";
                        }
                        else
                        {
                            TerminalsDropdown.SetValueWithoutNotify(idx);
                        }
                        TerminalsDropdown.RefreshShownValue();
                    }
                }
                if (_selectedTerminal != null)
                {
                    _selectedTerminal = _terminals[_selectedTerminal.TerminalId];
                    var availableSeats = Math.Max(0, _selectedTerminal.TotalSeats - _selectedTerminal.OccupiedSeats);
                    VesselLabel.text
                                    = $"{_selectedTerminal.VesselName} ({_selectedTerminal.TerminalId.Substring(0, 6)})";
                    SeatsLabel.text = $"{availableSeats} / {_selectedTerminal.TotalSeats}";
                }
            }
        }
Exemplo n.º 3
0
 public void ArrivalTerminalSelected(ArrivalMetadata terminal)
 {
     _controller.ArrivalTerminalSelected(terminal);
 }