From bd6c5a7e0fd8f24b1bd52e17997437ee41edd330 Mon Sep 17 00:00:00 2001 From: Tim Sarbin Date: Sat, 8 Dec 2018 09:32:09 -0500 Subject: [PATCH] Lots of minor code cleanup. --- OpenDiablo2.Common/Models/BitStream.cs | 2 +- OpenDiablo2.Common/Models/MPQ.cs | 22 +- OpenDiablo2.Common/Models/MPQCOF.cs | 10 +- OpenDiablo2.Common/Models/MPQDT1.cs | 2 +- OpenDiablo2.Common/Models/MPQHuffman.cs | 18 +- OpenDiablo2.Common/Models/MPQStream.cs | 2 +- .../Models/Mobs/LevelExperienceConfig.cs | 8 +- OpenDiablo2.Common/Models/Mobs/PlayerState.cs | 4 +- OpenDiablo2.Common/Models/PKLibDecompress.cs | 10 +- OpenDiablo2.Common/Models/PlayerInfo.cs | 12 +- OpenDiablo2.Core/GameEngine.cs | 5 +- OpenDiablo2.Core/GameState/GameState.cs | 2 +- OpenDiablo2.Core/GameState/MobManager.cs | 2 +- OpenDiablo2.Core/ItemManager.cs | 2 +- OpenDiablo2.Core/MPQProvider.cs | 7 +- OpenDiablo2.Core/Map Engine/MapEngine.cs | 22 +- OpenDiablo2.Core/ResourceManager.cs | 10 +- OpenDiablo2.Core/TextDictionary.cs | 2 +- OpenDiablo2.Core/UI/Button.cs | 9 +- OpenDiablo2.Core/UI/CharacterPanel.cs | 2 +- OpenDiablo2.Core/UI/InventoryPanel.cs | 8 +- OpenDiablo2.Core/UI/ItemContainer.cs | 227 +++++++++--------- OpenDiablo2.Core/UI/PanelFrame.cs | 4 +- OpenDiablo2.Core/UI/TextBox.cs | 6 +- OpenDiablo2.SDL2/CS-SDL/SDL2.cs | 78 +++--- OpenDiablo2.SDL2/SDL2CharacterRenderer.cs | 27 ++- OpenDiablo2.SDL2/SDL2Extensions.cs | 18 +- OpenDiablo2.SDL2/SDL2Font.cs | 24 +- OpenDiablo2.SDL2/SDL2Label.cs | 25 +- OpenDiablo2.SDL2/SDL2MouseCursor.cs | 19 +- OpenDiablo2.SDL2/SDL2MusicPlayer.cs | 25 +- OpenDiablo2.SDL2/SDL2RenderWindow.cs | 25 +- OpenDiablo2.SDL2/SDL2Sprite.cs | 25 +- OpenDiablo2.SDL2/SDL2Texture.cs | 18 +- OpenDiablo2.Scenes/CharacterSelection.cs | 4 - OpenDiablo2.Scenes/Game.cs | 12 +- OpenDiablo2.Scenes/MainMenu.cs | 22 +- OpenDiablo2.Scenes/SelectHeroClass.cs | 34 ++- OpenDiablo2.ServiceBus/SessionManager.cs | 2 +- OpenDiablo2.ServiceBus/SessionServer.cs | 2 +- 40 files changed, 420 insertions(+), 338 deletions(-) diff --git a/OpenDiablo2.Common/Models/BitStream.cs b/OpenDiablo2.Common/Models/BitStream.cs index e79ac503..13d86fd3 100644 --- a/OpenDiablo2.Common/Models/BitStream.cs +++ b/OpenDiablo2.Common/Models/BitStream.cs @@ -8,7 +8,7 @@ namespace OpenDiablo2.Common.Models /// internal class BitStream { - private Stream _baseStream; + private readonly Stream _baseStream; private int _current; private int _bitCount; diff --git a/OpenDiablo2.Common/Models/MPQ.cs b/OpenDiablo2.Common/Models/MPQ.cs index e923bc9d..8b4c98e5 100644 --- a/OpenDiablo2.Common/Models/MPQ.cs +++ b/OpenDiablo2.Common/Models/MPQ.cs @@ -1,17 +1,16 @@ -using OpenDiablo2.Common.Enums; -using System; +using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; -using System.Threading.Tasks; +using OpenDiablo2.Common.Enums; namespace OpenDiablo2.Common.Models { public sealed class MPQ : IDisposable { private const string HEADER_SIGNATURE = "MPQ\x1A"; - private const string USERDATA_SIGNATURE = "MPQ\x1B"; + //private const string USERDATA_SIGNATURE = "MPQ\x1B"; private const string LISTFILE_NAME = "(listfile)"; private const int MPQ_HASH_FILE_KEY = 3; private const int MPQ_HASH_TABLE_OFFSET = 0; @@ -34,7 +33,9 @@ namespace OpenDiablo2.Common.Models } [Flags] +#pragma warning disable IDE1006 // Naming Styles internal enum eBlockRecordFlags : UInt32 +#pragma warning restore IDE1006 // Naming Styles { IsFile = 0x80000000, // Block is a file, and follows the file data format; otherwise, block is free space or unused. If the block is not a file, all other flags should be cleared, and FileSize should be 0. SingleUnit = 0x01000000, // File is stored as a single unit, rather than split into sectors. @@ -72,8 +73,8 @@ namespace OpenDiablo2.Common.Models internal static UInt32[] cryptTable = new UInt32[0x500]; internal HeaderRecord Header; - private List blockTable = new List(); - private List hashTable = new List(); + private readonly List blockTable = new List(); + private readonly List hashTable = new List(); internal Stream fileStream; public UInt16 LanguageId = 0; @@ -85,7 +86,7 @@ namespace OpenDiablo2.Common.Models private List GetFilePaths() { - using (var stream = OpenFile("(listfile)")) + using (var stream = OpenFile(LISTFILE_NAME)) { if (stream == null) { @@ -346,13 +347,10 @@ namespace OpenDiablo2.Common.Models public MPQStream OpenFile(string filename) { - HashRecord hash; - BlockRecord block; - - if (!GetHashRecord(filename, out hash)) + if (!GetHashRecord(filename, out HashRecord hash)) throw new FileNotFoundException("File not found: " + filename); - block = blockTable[(int)hash.FileBlockIndex]; + BlockRecord block = blockTable[(int)hash.FileBlockIndex]; block.FileName = filename.ToLower(); block.EncryptionSeed = CalculateEncryptionSeed(block); return new MPQStream(this, block); diff --git a/OpenDiablo2.Common/Models/MPQCOF.cs b/OpenDiablo2.Common/Models/MPQCOF.cs index 277e47e7..6590465e 100644 --- a/OpenDiablo2.Common/Models/MPQCOF.cs +++ b/OpenDiablo2.Common/Models/MPQCOF.cs @@ -55,10 +55,12 @@ namespace OpenDiablo2.Common.Models var layers = new List(); for (var layerIdx = 0; layerIdx < numLayers; layerIdx++) { - var layer = new COFLayer(); - layer.COF = result; - layer.CompositType = (eCompositType)br.ReadByte(); - layer.Shadow = br.ReadByte(); + var layer = new COFLayer + { + COF = result, + CompositType = (eCompositType)br.ReadByte(), + Shadow = br.ReadByte() + }; br.ReadByte(); // Unknown layer.IsTransparent = br.ReadByte() != 0; layer.DrawEffect = (eDrawEffect)br.ReadByte(); diff --git a/OpenDiablo2.Common/Models/MPQDT1.cs b/OpenDiablo2.Common/Models/MPQDT1.cs index 6766f21a..8ad463b3 100644 --- a/OpenDiablo2.Common/Models/MPQDT1.cs +++ b/OpenDiablo2.Common/Models/MPQDT1.cs @@ -45,7 +45,7 @@ namespace OpenDiablo2.Common.Models public Int32 X2 { get; private set; } public Int32 NumberOfTiles { get; private set; } public MPQDT1Tile[] Tiles { get; private set; } - private Int32 tileHeaderOffset; + private readonly Int32 tileHeaderOffset; public MPQDT1(Stream stream) { diff --git a/OpenDiablo2.Common/Models/MPQHuffman.cs b/OpenDiablo2.Common/Models/MPQHuffman.cs index fdf2e408..0670ff96 100644 --- a/OpenDiablo2.Common/Models/MPQHuffman.cs +++ b/OpenDiablo2.Common/Models/MPQHuffman.cs @@ -297,8 +297,10 @@ namespace OpenDiablo2.Common.Models LinkedNode child1 = current.Prev; if (child1 == null) break; - LinkedNode parent = new LinkedNode(0, child0.Weight + child1.Weight); - parent.Child0 = child0; + LinkedNode parent = new LinkedNode(0, child0.Weight + child1.Weight) + { + Child0 = child0 + }; child0.Parent = parent; child1.Parent = parent; @@ -313,11 +315,15 @@ namespace OpenDiablo2.Common.Models LinkedNode parent = tail; LinkedNode result = tail.Prev; // This will be the new tail after the tree is updated - LinkedNode temp = new LinkedNode(parent.DecompressedValue, parent.Weight); - temp.Parent = parent; + LinkedNode temp = new LinkedNode(parent.DecompressedValue, parent.Weight) + { + Parent = parent + }; - LinkedNode newnode = new LinkedNode(decomp, 0); - newnode.Parent = parent; + LinkedNode newnode = new LinkedNode(decomp, 0) + { + Parent = parent + }; parent.Child0 = newnode; diff --git a/OpenDiablo2.Common/Models/MPQStream.cs b/OpenDiablo2.Common/Models/MPQStream.cs index 70be2d40..7bfed2e2 100644 --- a/OpenDiablo2.Common/Models/MPQStream.cs +++ b/OpenDiablo2.Common/Models/MPQStream.cs @@ -18,7 +18,7 @@ namespace OpenDiablo2.Common.Models private long position; private byte[] _currentData; private int _currentBlockIndex = -1; - private int blockSize; + private readonly int blockSize; internal MPQStream(MPQ mpq, BlockRecord blockRecord) { diff --git a/OpenDiablo2.Common/Models/Mobs/LevelExperienceConfig.cs b/OpenDiablo2.Common/Models/Mobs/LevelExperienceConfig.cs index 5c0c3691..f547fd74 100644 --- a/OpenDiablo2.Common/Models/Mobs/LevelExperienceConfig.cs +++ b/OpenDiablo2.Common/Models/Mobs/LevelExperienceConfig.cs @@ -10,7 +10,7 @@ namespace OpenDiablo2.Common.Models.Mobs { public class LevelExperienceConfig : ILevelExperienceConfig { - private List ExperiencePerLevel = new List(); + private readonly List ExperiencePerLevel = new List(); public LevelExperienceConfig(List expperlevel) { @@ -42,8 +42,7 @@ namespace OpenDiablo2.Common.Models.Mobs // i starts at 1 because we want to skip the first column // the first column is just the row titles string heroname = data[i][0]; // first row is the hero name - eHero herotype = default(eHero); - if(!Enum.TryParse(heroname, out herotype)) + if (!Enum.TryParse(heroname, out eHero herotype)) { continue; // skip this hero if we can't parse the name into a valid hero type } @@ -56,8 +55,7 @@ namespace OpenDiablo2.Common.Models.Mobs List expperlevel = new List(); for (int o = 2; o < data.Length && (o-2 < maxlevel || maxlevel == -1); o++) { - long exp = 0; - if(!long.TryParse(data[o][i], out exp)) + if (!long.TryParse(data[o][i], out long exp)) { throw new Exception("Could not parse experience number '" + data[o][i] + "'."); } diff --git a/OpenDiablo2.Common/Models/Mobs/PlayerState.cs b/OpenDiablo2.Common/Models/Mobs/PlayerState.cs index f8ec3afc..5c5203b5 100644 --- a/OpenDiablo2.Common/Models/Mobs/PlayerState.cs +++ b/OpenDiablo2.Common/Models/Mobs/PlayerState.cs @@ -9,8 +9,8 @@ namespace OpenDiablo2.Common.Models.Mobs { public Guid UID { get; protected set; } = Guid.NewGuid(); public eHero HeroType { get; protected set; } - private IHeroTypeConfig HeroTypeConfig; - private ILevelExperienceConfig ExperienceConfig; + private readonly IHeroTypeConfig HeroTypeConfig; + private readonly ILevelExperienceConfig ExperienceConfig; public int ClientHash { get; protected set; } public byte MovementDirection { get; set; } = 0; public eMovementType MovementType { get; set; } = eMovementType.Stopped; // TODO: This needs to mess with MobMode somehow diff --git a/OpenDiablo2.Common/Models/PKLibDecompress.cs b/OpenDiablo2.Common/Models/PKLibDecompress.cs index f44ea447..34b58715 100644 --- a/OpenDiablo2.Common/Models/PKLibDecompress.cs +++ b/OpenDiablo2.Common/Models/PKLibDecompress.cs @@ -41,12 +41,12 @@ namespace OpenDiablo2.Common.Models /// public class PKLibDecompress { - private BitStream _bitstream; - private CompressionType _compressionType; - private int _dictSizeBits; // Dictionary size in bits + private readonly BitStream _bitstream; + private readonly CompressionType _compressionType; + private readonly int _dictSizeBits; // Dictionary size in bits - private static byte[] sPosition1; - private static byte[] sPosition2; + private static readonly byte[] sPosition1; + private static readonly byte[] sPosition2; private static readonly byte[] sLenBits = { diff --git a/OpenDiablo2.Common/Models/PlayerInfo.cs b/OpenDiablo2.Common/Models/PlayerInfo.cs index b06e0d6c..963ab8ee 100644 --- a/OpenDiablo2.Common/Models/PlayerInfo.cs +++ b/OpenDiablo2.Common/Models/PlayerInfo.cs @@ -33,11 +33,13 @@ namespace OpenDiablo2.Common.Models public static PlayerInfo FromBytes(byte[] data, int offset = 0) { - var result = new PlayerInfo(); - result.Hero = (eHero)data[offset]; - result.WeaponClass= (eWeaponClass)data[offset + 1]; - result.ArmorType = (eArmorType)data[offset + 2]; - result.MobMode = (eMobMode)data[offset + 3]; + var result = new PlayerInfo + { + Hero = (eHero)data[offset], + WeaponClass = (eWeaponClass)data[offset + 1], + ArmorType = (eArmorType)data[offset + 2], + MobMode = (eMobMode)data[offset + 3] + }; var nameLength = BitConverter.ToInt32(data, offset + 4); result.Name = Encoding.UTF8.GetString(data, offset + 8, nameLength); result.LocationDetails = PlayerLocationDetails.FromBytes(data, offset + 8 + nameLength); diff --git a/OpenDiablo2.Core/GameEngine.cs b/OpenDiablo2.Core/GameEngine.cs index 17186b6c..effb1a2d 100644 --- a/OpenDiablo2.Core/GameEngine.cs +++ b/OpenDiablo2.Core/GameEngine.cs @@ -14,7 +14,6 @@ namespace OpenDiablo2.Core { static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - private readonly GlobalConfiguration globalConfig; private readonly IMPQProvider mpqProvider; private readonly Func getRenderWindow; private readonly Func getScene; @@ -27,11 +26,10 @@ namespace OpenDiablo2.Core private readonly MPQ[] MPQs; - private Dictionary soundTable = new Dictionary(); + private readonly Dictionary soundTable = new Dictionary(); public Dictionary PaletteTable { get; private set; } = new Dictionary(); public GameEngine( - GlobalConfiguration globalConfig, IMPQProvider mpqProvider, Func getRenderWindow, Func getScene, @@ -39,7 +37,6 @@ namespace OpenDiablo2.Core Func getGameState ) { - this.globalConfig = globalConfig; this.mpqProvider = mpqProvider; this.getRenderWindow = getRenderWindow; this.getScene = getScene; diff --git a/OpenDiablo2.Core/GameState/GameState.cs b/OpenDiablo2.Core/GameState/GameState.cs index 9a57d9c1..faf0faa4 100644 --- a/OpenDiablo2.Core/GameState/GameState.cs +++ b/OpenDiablo2.Core/GameState/GameState.cs @@ -24,7 +24,7 @@ namespace OpenDiablo2.Core.GameState_ private float animationTime = 0f; private List mapInfo; - private List mapDataLookup = new List(); + private readonly List mapDataLookup = new List(); private ISessionManager sessionManager; public int Act { get; private set; } diff --git a/OpenDiablo2.Core/GameState/MobManager.cs b/OpenDiablo2.Core/GameState/MobManager.cs index 5e6bb28a..af3c8858 100644 --- a/OpenDiablo2.Core/GameState/MobManager.cs +++ b/OpenDiablo2.Core/GameState/MobManager.cs @@ -15,7 +15,7 @@ namespace OpenDiablo2.Core.GameState_ IEnumerable IMobManager.Players => Players; IEnumerable IMobManager.Enemies => Enemies; - private HashSet IdsUsed = new HashSet(); + private readonly HashSet IdsUsed = new HashSet(); #region Player Controls public void AddPlayer(PlayerState player) diff --git a/OpenDiablo2.Core/ItemManager.cs b/OpenDiablo2.Core/ItemManager.cs index 713b7486..b8bebf24 100644 --- a/OpenDiablo2.Core/ItemManager.cs +++ b/OpenDiablo2.Core/ItemManager.cs @@ -11,7 +11,7 @@ namespace OpenDiablo2.Core { public sealed class ItemManager : IItemManager { - private IEngineDataManager engineDataManager; + private readonly IEngineDataManager engineDataManager; public ItemManager(IEngineDataManager engineDataManager) { diff --git a/OpenDiablo2.Core/MPQProvider.cs b/OpenDiablo2.Core/MPQProvider.cs index 9080e937..004a5417 100644 --- a/OpenDiablo2.Core/MPQProvider.cs +++ b/OpenDiablo2.Core/MPQProvider.cs @@ -11,18 +11,13 @@ namespace OpenDiablo2.Core { public sealed class MPQProvider : IMPQProvider { - private readonly GlobalConfiguration globalConfiguration; private readonly MPQ[] mpqs; - private Dictionary mpqLookup = new Dictionary(); + private readonly Dictionary mpqLookup = new Dictionary(); public MPQProvider(GlobalConfiguration globalConfiguration) { - this.globalConfiguration = globalConfiguration; // TODO: Make this less dumb. We need to an external file to configure mpq load order. - var mpqsToLoad = new string[] - { - }; this.mpqs = Directory .EnumerateFiles(globalConfiguration.BaseDataPath, "*.mpq") .Where(x => !Path.GetFileName(x).StartsWith("patch")) diff --git a/OpenDiablo2.Core/Map Engine/MapEngine.cs b/OpenDiablo2.Core/Map Engine/MapEngine.cs index 6a191870..d2c11334 100644 --- a/OpenDiablo2.Core/Map Engine/MapEngine.cs +++ b/OpenDiablo2.Core/Map Engine/MapEngine.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Drawing; using System.Linq; -using OpenDiablo2.Common; using OpenDiablo2.Common.Enums; using OpenDiablo2.Common.Interfaces; using OpenDiablo2.Common.Interfaces.Drawing; @@ -14,10 +13,8 @@ namespace OpenDiablo2.Core.Map_Engine { private readonly IGameState gameState; private readonly IRenderWindow renderWindow; - private readonly IResourceManager resourceManager; - private readonly ISessionManager sessionManager; - private List characterRenderers = new List(); + private readonly List characterRenderers = new List(); public int FocusedPlayerId { get; set; } = 0; @@ -31,33 +28,24 @@ namespace OpenDiablo2.Core.Map_Engine return; cameraLocation = value; - cOffX = (int)((cameraLocation.X - cameraLocation.Y) * (cellSizeX / 2)); - cOffY = (int)((cameraLocation.X + cameraLocation.Y) * (cellSizeY / 2)); + //cOffX = (int)((cameraLocation.X - cameraLocation.Y) * (cellSizeX / 2)); + //cOffY = (int)((cameraLocation.X + cameraLocation.Y) * (cellSizeY / 2)); } } - - private ISprite loadingSprite; - private int cOffX, cOffY; - + private const int cellSizeX = 160, - cellSizeY = 80, - renderCellsX = (800 / cellSizeX), - renderCellsY = (600 / cellSizeY); + cellSizeY = 80; public MapEngine( IGameState gameState, IRenderWindow renderWindow, - IResourceManager resourceManager, ISessionManager sessionManager ) { this.gameState = gameState; this.renderWindow = renderWindow; - this.resourceManager = resourceManager; - this.sessionManager = sessionManager; - loadingSprite = renderWindow.LoadSprite(ResourcePaths.LoadingScreen, Palettes.Loading, new Point(300, 400)); sessionManager.OnPlayerInfo += OnPlayerInfo; sessionManager.OnLocatePlayers += OnLocatePlayers; } diff --git a/OpenDiablo2.Core/ResourceManager.cs b/OpenDiablo2.Core/ResourceManager.cs index 12b39cfb..0dc2cec3 100644 --- a/OpenDiablo2.Core/ResourceManager.cs +++ b/OpenDiablo2.Core/ResourceManager.cs @@ -15,11 +15,11 @@ namespace OpenDiablo2.Core private readonly IMPQProvider mpqProvider; private readonly IEngineDataManager engineDataManager; - private Dictionary ImageSets = new Dictionary(); - private Dictionary MPQFonts = new Dictionary(); - private Dictionary Palettes = new Dictionary(); - private Dictionary DTs = new Dictionary(); - private Dictionary PlayerCOFs = new Dictionary(); + private readonly Dictionary ImageSets = new Dictionary(); + private readonly Dictionary MPQFonts = new Dictionary(); + private readonly Dictionary Palettes = new Dictionary(); + private readonly Dictionary DTs = new Dictionary(); + private readonly Dictionary PlayerCOFs = new Dictionary(); public Dictionary> Animations { get; private set; } = new Dictionary>(); diff --git a/OpenDiablo2.Core/TextDictionary.cs b/OpenDiablo2.Core/TextDictionary.cs index 4516f4f7..e1cb3ad8 100644 --- a/OpenDiablo2.Core/TextDictionary.cs +++ b/OpenDiablo2.Core/TextDictionary.cs @@ -23,7 +23,7 @@ namespace OpenDiablo2.Core { private readonly IMPQProvider mpqProvider; - private Dictionary lookupTable = new Dictionary(); + private readonly Dictionary lookupTable = new Dictionary(); public TextDictionary(IMPQProvider mpqProvider) { diff --git a/OpenDiablo2.Core/UI/Button.cs b/OpenDiablo2.Core/UI/Button.cs index 5d6c2195..2d39d2eb 100644 --- a/OpenDiablo2.Core/UI/Button.cs +++ b/OpenDiablo2.Core/UI/Button.cs @@ -32,10 +32,11 @@ namespace OpenDiablo2.Core.UI } } - private int buttonWidth, buttonHeight; - private ISprite sprite; - private IFont font; - private ILabel label; + private readonly int buttonWidth; + private readonly int buttonHeight; + private readonly ISprite sprite; + private readonly IFont font; + private readonly ILabel label; private bool pressed = false; private bool active = false; // When true, button is actively being focus pressed private bool activeLock = false; // When true, we have locked the mouse from everything else diff --git a/OpenDiablo2.Core/UI/CharacterPanel.cs b/OpenDiablo2.Core/UI/CharacterPanel.cs index 6f08f9a1..6223d18d 100644 --- a/OpenDiablo2.Core/UI/CharacterPanel.cs +++ b/OpenDiablo2.Core/UI/CharacterPanel.cs @@ -9,7 +9,7 @@ namespace OpenDiablo2.Core.UI public sealed class CharacterPanel : ICharacterPanel { private readonly IRenderWindow renderWindow; - private ISprite sprite; + private readonly ISprite sprite; public Point Location { get; set; } diff --git a/OpenDiablo2.Core/UI/InventoryPanel.cs b/OpenDiablo2.Core/UI/InventoryPanel.cs index d62491ff..3f5aeafc 100644 --- a/OpenDiablo2.Core/UI/InventoryPanel.cs +++ b/OpenDiablo2.Core/UI/InventoryPanel.cs @@ -13,7 +13,7 @@ namespace OpenDiablo2.Core.UI public sealed class InventoryPanel : IInventoryPanel { private readonly IRenderWindow renderWindow; - private ISprite sprite; + private readonly ISprite sprite; private Point location; public Point Location { @@ -30,9 +30,9 @@ namespace OpenDiablo2.Core.UI // Test vars public IItemContainer helmContainer, armorContainer, weaponLeftContainer, weaponRightContainer, beltContainer, gloveContainer, bootsContainer; private Point previouslyContainedItem; - private IItemContainer ringtLeftContainer; - private IItemContainer ringtRightContainer; - private IItemContainer amuletContainer; + private readonly IItemContainer ringtLeftContainer; + private readonly IItemContainer ringtRightContainer; + private readonly IItemContainer amuletContainer; public InventoryPanel(IRenderWindow renderWindow, IItemManager itemManager, Func createItemContainer) { diff --git a/OpenDiablo2.Core/UI/ItemContainer.cs b/OpenDiablo2.Core/UI/ItemContainer.cs index f67a1442..c6f59205 100644 --- a/OpenDiablo2.Core/UI/ItemContainer.cs +++ b/OpenDiablo2.Core/UI/ItemContainer.cs @@ -1,115 +1,114 @@ -using System; -using System.Collections.Generic; -using System.Drawing; -using OpenDiablo2.Common; -using OpenDiablo2.Common.Enums; -using OpenDiablo2.Common.Interfaces; -using OpenDiablo2.Common.Models; - -namespace OpenDiablo2.Core.UI -{ - // TODO: Self-align when side panels are open - public sealed class ItemContainer : IItemContainer - { - private readonly IRenderWindow renderWindow; - private readonly IGameState gameState; - private ISprite sprite; - - private ItemContainerLayout itemContainerLayout; - private IMouseInfoProvider mouseInfoProvider; - - public Item ContainedItem { get; internal set; } - - private Dictionary sprites = new Dictionary(); - - private Point location = new Point(); - - public Point Location - { - get => location; - set - { - if (location == value) - return; - location = value; - - placeholderSprite.Location = new Point(value.X, value.Y + placeholderSprite.LocalFrameSize.Height); - } - } - - private ISprite placeholderSprite; - - public Size Size { get; internal set; } - - public ItemContainer(IRenderWindow renderWindow, IGameState gameState, ItemContainerLayout itemContainerLayout, IMouseInfoProvider mouseInfoProvider) - { - this.renderWindow = renderWindow; - this.gameState = gameState; - this.itemContainerLayout = itemContainerLayout; - this.mouseInfoProvider = mouseInfoProvider; - - placeholderSprite = renderWindow.LoadSprite(itemContainerLayout.ResourceName, itemContainerLayout.PaletteName); - placeholderSprite.Location = new Point(location.X, location.Y + placeholderSprite.LocalFrameSize.Height); - this.Size = placeholderSprite.FrameSize; // For all but generic size is equal to the placeholder size. Source: me. - } - - public void SetContainedItem(Item containedItem) - { - ContainedItem = containedItem; - - if (ContainedItem != null) - { - sprite = renderWindow.LoadSprite(ResourcePaths.GeneratePathForItem(this.ContainedItem.InvFile), Palettes.Units); - sprite.Location = new Point(location.X, location.Y + sprite.LocalFrameSize.Height); - } - } - - public void Update() - { +using System.Collections.Generic; +using System.Drawing; +using OpenDiablo2.Common; +using OpenDiablo2.Common.Enums; +using OpenDiablo2.Common.Interfaces; +using OpenDiablo2.Common.Models; + +namespace OpenDiablo2.Core.UI +{ + // TODO: Self-align when side panels are open + public sealed class ItemContainer : IItemContainer + { + private readonly IRenderWindow renderWindow; + private readonly IGameState gameState; + private ISprite sprite; + + private readonly ItemContainerLayout itemContainerLayout; + private readonly IMouseInfoProvider mouseInfoProvider; + + public Item ContainedItem { get; internal set; } + + private readonly Dictionary sprites = new Dictionary(); + + private Point location = new Point(); + + public Point Location + { + get => location; + set + { + if (location == value) + return; + location = value; + + placeholderSprite.Location = new Point(value.X, value.Y + placeholderSprite.LocalFrameSize.Height); + } + } + + private readonly ISprite placeholderSprite; + + public Size Size { get; internal set; } + + public ItemContainer(IRenderWindow renderWindow, IGameState gameState, ItemContainerLayout itemContainerLayout, IMouseInfoProvider mouseInfoProvider) + { + this.renderWindow = renderWindow; + this.gameState = gameState; + this.itemContainerLayout = itemContainerLayout; + this.mouseInfoProvider = mouseInfoProvider; + + placeholderSprite = renderWindow.LoadSprite(itemContainerLayout.ResourceName, itemContainerLayout.PaletteName); + placeholderSprite.Location = new Point(location.X, location.Y + placeholderSprite.LocalFrameSize.Height); + this.Size = placeholderSprite.FrameSize; // For all but generic size is equal to the placeholder size. Source: me. + } + + public void SetContainedItem(Item containedItem) + { + ContainedItem = containedItem; + + if (ContainedItem != null) + { + sprite = renderWindow.LoadSprite(ResourcePaths.GeneratePathForItem(this.ContainedItem.InvFile), Palettes.Units); + sprite.Location = new Point(location.X, location.Y + sprite.LocalFrameSize.Height); + } + } + + public void Update() + { var hovered = (mouseInfoProvider.MouseX >= location.X && mouseInfoProvider.MouseX < (location.X + this.Size.Width)) - && (mouseInfoProvider.MouseY >= location.Y && mouseInfoProvider.MouseY < (location.Y + this.Size.Height)); - - if (hovered && mouseInfoProvider.LeftMousePressed) - { - // If there is an item contained, remove from container and send to mouse - if (this.ContainedItem != null) - { - if (this.gameState.SelectedItem != null) - { - var switchItem = this.gameState.SelectedItem; - - this.gameState.SelectItem(this.ContainedItem); - this.SetContainedItem(switchItem); - } else - { - this.gameState.SelectItem(this.ContainedItem); - this.SetContainedItem(null); - } - - } - else if (this.gameState.SelectedItem != null) - { - this.SetContainedItem(this.gameState.SelectedItem); - this.gameState.SelectItem(null); - } - } - } - - public void Render() - { - if (this.ContainedItem == null) - { - renderWindow.Draw(placeholderSprite, this.itemContainerLayout.BaseFrame); - } - else - { - renderWindow.Draw(sprite); - } - } - - public void Dispose() - { - sprite.Dispose(); - } - } -} + && (mouseInfoProvider.MouseY >= location.Y && mouseInfoProvider.MouseY < (location.Y + this.Size.Height)); + + if (hovered && mouseInfoProvider.LeftMousePressed) + { + // If there is an item contained, remove from container and send to mouse + if (this.ContainedItem != null) + { + if (this.gameState.SelectedItem != null) + { + var switchItem = this.gameState.SelectedItem; + + this.gameState.SelectItem(this.ContainedItem); + this.SetContainedItem(switchItem); + } else + { + this.gameState.SelectItem(this.ContainedItem); + this.SetContainedItem(null); + } + + } + else if (this.gameState.SelectedItem != null) + { + this.SetContainedItem(this.gameState.SelectedItem); + this.gameState.SelectItem(null); + } + } + } + + public void Render() + { + if (this.ContainedItem == null) + { + renderWindow.Draw(placeholderSprite, this.itemContainerLayout.BaseFrame); + } + else + { + renderWindow.Draw(sprite); + } + } + + public void Dispose() + { + sprite.Dispose(); + } + } +} diff --git a/OpenDiablo2.Core/UI/PanelFrame.cs b/OpenDiablo2.Core/UI/PanelFrame.cs index a9fd6717..62efa386 100644 --- a/OpenDiablo2.Core/UI/PanelFrame.cs +++ b/OpenDiablo2.Core/UI/PanelFrame.cs @@ -9,8 +9,8 @@ namespace OpenDiablo2.Core.UI public sealed class PanelFrame : IPanelFrame { private readonly IRenderWindow renderWindow; - private ISprite sprite; - private ePanelFrameType panelFrameType; + private readonly ISprite sprite; + private readonly ePanelFrameType panelFrameType; public Point Location { get; set; } diff --git a/OpenDiablo2.Core/UI/TextBox.cs b/OpenDiablo2.Core/UI/TextBox.cs index b298cfe0..4329c508 100644 --- a/OpenDiablo2.Core/UI/TextBox.cs +++ b/OpenDiablo2.Core/UI/TextBox.cs @@ -12,9 +12,9 @@ namespace OpenDiablo2.Core.UI public sealed class TextBox : ITextBox { private readonly IRenderWindow renderWindow; - private ISprite sprite; - private IFont font; - private ILabel label, linebar; + private readonly ISprite sprite; + private readonly IFont font; + private readonly ILabel label, linebar; private float frameTime = 0f; private Point location = new Point(); diff --git a/OpenDiablo2.SDL2/CS-SDL/SDL2.cs b/OpenDiablo2.SDL2/CS-SDL/SDL2.cs index 236a5a33..46bfc80b 100644 --- a/OpenDiablo2.SDL2/CS-SDL/SDL2.cs +++ b/OpenDiablo2.SDL2/CS-SDL/SDL2.cs @@ -3665,9 +3665,9 @@ namespace SDL2 public UInt32 timestamp; public UInt32 display; public SDL_DisplayEventID displayEvent; // event, lolC# - private byte padding1; - private byte padding2; - private byte padding3; + private readonly byte padding1; + private readonly byte padding2; + private readonly byte padding3; public Int32 data1; } #pragma warning restore 0169 @@ -3682,9 +3682,9 @@ namespace SDL2 public UInt32 timestamp; public UInt32 windowID; public SDL_WindowEventID windowEvent; // event, lolC# - private byte padding1; - private byte padding2; - private byte padding3; + private readonly byte padding1; + private readonly byte padding2; + private readonly byte padding3; public Int32 data1; public Int32 data2; } @@ -3701,8 +3701,8 @@ namespace SDL2 public UInt32 windowID; public byte state; public byte repeat; /* non-zero if this is a repeat */ - private byte padding2; - private byte padding3; + private readonly byte padding2; + private readonly byte padding3; public SDL_Keysym keysym; } #pragma warning restore 0169 @@ -3738,9 +3738,9 @@ namespace SDL2 public UInt32 windowID; public UInt32 which; public byte state; /* bitmask of buttons */ - private byte padding1; - private byte padding2; - private byte padding3; + private readonly byte padding1; + private readonly byte padding2; + private readonly byte padding3; public Int32 x; public Int32 y; public Int32 xrel; @@ -3761,7 +3761,7 @@ namespace SDL2 public byte button; /* button id */ public byte state; /* SDL_PRESSED or SDL_RELEASED */ public byte clicks; /* 1 for single-click, 2 for double-click, etc. */ - private byte padding1; + private readonly byte padding1; public Int32 x; public Int32 y; } @@ -3790,9 +3790,9 @@ namespace SDL2 public UInt32 timestamp; public Int32 which; /* SDL_JoystickID */ public byte axis; - private byte padding1; - private byte padding2; - private byte padding3; + private readonly byte padding1; + private readonly byte padding2; + private readonly byte padding3; public Int16 axisValue; /* value, lolC# */ public UInt16 padding4; } @@ -3808,9 +3808,9 @@ namespace SDL2 public UInt32 timestamp; public Int32 which; /* SDL_JoystickID */ public byte ball; - private byte padding1; - private byte padding2; - private byte padding3; + private readonly byte padding1; + private readonly byte padding2; + private readonly byte padding3; public Int16 xrel; public Int16 yrel; } @@ -3827,8 +3827,8 @@ namespace SDL2 public Int32 which; /* SDL_JoystickID */ public byte hat; /* index of the hat */ public byte hatValue; /* value, lolC# */ - private byte padding1; - private byte padding2; + private readonly byte padding1; + private readonly byte padding2; } #pragma warning restore 0169 @@ -3843,8 +3843,8 @@ namespace SDL2 public Int32 which; /* SDL_JoystickID */ public byte button; public byte state; /* SDL_PRESSED or SDL_RELEASED */ - private byte padding1; - private byte padding2; + private readonly byte padding1; + private readonly byte padding2; } #pragma warning restore 0169 @@ -3867,11 +3867,11 @@ namespace SDL2 public UInt32 timestamp; public Int32 which; /* SDL_JoystickID */ public byte axis; - private byte padding1; - private byte padding2; - private byte padding3; + private readonly byte padding1; + private readonly byte padding2; + private readonly byte padding3; public Int16 axisValue; /* value, lolC# */ - private UInt16 padding4; + private readonly UInt16 padding4; } #pragma warning restore 0169 @@ -3886,8 +3886,8 @@ namespace SDL2 public Int32 which; /* SDL_JoystickID */ public byte button; public byte state; - private byte padding1; - private byte padding2; + private readonly byte padding1; + private readonly byte padding2; } #pragma warning restore 0169 @@ -3912,9 +3912,9 @@ namespace SDL2 public UInt32 timestamp; public UInt32 which; public byte iscapture; - private byte padding1; - private byte padding2; - private byte padding3; + private readonly byte padding1; + private readonly byte padding2; + private readonly byte padding3; } #pragma warning restore 0169 @@ -5626,9 +5626,11 @@ namespace SDL2 gamecontroller, axis ); - SDL_GameControllerButtonBind result = new SDL_GameControllerButtonBind(); - result.bindType = (SDL_GameControllerBindType) dumb.bindType; - result.value.hat.hat = dumb.unionVal0; + SDL_GameControllerButtonBind result = new SDL_GameControllerButtonBind + { + bindType = (SDL_GameControllerBindType)dumb.bindType + }; + result.value.hat.hat = dumb.unionVal0; result.value.hat.hat_mask = dumb.unionVal1; return result; } @@ -5679,9 +5681,11 @@ namespace SDL2 gamecontroller, button ); - SDL_GameControllerButtonBind result = new SDL_GameControllerButtonBind(); - result.bindType = (SDL_GameControllerBindType) dumb.bindType; - result.value.hat.hat = dumb.unionVal0; + SDL_GameControllerButtonBind result = new SDL_GameControllerButtonBind + { + bindType = (SDL_GameControllerBindType)dumb.bindType + }; + result.value.hat.hat = dumb.unionVal0; result.value.hat.hat_mask = dumb.unionVal1; return result; } diff --git a/OpenDiablo2.SDL2/SDL2CharacterRenderer.cs b/OpenDiablo2.SDL2/SDL2CharacterRenderer.cs index 21ba9947..a8a46a93 100644 --- a/OpenDiablo2.SDL2/SDL2CharacterRenderer.cs +++ b/OpenDiablo2.SDL2/SDL2CharacterRenderer.cs @@ -1,6 +1,21 @@ -using System; +/* OpenDiablo 2 - An open source re-implementation of Diablo 2 in C# + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +using System; using System.Collections.Generic; -using System.Drawing; using System.Linq; using OpenDiablo2.Common; using OpenDiablo2.Common.Enums; @@ -34,9 +49,9 @@ namespace OpenDiablo2.SDL2_ public eArmorType ArmorType { get; set; } public eMobMode MobMode { get; set; } - private IntPtr renderer; + private readonly IntPtr renderer; - private List directionCache = new List(); + private readonly List directionCache = new List(); DirectionCacheItem currentDirectionCache; private float seconds; @@ -172,10 +187,8 @@ namespace OpenDiablo2.SDL2_ for (var frameIndex = 0; frameIndex < cache.FramesToAnimate; frameIndex++) { var texture = SDL.SDL_CreateTexture(renderer, SDL.SDL_PIXELFORMAT_ARGB8888, (int)SDL.SDL_TextureAccess.SDL_TEXTUREACCESS_STREAMING, frameW, frameH); - IntPtr pixels; - int pitch; - SDL.SDL_LockTexture(texture, IntPtr.Zero, out pixels, out pitch); + SDL.SDL_LockTexture(texture, IntPtr.Zero, out IntPtr pixels, out int pitch); UInt32* data = (UInt32*)pixels; foreach (var layer in layerData) diff --git a/OpenDiablo2.SDL2/SDL2Extensions.cs b/OpenDiablo2.SDL2/SDL2Extensions.cs index f936042e..aa931e33 100644 --- a/OpenDiablo2.SDL2/SDL2Extensions.cs +++ b/OpenDiablo2.SDL2/SDL2Extensions.cs @@ -1,4 +1,20 @@ -using System.Drawing; +/* OpenDiablo 2 - An open source re-implementation of Diablo 2 in C# + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +using System.Drawing; using SDL2; namespace OpenDiablo2.SDL2_ diff --git a/OpenDiablo2.SDL2/SDL2Font.cs b/OpenDiablo2.SDL2/SDL2Font.cs index f14d9fd7..bb09b202 100644 --- a/OpenDiablo2.SDL2/SDL2Font.cs +++ b/OpenDiablo2.SDL2/SDL2Font.cs @@ -1,11 +1,23 @@ -using OpenDiablo2.Common.Interfaces; -using OpenDiablo2.Common.Models; +/* OpenDiablo 2 - An open source re-implementation of Diablo 2 in C# + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + using System; -using System.Collections.Generic; using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using OpenDiablo2.Common.Interfaces; +using OpenDiablo2.Common.Models; namespace OpenDiablo2.SDL2_ { diff --git a/OpenDiablo2.SDL2/SDL2Label.cs b/OpenDiablo2.SDL2/SDL2Label.cs index ee7b4cd7..d7f6dc57 100644 --- a/OpenDiablo2.SDL2/SDL2Label.cs +++ b/OpenDiablo2.SDL2/SDL2Label.cs @@ -1,13 +1,26 @@ -using OpenDiablo2.Common.Enums; -using OpenDiablo2.Common.Interfaces; -using SDL2; +/* OpenDiablo 2 - An open source re-implementation of Diablo 2 in C# + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + using System; using System.Collections.Generic; using System.Drawing; using System.Linq; -using System.Runtime.InteropServices; -using System.Text; -using System.Threading.Tasks; +using OpenDiablo2.Common.Enums; +using OpenDiablo2.Common.Interfaces; +using SDL2; namespace OpenDiablo2.SDL2_ { diff --git a/OpenDiablo2.SDL2/SDL2MouseCursor.cs b/OpenDiablo2.SDL2/SDL2MouseCursor.cs index 386ff57e..62162fc9 100644 --- a/OpenDiablo2.SDL2/SDL2MouseCursor.cs +++ b/OpenDiablo2.SDL2/SDL2MouseCursor.cs @@ -1,7 +1,22 @@ -using System; +/* OpenDiablo 2 - An open source re-implementation of Diablo 2 in C# + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +using System; using System.Drawing; using OpenDiablo2.Common.Interfaces; -using SDL2; namespace OpenDiablo2.SDL2_ { diff --git a/OpenDiablo2.SDL2/SDL2MusicPlayer.cs b/OpenDiablo2.SDL2/SDL2MusicPlayer.cs index 2ec07dc9..c77dde55 100644 --- a/OpenDiablo2.SDL2/SDL2MusicPlayer.cs +++ b/OpenDiablo2.SDL2/SDL2MusicPlayer.cs @@ -1,12 +1,23 @@ -using OpenDiablo2.Common.Interfaces; -using SDL2; +/* OpenDiablo 2 - An open source re-implementation of Diablo 2 in C# + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + using System; -using System.Collections.Generic; using System.IO; -using System.Linq; -using System.Runtime.InteropServices; -using System.Text; -using System.Threading.Tasks; +using OpenDiablo2.Common.Interfaces; +using SDL2; namespace OpenDiablo2.SDL2_ { diff --git a/OpenDiablo2.SDL2/SDL2RenderWindow.cs b/OpenDiablo2.SDL2/SDL2RenderWindow.cs index eb6730ae..fdac7a3c 100644 --- a/OpenDiablo2.SDL2/SDL2RenderWindow.cs +++ b/OpenDiablo2.SDL2/SDL2RenderWindow.cs @@ -1,4 +1,20 @@ -using System; +/* OpenDiablo 2 - An open source re-implementation of Diablo 2 in C# + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +using System; using System.Drawing; using System.Linq; using System.Runtime.InteropServices; @@ -13,8 +29,8 @@ namespace OpenDiablo2.SDL2_ { private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - private IntPtr window, renderer; - private bool fullscreen; + private readonly IntPtr window, renderer; + private readonly bool fullscreen; public bool IsRunning { get; private set; } @@ -97,8 +113,7 @@ namespace OpenDiablo2.SDL2_ public unsafe bool KeyIsPressed(int scancode) { - int numKeys; - byte* keys = (byte*)SDL.SDL_GetKeyboardState(out numKeys); + byte* keys = (byte*)SDL.SDL_GetKeyboardState(out int numKeys); return keys[scancode] > 0; } diff --git a/OpenDiablo2.SDL2/SDL2Sprite.cs b/OpenDiablo2.SDL2/SDL2Sprite.cs index d02c4e11..d50f40da 100644 --- a/OpenDiablo2.SDL2/SDL2Sprite.cs +++ b/OpenDiablo2.SDL2/SDL2Sprite.cs @@ -1,8 +1,22 @@ -using System; +/* OpenDiablo 2 - An open source re-implementation of Diablo 2 in C# + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +using System; using System.Drawing; using System.Linq; -using System.Runtime.InteropServices; -using OpenDiablo2.Common.Enums; using OpenDiablo2.Common.Interfaces; using OpenDiablo2.Common.Models; using SDL2; @@ -108,13 +122,10 @@ namespace OpenDiablo2.SDL2_ private unsafe void LoadFrame(int index) { var frame = source.Frames[index]; - - IntPtr pixels; - int pitch; var fullRect = new SDL.SDL_Rect { x = 0, y = 0, w = FrameSize.Width, h = FrameSize.Height }; SDL.SDL_SetTextureBlendMode(texture, blend ? SDL.SDL_BlendMode.SDL_BLENDMODE_ADD : SDL.SDL_BlendMode.SDL_BLENDMODE_BLEND); - SDL.SDL_LockTexture(texture, IntPtr.Zero, out pixels, out pitch); + SDL.SDL_LockTexture(texture, IntPtr.Zero, out IntPtr pixels, out int pitch); try { UInt32* data = (UInt32*)pixels; diff --git a/OpenDiablo2.SDL2/SDL2Texture.cs b/OpenDiablo2.SDL2/SDL2Texture.cs index 9b8d94c1..31233218 100644 --- a/OpenDiablo2.SDL2/SDL2Texture.cs +++ b/OpenDiablo2.SDL2/SDL2Texture.cs @@ -1,4 +1,20 @@ -using System; +/* OpenDiablo 2 - An open source re-implementation of Diablo 2 in C# + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +using System; using OpenDiablo2.Common.Interfaces; namespace OpenDiablo2.SDL2_ diff --git a/OpenDiablo2.Scenes/CharacterSelection.cs b/OpenDiablo2.Scenes/CharacterSelection.cs index 4c16c260..7193d1d7 100644 --- a/OpenDiablo2.Scenes/CharacterSelection.cs +++ b/OpenDiablo2.Scenes/CharacterSelection.cs @@ -10,11 +10,7 @@ namespace OpenDiablo2.Scenes [Scene(eSceneType.SelectCharacter)] public sealed class CharacterSelection : IScene { - static readonly log4net.ILog log = - log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - private readonly IRenderWindow renderWindow; - private readonly ISprite backgroundSprite; private readonly IButton createNewCharacterButton, deleteCharacterButton, exitButton, okButton; diff --git a/OpenDiablo2.Scenes/Game.cs b/OpenDiablo2.Scenes/Game.cs index 52be0b10..0cf5eb6f 100644 --- a/OpenDiablo2.Scenes/Game.cs +++ b/OpenDiablo2.Scenes/Game.cs @@ -13,7 +13,6 @@ namespace OpenDiablo2.Scenes private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); private readonly IRenderWindow renderWindow; - private readonly IResourceManager resourceManager; private readonly IMapEngine mapEngine; private readonly IMouseInfoProvider mouseInfoProvider; private readonly IGameState gameState; @@ -22,11 +21,11 @@ namespace OpenDiablo2.Scenes //private ISprite[] testSprite; - private ISprite panelSprite, healthManaSprite, gameGlobeOverlapSprite; + private readonly ISprite panelSprite, healthManaSprite, gameGlobeOverlapSprite; private readonly IMiniPanel minipanel; - private IButton runButton, menuButton; + private readonly IButton runButton, menuButton; private eMovementType lastMovementType = eMovementType.Stopped; private byte lastDirection = 255; @@ -34,7 +33,6 @@ namespace OpenDiablo2.Scenes public Game( IRenderWindow renderWindow, - IResourceManager resourceManager, IMapEngine mapEngine, IGameState gameState, IMouseInfoProvider mouseInfoProvider, @@ -46,7 +44,6 @@ namespace OpenDiablo2.Scenes ) { this.renderWindow = renderWindow; - this.resourceManager = resourceManager; this.mapEngine = mapEngine; this.gameState = gameState; this.mouseInfoProvider = mouseInfoProvider; @@ -69,10 +66,7 @@ namespace OpenDiablo2.Scenes menuButton.Location = new Point(393, 561); menuButton.OnToggle = minipanel.OnMenuToggle; - /*var item = itemManager.getItem("hdm"); - var cursorsprite = renderWindow.LoadSprite(ResourcePaths.GeneratePathForItem(item.InvFile), Palettes.Units); - - renderWindow.MouseCursor = renderWindow.LoadCursor(cursorsprite, 0, new Point(cursorsprite.FrameSize.Width/2, cursorsprite.FrameSize.Height / 2));*/ + //var item = itemManager.getItem("hdm"); } private void OnRunToggle(bool isToggled) diff --git a/OpenDiablo2.Scenes/MainMenu.cs b/OpenDiablo2.Scenes/MainMenu.cs index f03b5d51..575302b6 100644 --- a/OpenDiablo2.Scenes/MainMenu.cs +++ b/OpenDiablo2.Scenes/MainMenu.cs @@ -11,27 +11,17 @@ namespace OpenDiablo2.Scenes [Scene(eSceneType.MainMenu)] public class MainMenu : IScene { - static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - private readonly IRenderWindow renderWindow; - private readonly IPaletteProvider paletteProvider; - private readonly IMPQProvider mpqProvider; - private readonly IMouseInfoProvider mouseInfoProvider; - //private readonly IMusicProvider musicProvider; private readonly ISceneManager sceneManager; private float logoFrame; - private ISprite backgroundSprite, diabloLogoLeft, diabloLogoRight, diabloLogoLeftBlack, diabloLogoRightBlack; - private IFont labelFont; - private ILabel versionLabel, urlLabel; - private IButton btnSinglePlayer, btnExit, btnWebsite; + private readonly ISprite backgroundSprite, diabloLogoLeft, diabloLogoRight, diabloLogoLeftBlack, diabloLogoRightBlack; + private readonly IFont labelFont; + private readonly ILabel versionLabel, urlLabel; + private readonly IButton btnSinglePlayer, btnExit, btnWebsite; public MainMenu( IRenderWindow renderWindow, - IPaletteProvider paletteProvider, - IMPQProvider mpqProvider, - IMouseInfoProvider mouseInfoProvider, - //IMusicProvider musicProvider, ISceneManager sceneManager, IResourceManager resourceManager, Func createButton, @@ -39,10 +29,6 @@ namespace OpenDiablo2.Scenes ) { this.renderWindow = renderWindow; - this.paletteProvider = paletteProvider; - this.mpqProvider = mpqProvider; - this.mouseInfoProvider = mouseInfoProvider; - this.sceneManager = sceneManager; backgroundSprite = renderWindow.LoadSprite(ResourcePaths.GameSelectScreen, Palettes.Sky); diabloLogoLeft = renderWindow.LoadSprite(ResourcePaths.Diablo2LogoFireLeft, Palettes.Units, new Point(400, 120)); diff --git a/OpenDiablo2.Scenes/SelectHeroClass.cs b/OpenDiablo2.Scenes/SelectHeroClass.cs index 4e01a726..a4471f75 100644 --- a/OpenDiablo2.Scenes/SelectHeroClass.cs +++ b/OpenDiablo2.Scenes/SelectHeroClass.cs @@ -31,11 +31,7 @@ namespace OpenDiablo2.Scenes [Scene(eSceneType.SelectHeroClass)] public sealed class SelectHeroClass : IScene { - static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - private readonly IRenderWindow renderWindow; - private readonly IPaletteProvider paletteProvider; - private readonly IMPQProvider mpqProvider; private readonly IMouseInfoProvider mouseInfoProvider; private readonly ISceneManager sceneManager; private readonly ITextDictionary textDictionary; @@ -45,17 +41,17 @@ namespace OpenDiablo2.Scenes private bool showEntryUi = false; private eHero? selectedHero = null; private float secondTimer; - private ISprite backgroundSprite, campfireSprite; - private IFont headingFont, heroDescFont, uiFont; - private ILabel headingLabel, heroClassLabel, heroDesc1Label, heroDesc2Label, heroDesc3Label, characterNameLabel; - private IButton exitButton, okButton; - private ITextBox characterNameTextBox; - private Dictionary heroRenderInfo = new Dictionary(); + private readonly ISprite backgroundSprite, campfireSprite; + private readonly IFont headingFont; + private readonly IFont heroDescFont; + private readonly IFont uiFont; + private readonly ILabel headingLabel, heroClassLabel, heroDesc1Label, heroDesc2Label, heroDesc3Label, characterNameLabel; + private readonly IButton exitButton, okButton; + private readonly ITextBox characterNameTextBox; + private readonly Dictionary heroRenderInfo = new Dictionary(); public SelectHeroClass( IRenderWindow renderWindow, - IPaletteProvider paletteProvider, - IMPQProvider mpqProvider, IMouseInfoProvider mouseInfoProvider, ISceneManager sceneManager, Func createButton, @@ -66,8 +62,6 @@ namespace OpenDiablo2.Scenes ) { this.renderWindow = renderWindow; - this.paletteProvider = paletteProvider; - this.mpqProvider = mpqProvider; this.mouseInfoProvider = mouseInfoProvider; this.sceneManager = sceneManager; this.textDictionary = textDictionary; @@ -452,7 +446,7 @@ namespace OpenDiablo2.Scenes } - private void setDescLabels(string descKey) + private void SetDescLabels(string descKey) { var heroDesc = textDictionary.Translate(descKey); var parts = StringUtils.SplitIntoLinesWithMaxWidth(heroDesc, 37); @@ -470,15 +464,15 @@ namespace OpenDiablo2.Scenes { case eHero.Barbarian: heroClassLabel.Text = textDictionary.Translate("strBarbarian"); - setDescLabels("strBarbDesc"); + SetDescLabels("strBarbDesc"); break; case eHero.Necromancer: heroClassLabel.Text = textDictionary.Translate("strNecromancer"); - setDescLabels("strNecroDesc"); + SetDescLabels("strNecroDesc"); break; case eHero.Paladin: heroClassLabel.Text = textDictionary.Translate("strPaladin"); - setDescLabels("strPalDesc"); + SetDescLabels("strPalDesc"); break; case eHero.Assassin: heroClassLabel.Text = textDictionary.Translate("strAssassin"); @@ -488,11 +482,11 @@ namespace OpenDiablo2.Scenes break; case eHero.Sorceress: heroClassLabel.Text = textDictionary.Translate("strSorceress"); - setDescLabels("strSorcDesc"); + SetDescLabels("strSorcDesc"); break; case eHero.Amazon: heroClassLabel.Text = textDictionary.Translate("strAmazon"); - setDescLabels("strAmazonDesc"); + SetDescLabels("strAmazonDesc"); break; case eHero.Druid: heroClassLabel.Text = textDictionary.Translate("strDruid"); diff --git a/OpenDiablo2.ServiceBus/SessionManager.cs b/OpenDiablo2.ServiceBus/SessionManager.cs index 51a644c0..60eaf1b3 100644 --- a/OpenDiablo2.ServiceBus/SessionManager.cs +++ b/OpenDiablo2.ServiceBus/SessionManager.cs @@ -38,7 +38,7 @@ namespace OpenDiablo2.ServiceBus private readonly Func getGameState; private RequestSocket requestSocket; - private AutoResetEvent resetEvent = new AutoResetEvent(false); + private readonly AutoResetEvent resetEvent = new AutoResetEvent(false); private ISessionServer sessionServer; private bool running = false; diff --git a/OpenDiablo2.ServiceBus/SessionServer.cs b/OpenDiablo2.ServiceBus/SessionServer.cs index e4bdbe65..c20b4742 100644 --- a/OpenDiablo2.ServiceBus/SessionServer.cs +++ b/OpenDiablo2.ServiceBus/SessionServer.cs @@ -36,7 +36,7 @@ namespace OpenDiablo2.ServiceBus private readonly IGameServer gameServer; private readonly Func getMessageFrame; - private AutoResetEvent resetEvent = new AutoResetEvent(false); + private readonly AutoResetEvent resetEvent = new AutoResetEvent(false); public AutoResetEvent WaitServerStartEvent { get; set; } = new AutoResetEvent(false); private bool running = false; private ResponseSocket responseSocket;