Esempio n. 1
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override async void Initialize()
        {
            base.Initialize();

            WinWarCS.Util.Log.Write(Util.LogType.Generic, Util.LogSeverity.Status, "WinWarCS -- Version: " + Version);

            bool result = await ValidateDataWar();

            if (result == false)
            {
                await Platform.UI.ShowMessageDialog("DATA.WAR not found at expected location '" + AssetProvider.ExpectedDataDirectory +
                                                    "'. Please copy the DATA.WAR from the demo or the full version to that location.\r\nIf you have the full version, " +
                                                    "please also copy all the other .WAR files from the data directory.");

                return;
            }

            Exception loadingException = null;

            try
            {
                Entity.LoadDefaultValues(AssetProvider);
                WarFile.LoadResources(AssetProvider);
                MapTileset.LoadAllTilesets();
            } catch (Exception ex)
            {
                loadingException = ex;
            }

            soundManager = new SoundManager();
            musicManager = new MusicManager();

            if (loadingException != null)
            {
                await Platform.UI.ShowMessageDialog("An error occured during loading of DATA.WAR (" + loadingException + ").");

                return;
            }

            if (WarFile.IsDemo)
            {
                SetNextGameScreen(new MenuGameScreen(false));
            }
            else
            {
                // Play demo
                SetNextGameScreen(new IntroGameScreen(
                                      delegate(bool wasCancelled) {
                    SetNextGameScreen(new MenuGameScreen(!wasCancelled));
                }));
            }
        }
Esempio n. 2
0
        void Core_InsertData(string filepath)
        {
            MapTileset tileset;

            try
            {
                string path = Path.GetDirectoryName(filepath) + '\\';
                string file = Path.GetFileNameWithoutExtension(filepath);

                if (!File.Exists(path + file + ".chr"))
                {
                    throw new Exception("Could not find Tileset file:\n" + path + file + ".chr");
                }
                if (!File.Exists(path + file + ".pal"))
                {
                    throw new Exception("Could not find Palette file:\n" + path + file + ".pal");
                }
                if (!File.Exists(path + file + ".tsa"))
                {
                    throw new Exception("Could not find TSA and Terrain file:\n" + path + file + ".tsa");
                }

                byte[] data_tileset = File.ReadAllBytes(path + file + ".chr");
                byte[] data_palette = File.ReadAllBytes(path + file + ".pal");
                byte[] data_tsa     = File.ReadAllBytes(path + file + ".tsa");
                uint   length       = 32 * 32 * Tile.LENGTH;
                if (data_tileset.Length != length && data_tileset.Length != length * 2)
                {
                    throw new Exception("Tileset .chr file has invalid length." +
                                        "\nIt should be " + length + " or " + length * 2 + " bytes long.");
                }

                tileset = new MapTileset(
                    data_palette,
                    data_tileset.GetBytes(0, (int)length),
                    data_tileset.GetBytes(length),
                    data_tsa);
            }
            catch (Exception ex)
            {
                Program.ShowError("Could not load image data.", ex);
                return;
            }
            Core_Insert(tileset);
        }
Esempio n. 3
0
        void Core_InsertImage(string filepath)
        {
            MapTileset tileset = null;

            try
            {
                string path = Path.GetDirectoryName(filepath) + '\\';
                string file = Path.GetFileNameWithoutExtension(filepath);

                Palette  palette    = null;
                Bitmap   maptileset = new Bitmap(filepath);
                Bitmap   tileset1   = null;
                Bitmap   tileset2   = null;
                string[] extensions = new string[] { "png", "PNG", "bmp", "BMP", "gif", "GIF" };
                for (int i = 0; i < extensions.Length; i++)
                {
                    if (File.Exists(path + file + " palette." + extensions[i]))
                    {
                        palette = new Palette(path + file + " palette." + extensions[i]);
                    }
                    if (File.Exists(path + file + " 1." + extensions[i]))
                    {
                        tileset1 = new Bitmap(path + file + " 1." + extensions[i]);
                    }
                    if (File.Exists(path + file + " 2." + extensions[i]))
                    {
                        tileset2 = new Bitmap(path + file + " 2." + extensions[i]);
                    }
                }
                if (File.Exists(path + file + " palette.pal"))
                {
                    palette = new Palette(path + file + " palette.pal");
                }

                tileset = new MapTileset(palette, maptileset, tileset1, tileset2);
            }
            catch (Exception ex)
            {
                Program.ShowError("Could not load the image file.", ex);
                return;
            }
            Core_Insert(tileset);
        }
Esempio n. 4
0
        void Core_LoadTileset()
        {
            try
            {
                CurrentTileset = new MapTileset(
                    Core.ReadData(Palette_PointerBox.Value, Map.PALETTES * Palette.LENGTH),
                    Core.ReadData(Tileset1_PointerBox.Value, 0),
                    Core.ReadData(Tileset2_PointerBox.Value, 0),
                    Core.ReadData(TilesetTSA_PointerBox.Value, 0));

                Tileset_GridBox.SelectionChanged -= Tileset_GridBox_SelectionChanged;
                Tileset_GridBox.Load(CurrentTileset);
                Tileset_GridBox.SelectionChanged += Tileset_GridBox_SelectionChanged;
            }
            catch (Exception ex)
            {
                Program.ShowError("Could not load the map tileset.", ex);
            }
        }
Esempio n. 5
0
        void Core_LoadTileset()
        {
            try
            {
                byte[] palette_data = Core.ReadData(Palette_PointerBox.Value, Map.PALETTES * GBA.Palette.LENGTH);

                CurrentTileset = new MapTileset(palette_data,
                                                Core.ReadData(Tileset1_PointerBox.Value, 0),
                                                Core.ReadData(Tileset2_PointerBox.Value, 0),
                                                Core.ReadData(TilesetTSA_PointerBox.Value, 0));

                Tileset_GridBox.Load(CurrentTileset);
                Palette_PaletteBox.Load(new GBA.Palette(palette_data, Map.PALETTES * GBA.Palette.MAX));
            }
            catch (Exception ex)
            {
                CurrentTileset = null;
                Program.ShowError("Could not load the the tileset for this chapter.", ex);
            }
        }
Esempio n. 6
0
        void Core_Insert(MapTileset map_tileset)
        {
            Core.SuspendUpdate();
            try
            {
                byte[] data_palette  = Palette.Merge(map_tileset.Palettes).ToBytes(false);
                byte[] data_tileset1 = map_tileset.Tileset1.ToBytes(true);
                byte[] data_tileset2 = map_tileset.Tileset2.ToBytes(true);
                byte[] data_tsa      = map_tileset.GetTSAandTerrain(true);

                var repoints = new List <Tuple <string, Pointer, int> >()
                {
                    Tuple.Create("Palette", Palette_PointerBox.Value, data_palette.Length),
                    Tuple.Create("Tileset 1", Tileset1_PointerBox.Value, data_tileset1.Length),
                    Tuple.Create("Tileset 2", Tileset2_PointerBox.Value, data_tileset2.Length),
                    Tuple.Create("TSA and Terrain", TilesetTSA_PointerBox.Value, data_tsa.Length),
                };
                Pointer address  = Core.GetPointer("Map Data Array");
                var     writepos = new List <Pointer>()
                {
                    address + 4 * Palette_ArrayBox.Value,
                    address + 4 * Tileset1_ArrayBox.Value,
                    address + 4 * Tileset2_ArrayBox.Value,
                    address + 4 * TilesetTSA_ArrayBox.Value,
                };

                bool cancel = Prompt.ShowRepointDialog(this, "Repoint Map Tileset",
                                                       "The map tileset to insert may need some of its parts to be repointed.",
                                                       CurrentEntry_Terrain, repoints.ToArray(), writepos.ToArray());
                if (cancel)
                {
                    return;
                }

                Core.WriteData(this,
                               Core.ReadPointer(writepos[0]),
                               data_palette,
                               "Map Data Array 0x" + Util.ByteToHex(Palette_ArrayBox.Value) + " - Palette written");

                Core.WriteData(this,
                               Core.ReadPointer(writepos[1]),
                               data_tileset1,
                               "Map Data Array 0x" + Util.ByteToHex(Tileset1_ArrayBox.Value) + " - Tileset 1 written");

                Core.WriteData(this,
                               Core.ReadPointer(writepos[2]),
                               data_tileset2,
                               "Map Data Array 0x" + Util.ByteToHex(Tileset2_ArrayBox.Value) + " - Tileset 2 written");

                Core.WriteData(this,
                               Core.ReadPointer(writepos[3]),
                               data_tsa,
                               "Map Data Array 0x" + Util.ByteToHex(TilesetTSA_ArrayBox.Value) + " - TSA and Terrain written");
            }
            catch (Exception ex)
            {
                Program.ShowError("Could not insert image file.", ex);
                Core_Update();
                return;
            }
            Core.ResumeUpdate();
            Core.PerformUpdate();
        }
Esempio n. 7
0
        void Core_LoadMap()
        {
            Pointer address         = Core.GetPointer("Map Data Array");
            Pointer poin_palette    = Core.ReadPointer(address + 4 * (byte)Current["Palette"]);
            Pointer poin_tileset1   = Core.ReadPointer(address + 4 * (byte)Current["Tileset1"]);
            Pointer poin_tileset2   = Core.ReadPointer(address + 4 * (byte)Current["Tileset2"]);
            Pointer poin_tsa        = Core.ReadPointer(address + 4 * (byte)Current["TSA"]);
            Pointer poin_mapdata    = Core.ReadPointer(address + 4 * (byte)Current["Map"]);
            Pointer poin_mapchanges = Core.ReadPointer(address + 4 * (byte)Current["MapChanges"]);

            MapTileset map_tileset;

            try
            {
                map_tileset = new MapTileset(
                    Core.ReadData(poin_palette, Map.PALETTES * Palette.LENGTH),
                    Core.ReadData(poin_tileset1, 0),
                    Core.ReadData(poin_tileset2, 0),
                    Core.ReadData(poin_tsa, 0));
            }
            catch (Exception ex)
            {
                map_tileset = null;
                Program.ShowError("Could not load the the tileset for this chapter.", ex);
            }

            try
            {
                CurrentMap = new Map(map_tileset,
                                     Core.ReadData(poin_mapdata, 0),
                                     poin_mapchanges, false);
            }
            catch (Exception ex)
            {
                CurrentMap = null;
                Program.ShowError("Could not load the map for this chapter.", ex);
            }

            if (CurrentMap.Changes != null)
            {
                MapChanges_ListBox.ItemCheck -= MapChanges_ListBox_ItemCheck;
                if (MapChanges_ListBox.Items.Count > 0)
                {
                    for (int i = 0; i < CurrentMap.ShowChanges.Length; i++)
                    {
                        CurrentMap.ShowChanges[i] = MapChanges_ListBox.GetItemChecked(i);
                    }
                    MapChanges_ListBox.Items.Clear();
                }
                for (int i = 0; i < CurrentMap.Changes.Count; i++)
                {
                    MapChanges_ListBox.Items.Add(
                        "0x" + Util.ByteToHex(CurrentMap.Changes.GetNumber(i)),
                        CurrentMap.ShowChanges[i]);
                }
                MapChanges_ListBox.ItemCheck += MapChanges_ListBox_ItemCheck;
            }

            GBA.Bitmap result = new GBA.Bitmap(CurrentMap);

            if (View_Units.Checked)
            {
                Core_LoadMap_Units(result);
            }

            MapViewBox.Size = new Size(CurrentMap.Width, CurrentMap.Height);
            MapViewBox.Load(result);
        }