diff --git a/OpenDiablo2.Common/Enums/eButtonType.cs b/OpenDiablo2.Common/Enums/eButtonType.cs index dd222d62..c984bffd 100644 --- a/OpenDiablo2.Common/Enums/eButtonType.cs +++ b/OpenDiablo2.Common/Enums/eButtonType.cs @@ -3,6 +3,7 @@ public enum eButtonType { Wide, + Medium, Cancel } } diff --git a/OpenDiablo2.Common/Models/ButtonLayout.cs b/OpenDiablo2.Common/Models/ButtonLayout.cs index 0b997a3a..cf4400d7 100644 --- a/OpenDiablo2.Common/Models/ButtonLayout.cs +++ b/OpenDiablo2.Common/Models/ButtonLayout.cs @@ -16,6 +16,7 @@ namespace OpenDiablo2.Common.Models public static Dictionary Values = new Dictionary { {eButtonType.Wide, new ButtonLayout { XSegments = 2, ResourceName = ResourcePaths.WideButtonBlank, PaletteName = Palettes.Units } }, + {eButtonType.Medium, new ButtonLayout{ XSegments = 1, ResourceName=ResourcePaths.MediumButtonBlank, PaletteName = Palettes.Units } }, {eButtonType.Cancel, new ButtonLayout {XSegments = 1,ResourceName = ResourcePaths.CancelButton,PaletteName = Palettes.Units } } }; } diff --git a/OpenDiablo2.Common/Models/ImageSet.cs b/OpenDiablo2.Common/Models/ImageSet.cs index f925f634..605b29ac 100644 --- a/OpenDiablo2.Common/Models/ImageSet.cs +++ b/OpenDiablo2.Common/Models/ImageSet.cs @@ -19,16 +19,16 @@ namespace OpenDiablo2.Common.Models public UInt32 Unknown; public UInt32 NextBlock; public UInt32 Length; - public Int16[,] ImageData; + public Int16[] ImageData; public void Dispose() { - ImageData = new Int16[0, 0]; + ImageData = new Int16[0]; } public Color GetColor(int x, int y, Palette palette) { - var index = ImageData[x, y]; + var index = ImageData[x + (y * Width)]; if (index == -1) return Color.Transparent; @@ -86,10 +86,10 @@ namespace OpenDiablo2.Common.Models Length = br.ReadUInt32() }; - result.Frames[i].ImageData = new Int16[result.Frames[i].Width, result.Frames[i].Height]; + result.Frames[i].ImageData = new Int16[result.Frames[i].Width * result.Frames[i].Height]; for (int ty = 0; ty < result.Frames[i].Height; ty++) for (int tx = 0; tx < result.Frames[i].Width; tx++) - result.Frames[i].ImageData[tx, ty] = -1; + result.Frames[i].ImageData[tx + (ty * result.Frames[i].Width)] = -1; int x = 0; @@ -110,17 +110,19 @@ namespace OpenDiablo2.Common.Models if ((b & 0x80) > 0) { var transparentPixelsToWrite = b & 0x7F; - for (int p = 0; p < transparentPixelsToWrite; p++) - { - result.Frames[i].ImageData[x++, y] = -1; - } + + Enumerable.Repeat(-1, transparentPixelsToWrite).ToArray() + .CopyTo(result.Frames[i].ImageData, x + (y * result.Frames[i].Width)); + x += transparentPixelsToWrite; + continue; } - for (int p = 0; p < b; p++) - { - result.Frames[i].ImageData[x++, y] = br.ReadByte(); - } + + br.ReadBytes(b).CopyTo(result.Frames[i].ImageData, x + (y * result.Frames[i].Width)); + x += b; + + } } diff --git a/OpenDiablo2.Common/ResourcePaths.cs b/OpenDiablo2.Common/ResourcePaths.cs index e0ddd703..9f183744 100644 --- a/OpenDiablo2.Common/ResourcePaths.cs +++ b/OpenDiablo2.Common/ResourcePaths.cs @@ -40,6 +40,7 @@ namespace OpenDiablo2.Common // --- UI --- public static string WideButtonBlank = "data\\global\\ui\\FrontEnd\\WideButtonBlank.dc6"; + public static string MediumButtonBlank = "data\\global\\ui\\FrontEnd\\MediumButtonBlank.dc6"; public static string CancelButton = "data\\global\\ui\\FrontEnd\\CancelButtonBlank.dc6"; } diff --git a/OpenDiablo2.SDL2/OpenDiablo2.SDL2.csproj b/OpenDiablo2.SDL2/OpenDiablo2.SDL2.csproj index 8500aeb7..825aafc7 100644 --- a/OpenDiablo2.SDL2/OpenDiablo2.SDL2.csproj +++ b/OpenDiablo2.SDL2/OpenDiablo2.SDL2.csproj @@ -49,6 +49,7 @@ x64 prompt MinimumRecommendedRules.ruleset + true diff --git a/OpenDiablo2.SDL2/SDL2Sprite.cs b/OpenDiablo2.SDL2/SDL2Sprite.cs index 1eabdf84..1eda1bb7 100644 --- a/OpenDiablo2.SDL2/SDL2Sprite.cs +++ b/OpenDiablo2.SDL2/SDL2Sprite.cs @@ -67,17 +67,13 @@ namespace OpenDiablo2.SDL2_ public Size LocalFrameSize => new Size((int)source.Frames[Frame].Width, (int)source.Frames[Frame].Height); + // TODO: This is slow. Make fix. private void UpdateTextureData() { - foreach (var texture in textures) - { - SDL.SDL_DestroyTexture(texture); - } - textures = new IntPtr[TotalFrames]; for (var i = 0; i < source.Frames.Count(); i++) - textures[i] = LoadFrame(source.Frames[i], renderer); + LoadFrame(i, renderer); } @@ -91,32 +87,40 @@ namespace OpenDiablo2.SDL2_ (byte)Math.Min((float)source.B * 1.2, 255) ); - private IntPtr LoadFrame(ImageFrame frame, IntPtr renderer) + object bob = new object(); + private void LoadFrame(int index, IntPtr renderer) { - var texture = SDL.SDL_CreateTexture(renderer, SDL.SDL_PIXELFORMAT_ARGB8888, (int)SDL.SDL_TextureAccess.SDL_TEXTUREACCESS_TARGET, Pow2(FrameSize.Width), Pow2(FrameSize.Height)); + var frame = source.Frames[index]; - if (texture == IntPtr.Zero) + if (textures[index] == IntPtr.Zero) + textures[index] = SDL.SDL_CreateTexture(renderer, SDL.SDL_PIXELFORMAT_ARGB8888, (int)SDL.SDL_TextureAccess.SDL_TEXTUREACCESS_TARGET, Pow2(FrameSize.Width), Pow2(FrameSize.Height)); + + if (textures[index] == IntPtr.Zero) throw new ApplicationException("Unaple to initialize texture."); - SDL.SDL_SetTextureBlendMode(texture, SDL.SDL_BlendMode.SDL_BLENDMODE_BLEND); - SDL.SDL_SetRenderTarget(renderer, texture); + SDL.SDL_SetTextureBlendMode(textures[index], SDL.SDL_BlendMode.SDL_BLENDMODE_BLEND); + SDL.SDL_SetRenderTarget(renderer, textures[index]); SDL.SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0); SDL.SDL_RenderFillRect(renderer, IntPtr.Zero); SDL.SDL_SetRenderTarget(renderer, IntPtr.Zero); var binaryData = new UInt32[frame.Width * frame.Height]; - for (int y = 0; y < frame.Height; y++) + for (var y = 0; y < frame.Height; y++) + { for (int x = 0; x < frame.Width; x++) { - var col = AdjustColor(frame.GetColor(x, y, CurrentPalette)); - binaryData[x + y * frame.Width] = (uint)col.ToArgb(); + var palColor = frame.GetColor(x, (int)y, CurrentPalette); + //var col = AdjustColor(palColor); + binaryData[x + y * frame.Width] = (uint)palColor.ToArgb(); } + } + + var rect = new SDL.SDL_Rect { x = 0, y = FrameSize.Height - (int)frame.Height, w = (int)frame.Width, h = (int)frame.Height }; GCHandle pinnedArray = GCHandle.Alloc(binaryData, GCHandleType.Pinned); - SDL.SDL_UpdateTexture(texture, ref rect, pinnedArray.AddrOfPinnedObject(), (int)frame.Width * 4); + SDL.SDL_UpdateTexture(textures[index], ref rect, pinnedArray.AddrOfPinnedObject(), (int)frame.Width * 4); pinnedArray.Free(); - return texture; } diff --git a/OpenDiablo2.Scenes/MainMenu.cs b/OpenDiablo2.Scenes/MainMenu.cs index 8985fc07..7a8c8720 100644 --- a/OpenDiablo2.Scenes/MainMenu.cs +++ b/OpenDiablo2.Scenes/MainMenu.cs @@ -85,18 +85,6 @@ namespace OpenDiablo2.Scenes /* musicProvider.LoadSong(mpqProvider.GetStream("data\\global\\music\\introedit.wav")); - // TODO: Fake loading for now, this should be in its own scene as we start loading real stuff - var r = new Random(); - for (int i = 1; i < 10; i++) - { - renderWindow.Clear(); - loadingSprite.Frame = i; - renderWindow.Draw(loadingSprite); - renderWindow.Sync(); - Thread.Sleep(r.Next(150)); - - } - musicProvider.PlaySong(); */ } diff --git a/OpenDiablo2.Scenes/SelectHeroClass.cs b/OpenDiablo2.Scenes/SelectHeroClass.cs index 67a1fcfc..022d8c34 100644 --- a/OpenDiablo2.Scenes/SelectHeroClass.cs +++ b/OpenDiablo2.Scenes/SelectHeroClass.cs @@ -51,11 +51,11 @@ namespace OpenDiablo2.Scenes headingFont = renderWindow.LoadFont(ResourcePaths.Font30, Palettes.Units); headingLabel = renderWindow.CreateLabel(headingFont); headingLabel.Text = "Select Hero Class"; - headingLabel.Location = new System.Drawing.Point(400 - (headingLabel.TextArea.Width / 2), 20); + headingLabel.Location = new System.Drawing.Point(400 - (headingLabel.TextArea.Width / 2), 17); - exitButton = createButton(eButtonType.Cancel); + exitButton = createButton(eButtonType.Medium); exitButton.Text = "EXIT"; - exitButton.Location = new System.Drawing.Point(30, 550); + exitButton.Location = new System.Drawing.Point(30, 540); exitButton.OnActivate = OnExitClicked; }