Beispiel #1
0
        private void Form1_KeyUp(object sender, KeyEventArgs e)
        {
            NoxicoGame.KeyMap[e.KeyCode] = false;
            NoxicoGame.KeyTrg[e.KeyCode] = true;
            if (numpad.ContainsKey(e.KeyCode))
            {
                NoxicoGame.KeyMap[numpad[e.KeyCode]] = false;
                NoxicoGame.KeyTrg[numpad[e.KeyCode]] = true;
            }
            if (e.Modifiers == Keys.Shift)
            {
                NoxicoGame.Modifiers[0] = false;
            }

            if (e.KeyCode == (Keys)NoxicoGame.KeyBindings[KeyBinding.Screenshot])
            {
                if (e.Modifiers == Keys.Shift)
                {
                    using (var dumpFile = new StreamWriter("lol.txt", false, System.Text.Encoding.GetEncoding(437)))
                    {
                        for (int row = 0; row < Program.Rows; row++)
                        {
                            for (int col = 0; col < Program.Cols; col++)
                            {
                                dumpFile.Write(NoxicoGame.IngameTo437[image[col, row].Character]);
                            }
                            dumpFile.WriteLine();
                        }
                    }
                    using (var dumpFile = new StreamWriter("lol.html"))
                    {
                        dumpFile.WriteLine("<!DOCTYPE html><html><head>");
                        dumpFile.WriteLine("<meta http-equiv=\"Content-Type\" content=\"text/html; CHARSET=utf-8\" />");
                        dumpFile.WriteLine("</head><body>");
                        dumpFile.WriteLine("<table style=\"font-family: Unifont, monospace\" cellspacing=0 cellpadding=0>");
                        for (int row = 0; row < Program.Rows; row++)
                        {
                            dumpFile.Write("<tr>");
                            for (int col = 0; col < Program.Cols; col++)
                            {
                                var ch = string.Format("&#x{0:X};", (int)NoxicoGame.IngameToUnicode[image[col, row].Character]);
                                if (ch == "&#x20;")
                                {
                                    ch = "&nbsp;";
                                }
                                dumpFile.Write("<td style=\"background:{1};color:{2}\">{0}</td>", ch, image[col, row].Background.ToHex(), image[col, row].Foreground.ToHex());
                            }
                            dumpFile.WriteLine("</tr>");
                        }
                        dumpFile.WriteLine("</table>");
                        dumpFile.WriteLine("</body></html>");
                    }
                    return;
                }

                var shotDir = IniFile.GetValue("misc", "shotpath", "screenshots");
                if (shotDir.StartsWith('$'))
                {
                    shotDir = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + shotDir.Substring(1);
                }

                if (!Directory.Exists(shotDir))
                {
                    Directory.CreateDirectory(shotDir);
                }
                int i = 1;
                while (File.Exists(Path.Combine(shotDir, "screenshot" + i.ToString("000") + ".png")))
                {
                    i++;
                }
                backBuffer.Save(Path.Combine(shotDir, "screenshot" + i.ToString("000") + ".png"), ImageFormat.Png);
                Program.WriteLine("Screenshot saved.");
            }
            if (e.KeyValue == 191)
            {
                NoxicoGame.KeyMap[Keys.L] = false;
            }

            if (e.KeyCode == Keys.R && e.Control)
            {
                NoxicoGame.KeyMap[Keys.R] = false;
                for (int row = 0; row < Program.Rows; row++)
                {
                    for (int col = 0; col < Program.Cols; col++)
                    {
                        previousImage[col, row].Character = '\uFFFE';
                    }
                }
            }

            if (e.KeyCode == Keys.A && e.Control && NoxicoGame.Mode == UserMode.Walkabout)
            {
                NoxicoGame.KeyMap[Keys.A] = false;
                NoxicoGame.ShowMessageLog();
            }

#if DEBUG
            if (e.KeyCode == Keys.E && e.Control && NoxicoGame.Mode == UserMode.Walkabout)
            {
                (new Editor()).LoadBoard(Noxico.CurrentBoard);
            }
#endif
        }
Beispiel #2
0
        public static void Handler()
        {
            if (Subscreens.FirstDraw)
            {
                Subscreens.FirstDraw = false;
                if (!Options.FromTitle)
                {
                    UIManager.Initialize();
                    UIManager.Elements.Clear();
                }
                else
                {
                    UIManager.Highlight = UIManager.Elements[0];
                    UIManager.Elements.RemoveRange(3, UIManager.Elements.Count - 3);
                }

                NoxicoGame.Immediate = true;
                NoxicoGame.Me.CurrentBoard.Redraw();
                NoxicoGame.Me.CurrentBoard.Draw(true);

                var items = Enum.GetNames(typeof(KeyBinding));
                numControls = items.Length;
                var numShown = numControls > 17 ? 17 : numControls;

                var window = new UIWindow(i18n.GetString("key_Title"))
                {
                    Width  = 44,
                    Height = numShown + 6
                };
                window.Center();

                controlList = new UIList(string.Empty, null, items)
                {
                    Width  = 40,
                    Height = numShown
                };
                controlList.Move(2, 2, window);
                controlList.Enter = (s, e) =>
                {
                    waitingForKey = true;
                    controlList.Items[controlList.Index] = i18n.GetString("key_" + Enum.GetName(typeof(KeyBinding), controlList.Index)).PadEffective(16) + "........";
                    controlList.DrawQuick();
                };

                saveButton = new UIButton(i18n.GetString("key_Save"), (s, e) =>
                {
                    //TODO: set values
                    IniFile.Save("noxico.ini");
                    Options.Open();
                })
                {
                    Width = 12
                };
                saveButton.MoveBelow(0, 1, controlList);

                resetButton = new UIButton(i18n.GetString("key_Reset"), (s, e) =>
                {
                    NoxicoGame.ResetKeymap();
                    UpdateItems();
                    UIManager.Highlight = controlList;
                    UIManager.Draw();
                })
                {
                    Width = 12
                };
                resetButton.MoveBeside(2, 0, saveButton);

                UpdateItems();
                UIManager.Elements.Add(window);
                UIManager.Elements.Add(controlList);
                UIManager.Elements.Add(saveButton);
                UIManager.Elements.Add(resetButton);

                Subscreens.Redraw = true;
            }

            if (Subscreens.Redraw)
            {
                Subscreens.Redraw = false;
                UIManager.Draw();
            }

            if (!waitingForKey)
            {
                UIManager.CheckKeys();
            }
            else
            {
                var binding = (KeyBinding)controlList.Index;
                for (var i = 0; i < 255; i++)
                {
                    if ((i >= 16 && i <= 18) || i == 91)
                    {
                        continue;                         //skip modifiers
                    }
                    if (NoxicoGame.KeyMap[(Keys)i])
                    {
                        var theKey = (Keys)i;
                        NoxicoGame.KeyBindings[binding]    = theKey;
                        NoxicoGame.RawBindings[binding]    = theKey.ToString().ToUpperInvariant();
                        NoxicoGame.KeyBindingMods[binding] = NoxicoGame.Modifiers[0];
                        UpdateItems();
                        controlList.DrawQuick();

                        waitingForKey = false;
                        NoxicoGame.KeyMap[(Keys)i] = false;
                        break;
                    }
                }
            }
        }
Beispiel #3
0
        public void RestartGraphics(bool full)
        {
            pngFont = IniFile.GetValue("misc", "font", "8x16-bold");
            if (!Mix.FileExists("fonts\\" + pngFont + ".png"))
            {
                pngFont = "8x16-bold";
                if (!Mix.FileExists("fonts\\" + pngFont + ".png"))
                {
                    SystemMessageBox.Show(this, "Could not find font bitmaps. Please redownload the game.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Close();
                    return;
                }
            }
            var fontBitmap = Mix.GetBitmap("fonts\\" + pngFont + ".png");

            cellWidth  = fontBitmap.Width / 32;
            cellHeight = fontBitmap.Height / 32;

            IsSquare = cellWidth == cellHeight;

            Program.Cols = IniFile.GetValue("misc", "screencols", Program.Cols);
            Program.Rows = IniFile.GetValue("misc", "screenrows", Program.Rows);
            if (full)
            {
                image         = new Cell[Program.Cols, Program.Rows];
                previousImage = new Cell[Program.Cols, Program.Rows];
            }

            CachePNGFont(fontBitmap);

            fourThirtySeven = IniFile.GetValue("misc", "437", false);
            youtube         = IniFile.GetValue("misc", "youtube", false);
            ClientSize      = new Size(Program.Cols * cellWidth, Program.Rows * cellHeight);
            if (youtube)
            {
                //Find nearest YT size
                var eW = Program.Cols * cellWidth;
                var eH = Program.Rows * cellHeight;
                if (eW <= 854 || eH <= 480)
                {
                    ClientSize = new Size(854, 480);
                }
                else if (eW <= 1280 || eH <= 720)
                {
                    ClientSize = new Size(1280, 720);
                }
                else
                {
                    ClientSize = new Size(1920, 1080);
                }

                var prime = Screen.FromRectangle(ClientRectangle).Bounds;
                if (ClientSize.Width == prime.Width && ClientSize.Height == prime.Height)
                {
                    FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
                    Left            = Top = 0;
                }
                else
                {
                    FormBorderStyle = IniFile.GetValue("misc", "border", true) ? System.Windows.Forms.FormBorderStyle.FixedSingle : System.Windows.Forms.FormBorderStyle.None;
                }
                youtubeRect = new System.Drawing.Rectangle((ClientSize.Width / 2) - (eW / 2), (ClientSize.Height / 2) - (eH / 2), eW, eH);
            }
            else
            {
                FormBorderStyle = IniFile.GetValue("misc", "border", true) ? System.Windows.Forms.FormBorderStyle.FixedSingle : System.Windows.Forms.FormBorderStyle.None;
            }

            Show();
            Refresh();

            backBuffer   = new Bitmap(Program.Cols * cellWidth, Program.Rows * cellHeight, PixelFormat.Format24bppRgb);
            scrollBuffer = new Bitmap(Program.Cols * cellWidth, Program.Rows * cellHeight, PixelFormat.Format24bppRgb);
            for (int row = 0; row < Program.Rows; row++)
            {
                for (int col = 0; col < Program.Cols; col++)
                {
                    previousImage[col, row].Character = '\uFFFE';
                }
            }
        }
Beispiel #4
0
        public MainForm()
        {
#if !DEBUG
            try
#endif
            {
                this.Text            = "Noxico";
                this.BackColor       = System.Drawing.Color.Black;
                this.DoubleBuffered  = true;
                this.FormBorderStyle = FormBorderStyle.FixedSingle;
                this.MaximizeBox     = false;             //it's about time, too!
                this.FormClosing    += new FormClosingEventHandler(this.Form1_FormClosing);
                this.KeyDown        += new KeyEventHandler(this.Form1_KeyDown);
                this.KeyPress       += new KeyPressEventHandler(this.Form1_KeyPress);
                this.KeyUp          += new KeyEventHandler(this.Form1_KeyUp);
                this.Icon            = global::Noxico.Properties.Resources.app;
                this.ClientSize      = new Size(Program.Cols * cellWidth, Program.Rows * cellHeight);
                this.Controls.Add(new Label()
                {
                    Text      = "Loading...",
                    AutoSize  = true,
                    Font      = new System.Drawing.Font("Arial", 24, FontStyle.Bold | FontStyle.Italic),
                    ForeColor = System.Drawing.Color.White,
                    Visible   = true,
                    Location  = new System.Drawing.Point(16, 16)
                });

                foreach (var reqDll in new[] { "Neo.Lua.dll" })
                {
                    if (!File.Exists(reqDll))
                    {
                        throw new FileNotFoundException("Required DLL " + reqDll + " is missing.");
                    }
                }

                try
                {
                    Mix.Initialize("Noxico");
                }
                catch (UnauthorizedAccessException)
                {
                    if (!UacHelper.IsProcessElevated)
                    {
                        var proc = new System.Diagnostics.ProcessStartInfo();
                        proc.UseShellExecute  = true;
                        proc.WorkingDirectory = Environment.CurrentDirectory;
                        proc.FileName         = Application.ExecutablePath;
                        proc.Verb             = "runas";
                        try
                        {
                            System.Diagnostics.Process.Start(proc);
                        }
                        catch
                        {
                        }
                    }
                    Close();
                    return;
                }

                if (!Mix.FileExists("credits.txt"))
                {
                    SystemMessageBox.Show(this, "Could not find game data. Please redownload the game.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Close();
                    return;
                }

                var portable = false;
                IniPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "noxico.ini");
                if (File.Exists("noxico.ini"))
                {
                    portable = true;
                    var oldIniPath = IniPath;
                    IniPath = "noxico.ini";
                    Program.CanWrite();

                    /*
                     * if (!Program.CanWrite())
                     * {
                     *      var response = SystemMessageBox.Show(this, "Trying to start in portable mode, but from a protected location. Use non-portable mode?" + Environment.NewLine + "Selecting \"no\" may cause errors.", Application.ProductName, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
                     *      if (response == DialogResult.Cancel)
                     *      {
                     *              Close();
                     *              return;
                     *      }
                     *      else if (response == DialogResult.Yes)
                     *      {
                     *              IniPath = oldIniPath;
                     *              portable = false;
                     *      }
                     * }
                     */
                }

                if (!File.Exists(IniPath) || (new FileInfo(IniPath)).Length < 4)
                {
                    File.WriteAllText(IniPath, Mix.GetString("noxico.ini"));
                }
                IniFile.Load(IniPath);

                if (portable)
                {
                    IniFile.SetValue("misc", "vistasaves", false);
                    IniFile.SetValue("misc", "savepath", "./saves");
                    IniFile.SetValue("misc", "shotpath", "./screenshots");
                }

                RestartGraphics(true);
                fourThirtySeven = IniFile.GetValue("misc", "437", false);

                Noxico = new NoxicoGame();
                Noxico.Initialize(this);

                MouseUp    += new MouseEventHandler(MainForm_MouseUp);
                MouseWheel += new MouseEventHandler(MainForm_MouseWheel);

                GotFocus  += (s, e) => { Vista.GamepadFocused = true; };
                LostFocus += (s, e) => { Vista.GamepadFocused = false; };

                Vista.GamepadEnabled = IniFile.GetValue("misc", "xinput", true);

                Program.WriteLine("Environment: {0} {1}", Environment.OSVersion.Platform, Environment.OSVersion);
                Program.WriteLine("Application: {0}", Application.ProductVersion);
                if (Environment.OSVersion.Platform == PlatformID.Unix)
                {
                    Program.WriteLine("*** You are running on a *nix system. ***");
                    Program.WriteLine("Key repeat delays exaggerated.");
                    NoxicoGame.Mono      = true;
                    Vista.GamepadEnabled = false;
                }

                this.Controls.Clear();
                starting = false;
                Running  = true;

                Cursor           = new Point(-1, -1);
                cursorPens       = new Pen[3, 16];
                cursorPens[0, 0] = cursorPens[1, 0] = cursorPens[2, 0] = Pens.Black;
                for (var i = 1; i < 9; i++)
                {
                    cursorPens[0, i] = cursorPens[0, 16 - i] = new Pen(Color.FromArgb((i * 16) - 1, (i * 16) - 1, 0));
                    cursorPens[1, i] = cursorPens[1, 16 - i] = new Pen(Color.FromArgb(0, (i * 32) - 1, 0));
                    cursorPens[2, i] = cursorPens[2, 16 - i] = new Pen(Color.FromArgb((i * 32) - 1, (i * 32) - 1, (i * 32) - 1));
                }

                fpsTimer = new Timer()
                {
                    Interval = 1000,
                    Enabled  = true,
                };
                fpsTimer.Tick += (s, e) =>
                {
                    this.Text          = "Noxico - " + NoxicoGame.Updates + " updates, " + Frames + " frames";
                    NoxicoGame.Updates = 0;
                    Frames             = 0;
                };
#if GAMELOOP
                while (Running)
                {
                    Noxico.Update();
                    Application.DoEvents();
                }
#else
                FormClosing += new FormClosingEventHandler(MainForm_FormClosing);
                var speed = IniFile.GetValue("misc", "speed", 15);
                if (speed <= 0)
                {
                    speed = 15;
                }
                timer = new Timer()
                {
                    Interval = speed,
                    Enabled  = true,
                };
                timer.Tick += new EventHandler(timer_Tick);
#endif
            }
#if !DEBUG
            catch (Exception x)
            {
                new ErrorForm(x).ShowDialog(this);
                SystemMessageBox.Show(this, x.ToString(), Application.ProductName, MessageBoxButtons.OK);
                Running = false;
                fatal   = true;
                Application.ExitThread();
            }
#endif
            if (!fatal)
            {
                Noxico.SaveGame();
            }
        }
Beispiel #5
0
        public static void Handler()
        {
            if (Subscreens.FirstDraw)
            {
                Subscreens.FirstDraw = false;
                UIManager.Initialize();
                UIManager.Elements.Clear();

                window = new UIWindow(i18n.GetString("opt_title"))
                {
                    Left   = 0,
                    Top    = 0,
                    Width  = 80,
                    Height = 25,
                };
                window.Center();

                var speedLabel = new UILabel(i18n.GetString("opt_speed"));
                speedLabel.Move(3, 2, window);
                speed = new UITextBox(IniFile.GetValue("misc", "speed", "15"))
                {
                    Width   = 4,
                    Numeric = true
                };
                speed.Move(1, 1, speedLabel);

                var fonts            = Mix.GetFilesWithPattern("fonts\\*.png").Select(x => System.IO.Path.GetFileNameWithoutExtension(x)).ToArray();
                var currentFont      = IniFile.GetValue("misc", "font", "8x8-thin");
                var currentFontIndex = 0;
                if (fonts.Contains(currentFont))
                {
                    for (currentFontIndex = 0; currentFontIndex < fonts.Length; currentFontIndex++)
                    {
                        if (fonts[currentFontIndex] == currentFont)
                        {
                            break;
                        }
                    }
                }
                var fontLabel = new UILabel(i18n.GetString("opt_font"));
                fontLabel.Move(0, 3, speedLabel);
                font = new UIList(string.Empty, null, fonts, currentFontIndex)
                {
                    Width  = 20,
                    Height = 8,
                };
                font.Move(1, 1, fontLabel);
                font.Enter = (s, e) =>
                {
                    var previousFont = font.Text;
                    IniFile.SetValue("misc", "font", font.Text);
                    NoxicoGame.HostForm.RestartGraphics(false);
                    IniFile.SetValue("misc", "font", previousFont);
                };
                font.EnsureVisible();

                var screenColsLabel = new UILabel(i18n.GetString("opt_screencols"));
                screenColsLabel.MoveBelow(-1, 1, font);
                screenCols = new UITextBox(IniFile.GetValue("misc", "screencols", "80"))
                {
                    Width   = 4,
                    Numeric = true
                };
                screenCols.Move(1, 1, screenColsLabel);
                var screenRowsLabel = new UILabel(i18n.GetString("opt_screenrows"));
                screenRowsLabel.Move(-1, 1, screenCols);
                screenRows = new UITextBox(IniFile.GetValue("misc", "screenrows", "25"))
                {
                    Width   = 4,
                    Numeric = true
                };
                screenRows.Move(1, 1, screenRowsLabel);
                screenCols.Enter = screenRows.Enter = (s, e) =>
                {
                    var resetGraphics = false;
                    var i             = int.Parse(screenCols.Text);
                    if (i < 80)
                    {
                        i = 80;
                    }
                    if (i > 300)
                    {
                        i = 300;
                    }
                    if (i != Program.Cols)
                    {
                        resetGraphics = true;
                    }
                    Program.Cols = i;
                    IniFile.SetValue("misc", "screencols", i);
                    i = int.Parse(screenRows.Text);
                    if (i < 25)
                    {
                        i = 25;
                    }
                    if (i > 100)
                    {
                        i = 100;
                    }
                    if (i != Program.Rows)
                    {
                        resetGraphics = true;
                    }
                    Program.Rows = i;
                    IniFile.SetValue("misc", "screenrows", i);
                    if (resetGraphics)
                    {
                        NoxicoGame.HostForm.RestartGraphics(true);
                        window.Center();
                        UIManager.ReMove();
                    }
                    Subscreens.Redraw = true;
                    NoxicoGame.Me.CurrentBoard.AimCamera();
                    NoxicoGame.Me.CurrentBoard.Redraw();
                    NoxicoGame.Me.CurrentBoard.Draw();
                };

                var miscWindow = new UIWindow(i18n.GetString("opt_misc"))
                {
                    Width  = 50,
                    Height = 11,
                };
                miscWindow.MoveBeside(2, 0, speedLabel);

                rememberPause = new UIToggle(i18n.GetString("opt_rememberpause"))
                {
                    Checked    = IniFile.GetValue("misc", "rememberpause", true),
                    Background = Color.Transparent,
                };
                rememberPause.Move(2, 1, miscWindow);

                vistaSaves = new UIToggle(i18n.GetString("opt_vistasaves"))
                {
                    Checked    = IniFile.GetValue("misc", "vistasaves", true),
                    Enabled    = Vista.IsVista,
                    Background = Color.Transparent,
                };
                vistaSaves.MoveBelow(0, 1, rememberPause);

                xInput = new UIToggle(i18n.GetString("opt_xinput"))
                {
                    Checked    = IniFile.GetValue("misc", "xinput", true),
                    Enabled    = Vista.IsVista,
                    Background = Color.Transparent,
                };
                xInput.MoveBelow(0, 1, vistaSaves);

                imperial = new UIToggle(i18n.GetString("opt_imperial"))
                {
                    Checked    = IniFile.GetValue("misc", "imperial", false),
                    Background = Color.Transparent,
                };
                imperial.MoveBelow(0, 1, xInput);

                fourThirtySeven = new UIToggle(i18n.GetString("opt_437"))
                {
                    Checked    = IniFile.GetValue("misc", "437", false),
                    Background = Color.Transparent,
                };
                fourThirtySeven.MoveBelow(0, 1, imperial);

                var audioWindow = new UIWindow(i18n.GetString("opt_audio"))
                {
                    Width  = 30,
                    Height = 8,
                };
                audioWindow.MoveBelow(0, 1, miscWindow);

                enableAudio = new UIToggle(i18n.GetString("opt_enableaudio"))
                {
                    Checked    = IniFile.GetValue("audio", "enabled", true),
                    Background = Color.Transparent,
                };
                enableAudio.Move(2, 1, audioWindow);

                var musicVolumeLabel = new UILabel(i18n.GetString("opt_musicvolume"));
                musicVolumeLabel.MoveBelow(0, 1, enableAudio);
                musicVolume = new UITextBox(IniFile.GetValue("audio", "musicvolume", "100"));
                musicVolume.Move(1, 1, musicVolumeLabel);
                var soundVolumeLabel = new UILabel(i18n.GetString("opt_soundvolume"));
                soundVolumeLabel.Move(-1, 1, musicVolume);
                soundVolume = new UITextBox(IniFile.GetValue("audio", "soundvolume", "100"));
                soundVolume.Move(1, 1, soundVolumeLabel);

                saveButton = new UIButton(i18n.GetString("opt_save"), (s, e) =>
                {
                    var i = int.Parse(speed.Text);
                    if (i < 1)
                    {
                        i = 1;
                    }
                    if (i > 200)
                    {
                        i = 200;
                    }
                    IniFile.SetValue("misc", "speed", i);
                    IniFile.SetValue("misc", "font", font.Text);
                    IniFile.SetValue("misc", "rememberpause", rememberPause.Checked);
                    IniFile.SetValue("misc", "vistasaves", vistaSaves.Checked);
                    IniFile.SetValue("misc", "xinput", xInput.Checked);
                    IniFile.SetValue("misc", "imperial", imperial.Checked);
                    IniFile.SetValue("misc", "437", fourThirtySeven.Checked);
                    Vista.GamepadEnabled = xInput.Checked;

                    var resetGraphics = false;
                    i = int.Parse(screenCols.Text);
                    if (i < 80)
                    {
                        i = 80;
                    }
                    if (i > 300)
                    {
                        i = 300;
                    }
                    if (i != Program.Cols)
                    {
                        resetGraphics = true;
                    }
                    Program.Cols = i;
                    IniFile.SetValue("misc", "screencols", i);
                    i = int.Parse(screenRows.Text);
                    if (i < 25)
                    {
                        i = 25;
                    }
                    if (i > 100)
                    {
                        i = 100;
                    }
                    if (i != Program.Rows)
                    {
                        resetGraphics = true;
                    }
                    Program.Rows = i;
                    IniFile.SetValue("misc", "screenrows", i);

                    IniFile.SetValue("misc", "imperial", imperial.Checked);
                    IniFile.SetValue("audio", "enabled", enableAudio.Checked);
                    i = int.Parse(musicVolume.Text);
                    if (i < 0)
                    {
                        i = 0;
                    }
                    if (i > 100)
                    {
                        i = 100;
                    }
                    NoxicoGame.Sound.MusicVolume = i / 100f;
                    IniFile.SetValue("audio", "musicvolume", i);
                    i = int.Parse(soundVolume.Text);
                    if (i < 0)
                    {
                        i = 0;
                    }
                    if (i > 100)
                    {
                        i = 100;
                    }
                    NoxicoGame.Sound.SoundVolume = i / 100f;
                    IniFile.SetValue("audio", "soundvolume", i);

                    if (!enableAudio.Checked && NoxicoGame.Sound != null)
                    {
                        NoxicoGame.Sound.ShutDown();
                    }
                    else if (enableAudio.Checked && !NoxicoGame.Sound.Enabled)
                    {
                        NoxicoGame.Sound = new SoundSystem();
                        if (NoxicoGame.Me.CurrentBoard != null)
                        {
                            NoxicoGame.Me.CurrentBoard.PlayMusic();
                        }
                    }

                    if (resetGraphics)
                    {
                        NoxicoGame.HostForm.RestartGraphics(true);
                    }

                    IniFile.Save(string.Empty);
                    cancelButton.DoEnter();
                })
                {
                    Width = 16
                };
                saveButton.MoveBeside(2, 0, audioWindow);
                keysButton = new UIButton(i18n.GetString("opt_keys"), (s, e) =>
                {
                    Controls.Open();
                })
                {
                    Width = 16
                };
                keysButton.MoveBelow(0, 1, saveButton);
                openButton = new UIButton(i18n.GetString("opt_open"), (s, e) =>
                {
                    System.Diagnostics.Process.Start(NoxicoGame.HostForm.IniPath);
                })
                {
                    Width = 16
                };
                openButton.MoveBelow(0, 1, keysButton);
                cancelButton = new UIButton(i18n.GetString("opt_cancel"), (s, e) =>
                {
                    UIManager.Elements.Clear();
                    NoxicoGame.ClearKeys();
                    NoxicoGame.Immediate = true;
                    NoxicoGame.Me.CurrentBoard.Redraw();
                    NoxicoGame.Me.CurrentBoard.Draw(true);
                    NoxicoGame.Mode      = UserMode.Walkabout;
                    Subscreens.FirstDraw = true;
                })
                {
                    Width = 16
                };
                cancelButton.MoveBelow(0, 1, openButton);

                UIManager.Elements.Add(window);
                UIManager.Elements.Add(speedLabel);
                UIManager.Elements.Add(speed);
                UIManager.Elements.Add(fontLabel);
                UIManager.Elements.Add(font);
                UIManager.Elements.Add(screenColsLabel);
                UIManager.Elements.Add(screenCols);
                UIManager.Elements.Add(screenRowsLabel);
                UIManager.Elements.Add(screenRows);
                UIManager.Elements.Add(miscWindow);
                UIManager.Elements.Add(rememberPause);
                UIManager.Elements.Add(vistaSaves);
                UIManager.Elements.Add(xInput);
                UIManager.Elements.Add(imperial);
                UIManager.Elements.Add(fourThirtySeven);
                UIManager.Elements.Add(audioWindow);
                UIManager.Elements.Add(enableAudio);
                UIManager.Elements.Add(musicVolumeLabel);
                UIManager.Elements.Add(musicVolume);
                UIManager.Elements.Add(soundVolumeLabel);
                UIManager.Elements.Add(soundVolume);
                UIManager.Elements.Add(saveButton);
                UIManager.Elements.Add(keysButton);
                UIManager.Elements.Add(openButton);
                UIManager.Elements.Add(cancelButton);

                Subscreens.FirstDraw = false;
                Subscreens.Redraw    = true;
            }
            if (Subscreens.Redraw)
            {
                Subscreens.Redraw = false;
                UIManager.Draw();
            }

            if (NoxicoGame.IsKeyDown(KeyBinding.Back) || Vista.Triggers == XInputButtons.B)
            {
                cancelButton.DoEnter();
            }
            else
            {
                UIManager.CheckKeys();
            }
        }
Beispiel #6
0
        public static void Handler()
        {
            var host = NoxicoGame.HostForm;

            if (Subscreens.FirstDraw)
            {
                Subscreens.FirstDraw = false;
                UIManager.Initialize();
                UIManager.Elements.Add(new UIWindow(i18n.GetString("pause_title"))
                {
                    Left = 3, Top = 1, Width = 22, Height = pages.Count + 2
                });
                UIManager.Elements.Add(new UIWindow(string.Empty)
                {
                    Left = 28, Top = 1, Width = 49, Height = 23
                });
                list = new UIList()
                {
                    Width = 20, Height = pages.Count, Left = 4, Top = 2, Background = UIColors.WindowBackground
                };
                list.Items.AddRange(pages.Keys);
                list.Change += (s, e) =>
                {
                    page      = list.Index;
                    text.Text = pages.Values.ElementAt(page);
                    UIManager.Draw();
                };
                list.Enter += (s, e) =>
                {
                    if (list.Index == list.Items.Count - 1)                     //can't use absolute index because Debug might be missing.
                    {
                        host.Close();
                    }
                    else if (list.Index == list.Items.Count - 2)                     //same
                    {
                        //System.Diagnostics.Process.Start(host.IniPath);
                        Options.Open();
                    }
                    else if (list.Index == 4)
                    {
                        TextScroller.Plain(Mix.GetString("credits.txt"), i18n.GetString("pause_credits"), false);
                    }
                };
                text = new UILabel("...")
                {
                    Left = 30, Top = 2
                };
                UIManager.Elements.Add(list);
                UIManager.Elements.Add(text);
                list.Index          = IniFile.GetValue("misc", "rememberpause", true) ? page : 0;
                UIManager.Highlight = list;

                Subscreens.Redraw = true;
            }
            if (Subscreens.Redraw)
            {
                Subscreens.Redraw = false;
                UIManager.Draw();
            }

            if (NoxicoGame.IsKeyDown(KeyBinding.Back) || Vista.Triggers == XInputButtons.B)
            {
                NoxicoGame.ClearKeys();
                NoxicoGame.Immediate = true;
                NoxicoGame.Me.CurrentBoard.Redraw();
                NoxicoGame.Me.CurrentBoard.Draw(true);
                NoxicoGame.Mode      = UserMode.Walkabout;
                Subscreens.FirstDraw = true;
            }
            else
            {
                UIManager.CheckKeys();
            }
        }
Beispiel #7
0
        public static void Open()
        {
            var host   = NoxicoGame.HostForm;
            var nox    = host.Noxico;
            var player = nox.Player.Character;

            var hpNow  = player.Health;
            var hpMax  = player.MaximumHealth;
            var health = hpNow + " / " + hpMax;

            if (hpNow <= hpMax / 4)
            {
                health = "<cRed>" + health + "<cSilver>";
            }
            else if (hpNow <= hpMax / 2)
            {
                health = "<cYellow>" + health + "<cSilver>";
            }

            var sb = new StringBuilder();

            sb.AppendLine(i18n.GetString("pause_name").PadEffective(20) + player.Name);
            sb.AppendLine(i18n.GetString("pause_gender").PadEffective(20) + player.Gender);
            sb.AppendLine(i18n.GetString("pause_health").PadEffective(20) + health);
            sb.AppendLine(i18n.GetString("pause_money").PadEffective(20) + player.GetToken("money").Value.ToString("C"));
            sb.AppendLine(i18n.GetString("pause_playtime").PadEffective(20) + nox.Player.PlayingTime.ToString());
            sb.AppendLine(i18n.GetString("pause_worldtime").PadEffective(20) + NoxicoGame.InGameTime.ToString());
            sb.AppendLine();

            player.RecalculateStatBonuses();
            player.CheckHasteSlow();
            foreach (var stat in Lua.Environment.stats)
            {
                if (stat.Value.panel == null)
                {
                    continue;
                }
                string properName = stat.Value.name.ToString();
                string statName   = properName.ToLowerInvariant();
                if (!player.HasToken(statName))
                {
                    sb.AppendLine(properName.PadEffective(20) + "<cGray>-?-");
                }
                else
                {
                    var bonus     = string.Empty;
                    var statBonus = player.GetToken(statName + "bonus").Value;
                    var statBase  = player.GetToken(statName).Value;
                    var total     = statBase + statBonus;
                    if (statBonus > 0)
                    {
                        bonus = "<cGray> (" + statBase + "+" + statBonus + ")<cSilver>";
                    }
                    else if (statBonus < 0)
                    {
                        bonus = "<cFirebrick> (" + statBase + "-" + (-statBonus) + ")<cSilver>";
                    }
                    sb.AppendLine(properName.PadEffective(20) + total + bonus);
                }
            }

            pages[i18n.GetString("pause_charstats")] = sb.ToString();

            sb.Clear();
            foreach (var skill in player.GetToken("skills").Tokens)
            {
                if ((int)skill.Value > 0)
                {
                    var skillName = i18n.GetString("skill_" + skill.Name);
                    if (skillName[0] == '[')                     //Ignore missing skill translations for now.
                    {
                        skillName = skillName.Substring(7, skillName.Length - 8);
                    }
                    sb.AppendLine(skillName.Replace('_', ' ').Titlecase().PadEffective(30) + ((int)skill.Value).ToString());
                }
            }
            pages[i18n.GetString("pause_skills")] = sb.ToString();

            sb.Clear();
            for (var i = 0; i < 4; i++)
            {
                sb.Append(Toolkit.TranslateKey((KeyBinding)i));
            }
            sb.AppendLine("         - " + i18n.GetString("pause_keymove"));
            sb.AppendLine(Toolkit.TranslateKey(KeyBinding.Interact, true).PadEffective(12) + " - " + i18n.GetString("pause_keyinteract"));
            sb.AppendLine(Toolkit.TranslateKey(KeyBinding.Activate, true).PadEffective(12) + " - " + i18n.GetString("pause_keyactivate"));
            sb.AppendLine(Toolkit.TranslateKey(KeyBinding.Rest, true).PadEffective(12) + " - " + i18n.GetString("pause_keyrest"));
            sb.AppendLine(Toolkit.TranslateKey(KeyBinding.Fly, true).PadEffective(12) + " - " + i18n.GetString("pause_keyfly"));
            sb.AppendLine(Toolkit.TranslateKey(KeyBinding.Items, true).PadEffective(12) + " - " + i18n.GetString("pause_keyitems"));
            sb.AppendLine(Toolkit.TranslateKey(KeyBinding.Travel, true).PadEffective(12) + " - " + i18n.GetString("pause_keytravel"));
            sb.AppendLine(Toolkit.TranslateKey(KeyBinding.Accept, true).PadEffective(12) + " - " + i18n.GetString("pause_keyaccept"));
            sb.AppendLine(Toolkit.TranslateKey(KeyBinding.Back, true).PadEffective(12) + " - " + i18n.GetString("pause_keyback"));
            pages[i18n.GetString("pause_keys1")] = sb.ToString();
            sb.Clear();
            sb.AppendLine(Toolkit.TranslateKey(KeyBinding.Pause, true).PadEffective(8) + " - " + i18n.GetString("pause_keypause"));
#if DEBUG
            sb.AppendLine(Toolkit.TranslateKey(System.Windows.Forms.Keys.F3, true).PadEffective(8) + " - Dump board to HTML (debug only)");
#endif
            sb.AppendLine(Toolkit.TranslateKey(KeyBinding.Screenshot, true).PadEffective(8) + " - " + i18n.GetString("pause_keyscreenshot"));
            pages[i18n.GetString("pause_keys2")] = sb.ToString();

#if DEBUG
            var entities = 0;
            var tokens   = 0;
            foreach (var x in nox.Boards.Where(x => x != null))
            {
                if (x == null)
                {
                    continue;
                }
                entities += x.Entities.Count;
                foreach (var c in x.Entities.OfType <BoardChar>())
                {
                    tokens += c.Character.Tokens.Count;
                    foreach (var t in c.Character.Tokens)
                    {
                        tokens += CountTokens(t);
                    }
                }
            }
            ;
            NoxicoGame.KnownItems.ForEach(x =>
            {
                tokens += x.Tokens.Count;
                foreach (var t in x.Tokens)
                {
                    tokens += CountTokens(t);
                }
            });

            pages[i18n.GetString("pause_memstats")] = i18n.Format("pause_memstatscontent",
                                                                  nox.Boards.Count.ToString("G"),
                                                                  nox.Boards.Where(b => b != null).Count().ToString("G"),
                                                                  NoxicoGame.KnownItems.Count.ToString("G"),
                                                                  entities.ToString("G"),
                                                                  tokens.ToString("G"));
#endif

            if (!IniFile.GetValue("misc", "rememberpause", true))
            {
                page = 0;
            }

            NoxicoGame.Subscreen = Handler;
            NoxicoGame.Mode      = UserMode.Subscreen;
            Subscreens.FirstDraw = true;
            NoxicoGame.ClearKeys();
        }