Example #1
0
        /// <summary>Is called once by the main renderer loop, in order to render all overlays shown on the screen</summary>
        /// <param name="TimeElapsed">The time elapsed since the last call to this function</param>
        internal void Render(double TimeElapsed)
        {
            //Initialize openGL
            renderer.SetBlendFunc();
            GL.Enable(EnableCap.Blend);
            renderer.PushMatrix(MatrixMode.Projection);
            Matrix4D.CreateOrthographicOffCenter(0.0f, renderer.Screen.Width, renderer.Screen.Height, 0.0f, -1.0f, 1.0f, out renderer.CurrentProjectionMatrix);
            renderer.PushMatrix(MatrixMode.Modelview);
            renderer.CurrentViewMatrix = Matrix4D.Identity;

            //Check which overlays to show
            switch (renderer.CurrentOutputMode)
            {
            case OutputMode.Default:

                //Route info overlay (if selected)
                Game.routeInfoOverlay.Show();

                //HUD
                foreach (HUD.Element element in HUD.CurrentHudElements)
                {
                    switch (element.Subject.ToLowerInvariant())
                    {
                    case "messages":
                        RenderGameMessages(element, TimeElapsed);
                        break;

                    case "scoremessages":
                        RenderScoreMessages(element, TimeElapsed);
                        break;

                    case "ats":
                        RenderATSLamps(element, TimeElapsed);
                        break;

                    default:
                        RenderHUDElement(element, TimeElapsed);
                        break;
                    }
                }

                //Marker textures
                if (Interface.CurrentOptions.GameMode != GameMode.Expert)
                {
                    double y = 8.0;

                    foreach (Texture t in renderer.Marker.MarkerTextures)
                    {
                        if (Program.CurrentHost.LoadTexture(t, OpenGlTextureWrapMode.ClampClamp))
                        {
                            double w = t.Width;
                            double h = t.Height;
                            renderer.Rectangle.Draw(t, new OpenBveApi.Math.Vector2(renderer.Screen.Width - w - 8.0, y), new Vector2(w, h), Color128.White);
                            y += h + 8.0;
                        }
                    }
                }

                //Timetable overlay
                //NOTE: Only affects auto-generated timetable, possibly change this inconsistant behaviour
                if (Program.Renderer.CurrentTimetable == DisplayedTimetable.Default)
                {
                    // default
                    if (Program.CurrentHost.LoadTexture(Timetable.DefaultTimetableTexture, OpenGlTextureWrapMode.ClampClamp))
                    {
                        int w = Timetable.DefaultTimetableTexture.Width;
                        int h = Timetable.DefaultTimetableTexture.Height;
                        renderer.Rectangle.Draw(Timetable.DefaultTimetableTexture, new OpenBveApi.Math.Vector2(renderer.Screen.Width - w, Timetable.DefaultTimetablePosition), new Vector2(w, h), Color128.White);
                    }
                }
                else if (Program.Renderer.CurrentTimetable == DisplayedTimetable.Custom & Timetable.CustomObjectsUsed == 0)
                {
                    // custom
                    if (Program.CurrentHost.LoadTexture(Timetable.CurrentCustomTimetableDaytimeTexture, OpenGlTextureWrapMode.ClampClamp))
                    {
                        int w = Timetable.CurrentCustomTimetableDaytimeTexture.Width;
                        int h = Timetable.CurrentCustomTimetableDaytimeTexture.Height;
                        renderer.Rectangle.Draw(Timetable.CurrentCustomTimetableDaytimeTexture, new OpenBveApi.Math.Vector2(renderer.Screen.Width - w, Timetable.CustomTimetablePosition), new Vector2(w, h), Color128.White);
                    }

                    if (Program.CurrentHost.LoadTexture(Timetable.CurrentCustomTimetableDaytimeTexture, OpenGlTextureWrapMode.ClampClamp))
                    {
                        int   w = Timetable.CurrentCustomTimetableDaytimeTexture.Width;
                        int   h = Timetable.CurrentCustomTimetableDaytimeTexture.Height;
                        float alpha;

                        if (Timetable.CurrentCustomTimetableDaytimeTexture != null)
                        {
                            double t = (TrainManager.PlayerTrain.Cars[TrainManager.PlayerTrain.DriverCar].TrackPosition - TrainManager.PlayerTrain.Cars[TrainManager.PlayerTrain.DriverCar].Brightness.PreviousTrackPosition) / (TrainManager.PlayerTrain.Cars[TrainManager.PlayerTrain.DriverCar].Brightness.NextTrackPosition - TrainManager.PlayerTrain.Cars[TrainManager.PlayerTrain.DriverCar].Brightness.PreviousTrackPosition);
                            alpha = (float)((1.0 - t) * TrainManager.PlayerTrain.Cars[TrainManager.PlayerTrain.DriverCar].Brightness.PreviousBrightness + t * TrainManager.PlayerTrain.Cars[TrainManager.PlayerTrain.DriverCar].Brightness.NextBrightness);
                        }
                        else
                        {
                            alpha = 1.0f;
                        }

                        renderer.Rectangle.Draw(Timetable.CurrentCustomTimetableDaytimeTexture, new OpenBveApi.Math.Vector2(renderer.Screen.Width - w, Timetable.CustomTimetablePosition), new Vector2(w, h), new Color128(1.0f, 1.0f, 1.0f, alpha));
                    }
                }
                break;

            case OutputMode.Debug:
                RenderDebugOverlays();
                break;

            case OutputMode.DebugATS:
                RenderATSDebugOverlay();
                break;
            }

            // air brake debug output
            if (Interface.CurrentOptions.GameMode != GameMode.Expert & renderer.OptionBrakeSystems)
            {
                RenderBrakeSystemDebug();
            }

            switch (Program.Renderer.CurrentInterface)
            {
            case InterfaceType.Pause:
            {
                //If paused, fade out the screen & write PAUSE
                renderer.Rectangle.Draw(null, Vector2.Null, new Vector2(renderer.Screen.Width, renderer.Screen.Height), new Color128(0.0f, 0.0f, 0.0f, 0.5f));
                renderer.OpenGlString.Draw(renderer.Fonts.VeryLargeFont, Translations.GetInterfaceString("menu_pause_title"), new Point(renderer.Screen.Width / 2, renderer.Screen.Height / 2), TextAlignment.CenterMiddle, Color128.White, true);
                if (Interface.CurrentOptions.ScreenReaderAvailable && !PauseAnnounced)
                {
                    if (!Tolk.Output(Translations.GetInterfaceString("menu_pause_title")))
                    {
                        Interface.CurrentOptions.ScreenReaderAvailable = false;
                    }
                    PauseAnnounced = true;
                }
                break;
            }

            case InterfaceType.Menu:
                Game.Menu.Draw();
                PauseAnnounced = false;
                break;

            default:
                PauseAnnounced = false;
                break;
            }

            //Fade to black on change ends
            if (TrainManager.PlayerTrain != null)
            {
                if (TrainManager.PlayerTrain.Station >= 0 && Program.CurrentRoute.Stations[TrainManager.PlayerTrain.Station].Type == StationType.ChangeEnds && TrainManager.PlayerTrain.StationState == TrainStopState.Boarding)
                {
                    double time = TrainManager.PlayerTrain.StationDepartureTime - Program.CurrentRoute.SecondsSinceMidnight;
                    if (time < 1.0)
                    {
                        FadeToBlackDueToChangeEnds = Math.Max(0.0, 1.0 - time);
                    }
                    else if (FadeToBlackDueToChangeEnds > 0.0)
                    {
                        FadeToBlackDueToChangeEnds -= TimeElapsed;
                        if (FadeToBlackDueToChangeEnds < 0.0)
                        {
                            FadeToBlackDueToChangeEnds = 0.0;
                        }
                    }
                }
                else if (FadeToBlackDueToChangeEnds > 0.0)
                {
                    FadeToBlackDueToChangeEnds -= TimeElapsed;
                    if (FadeToBlackDueToChangeEnds < 0.0)
                    {
                        FadeToBlackDueToChangeEnds = 0.0;
                    }
                }
                if (FadeToBlackDueToChangeEnds > 0.0 & (renderer.Camera.CurrentMode == CameraViewMode.Interior | renderer.Camera.CurrentMode == CameraViewMode.InteriorLookAhead))
                {
                    renderer.Rectangle.Draw(null, Vector2.Null, new Vector2(renderer.Screen.Width, renderer.Screen.Height), new Color128(0.0f, 0.0f, 0.0f, (float)FadeToBlackDueToChangeEnds));
                }
            }

            // finalize
            renderer.PopMatrix(MatrixMode.Projection);
            renderer.PopMatrix(MatrixMode.Modelview);
        }
        private void GageValueTextBox_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                var apGage = GageComboBox.SelectedItem.ToString();
                switch (apGage)
                {
                case "Air speed":
                    if (Double.TryParse(GageValueTextBox.Text, out double airSpeed) && airSpeed > 0)
                    {
                        Autopilot.ApAirspeed  = airSpeed;
                        GageValueTextBox.Text = Autopilot.ApAirspeed.ToString();
                    }
                    else
                    {
                        GageValueTextBox.Text = string.Empty;
                        Tolk.Output("Invalid air speed");
                    }
                    break;

                case "Vertical speed":
                    if (Double.TryParse(GageValueTextBox.Text, out double verticalSpeed))
                    {
                        Autopilot.ApVerticalSpeed = verticalSpeed;
                        GageValueTextBox.Text     = Autopilot.ApVerticalSpeed.ToString();
                    }
                    else
                    {
                        GageValueTextBox.Text = string.Empty;
                        Tolk.Output("Invalid vertical speed");
                    }
                    break;

                case "Mach":
                    if (Double.TryParse(GageValueTextBox.Text, out double machSpeed))
                    {
                        Autopilot.ApMachSpeed = machSpeed;
                        GageValueTextBox.Text = Autopilot.ApMachSpeed.ToString();
                    }
                    else
                    {
                        GageValueTextBox.Text = string.Empty;
                        Tolk.Output("Invalid mach speed");
                    }
                    break;

                case "Altitude":
                    if (Double.TryParse(GageValueTextBox.Text, out double altitude))
                    {
                        Autopilot.ApAltitude  = altitude;
                        GageValueTextBox.Text = Autopilot.ApAltitude.ToString();
                    }
                    else
                    {
                        GageValueTextBox.Text = string.Empty;
                        Tolk.Output("Invalid altitude.");
                    }
                    break;

                case "Heading":
                    if (Double.TryParse(GageValueTextBox.Text, out Double heading) && heading <= 359)
                    {
                        Autopilot.ApHeading   = heading;
                        GageValueTextBox.Text = Autopilot.ApHeading.ToString();
                    }
                    else
                    {
                        GageValueTextBox.Text = string.Empty;
                        Tolk.Output("Invalid heading.");
                    }
                    break;

                case "Com 1":
                    if (Decimal.TryParse(GageValueTextBox.Text, out decimal com1))
                    {
                        Autopilot.Com1Freq    = com1;
                        GageValueTextBox.Text = Autopilot.Com1Freq.ToString();
                    }
                    else
                    {
                        GageValueTextBox.Text = string.Empty;
                        Tolk.Output("Invalid frequency.");
                    }
                    break;

                case "Com 2":
                    if (Decimal.TryParse(GageValueTextBox.Text, out decimal com2))
                    {
                        Autopilot.Com2Freq    = com2;
                        GageValueTextBox.Text = Autopilot.Com2Freq.ToString();
                    }
                    else
                    {
                        GageValueTextBox.Text = string.Empty;
                        Tolk.Output("Invalid frequency.");
                    }
                    break;

                case "Transponder":
                    if (int.TryParse(GageValueTextBox.Text, out int transponder) && transponder < 9999)
                    {
                        Autopilot.Transponder = transponder;
                        GageValueTextBox.Text = Autopilot.Transponder.ToString();
                    }
                    else
                    {
                        GageValueTextBox.Text = string.Empty;
                        Tolk.Output("Invalid transponder number.");
                    }
                    break;

                case "Altimeter [inches]":
                    if (Double.TryParse(GageValueTextBox.Text, out double altimeterInches))
                    {
                        Autopilot.AltimeterInches = altimeterInches;
                        GageValueTextBox.Text     = Autopilot.AltimeterInches.ToString();
                    }
                    else
                    {
                        GageValueTextBox.Text = string.Empty;
                        Tolk.Output("Invalid altimeter value.");
                    }
                    break;

                case "Altimeter [QNH]":
                    if (double.TryParse(GageValueTextBox.Text, out double altimeterQNH))
                    {
                        Autopilot.AltimeterQNH = altimeterQNH;
                        GageValueTextBox.Text  = Autopilot.AltimeterQNH.ToString();
                    }
                    else
                    {
                        GageValueTextBox.Text = string.Empty;
                        Tolk.Output("Invalid altimeter value.");
                    }
                    break;

                case "Nav 1":
                    if (Decimal.TryParse(GageValueTextBox.Text, out decimal nav1))
                    {
                        Autopilot.Nav1Freq    = nav1;
                        GageValueTextBox.Text = Autopilot.Nav1Freq.ToString();
                    }
                    else
                    {
                        GageValueTextBox.Text = string.Empty;
                        GageValueTextBox.Text = Autopilot.Nav1Freq.ToString();
                    }
                    break;

                case "Nav 2":
                    if (Decimal.TryParse(GageValueTextBox.Text, out decimal nav2))
                    {
                        Autopilot.Nav2Freq    = nav2;
                        GageValueTextBox.Text = Autopilot.Nav2Freq.ToString();
                    }
                    else
                    {
                        GageValueTextBox.Text = string.Empty;
                        Tolk.Output("Invalid frequency.");
                    }
                    break;

                case "ADF":
                    if (Decimal.TryParse(GageValueTextBox.Text, out decimal adf))
                    {
                        Autopilot.Adf1Freq    = adf;
                        GageValueTextBox.Text = Autopilot.Adf1Freq.ToString();
                    }
                    else
                    {
                        GageValueTextBox.Text = string.Empty;
                        Tolk.Output("Invalid frequency.");
                    }
                    break;

                case "default":
                    break;
                }
                e.Handled          = true;
                e.SuppressKeyPress = true;
            } //End apGage input.
        }                                //End sending data to the simulator.
        protected void onScreenReaderOutput(object sender, ScreenReaderOutputEventArgs e)
        {
            // We can do anything we want since the gage/value are broken up into different variables now.
            // The event should take care of anything the screen reader needs to output to the user.

            // when e.isGage is true, e.output is empty.
            // Otherwise, e.output should contain a string to send to the screen reader.
            // EX: the next waypoint feature is inappropriate for e.gageName and e.gageValue, so e.isGage will be false, and e.output will have the output for the next waypoint.

            if (e.isGauge)
            {
                switch (e.gaugeName)
                {
                case "Vertical speed":
                    // We can implement different settings here. One of them is braille support.
                    // After including a braille only, speech only, or both setting,
                    // All we need to do is check for the setting and respond to it.
                    // Braile, speech, and output can have different output without toying with the backend code.
                    // This also makes way for message type: short or long. A pilot might not want
                    // to hear "feet per minute" every time he/she presses ]v, so, give them a choice.
                    // That setting would be checked here because it influences screen reader/braille output.
                    // The log may also contain different formatting options. For now, stick with
                    // reasonable defaults.

                    speak($"{e.gaugeValue} feet per minute.");
                    braille($"VSPD {e.gaugeValue}\n");
                    history.AddItem($"{e.gaugeName}: {e.gaugeValue}\n");

                    break;

                case "Outside temperature":
                    speak($"{e.gaugeValue} degrees");
                    braille($"temp {e.gaugeValue}\n");
                    history.AddItem($"{e.gaugeName}: {e.gaugeValue}\n");
                    break;

                case "ASL altitude":
                    speak($"{e.gaugeValue} feet ASL.");
                    braille($"ASL  {e.gaugeValue}\n");
                    history.AddItem($"{e.gaugeName}: {e.gaugeValue}\n");
                    break;

                case "AGL altitude":
                    speak($"{e.gaugeValue} feet AGL.");
                    braille($"AGL {e.gaugeValue}\n");
                    history.AddItem($"{e.gaugeName}: {e.gaugeValue}\n");
                    break;

                case "Airspeed true":
                    speak($"{e.gaugeValue} knotts true");
                    braille($"TAS {e.gaugeValue}\n");
                    history.AddItem($"{e.gaugeName}: {e.gaugeValue}\n");
                    break;

                case "Airspeed indicated":
                    speak($"{e.gaugeValue} knotts indicated");
                    braille($"IAS {e.gaugeValue}\n");
                    history.AddItem($"{e.gaugeName}: {e.gaugeValue}\n");
                    break;

                case "Ground speed":
                    speak($"{e.gaugeValue} knotts ground speed");
                    braille($"{e.gaugeName}: {e.gaugeValue}\n");
                    history.AddItem($"gnd: {e.gaugeValue}\n");
                    break;

                case "Mach":
                    speak($"Mach {e.gaugeValue}. ");
                    braille($"mach{e.gaugeValue}\n");
                    history.AddItem($"{e.gaugeName}: {e.gaugeValue}\n");
                    break;

                case "Localiser":
                    speak($"{e.gaugeValue}. ", useSAPI: true);
                    braille($"loc {e.gaugeValue}\n");
                    break;

                case "Glide slope":
                    speak($"{e.gaugeValue}. ", useSAPI: true);
                    braille($"gs {e.gaugeValue}\n");
                    break;

                case "Altimeter":
                    speak($"{e.gaugeName}: {e.gaugeValue}. ");
                    braille($"{e.gaugeName}: {e.gaugeValue}\n");
                    history.AddItem($"{e.gaugeName}: {e.gaugeValue}\n");
                    break;

                case "Flaps":
                    speak($"{e.gaugeName} {e.gaugeValue}. ");
                    braille($"{e.gaugeName} {e.gaugeValue}\n");
                    history.AddItem($"{e.gaugeName}: {e.gaugeValue}\n");
                    break;

                case "Gear":
                    speak($"{e.gaugeName} {e.gaugeValue}. ");
                    braille($"{e.gaugeName}: {e.gaugeValue}\n");
                    history.AddItem($"{e.gaugeName}: {e.gaugeValue}\n");
                    break;

                case "AP heading":
                    speak($"heading {e.gaugeValue}. ");
                    braille($"hdg: {e.gaugeValue}\n");
                    history.AddItem($"{e.gaugeName}: {e.gaugeValue}\n");
                    break;

                case "AP airspeed":
                    speak($"{e.gaugeValue} knotts. ");
                    braille($"{e.gaugeName}: {e.gaugeValue}\n");
                    history.AddItem($"{e.gaugeName}: {e.gaugeValue}\n");
                    break;

                case "AP mach":
                    speak($"Mach {e.gaugeValue}");
                    braille($"{e.gaugeName}: {e.gaugeValue}\n");
                    history.AddItem($"{e.gaugeName}: {e.gaugeValue}\n");
                    break;

                case "AP vertical speed":
                    speak($"{e.gaugeValue} feet per minute. ");
                    braille($"{e.gaugeValue} FPM\n");
                    history.AddItem($"{e.gaugeName}: {e.gaugeValue}\n");
                    break;

                case "AP altitude":
                    speak($"{e.gaugeName}: {e.gaugeValue} feet. ");
                    braille($"{e.gaugeName}: {e.gaugeValue}\n");
                    history.AddItem($"{e.gaugeName}: {e.gaugeValue}\n");
                    break;


                case "Com1":
                    speak($"{e.gaugeName}: {e.gaugeValue}. ");
                    braille($"{e.gaugeName}: {e.gaugeValue}\n");
                    history.AddItem($"{e.gaugeName}: {e.gaugeValue}\n");
                    break;

                case "Com2":
                    speak($"{e.gaugeName}: {e.gaugeValue}. ");
                    braille($"{e.gaugeName}: {e.gaugeValue}\n");
                    history.AddItem($"{e.gaugeName}: {e.gaugeValue}\n");
                    break;

                case "Nav1":
                    speak($"{e.gaugeName}: {e.gaugeValue}. ");
                    braille($"{e.gaugeName}: {e.gaugeValue}\n");
                    history.AddItem($"{e.gaugeName}: {e.gaugeValue}\n");
                    break;

                case "Nav2":
                    speak($"{e.gaugeName}: {e.gaugeValue}. ");
                    braille($"{e.gaugeName}: {e.gaugeValue}\n");
                    history.AddItem($"{e.gaugeName}: {e.gaugeValue}\n");
                    break;

                case "Transponder":
                    speak($"squawk {e.gaugeValue}. ");
                    braille($"Squawk: {e.gaugeValue}\n");
                    history.AddItem($"{e.gaugeName}: {e.gaugeValue}\n");
                    break;



                default:
                    Tolk.Output("Gage or instrument not supported.\n");
                    break;
                }
            } // End gage output.
            else
            {
                if (e.useSAPI == true)
                {
                    speak(useSAPI: true, interruptSpeech:  e.interruptSpeech, output: e.output);
                }
                else
                {
                    speak(e.output, interruptSpeech: e.interruptSpeech);
                }
                if (e.textOutput == true)
                {
                    history.AddItem($"{e.output}\n");
                }
            } // end generic output
        }     // End screenreader output event.
        private void btnOk_Click(object sender, EventArgs e)
        {
            switch (this.instrument)
            {
            case "Altitude":
                if (double.TryParse(txtSetting.Text, out double altitude))
                {
                    ap.ApAltitude     = altitude;
                    ap.ApAltitudeLock = chkLock.Checked;
                    this.DialogResult = DialogResult.OK;
                }
                else
                {
                    Tolk.Output("invalid altitude");
                    txtSetting.Text = string.Empty;
                    txtSetting.Focus();
                }

                break;

            case "Heading":
                if (double.TryParse(txtSetting.Text, out double heading) && heading >= 0 && heading <= 360)
                {
                    ap.ApHeading      = heading;
                    ap.ApHeadingLock  = chkLock.Checked;
                    this.DialogResult = DialogResult.OK;
                }
                else
                {
                    Tolk.Output("invalid heading");
                    txtSetting.Text = string.Empty;
                    txtSetting.Focus();
                }
                break;

            case "Airspeed":
                if (double.TryParse(txtSetting.Text, out double airspeed))
                {
                    ap.ApAirspeed     = airspeed;
                    ap.ApAirspeedHold = chkLock.Checked;
                    this.DialogResult = DialogResult.OK;
                }
                else
                {
                    Tolk.Output("invalid airspeed");
                    txtSetting.Text = string.Empty;
                    txtSetting.Focus();
                }

                break;

            case "Mach":
                if (double.TryParse(txtSetting.Text, out double mach))
                {
                    ap.ApMachSpeed    = mach;
                    ap.ApMachHold     = chkLock.Checked;
                    this.DialogResult = DialogResult.OK;
                }
                else
                {
                    Tolk.Output("invalid mach speed");
                    txtSetting.Text = string.Empty;
                    txtSetting.Focus();
                }

                break;

            case "Vertical speed":
                if (double.TryParse(txtSetting.Text, out double verticalSpeed))
                {
                    ap.ApVerticalSpeed     = verticalSpeed;
                    ap.ApVerticalSpeedHold = chkLock.Checked;
                    this.DialogResult      = DialogResult.OK;
                }
                else
                {
                    Tolk.Output("invalid vertical speed");
                    txtSetting.Text = string.Empty;
                    txtSetting.Focus();
                }

                break;

            case "Transponder":
                if (int.TryParse(txtSetting.Text, out int transponder))
                {
                    ap.Transponder    = transponder;
                    this.DialogResult = DialogResult.OK;
                }
                else
                {
                    Tolk.Output("invalid transponder setting");
                    txtSetting.Text = string.Empty;
                    txtSetting.Focus();
                }

                break;

            case "Throttle":
                if (Double.TryParse(txtSetting.Text, out double thrPercent))
                {
                    if ((0.0 <= thrPercent) && (thrPercent <= 100.0))
                    {
                        ap.Engine1ThrottlePercent = ap.Engine2ThrottlePercent = ap.Engine3ThrottlePercent = ap.Engine4ThrottlePercent = thrPercent;
                        this.DialogResult         = DialogResult.OK;
                    }
                    else
                    {
                        Tolk.Output("Invalid throttle setting. Must be between 0 and 100.");
                        txtSetting.Text = String.Empty;
                        txtSetting.Focus();
                    }
                }
                else
                {
                    Tolk.Output("Invalid throttle setting.");
                    txtSetting.Text = String.Empty;
                    txtSetting.Focus();
                }
                break;

            case "spoilers":
                if (uint.TryParse(txtSetting.Text, out uint spoilerPercent))
                {
                    if ((spoilerPercent == 0) || (spoilerPercent == 1) || (spoilerPercent >= 7 && spoilerPercent <= 100))
                    {
                        ap.SpoilerPercent = spoilerPercent;
                        this.DialogResult = DialogResult.OK;
                    }
                    else
                    {
                        Tolk.Output("Invalid spoiler value.");
                        txtSetting.Text = string.Empty;
                        txtSetting.Focus();
                    }
                }
                else
                {
                    Tolk.Output("Invalid spoiler value.");
                    txtSetting.Text = string.Empty;
                    txtSetting.Focus();
                }
                break;

            case "n1Monitor":
                if (double.TryParse(txtSetting.Text, out double n1MonitorValue) && (n1MonitorValue >= 0) && (n1MonitorValue <= 100))
                {
                    Aircraft.n1MonitorValue = n1MonitorValue;
                    this.DialogResult       = DialogResult.OK;
                }
                else
                {
                    Tolk.Output("Invalid n1 limit. Value is 0 - 100");
                    txtSetting.Text = string.Empty;
                    txtSetting.Focus();
                }
                break;
            }
        }
        }             //End KeyDown event.

        private void GageComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            ComboBox GagesList = (ComboBox)sender;
            var      item      = GagesList.SelectedItem.ToString();

            GageValueTextBox.AccessibleName = "Enter " + item;
            LockGageCheckBox.AccessibleName = item + " lock";
            // Assign the airplane auto pilot gages to the gage value field.
            // See related checked changed events for locks and apMaster switch.

            switch (item)
            {
            case "ADF":
                GageValueTextBox.Text    = Autopilot.Adf1Freq.ToString();
                LockGageCheckBox.Visible = false;
                break;

            case "Air speed":
                GageValueTextBox.Text    = Autopilot.ApAirspeed.ToString();
                LockGageCheckBox.Visible = true;
                LockGageCheckBox.Checked = Autopilot.ApAirspeedHold;
                break;

            case "Vertical speed":
                GageValueTextBox.Text    = Autopilot.ApVerticalSpeed.ToString();
                LockGageCheckBox.Visible = true;
                LockGageCheckBox.Checked = Autopilot.ApVerticalSpeedHold;
                break;

            case "Mach":
                GageValueTextBox.Text    = Autopilot.ApMachSpeed.ToString();
                LockGageCheckBox.Visible = true;
                LockGageCheckBox.Checked = Autopilot.ApMachHold;
                break;

            case "Altitude":
                GageValueTextBox.Text    = Autopilot.ApAltitude.ToString();
                LockGageCheckBox.Visible = true;
                LockGageCheckBox.Checked = Autopilot.ApAltitudeLock;
                break;

            case "Heading":
                GageValueTextBox.Text    = Autopilot.ApHeading.ToString();
                LockGageCheckBox.Visible = true;
                LockGageCheckBox.Checked = Autopilot.ApHeadingLock;
                break;

            case "Com 1":
                GageValueTextBox.Text    = Autopilot.Com1Freq.ToString();
                LockGageCheckBox.Visible = false;
                break;

            case "Com 2":
                GageValueTextBox.Text    = Autopilot.Com2Freq.ToString();
                LockGageCheckBox.Checked = false;
                break;

            case "Transponder":
                GageValueTextBox.Text    = Autopilot.Transponder.ToString();
                LockGageCheckBox.Visible = false;
                break;

            case "Altimeter [inches]":
                GageValueTextBox.Text    = Autopilot.AltimeterInches.ToString();
                LockGageCheckBox.Visible = false;
                break;

            case "Altimeter [QNH]":
                GageValueTextBox.Text    = Autopilot.AltimeterQNH.ToString();
                LockGageCheckBox.Visible = false;
                break;

            case "Nav 1":
                GageValueTextBox.Text    = Autopilot.Nav1Freq.ToString();
                LockGageCheckBox.Visible = true;
                LockGageCheckBox.Checked = Autopilot.ApNavLock;
                break;

            case "Nav 2":
                GageValueTextBox.Text    = Autopilot.Nav2Freq.ToString();
                LockGageCheckBox.Visible = false;
                break;

            case "default":
                GageValueTextBox.Text = "That gage is not supported at this time.";
                break;
            }

            var screenReader = Tolk.DetectScreenReader();

            if (screenReader == "NVDA" && GagesList.DroppedDown == false)
            {
                Tolk.Output(GageValueTextBox.Text + ", " + GagesList.SelectedItem.ToString());
            }
            else
            {
                Tolk.Output(GageValueTextBox.Text);
            }
        } //End gages list selected index change event.
 private void altitudeButton_Click(object sender, EventArgs e)
 {
     PMDG777Aircraft.AltitudeIntervene();
     Tolk.Output("Altitude intervene");
 } // End AltitudeButton_Click.
Example #7
0
            public override void Update()
            {
                //If our message timeout is greater than or equal to the current time, queue it for removal
                bool remove = Program.CurrentRoute.SecondsSinceMidnight >= Timeout;

                switch (Depencency)
                {
                case MessageDependency.AccessibilityHelper:
                case MessageDependency.RouteLimit:
                {
                    double spd = Math.Abs(TrainManager.PlayerTrain.CurrentSpeed);
                    double lim = TrainManager.PlayerTrain.CurrentRouteLimit;
                    //Get the speed and limit in km/h
                    spd    = Math.Round(spd * 3.6);
                    lim    = Math.Round(lim * 3.6);
                    remove = spd <= lim;
                    string s = InternalText, t;
                    if (lim == double.PositiveInfinity)
                    {
                        s = s.Replace("[limit]", "unlimited");
                        s = s.Replace("[unit]", string.Empty);
                    }
                    else
                    {
                        if (Interface.CurrentOptions.SpeedConversionFactor != 0.0)
                        {
                            spd = Math.Round(spd * Interface.CurrentOptions.SpeedConversionFactor);
                            lim = Math.Round(lim * Interface.CurrentOptions.SpeedConversionFactor);
                        }
                        t = spd.ToString(System.Globalization.CultureInfo.InvariantCulture);
                        s = s.Replace("[speed]", t);
                        t = lim.ToString(System.Globalization.CultureInfo.InvariantCulture);
                        s = s.Replace("[limit]", t);
                        s = s.Replace("[unit]", Interface.CurrentOptions.UnitOfSpeed);
                    }
                    MessageToDisplay = s;
                } break;

                case MessageDependency.PassedRedSignal:
                case MessageDependency.SectionLimit:
                {
                    double spd = Math.Abs(TrainManager.PlayerTrain.CurrentSpeed);
                    double lim = TrainManager.PlayerTrain.CurrentSectionLimit;
                    spd    = Math.Round(spd * 3.6);
                    lim    = Math.Round(lim * 3.6);
                    remove = spd <= lim;
                    string s = InternalText, t;
                    if (Interface.CurrentOptions.SpeedConversionFactor != 0.0)
                    {
                        spd = Math.Round(spd * Interface.CurrentOptions.SpeedConversionFactor);
                        lim = Math.Round(lim * Interface.CurrentOptions.SpeedConversionFactor);
                    }
                    t = spd.ToString(System.Globalization.CultureInfo.InvariantCulture);
                    s = s.Replace("[speed]", t);
                    t = lim.ToString(System.Globalization.CultureInfo.InvariantCulture);
                    s = s.Replace("[limit]", t);
                    s = s.Replace("[unit]", Interface.CurrentOptions.UnitOfSpeed);
                    MessageToDisplay = s;
                } break;

                case MessageDependency.StationArrival:
                case MessageDependency.StationDeparture:
                {
                    int j = TrainManager.PlayerTrain.Station;
                    if (j >= 0 & TrainManager.PlayerTrain.StationState != TrainStopState.Completed)
                    {
                        double d = TrainManager.PlayerTrain.StationDepartureTime - Program.CurrentRoute.SecondsSinceMidnight + 1.0;
                        if (d < 0.0)
                        {
                            d = 0.0;
                        }
                        string   s = InternalText;
                        TimeSpan a = TimeSpan.FromSeconds(d);
                        System.Globalization.CultureInfo Culture = System.Globalization.CultureInfo.InvariantCulture;
                        string t = a.Hours.ToString("00", Culture) + ":" + a.Minutes.ToString("00", Culture) + ":" + a.Seconds.ToString("00", Culture);
                        s = s.Replace("[time]", t);
                        s = s.Replace("[name]", Program.CurrentRoute.Stations[j].Name);
                        MessageToDisplay = s;
                        if (d > 0.0)
                        {
                            remove = false;
                        }
                    }
                    else
                    {
                        //Queue the mesasge for removal if we have completed the station stop for this message
                        remove = true;
                    }
                } break;

                default:
                    MessageToDisplay = InternalText;
                    break;
                }

                if (Interface.CurrentOptions.ScreenReaderAvailable && !ScreenReaderAnnounced)
                {
                    if (!Tolk.Output((string)MessageToDisplay))
                    {
                        Interface.CurrentOptions.ScreenReaderAvailable = false;
                    }
                    ScreenReaderAnnounced = true;
                }
                if (remove)
                {
                    if (Timeout == double.PositiveInfinity)
                    {
                        Timeout = Program.CurrentRoute.SecondsSinceMidnight - 1.0;
                    }
                    //Remove the message if it has completely faded out
                    //NOTE: The fadeout is done in the renderer itself...
                    if (Program.CurrentRoute.SecondsSinceMidnight >= Timeout & RendererAlpha == 0.0)
                    {
                        QueueForRemoval = true;
                    }
                }
            }
 private void TalkString(string text)
 {
     Tolk.Load();
     Tolk.Output(text, true);
     Tolk.Unload();
 }
        } // End form keydown.

        private void interveneButton_Click(object sender, EventArgs e)
        {
            PMDG777Aircraft.HeadingIntervene();
            Tolk.Output("Heading intervene.");
        } // End headingButton click.
Example #10
0
        static void Main(string[] args)
        {
            Tolk.TrySAPI(true);
            Tolk.Load();

            string introText =
                @"Atlas Warriors - Screen Reader Edition
Lachlan Kingsford

Welcome to Atlas Warriors. This screen reader edition provides screen-reader specific functionality:
F1: Screen mode - whole map
F2: Screen mode - current room only
F3: Screen mode - no refresh
Space: Draw whole screen

Move with Vim keys, arrows or numeric keypad.

Push any key to continue";

            Console.WriteLine(introText);
            Tolk.Output(introText);

            Console.ReadKey();

            var  G    = new AtlasWarriorsGame.Game();
            bool quit = false;

            displayMode = DisplayMode.ROOM;
            bool skipDraw = false;

            while (!quit)
            {
                // Interrupt reader at start of turn
                Tolk.Output("", true);

                // If not skipping draw, draw map. If so - reset skipDraw to draw map next time.
                if (!skipDraw)
                {
                    if (displayMode != DisplayMode.REFRESH_ONLY)
                    {
                        DrawMap(G.CurrentDungeon);
                    }
                }
                else
                {
                    skipDraw = false;
                }
                Console.Write($"\nHP {G.Player.CurrentHealth} ({G.Player.MaxHealth})");
                Tolk.Output($"{G.Player.CurrentHealth} of {G.Player.MaxHealth}");
                Console.Write("\n>");
                var input = Console.ReadKey();
                switch (input.Key)
                {
                case ConsoleKey.H:
                case ConsoleKey.LeftArrow:
                case ConsoleKey.NumPad4:
                    G.Player.NextMove = Player.Instruction.MOVE_W;
                    break;

                case ConsoleKey.K:
                case ConsoleKey.UpArrow:
                case ConsoleKey.NumPad8:
                    G.Player.NextMove = Player.Instruction.MOVE_N;
                    break;

                case ConsoleKey.L:
                case ConsoleKey.RightArrow:
                case ConsoleKey.NumPad6:
                    G.Player.NextMove = Player.Instruction.MOVE_E;
                    break;

                case ConsoleKey.J:
                case ConsoleKey.DownArrow:
                case ConsoleKey.NumPad2:
                    G.Player.NextMove = Player.Instruction.MOVE_S;
                    break;

                case ConsoleKey.Y:
                case ConsoleKey.NumPad7:
                    G.Player.NextMove = Player.Instruction.MOVE_NW;
                    break;

                case ConsoleKey.U:
                case ConsoleKey.NumPad9:
                    G.Player.NextMove = Player.Instruction.MOVE_NE;
                    break;

                case ConsoleKey.B:
                case ConsoleKey.NumPad1:
                    G.Player.NextMove = Player.Instruction.MOVE_SW;
                    break;

                case ConsoleKey.N:
                case ConsoleKey.NumPad3:
                    G.Player.NextMove = Player.Instruction.MOVE_SE;
                    break;

                // Non move options
                // Refresh screen
                case ConsoleKey.Spacebar:
                    DrawMap(G.CurrentDungeon, true);
                    skipDraw = true;
                    break;

                // Change draw mode - F1, F2, F3
                case ConsoleKey.F1:
                    displayMode = DisplayMode.ALL;
                    Console.Write("Display mode set to show all");
                    break;

                case ConsoleKey.F2:
                    displayMode = DisplayMode.ROOM;
                    Console.Write("Display mode set to show current visible area only");
                    break;

                case ConsoleKey.F3:
                    displayMode = DisplayMode.REFRESH_ONLY;
                    Console.Write("Display mode set to only show on refresh (Space)");
                    break;
                }
                G.DoTurn();

                if (G.GameOver)
                {
                    Console.WriteLine(G.EndGameTitle);
                    Tolk.Output(G.EndGameTitle, true);
                    Console.WriteLine(G.EndGameText);
                    Tolk.Output(G.EndGameText, false);
                    Console.WriteLine("(Press any key to quit)");
                    Tolk.Output("Press any key to quit");
                    Console.ReadKey();
                    quit = true;
                }
            }
        }
Example #11
0
            /********************
             *      MENU C'TOR
             *********************/
            public SingleMenu(MenuType menuType, int data = 0, double maxWidth = 0)
            {
                MaxWidth = maxWidth;
                Type     = menuType;
                int     i, menuItem;
                int     jump = 0;
                Vector2 size;

                Align     = TextAlignment.TopMiddle;
                Height    = Width = 0;
                Selection = 0;                                      // defaults to first menu item
                switch (menuType)
                {
                case MenuType.GameStart:                                  // top level menu
                    if (routeWorkerThread == null)
                    {
                        //Create the worker threads on first launch of main menu
                        routeWorkerThread                       = new BackgroundWorker();
                        routeWorkerThread.DoWork               += routeWorkerThread_doWork;
                        routeWorkerThread.RunWorkerCompleted   += routeWorkerThread_completed;
                        packageWorkerThread                     = new BackgroundWorker();
                        packageWorkerThread.DoWork             += packageWorkerThread_doWork;
                        packageWorkerThread.RunWorkerCompleted += packageWorkerThread_completed;
                        Manipulation.ProgressChanged           += OnWorkerProgressChanged;
                        Manipulation.ProblemReport             += OnWorkerReportsProblem;
                        Manipulation.OperationCompleted        += OnPackageOperationCompleted;
                        //Load texture
                        Program.CurrentHost.RegisterTexture(Path.CombineFile(Program.FileSystem.DataFolder, "Menu\\loading.png"), new TextureParameters(null, null), out routePictureBox.Texture);
                    }
                    Items    = new MenuEntry[5];
                    Items[0] = new MenuCommand("Open Route File", MenuTag.RouteList, 0);

                    if (!Interface.CurrentOptions.KioskMode)
                    {
                        //Don't allow quitting or customisation of the controls in kiosk mode
                        Items[1] = new MenuCommand(Translations.GetInterfaceString("options"), MenuTag.Options, 0);
                        Items[2] = new MenuCommand(Translations.GetInterfaceString("menu_customize_controls"), MenuTag.MenuControls, 0);
                        Items[3] = new MenuCommand(Translations.GetInterfaceString("packages_title"), MenuTag.Packages, 0);
                        Items[4] = new MenuCommand(Translations.GetInterfaceString("menu_quit"), MenuTag.MenuQuit, 0);
                    }
                    else
                    {
                        Array.Resize(ref Items, Items.Length - 3);
                    }
                    SearchDirectory = Program.FileSystem.InitialRouteFolder;
                    Align           = TextAlignment.TopLeft;
                    break;

                case MenuType.Packages:
                    Items    = new MenuEntry[4];
                    Items[0] = new MenuCaption(Translations.GetInterfaceString("packages_title"));
                    Items[1] = new MenuCommand(Translations.GetInterfaceString("packages_install_header"), MenuTag.PackageInstall, 0);
                    Items[2] = new MenuCommand(Translations.GetInterfaceString("packages_uninstall_button"), MenuTag.PackageUninstall, 0);
                    Items[3] = new MenuCommand(Translations.GetInterfaceString("packages_button_cancel"), MenuTag.MenuBack, 0);
                    Align    = TextAlignment.TopLeft;
                    break;

                case MenuType.PackageUninstall:
                    routeDescriptionBox.Text = string.Empty;
                    Items    = new MenuEntry[5];
                    Items[0] = new MenuCaption(Translations.GetInterfaceString("packages_list_type"));
                    Items[1] = new MenuCommand(Translations.GetInterfaceString("packages_type_route"), MenuTag.UninstallRoute, 0);
                    Items[2] = new MenuCommand(Translations.GetInterfaceString("packages_type_train"), MenuTag.UninstallTrain, 0);
                    Items[3] = new MenuCommand(Translations.GetInterfaceString("packages_type_other"), MenuTag.UninstallOther, 0);
                    Items[4] = new MenuCommand(Translations.GetInterfaceString("packages_button_cancel"), MenuTag.MenuBack, 0);
                    Align    = TextAlignment.TopLeft;
                    break;

                case MenuType.UninstallRoute:
                    Items    = new MenuEntry[Database.currentDatabase.InstalledRoutes.Count + 1];
                    Items[0] = new MenuCaption(Translations.GetInterfaceString("packages_list"));
                    for (int j = 0; j < Database.currentDatabase.InstalledRoutes.Count; j++)
                    {
                        Items[j + 1] = new MenuCommand(Database.currentDatabase.InstalledRoutes[j].Name, MenuTag.Package, Database.currentDatabase.InstalledRoutes[j]);
                    }
                    Align = TextAlignment.TopLeft;
                    break;

                case MenuType.UninstallTrain:
                    Items    = new MenuEntry[Database.currentDatabase.InstalledTrains.Count + 1];
                    Items[0] = new MenuCaption(Translations.GetInterfaceString("packages_list"));
                    for (int j = 0; j < Database.currentDatabase.InstalledTrains.Count; j++)
                    {
                        Items[j + 1] = new MenuCommand(Database.currentDatabase.InstalledTrains[j].Name, MenuTag.Package, Database.currentDatabase.InstalledTrains[j]);
                    }
                    Align = TextAlignment.TopLeft;
                    break;

                case MenuType.UninstallOther:
                    Items    = new MenuEntry[Database.currentDatabase.InstalledOther.Count + 1];
                    Items[0] = new MenuCaption(Translations.GetInterfaceString("packages_list"));
                    for (int j = 0; j < Database.currentDatabase.InstalledOther.Count; j++)
                    {
                        Items[j + 1] = new MenuCommand(Database.currentDatabase.InstalledOther[j].Name, MenuTag.Package, Database.currentDatabase.InstalledOther[j]);
                    }
                    Align = TextAlignment.TopLeft;
                    break;

                case MenuType.PackageInstall:
                    string[] potentialFiles = { };
                    string[] directoryList  = { };
                    bool     drives         = false;
                    if (SearchDirectory != string.Empty)
                    {
                        try
                        {
                            potentialFiles = Directory.GetFiles(SearchDirectory);
                            directoryList  = Directory.GetDirectories(SearchDirectory);
                        }
                        catch
                        {
                            // Ignored
                        }
                    }
                    else
                    {
                        DriveInfo[] systemDrives = DriveInfo.GetDrives();
                        directoryList = new string[systemDrives.Length];
                        for (int k = 0; k < systemDrives.Length; k++)
                        {
                            directoryList[k] = systemDrives[k].Name;
                        }
                        drives = true;
                    }

                    Items    = new MenuEntry[potentialFiles.Length + directoryList.Length + 2];
                    Items[0] = new MenuCaption(SearchDirectory);
                    Items[1] = new MenuCommand("...", MenuTag.ParentDirectory, 0);
                    int totalEntries = 2;
                    for (int j = 0; j < directoryList.Length; j++)
                    {
                        DirectoryInfo directoryInfo = new DirectoryInfo(directoryList[j]);
                        if (Program.CurrentHost.Platform != HostPlatform.MicrosoftWindows && directoryInfo.Name[0] == '.')
                        {
                            continue;
                        }
                        Items[totalEntries] = new MenuCommand(directoryInfo.Name, MenuTag.Directory, 0);
                        if (drives)
                        {
                            Program.CurrentHost.RegisterTexture(Path.CombineFile(Program.FileSystem.DataFolder, "Menu\\icon_disk.png"), new TextureParameters(null, null), out Items[totalEntries].Icon);
                        }
                        else
                        {
                            Program.CurrentHost.RegisterTexture(Path.CombineFile(Program.FileSystem.DataFolder, "Menu\\icon_folder.png"), new TextureParameters(null, null), out Items[totalEntries].Icon);
                        }

                        totalEntries++;
                    }

                    for (int j = 0; j < potentialFiles.Length; j++)
                    {
                        string fileName = System.IO.Path.GetFileName(potentialFiles[j]);
                        if (Program.CurrentHost.Platform != HostPlatform.MicrosoftWindows && fileName[0] == '.')
                        {
                            continue;
                        }
                        Items[totalEntries] = new MenuCommand(fileName, MenuTag.File, 0);
                        string ext = System.IO.Path.GetExtension(fileName);
                        if (!iconCache.ContainsKey(ext))
                        {
                            // As some people have used arbritary extensions for packages, let's show all files
                            // Try and pull out the default icon from the cache for something a little nicer looking
                            try
                            {
                                Icon icon = Icon.ExtractAssociatedIcon(potentialFiles[j]);
                                if (icon != null)
                                {
                                    Texture t;
                                    Program.CurrentHost.RegisterTexture(icon.ToBitmap(), new TextureParameters(null, null), out t);
                                    iconCache.Add(ext, t);
                                    Items[totalEntries].Icon = t;
                                }
                            }
                            catch
                            {
                                // Ignored
                            }
                        }
                        else
                        {
                            Items[totalEntries].Icon = iconCache[ext];
                        }
                        totalEntries++;
                    }
                    Array.Resize(ref Items, totalEntries);
                    Align = TextAlignment.TopLeft;
                    break;

                case MenuType.Options:
                    Items    = new MenuEntry[8];
                    Items[0] = new MenuCaption(Translations.GetInterfaceString("panel_options"));
                    Items[1] = new MenuOption(MenuOptionType.ScreenResolution, Translations.GetInterfaceString("options_resolution"), Program.Renderer.Screen.AvailableResolutions.ToArray());
                    Items[2] = new MenuOption(MenuOptionType.FullScreen, Translations.GetInterfaceString("options_display_mode_fullscreen"), new[] { "true", "false" });
                    Items[3] = new MenuOption(MenuOptionType.Interpolation, Translations.GetInterfaceString("options_quality_interpolation"), new[]
                    {
                        Translations.GetInterfaceString("options_quality_interpolation_mode_nearest"),
                        Translations.GetInterfaceString("options_quality_interpolation_mode_bilinear"),
                        Translations.GetInterfaceString("options_quality_interpolation_mode_nearestmipmap"),
                        Translations.GetInterfaceString("options_quality_interpolation_mode_bilinearmipmap"),
                        Translations.GetInterfaceString("options_quality_interpolation_mode_trilinearmipmap"),
                        Translations.GetInterfaceString("options_quality_interpolation_mode_anisotropic")
                    });
                    Items[4] = new MenuOption(MenuOptionType.AnisotropicLevel, Translations.GetInterfaceString("options_quality_interpolation_anisotropic_level"), new[] { "0", "2", "4", "8", "16" });
                    Items[5] = new MenuOption(MenuOptionType.AntialiasingLevel, Translations.GetInterfaceString("options_quality_interpolation_antialiasing_level"), new[] { "0", "2", "4", "8", "16" });
                    Items[6] = new MenuOption(MenuOptionType.ViewingDistance, Translations.GetInterfaceString("options_quality_distance_viewingdistance"), new[] { "400", "600", "800", "1000", "1500", "2000" });
                    Items[7] = new MenuCommand(Translations.GetInterfaceString("menu_back"), MenuTag.MenuBack, 0);
                    Align    = TextAlignment.TopLeft;
                    break;

                case MenuType.RouteList:
                    potentialFiles = new string[] { };
                    directoryList  = new string[] { };
                    drives         = false;
                    if (SearchDirectory != string.Empty)
                    {
                        try
                        {
                            potentialFiles = Directory.GetFiles(SearchDirectory);
                            directoryList  = Directory.GetDirectories(SearchDirectory);
                        }
                        catch
                        {
                            // Ignored
                        }
                    }
                    else
                    {
                        DriveInfo[] systemDrives = DriveInfo.GetDrives();
                        directoryList = new string[systemDrives.Length];
                        for (int k = 0; k < systemDrives.Length; k++)
                        {
                            directoryList[k] = systemDrives[k].Name;
                        }
                        drives = true;
                    }

                    Items        = new MenuEntry[potentialFiles.Length + directoryList.Length + 2];
                    Items[0]     = new MenuCaption(SearchDirectory);
                    Items[1]     = new MenuCommand("...", MenuTag.ParentDirectory, 0);
                    totalEntries = 2;
                    for (int j = 0; j < directoryList.Length; j++)
                    {
                        DirectoryInfo directoryInfo = new DirectoryInfo(directoryList[j]);
                        if (Program.CurrentHost.Platform != HostPlatform.MicrosoftWindows && directoryInfo.Name[0] == '.')
                        {
                            continue;
                        }
                        Items[totalEntries] = new MenuCommand(directoryInfo.Name, MenuTag.Directory, 0);
                        if (drives)
                        {
                            Program.CurrentHost.RegisterTexture(Path.CombineFile(Program.FileSystem.DataFolder, "Menu\\icon_disk.png"), new TextureParameters(null, null), out Items[totalEntries].Icon);
                        }
                        else
                        {
                            Program.CurrentHost.RegisterTexture(Path.CombineFile(Program.FileSystem.DataFolder, "Menu\\icon_folder.png"), new TextureParameters(null, null), out Items[totalEntries].Icon);
                        }

                        totalEntries++;
                    }

                    for (int j = 0; j < potentialFiles.Length; j++)
                    {
                        string fileName = System.IO.Path.GetFileName(potentialFiles[j]);
                        if (Program.CurrentHost.Platform != HostPlatform.MicrosoftWindows && fileName[0] == '.')
                        {
                            continue;
                        }
                        if (fileName.ToLowerInvariant().EndsWith(".csv") || fileName.ToLowerInvariant().EndsWith(".rw"))
                        {
                            Items[totalEntries] = new MenuCommand(fileName, MenuTag.RouteFile, 0);
                            Program.CurrentHost.RegisterTexture(Path.CombineFile(Program.FileSystem.DataFolder, "Menu\\icon_route.png"), new TextureParameters(null, null), out Items[totalEntries].Icon);
                            totalEntries++;
                        }
                    }
                    Array.Resize(ref Items, totalEntries);
                    Align = TextAlignment.TopLeft;
                    break;

                case MenuType.TrainList:
                    potentialFiles = new string[] { };
                    directoryList  = new string[] { };
                    drives         = false;
                    if (SearchDirectory != string.Empty)
                    {
                        try
                        {
                            potentialFiles = Directory.GetFiles(SearchDirectory);
                            directoryList  = Directory.GetDirectories(SearchDirectory);
                        }
                        catch
                        {
                            // Ignored
                        }
                    }
                    else
                    {
                        DriveInfo[] systemDrives = DriveInfo.GetDrives();
                        directoryList = new string[systemDrives.Length];
                        for (int k = 0; k < systemDrives.Length; k++)
                        {
                            directoryList[k] = systemDrives[k].Name;
                        }
                        drives = true;
                    }

                    Items        = new MenuEntry[potentialFiles.Length + directoryList.Length + 2];
                    Items[0]     = new MenuCaption(SearchDirectory);
                    Items[1]     = new MenuCommand("...", MenuTag.ParentDirectory, 0);
                    totalEntries = 2;
                    for (int j = 0; j < directoryList.Length; j++)
                    {
                        bool isTrain = false;
                        for (int k = 0; k < Program.CurrentHost.Plugins.Length; k++)
                        {
                            if (Program.CurrentHost.Plugins[k].Train != null && Program.CurrentHost.Plugins[k].Train.CanLoadTrain(directoryList[j]))
                            {
                                isTrain = true;
                                break;
                            }
                        }
                        DirectoryInfo directoryInfo = new DirectoryInfo(directoryList[j]);
                        if (Program.CurrentHost.Platform != HostPlatform.MicrosoftWindows && directoryInfo.Name[0] == '.')
                        {
                            continue;
                        }
                        if (!isTrain)
                        {
                            Items[totalEntries] = new MenuCommand(directoryInfo.Name, MenuTag.Directory, 0);
                            if (drives)
                            {
                                Program.CurrentHost.RegisterTexture(Path.CombineFile(Program.FileSystem.DataFolder, "Menu\\icon_disk.png"), new TextureParameters(null, null), out Items[totalEntries].Icon);
                            }
                            else
                            {
                                Program.CurrentHost.RegisterTexture(Path.CombineFile(Program.FileSystem.DataFolder, "Menu\\icon_folder.png"), new TextureParameters(null, null), out Items[totalEntries].Icon);
                            }
                        }
                        else
                        {
                            Items[totalEntries] = new MenuCommand(directoryInfo.Name, MenuTag.TrainDirectory, 0);
                            Program.CurrentHost.RegisterTexture(Path.CombineFile(Program.FileSystem.DataFolder, "Menu\\icon_train.png"), new TextureParameters(null, null), out Items[totalEntries].Icon);
                        }
                        totalEntries++;
                    }
                    Array.Resize(ref Items, totalEntries);
                    Align = TextAlignment.TopLeft;
                    break;

                case MenuType.Top:                                  // top level menu
                    if (Interface.CurrentOptions.ScreenReaderAvailable)
                    {
                        if (!Tolk.Output(Translations.GetInterfaceString("menu_title")))
                        {
                            // failed to output to screen reader, so don't keep trying
                            Interface.CurrentOptions.ScreenReaderAvailable = false;
                        }
                    }
                    for (i = 0; i < Program.CurrentRoute.Stations.Length; i++)
                    {
                        if (Program.CurrentRoute.Stations[i].PlayerStops() & Program.CurrentRoute.Stations[i].Stops.Length > 0)
                        {
                            jump = 1;
                            break;
                        }
                    }
                    Items    = new MenuEntry[4 + jump];
                    Items[0] = new MenuCommand(Translations.GetInterfaceString("menu_resume"), MenuTag.BackToSim, 0);
                    if (jump > 0)
                    {
                        Items[1] = new MenuCommand(Translations.GetInterfaceString("menu_jump"), MenuTag.MenuJumpToStation, 0);
                    }
                    if (!Interface.CurrentOptions.KioskMode)
                    {
                        //Don't allow quitting or customisation of the controls in kiosk mode
                        Items[1 + jump] = new MenuCommand(Translations.GetInterfaceString("menu_exit"), MenuTag.MenuExitToMainMenu, 0);
                        Items[2 + jump] = new MenuCommand(Translations.GetInterfaceString("menu_customize_controls"), MenuTag.MenuControls, 0);
                        Items[3 + jump] = new MenuCommand(Translations.GetInterfaceString("menu_quit"), MenuTag.MenuQuit, 0);
                    }
                    else
                    {
                        Array.Resize(ref Items, Items.Length - 3);
                    }
                    break;

                case MenuType.JumpToStation:                            // list of stations to jump to
                    // count the number of available stations
                    menuItem = 0;
                    for (i = 0; i < Program.CurrentRoute.Stations.Length; i++)
                    {
                        if (Program.CurrentRoute.Stations[i].PlayerStops() & Program.CurrentRoute.Stations[i].Stops.Length > 0)
                        {
                            menuItem++;
                        }
                    }
                    // list available stations, selecting the next station as predefined choice
                    jump     = 0;                                                   // no jump found yet
                    Items    = new MenuEntry[menuItem + 1];
                    Items[0] = new MenuCommand(Translations.GetInterfaceString("menu_back"), MenuTag.MenuBack, 0);
                    menuItem = 1;
                    for (i = 0; i < Program.CurrentRoute.Stations.Length; i++)
                    {
                        if (Program.CurrentRoute.Stations[i].PlayerStops() & Program.CurrentRoute.Stations[i].Stops.Length > 0)
                        {
                            Items[menuItem] = new MenuCommand(Program.CurrentRoute.Stations[i].Name, MenuTag.JumpToStation, i);
                            // if no preferred jump-to-station found yet and this station is
                            // after the last station the user stopped at, select this item
                            if (jump == 0 && i > TrainManagerBase.PlayerTrain.LastStation)
                            {
                                jump      = i;
                                Selection = menuItem;
                            }
                            menuItem++;
                        }
                    }
                    Align = TextAlignment.TopLeft;
                    break;

                case MenuType.ExitToMainMenu:
                    Items     = new MenuEntry[3];
                    Items[0]  = new MenuCaption(Translations.GetInterfaceString("menu_exit_question"));
                    Items[1]  = new MenuCommand(Translations.GetInterfaceString("menu_exit_no"), MenuTag.MenuBack, 0);
                    Items[2]  = new MenuCommand(Translations.GetInterfaceString("menu_exit_yes"), MenuTag.ExitToMainMenu, 0);
                    Selection = 1;
                    break;

                case MenuType.Quit:                                 // ask for quit confirmation
                    Items     = new MenuEntry[3];
                    Items[0]  = new MenuCaption(Translations.GetInterfaceString("menu_quit_question"));
                    Items[1]  = new MenuCommand(Translations.GetInterfaceString("menu_quit_no"), MenuTag.MenuBack, 0);
                    Items[2]  = new MenuCommand(Translations.GetInterfaceString("menu_quit_yes"), MenuTag.Quit, 0);
                    Selection = 1;
                    break;

                case MenuType.Controls:
                    //Refresh the joystick list
                    Program.Joysticks.RefreshJoysticks();
                    Items    = new MenuEntry[Interface.CurrentControls.Length + 1];
                    Items[0] = new MenuCommand(Translations.GetInterfaceString("menu_back"), MenuTag.MenuBack, 0);
                    for (i = 0; i < Interface.CurrentControls.Length; i++)
                    {
                        Items[i + 1] = new MenuCommand(Interface.CurrentControls[i].Command.ToString(), MenuTag.Control, i);
                    }
                    Align = TextAlignment.TopLeft;
                    break;

                case MenuType.Control:
                    //Refresh the joystick list
                    Program.Joysticks.RefreshJoysticks();
                    Selection = SelectionNone;
                    Items     = new MenuEntry[4];
                    // get code name and description
                    Control loadedControl = Interface.CurrentControls[data];
                    for (int h = 0; h < Translations.CommandInfos.Length; h++)
                    {
                        if (Translations.CommandInfos[h].Command == loadedControl.Command)
                        {
                            Items[0] = new MenuCommand(loadedControl.Command.ToString() + " - " +
                                                       Translations.CommandInfos[h].Description, MenuTag.None, 0);
                            break;
                        }
                    }
                    // get assignment
                    String str = "";
                    switch (loadedControl.Method)
                    {
                    case ControlMethod.Keyboard:
                        string keyName = loadedControl.Key.ToString();
                        for (int k = 0; k < Translations.TranslatedKeys.Length; k++)
                        {
                            if (Translations.TranslatedKeys[k].Key == loadedControl.Key)
                            {
                                keyName = Translations.TranslatedKeys[k].Description;
                                break;
                            }
                        }
                        if (loadedControl.Modifier != KeyboardModifier.None)
                        {
                            str = Translations.GetInterfaceString("menu_keyboard") + " [" + loadedControl.Modifier + "-" + keyName + "]";
                        }
                        else
                        {
                            str = Translations.GetInterfaceString("menu_keyboard") + " [" + keyName + "]";
                        }
                        break;

                    case ControlMethod.Joystick:
                        str = Translations.GetInterfaceString("menu_joystick") + " " + loadedControl.Device + " [" + loadedControl.Component + " " + loadedControl.Element + "]";
                        switch (loadedControl.Component)
                        {
                        case JoystickComponent.FullAxis:
                        case JoystickComponent.Axis:
                            str += " " + (loadedControl.Direction == 1 ? Translations.GetInterfaceString("menu_joystickdirection_positive") : Translations.GetInterfaceString("menu_joystickdirection_negative"));
                            break;

                        //						case Interface.JoystickComponent.Button:	// NOTHING TO DO FOR THIS CASE!
                        //							str = str;
                        //							break;
                        case JoystickComponent.Hat:
                            str += " " + (OpenTK.Input.HatPosition)loadedControl.Direction;
                            break;

                        case JoystickComponent.Invalid:
                            str = Translations.GetInterfaceString("menu_joystick_notavailable");
                            break;
                        }
                        break;

                    case ControlMethod.RailDriver:
                        str = "RailDriver [" + loadedControl.Component + " " + loadedControl.Element + "]";
                        switch (loadedControl.Component)
                        {
                        case JoystickComponent.FullAxis:
                        case JoystickComponent.Axis:
                            str += " " + (loadedControl.Direction == 1 ? Translations.GetInterfaceString("menu_joystickdirection_positive") : Translations.GetInterfaceString("menu_joystickdirection_negative"));
                            break;

                        case JoystickComponent.Invalid:
                            str = Translations.GetInterfaceString("menu_joystick_notavailable");
                            break;
                        }
                        break;

                    case ControlMethod.Invalid:
                        str = Translations.GetInterfaceString("menu_joystick_notavailable");
                        break;
                    }
                    Items[1] = new MenuCommand(Translations.GetInterfaceString("menu_assignment_current") + " " + str, MenuTag.None, 0);
                    Items[2] = new MenuCommand(" ", MenuTag.None, 0);
                    Items[3] = new MenuCommand(Translations.GetInterfaceString("menu_assign"), MenuTag.None, 0);
                    break;

                case MenuType.TrainDefault:
                    Interface.CurrentOptions.TrainFolder = Loading.GetDefaultTrainFolder(currentFile);
                    bool canLoad = false;
                    for (int j = 0; j < Program.CurrentHost.Plugins.Length; j++)
                    {
                        if (Program.CurrentHost.Plugins[j].Train != null && Program.CurrentHost.Plugins[j].Train.CanLoadTrain(Interface.CurrentOptions.TrainFolder))
                        {
                            canLoad = true;
                            break;
                        }
                    }

                    if (canLoad)
                    {
                        Items     = new MenuEntry[3];
                        Items[0]  = new MenuCaption(Translations.GetInterfaceString("start_train_default"));
                        Items[1]  = new MenuCommand(Translations.GetInterfaceString("start_train_default_yes"), MenuTag.Yes, 0);
                        Items[2]  = new MenuCommand(Translations.GetInterfaceString("start_train_default_no"), MenuTag.No, 0);
                        Selection = 1;
                    }
                    else
                    {
                        SearchDirectory = Program.FileSystem.InitialTrainFolder;
                        //Default train not found or not valid
                        Instance.PushMenu(MenuType.TrainList);
                    }
                    break;
                }
                // compute menu extent
                for (i = 0; i < Items.Length; i++)
                {
                    if (Items[i] == null)
                    {
                        continue;
                    }
                    size = Game.Menu.MenuFont.MeasureString(Items[i].Text);
                    if (Items[i].Icon != null)
                    {
                        size.X += size.Y * 1.25;
                    }
                    if (size.X > Width)
                    {
                        Width = size.X;
                    }

                    if (MaxWidth != 0 && size.X > MaxWidth)
                    {
                        for (int j = Items[i].Text.Length - 1; j > 0; j--)
                        {
                            string trimmedText = Items[i].Text.Substring(0, j);
                            size = Game.Menu.MenuFont.MeasureString(trimmedText);
                            double mwi = MaxWidth;
                            if (Items[i].Icon != null)
                            {
                                mwi -= size.Y * 1.25;
                            }
                            if (size.X < mwi)
                            {
                                Items[i].DisplayLength = trimmedText.Length;
                                break;
                            }
                        }
                        Width = MaxWidth;
                    }
                    if (!(Items[i] is MenuCaption && menuType != MenuType.RouteList && menuType != MenuType.GameStart && menuType != MenuType.Packages) && size.X > ItemWidth)
                    {
                        ItemWidth = size.X;
                    }
                }
                Height  = Items.Length * Game.Menu.LineHeight;
                TopItem = 0;
            }
        } // End btnPREV_Click.

        private void btnNext_Click(object sender, EventArgs e)
        {
            FSUIPCConnection.SendControlToFS(PMDG_747QOTSII_Control.EVT_CDU_L_NEXT_PAGE, Aircraft.ClkL);
            RefreshCDU();
            Tolk.Output($"{pmdg.cdu0.Rows[0]}");
        } // End btnNEXT_Click.
Example #13
0
        } // End btnFIX_Click.

        private void btnPrev_Click(object sender, EventArgs e)
        {
            FSUIPCConnection.SendControlToFS(PMDG_777X_Control.EVT_CDU_L_PREV_PAGE, Aircraft.ClkL);
            RefreshCDU();
            Tolk.Output($"{pmdg.cdu0.Rows[0]}");
        } // End btnPREV_Click.
Example #14
0
File: Menu.cs Project: s520/OpenBVE
            public int TopItem;                     // the top displayed menu item


            /********************
             *      MENU C'TOR
             *********************/
            public SingleMenu(MenuType menuType, int data = 0)
            {
                int  i, menuItem;
                int  jump = 0;
                Size size;

                Align     = TextAlignment.TopMiddle;
                Height    = Width = 0;
                Selection = 0;                                      // defaults to first menu item
                switch (menuType)
                {
                case MenuType.Top:                                  // top level menu
                    if (Interface.CurrentOptions.ScreenReaderAvailable)
                    {
                        if (!Tolk.Output(Translations.GetInterfaceString("menu_title")))
                        {
                            // failed to output to screen reader, so don't keep trying
                            Interface.CurrentOptions.ScreenReaderAvailable = false;
                        }
                    }
                    for (i = 0; i < Program.CurrentRoute.Stations.Length; i++)
                    {
                        if (Program.CurrentRoute.Stations[i].PlayerStops() & Program.CurrentRoute.Stations[i].Stops.Length > 0)
                        {
                            jump = 1;
                            break;
                        }
                    }
                    Items    = new MenuEntry[4 + jump];
                    Items[0] = new MenuCommand(Translations.GetInterfaceString("menu_resume"), MenuTag.BackToSim, 0);
                    if (jump > 0)
                    {
                        Items[1] = new MenuCommand(Translations.GetInterfaceString("menu_jump"), MenuTag.MenuJumpToStation, 0);
                    }
                    if (!Interface.CurrentOptions.KioskMode)
                    {
                        //Don't allow quitting or customisation of the controls in kiosk mode
                        Items[1 + jump] = new MenuCommand(Translations.GetInterfaceString("menu_exit"), MenuTag.MenuExitToMainMenu, 0);
                        Items[2 + jump] = new MenuCommand(Translations.GetInterfaceString("menu_customize_controls"), MenuTag.MenuControls, 0);
                        Items[3 + jump] = new MenuCommand(Translations.GetInterfaceString("menu_quit"), MenuTag.MenuQuit, 0);
                    }
                    else
                    {
                        Array.Resize(ref Items, Items.Length - 3);
                    }
                    break;

                case MenuType.JumpToStation:                            // list of stations to jump to
                    // count the number of available stations
                    menuItem = 0;
                    for (i = 0; i < Program.CurrentRoute.Stations.Length; i++)
                    {
                        if (Program.CurrentRoute.Stations[i].PlayerStops() & Program.CurrentRoute.Stations[i].Stops.Length > 0)
                        {
                            menuItem++;
                        }
                    }
                    // list available stations, selecting the next station as predefined choice
                    jump     = 0;                                                   // no jump found yet
                    Items    = new MenuEntry[menuItem + 1];
                    Items[0] = new MenuCommand(Translations.GetInterfaceString("menu_back"), MenuTag.MenuBack, 0);
                    menuItem = 1;
                    for (i = 0; i < Program.CurrentRoute.Stations.Length; i++)
                    {
                        if (Program.CurrentRoute.Stations[i].PlayerStops() & Program.CurrentRoute.Stations[i].Stops.Length > 0)
                        {
                            Items[menuItem] = new MenuCommand(Program.CurrentRoute.Stations[i].Name, MenuTag.JumpToStation, i);
                            // if no preferred jump-to-station found yet and this station is
                            // after the last station the user stopped at, select this item
                            if (jump == 0 && i > TrainManager.PlayerTrain.LastStation)
                            {
                                jump      = i;
                                Selection = menuItem;
                            }
                            menuItem++;
                        }
                    }
                    Align = TextAlignment.TopLeft;
                    break;

                case MenuType.ExitToMainMenu:
                    Items     = new MenuEntry[3];
                    Items[0]  = new MenuCaption(Translations.GetInterfaceString("menu_exit_question"));
                    Items[1]  = new MenuCommand(Translations.GetInterfaceString("menu_exit_no"), MenuTag.MenuBack, 0);
                    Items[2]  = new MenuCommand(Translations.GetInterfaceString("menu_exit_yes"), MenuTag.ExitToMainMenu, 0);
                    Selection = 1;
                    break;

                case MenuType.Quit:                                 // ask for quit confirmation
                    Items     = new MenuEntry[3];
                    Items[0]  = new MenuCaption(Translations.GetInterfaceString("menu_quit_question"));
                    Items[1]  = new MenuCommand(Translations.GetInterfaceString("menu_quit_no"), MenuTag.MenuBack, 0);
                    Items[2]  = new MenuCommand(Translations.GetInterfaceString("menu_quit_yes"), MenuTag.Quit, 0);
                    Selection = 1;
                    break;

                case MenuType.Controls:
                    //Refresh the joystick list
                    Program.Joysticks.RefreshJoysticks();
                    Items    = new MenuEntry[Interface.CurrentControls.Length + 1];
                    Items[0] = new MenuCommand(Translations.GetInterfaceString("menu_back"), MenuTag.MenuBack, 0);
                    for (i = 0; i < Interface.CurrentControls.Length; i++)
                    {
                        Items[i + 1] = new MenuCommand(Interface.CurrentControls[i].Command.ToString(), MenuTag.Control, i);
                    }
                    Align = TextAlignment.TopLeft;
                    break;

                case MenuType.Control:
                    //Refresh the joystick list
                    Program.Joysticks.RefreshJoysticks();
                    Selection = SelectionNone;
                    Items     = new MenuEntry[4];
                    // get code name and description
                    Control loadedControl = Interface.CurrentControls[data];
                    for (int h = 0; h < Translations.CommandInfos.Length; h++)
                    {
                        if (Translations.CommandInfos[h].Command == loadedControl.Command)
                        {
                            Items[0] = new MenuCommand(loadedControl.Command.ToString() + " - " +
                                                       Translations.CommandInfos[h].Description, MenuTag.None, 0);
                            break;
                        }
                    }
                    // get assignment
                    String str = "";
                    switch (loadedControl.Method)
                    {
                    case ControlMethod.Keyboard:
                        string keyName = loadedControl.Key.ToString();
                        for (int k = 0; k < Translations.TranslatedKeys.Length; k++)
                        {
                            if (Translations.TranslatedKeys[k].Key == loadedControl.Key)
                            {
                                keyName = Translations.TranslatedKeys[k].Description;
                                break;
                            }
                        }
                        if (loadedControl.Modifier != KeyboardModifier.None)
                        {
                            str = Translations.GetInterfaceString("menu_keyboard") + " [" + loadedControl.Modifier + "-" + keyName + "]";
                        }
                        else
                        {
                            str = Translations.GetInterfaceString("menu_keyboard") + " [" + keyName + "]";
                        }
                        break;

                    case ControlMethod.Joystick:
                        str = Translations.GetInterfaceString("menu_joystick") + " " + loadedControl.Device + " [" + loadedControl.Component + " " + loadedControl.Element + "]";
                        switch (loadedControl.Component)
                        {
                        case JoystickComponent.FullAxis:
                        case JoystickComponent.Axis:
                            str += " " + (loadedControl.Direction == 1 ? Translations.GetInterfaceString("menu_joystickdirection_positive") : Translations.GetInterfaceString("menu_joystickdirection_negative"));
                            break;

                        //						case Interface.JoystickComponent.Button:	// NOTHING TO DO FOR THIS CASE!
                        //							str = str;
                        //							break;
                        case JoystickComponent.Hat:
                            str += " " + (OpenTK.Input.HatPosition)loadedControl.Direction;
                            break;

                        case JoystickComponent.Invalid:
                            str = Translations.GetInterfaceString("menu_joystick_notavailable");
                            break;
                        }
                        break;

                    case ControlMethod.RailDriver:
                        str = "RailDriver [" + loadedControl.Component + " " + loadedControl.Element + "]";
                        switch (loadedControl.Component)
                        {
                        case JoystickComponent.FullAxis:
                        case JoystickComponent.Axis:
                            str += " " + (loadedControl.Direction == 1 ? Translations.GetInterfaceString("menu_joystickdirection_positive") : Translations.GetInterfaceString("menu_joystickdirection_negative"));
                            break;

                        case JoystickComponent.Invalid:
                            str = Translations.GetInterfaceString("menu_joystick_notavailable");
                            break;
                        }
                        break;

                    case ControlMethod.Invalid:
                        str = Translations.GetInterfaceString("menu_joystick_notavailable");
                        break;
                    }
                    Items[1] = new MenuCommand(Translations.GetInterfaceString("menu_assignment_current") + " " + str, MenuTag.None, 0);
                    Items[2] = new MenuCommand(" ", MenuTag.None, 0);
                    Items[3] = new MenuCommand(Translations.GetInterfaceString("menu_assign"), MenuTag.None, 0);
                    break;
                }

                // compute menu extent
                for (i = 0; i < Items.Length; i++)
                {
                    if (Items[i] == null)
                    {
                        continue;
                    }
                    size = Game.Menu.MenuFont.MeasureString(Items[i].Text);
                    if (size.Width > Width)
                    {
                        Width = size.Width;
                    }
                    if (!(Items[i] is MenuCaption) && size.Width > ItemWidth)
                    {
                        ItemWidth = size.Width;
                    }
                }
                Height  = Items.Length * Game.Menu.LineHeight;
                TopItem = 0;
            }