コード例 #1
0
        public ImageSet GetImageSet(string resourcePath)
        {
            if (!ImageSets.ContainsKey(resourcePath))
            {
                ImageSets[resourcePath] = ImageSet.LoadFromStream(mpqProvider.GetStream(resourcePath));
            }

            return(ImageSets[resourcePath]);
        }
コード例 #2
0
        public ResourceManager(ICache cache, IMPQProvider mpqProvider, IEngineDataManager engineDataManager)
        {
            this.cache             = cache;
            this.mpqProvider       = mpqProvider;
            this.engineDataManager = engineDataManager;

            Animations = AnimationData.LoadFromStream(mpqProvider.GetStream(ResourcePaths.AnimationData));
        }
コード例 #3
0
        private void LoadExpansionTable()
        {
            using (var stream = mpqProvider.GetStream(ResourcePaths.ExpansionStringTable))
                using (var br = new BinaryReader(stream))
                {
                    br.ReadBytes(2); // CRC
                    var numberOfElements = br.ReadUInt16();
                    var hashTableSize    = br.ReadUInt32();
                    br.ReadByte();   // Version (always 0)
                    br.ReadUInt32(); // StringOffset
                    br.ReadUInt32(); // NumberOfLoopsOffset
                    br.ReadUInt32(); // FileSize

                    var elementIndexes = new List <UInt16>();
                    for (var elementIndex = 0; elementIndex < numberOfElements; elementIndex++)
                    {
                        elementIndexes.Add(br.ReadUInt16());
                    }

                    var hashEntries = new List <HashTableEntry>();
                    for (var hashEntryIndex = 0; hashEntryIndex < hashTableSize; hashEntryIndex++)
                    {
                        hashEntries.Add(new HashTableEntry
                        {
                            IsActive    = br.ReadByte() == 1,
                            Index       = br.ReadUInt16(),
                            HashValue   = br.ReadUInt32(),
                            IndexString = br.ReadUInt32(),
                            NameString  = br.ReadUInt32(),
                            NameLength  = br.ReadUInt16()
                        });
                    }

                    foreach (var hashEntry in hashEntries.Where(x => x.IsActive))
                    {
                        stream.Seek(hashEntry.NameString, SeekOrigin.Begin);
                        var value = Encoding.ASCII.GetString(br.ReadBytes(hashEntry.NameLength - 1));

                        stream.Seek(hashEntry.IndexString, SeekOrigin.Begin);

                        var key = new StringBuilder();
                        while (true)
                        {
                            var b = br.ReadByte();
                            if (b == 0)
                            {
                                break;
                            }
                            key.Append((char)b);
                        }

                        lookupTable[key.ToString()] = value;
                    }
                }
        }
コード例 #4
0
        public MainMenu(
            IRenderWindow renderWindow,
            ISceneManager sceneManager,
            ITextDictionary textDictionary,
            IResourceManager resourceManager,
            ISoundProvider soundProvider,
            IMPQProvider mpqProvider,
            Func <eButtonType, IButton> createButton
            )
        {
            this.renderWindow = renderWindow;
            this.sceneManager = sceneManager;

            backgroundSprite      = renderWindow.LoadSprite(ResourcePaths.GameSelectScreen, Palettes.Sky);
            diabloLogoLeft        = renderWindow.LoadSprite(ResourcePaths.Diablo2LogoFireLeft, Palettes.Units, new Point(400, 120));
            diabloLogoLeft.Blend  = true;
            diabloLogoRight       = renderWindow.LoadSprite(ResourcePaths.Diablo2LogoFireRight, Palettes.Units, new Point(400, 120));
            diabloLogoRight.Blend = true;
            diabloLogoLeftBlack   = renderWindow.LoadSprite(ResourcePaths.Diablo2LogoBlackLeft, Palettes.Units, new Point(400, 120));
            diabloLogoRightBlack  = renderWindow.LoadSprite(ResourcePaths.Diablo2LogoBlackRight, Palettes.Units, new Point(400, 120));

            btnSinglePlayer            = createButton(eButtonType.Wide);
            btnSinglePlayer.Text       = textDictionary.Translate("strStartMenu1");
            btnSinglePlayer.Location   = new Point(264, 290);
            btnSinglePlayer.OnActivate = OnSinglePlayerClicked;

            btnWebsite            = createButton(eButtonType.Wide);
            btnWebsite.Text       = "Visit Github".ToUpper();
            btnWebsite.Location   = new Point(264, 330);
            btnWebsite.OnActivate = OnVisitWebsiteClicked;

            btnExit            = createButton(eButtonType.Wide);
            btnExit.Text       = textDictionary.Translate("strexitentiregame");
            btnExit.Location   = new Point(264, 500);
            btnExit.OnActivate = OnExitClicked;

            btnCredits            = createButton(eButtonType.Short);
            btnCredits.Text       = textDictionary.Translate("strGameCredits"); /* TODO: We apparently need a 'half font' option... */
            btnCredits.Location   = new Point(264, 470);
            btnCredits.OnActivate = OnCreditsClicked;

            labelFont          = renderWindow.LoadFont(ResourcePaths.Font16, Palettes.Static);
            versionLabel       = renderWindow.CreateLabel(labelFont, new Point(50, 555), "v0.02 Pre-Alpha");
            urlLabel           = renderWindow.CreateLabel(labelFont, new Point(50, 569), "https://github.com/essial/OpenDiablo2/");
            urlLabel.TextColor = Color.Magenta;

            soundProvider.LoadSong(mpqProvider.GetStream(ResourcePaths.BGMTitle));
            soundProvider.PlaySong();
        }
コード例 #5
0
        public MainMenu(
            IRenderWindow renderWindow,
            ISceneManager sceneManager,
            IResourceManager resourceManager,
            ISoundProvider soundProvider,
            IMPQProvider mpqProvider,
            Func <eButtonType, IButton> createButton,
            Func <eSceneType, IScene> getScene // Temporary until SDL load functions are sped up
            )
        {
            this.renderWindow = renderWindow;
            this.sceneManager = sceneManager;

            backgroundSprite      = renderWindow.LoadSprite(ResourcePaths.GameSelectScreen, Palettes.Sky);
            diabloLogoLeft        = renderWindow.LoadSprite(ResourcePaths.Diablo2LogoFireLeft, Palettes.Units, new Point(400, 120));
            diabloLogoLeft.Blend  = true;
            diabloLogoRight       = renderWindow.LoadSprite(ResourcePaths.Diablo2LogoFireRight, Palettes.Units, new Point(400, 120));
            diabloLogoRight.Blend = true;
            diabloLogoLeftBlack   = renderWindow.LoadSprite(ResourcePaths.Diablo2LogoBlackLeft, Palettes.Units, new Point(400, 120));
            diabloLogoRightBlack  = renderWindow.LoadSprite(ResourcePaths.Diablo2LogoBlackRight, Palettes.Units, new Point(400, 120));

            btnSinglePlayer            = createButton(eButtonType.Wide);
            btnSinglePlayer.Text       = "Single Player".ToUpper();
            btnSinglePlayer.Location   = new Point(264, 290);
            btnSinglePlayer.OnActivate = OnSinglePlayerClicked;

            btnWebsite            = createButton(eButtonType.Wide);
            btnWebsite.Text       = "Visit Github".ToUpper();
            btnWebsite.Location   = new Point(264, 460);
            btnWebsite.OnActivate = OnVisitWebsiteClicked;

            btnExit            = createButton(eButtonType.Wide);
            btnExit.Text       = "Exit Diablo II".ToUpper();
            btnExit.Location   = new Point(264, 500);
            btnExit.OnActivate = OnExitClicked;

            labelFont          = renderWindow.LoadFont(ResourcePaths.Font16, Palettes.Static);
            versionLabel       = renderWindow.CreateLabel(labelFont, new Point(50, 555), "v0.01 Pre-Alpha");
            urlLabel           = renderWindow.CreateLabel(labelFont, new Point(50, 569), "https://github.com/essial/OpenDiablo2/");
            urlLabel.TextColor = Color.Magenta;

            soundProvider.LoadSong(mpqProvider.GetStream(ResourcePaths.BGMTitle));
            soundProvider.PlaySong();
        }
コード例 #6
0
 public ImageSet GetImageSet(string resourcePath)
 // => cache.AddOrGetExisting($"ImageSet::{resourcePath}", () => ImageSet.LoadFromStream(mpqProvider.GetStream(resourcePath)));
 => ImageSet.LoadFromStream(mpqProvider.GetStream(resourcePath));
コード例 #7
0
ファイル: GameState.cs プロジェクト: tongbenchuan/OpenDiablo2
        public IMapInfo InsertMap(int levelId, Point origin, IMapInfo parentMap = null)
        {
            var levelDetails = engineDataManager.Levels.First(x => x.Id == levelId);

            if (levelDetails.LevelPreset == null)
            {
                // There is no preset level, so we must generate one
                var generator = getRandomizedMapGenerator(levelDetails.LevelName);

                if (generator == null)
                {
                    throw new OpenDiablo2Exception($"Could not locate a map generator for '{levelDetails.LevelName}'.");
                }

                generator.Generate(parentMap, origin);

                // There is no core map so we cannot return a value here. If anyone actually uses
                // this value on a generated map they are making a terrible mistake anyway...
                return(null);
            }

            // Some maps have variations, so lets pick a random one
            var mapNames = new List <string>();

            if (levelDetails.LevelPreset.File1 != "0")
            {
                mapNames.Add(levelDetails.LevelPreset.File1);
            }
            if (levelDetails.LevelPreset.File2 != "0")
            {
                mapNames.Add(levelDetails.LevelPreset.File2);
            }
            if (levelDetails.LevelPreset.File3 != "0")
            {
                mapNames.Add(levelDetails.LevelPreset.File3);
            }
            if (levelDetails.LevelPreset.File4 != "0")
            {
                mapNames.Add(levelDetails.LevelPreset.File4);
            }
            if (levelDetails.LevelPreset.File5 != "0")
            {
                mapNames.Add(levelDetails.LevelPreset.File5);
            }
            if (levelDetails.LevelPreset.File6 != "0")
            {
                mapNames.Add(levelDetails.LevelPreset.File6);
            }


            var random = new Random(Seed);
            // -------------------------------------------------------------------------------------
            // var mapName = "data\\global\\tiles\\" + mapNames[random.Next(mapNames.Count)].Replace("/", "\\");
            // -------------------------------------------------------------------------------------
            // TODO: ***TEMP FOR TESTING
            var mapName = "data\\global\\tiles\\" + mapNames[0].Replace("/", "\\");

            // -------------------------------------------------------------------------------------
            MapName = levelDetails.LevelPreset.Name;
            Act     = levelDetails.LevelType.Act;

            var fileData = resourceManager.GetMPQDS1(mapName, levelDetails.LevelPreset, levelDetails.LevelType);

            var result = new MapInfo
            {
                LevelId      = levelId,
                FileData     = fileData,
                CellInfo     = new Dictionary <eRenderCellType, MapCellInfo[]>(),
                TileLocation = new Rectangle(origin, new Size(fileData.Width - 1, fileData.Height - 1))
            };

            mapInfo.Add(result);

            // Only change music if loading a 'core' map
            if (Enum.IsDefined(typeof(eLevelId), levelId))
            {
                soundProvider.StopSong();
                soundProvider.LoadSong(mpqProvider.GetStream(ResourcePaths.GetMusicPathForLevel((eLevelId)levelId)));
                soundProvider.PlaySong();
            }


            return(result);
        }