/// <summary> /// Runs a block of Lua code from a file, which may be archived. /// </summary> /// <param name="name">The name of the file with the code to run.</param> /// <param name="env">The Lua environment to run it in.</param> /// <returns>The script's return value, or False if an error occurred.</returns> public static LuaResult RunFile(string name, LuaGlobal env = null) { var ret = Run(Mix.GetString(name), env); var files = Mix.GetFilesWithPattern("*-" + name); if (files.Length > 0) { foreach (var extra in files) { ret = Run(Mix.GetString(extra), env); } } return(ret); }
/// <summary> /// Generic Subscreen handler. /// </summary> public static void TitleHandler() { var host = NoxicoGame.HostForm; if (Subscreens.FirstDraw) { Subscreens.FirstDraw = false; host.Clear(); var xScale = Program.Cols / 80f; var yScale = Program.Rows / 25f; var background = new Bitmap(Program.Cols, Program.Rows * 2, System.Drawing.Imaging.PixelFormat.Format24bppRgb); var logo = Mix.GetBitmap("logo.png"); var titleOptions = Mix.GetFilesWithPattern("titles\\*.png"); var chosen = Mix.GetBitmap(titleOptions.PickOne()); //Given our random backdrop and fixed logo, draw them both onto background //because we can't -just- display alpha-blended PNGs. using (var gfx = Graphics.FromImage(background)) { gfx.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High; gfx.Clear(Color.Black); gfx.DrawImage(chosen, 0, 0, Program.Cols, Program.Rows * 2); gfx.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor; gfx.DrawImage(logo, 0, 0, logo.Width * xScale, logo.Height * yScale); } UIManager.Initialize(); titleBack = new UIPNGBackground(background); var subtitleLeft = (int)(10 * xScale); var subtitleTop = (int)((logo.Height * yScale) / 2) + 1; var subtitle = i18n.GetString("ts_subtitle"); var pressEnter = "\xC4\xC4\xC4\xC4\xB4 " + i18n.GetString("ts_pressentertobegin") + " <cGray>\xC3\xC4\xC4\xC4\xC4"; titleCaption = new UILabel(subtitle) { Top = subtitleTop, Left = subtitleLeft + 2, Foreground = Color.Teal, Darken = true }; titlePressEnter = new UILabel(pressEnter) { Top = subtitleTop + 2, Left = subtitleLeft, Foreground = Color.Gray, Darken = true }; UIManager.Elements.Add(titleBack); UIManager.Elements.Add(titleCaption); UIManager.Elements.Add(titlePressEnter); //UIManager.Elements.Add(new UILabel("\u015c") { Top = 6, Left = 50, Foreground = Color.Gray }); UIManager.Draw(); Options.FromTitle = true; } if (NoxicoGame.IsKeyDown(KeyBinding.Accept) || Subscreens.Mouse || Vista.Triggers != 0) { if (Subscreens.Mouse) { Subscreens.UsingMouse = true; } Subscreens.Mouse = false; Subscreens.FirstDraw = true; var rawSaves = Directory.GetDirectories(NoxicoGame.SavePath); var saves = new List <string>(); //Check each possible save's version. foreach (var s in rawSaves) { var verCheck = Path.Combine(s, "version"); if (!File.Exists(verCheck)) { continue; } var version = int.Parse(File.ReadAllText(verCheck)); if (version < 20) { continue; } if (File.Exists(Path.Combine(s, "global.bin"))) { saves.Add(s); } } NoxicoGame.ClearKeys(); Subscreens.Mouse = false; //Linq up a set of options for each save game. This returns the game's names as the keys. var options = saves.ToDictionary(new Func <string, object>(s => Path.GetFileName(s)), new Func <string, string>(s => { string p; var playerFile = Path.Combine(s, "player.bin"); if (File.Exists(playerFile)) { using (var f = new BinaryReader(File.OpenRead(playerFile))) { p = Player.LoadFromFile(f).Character.Name.ToString(true); } return(i18n.Format("ts_loadgame", p, Path.GetFileName(s))); } return(i18n.Format("ts_startoverinx", Path.GetFileName(s))); })); options.Add("~", i18n.GetString("ts_startnewgame")); options.Add("~~", i18n.GetString("ts_testingarena")); options.Add("~~~", i18n.GetString("ts_options")); //Display our list of saves. MessageBox.List(saves.Count == 0 ? i18n.GetString("ts_welcometonoxico") : i18n.GetString(saves.Count == 1 ? "ts_thereisasave" : "ts_therearesaves"), options, () => { if ((string)MessageBox.Answer == "~") { //Restore our title screen backdrop, since the MessageBox subscreen purged it. UIManager.Elements.Add(titleBack); UIManager.Elements.Add(titleCaption); UIManager.Elements.Add(titlePressEnter); UIManager.Draw(); MessageBox.Input("What name would you like for your new world?", NoxicoGame.RollWorldName(), () => { NoxicoGame.WorldName = (string)MessageBox.Answer; NoxicoGame.Mode = UserMode.Subscreen; NoxicoGame.Subscreen = Introduction.CharacterCreator; NoxicoGame.Immediate = true; } ); } else if ((string)MessageBox.Answer == "~~") { NoxicoGame.WorldName = "<Testing Arena>"; var env = Lua.Environment; Lua.RunFile("testarena.lua"); var testBoard = new Board(env.TestArena.ArenaWidth, env.TestArena.ArenaHeight); var me = NoxicoGame.Me; me.Boards.Add(testBoard); me.CurrentBoard = testBoard; me.CreatePlayerCharacter(env.TestArena.Name, env.TestArena.BioGender, env.TestArena.IdentifyAs, env.TestArena.Preference, env.TestArena.Bodyplan, new Dictionary <string, string>(), env.TestArena.BonusTrait); env.BuildTestArena(testBoard); me.Player.ParentBoard = testBoard; testBoard.EntitiesToAdd.Add(me.Player); NoxicoGame.InGameTime = new DateTime(740 + Random.Next(0, 20), 6, 26, 12, 0, 0); testBoard.UpdateLightmap(null, true); testBoard.AimCamera(); testBoard.Redraw(); testBoard.Draw(); Options.FromTitle = false; Subscreens.FirstDraw = true; NoxicoGame.Immediate = true; NoxicoGame.AddMessage(i18n.GetString("welcometest"), Color.Yellow); NoxicoGame.AddMessage(i18n.GetString("rememberhelp")); NoxicoGame.Mode = UserMode.Walkabout; } else if ((string)MessageBox.Answer == "~~~") { Options.FromTitle = true; //Restore our title screen backdrop, since the MessageBox subscreen purged it. UIManager.Initialize(); UIManager.Elements.Add(titleBack); UIManager.Elements.Add(titleCaption); UIManager.Elements.Add(titlePressEnter); Options.Open(); } else { Options.FromTitle = false; NoxicoGame.WorldName = (string)MessageBox.Answer; host.Noxico.LoadGame(); NoxicoGame.Me.CurrentBoard.Draw(); Subscreens.FirstDraw = true; NoxicoGame.Immediate = true; NoxicoGame.AddMessage(i18n.GetString("welcomeback"), Color.Yellow); NoxicoGame.AddMessage(i18n.GetString("rememberhelp")); //TextScroller.LookAt(NoxicoGame.Me.Player); NoxicoGame.Mode = UserMode.Walkabout; } } ); } }
public static void Handler() { if (Subscreens.FirstDraw) { Subscreens.FirstDraw = false; if (!FromTitle) { UIManager.Initialize(); UIManager.Elements.Clear(); } else { //Leave the title screen background UIManager.Highlight = UIManager.Elements[0]; UIManager.Elements.RemoveRange(3, UIManager.Elements.Count - 3); } 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; if (FromTitle) { Introduction.Title(); } 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(); } }