1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-11-16 01:17:10 -05:00

Added ability to stop sfx. Minor map engine updates.

This commit is contained in:
Tim Sarbin 2018-12-08 20:29:10 -05:00
parent 3baa4673c9
commit 468ec1ef2a
5 changed files with 46 additions and 30 deletions

View File

@ -8,6 +8,7 @@ namespace OpenDiablo2.Common.Interfaces
void LoadSong(Stream data); void LoadSong(Stream data);
void PlaySong(); void PlaySong();
void StopSong(); void StopSong();
void PlaySfx(byte[] data); void StopSfx(int channel);
int PlaySfx(byte[] data);
} }
} }

View File

@ -125,7 +125,7 @@ namespace OpenDiablo2.Core.Map_Engine
foreach (var cellInfo in gameState.GetMapCellInfo((int)ax, (int)ay, eRenderCellType.WallLower)) foreach (var cellInfo in gameState.GetMapCellInfo((int)ax, (int)ay, eRenderCellType.WallLower))
renderWindow.DrawMapCell(cellInfo, 320 + px + (int)ox + xOffset, 210 + py + (int)oy); renderWindow.DrawMapCell(cellInfo, 320 + px + (int)ox + xOffset, 210 + py + (int)oy + 80);
foreach (var cellInfo in gameState.GetMapCellInfo((int)ax, (int)ay, eRenderCellType.WallUpper)) foreach (var cellInfo in gameState.GetMapCellInfo((int)ax, (int)ay, eRenderCellType.WallUpper))
renderWindow.DrawMapCell(cellInfo, 320 + px + (int)ox + xOffset, 210 + py + (int)oy); renderWindow.DrawMapCell(cellInfo, 320 + px + (int)ox + xOffset, 210 + py + (int)oy);

View File

@ -73,10 +73,15 @@ namespace OpenDiablo2.SDL2_
SDL_mixer.Mix_CloseAudio(); SDL_mixer.Mix_CloseAudio();
} }
public void PlaySfx(byte[] data) public int PlaySfx(byte[] data)
{ {
var sound = SDL_mixer.Mix_QuickLoad_WAV(data); var sound = SDL_mixer.Mix_QuickLoad_WAV(data);
SDL_mixer.Mix_PlayChannel(-1, sound, 0); return SDL_mixer.Mix_PlayChannel(-1, sound, 0);
}
public void StopSfx(int channel)
{
SDL_mixer.Mix_HaltChannel(channel);
} }
} }
} }

View File

@ -354,11 +354,9 @@ namespace OpenDiablo2.SDL2_
var offX = -minX; var offX = -minX;
var offY = -minY; var offY = -minY;
var frameSize = new Size(diffX, Math.Abs(diffY)); var frameSize = new Size(Math.Abs(diffX), Math.Abs(diffY));
var srcRect = new SDL.SDL_Rect { x = 0, y = 0, w = frameSize.Width, h = Math.Abs(frameSize.Height) };
//var frameSizeMax = diffX * Math.Abs(diffY);
var srcRect = new SDL.SDL_Rect { x = minX, y = minY, w = frameSize.Width, h = frameSize.Height };
var texId = SDL.SDL_CreateTexture(renderer, SDL.SDL_PIXELFORMAT_ARGB8888, (int)SDL.SDL_TextureAccess.SDL_TEXTUREACCESS_STREAMING, frameSize.Width, frameSize.Height); var texId = SDL.SDL_CreateTexture(renderer, SDL.SDL_PIXELFORMAT_ARGB8888, (int)SDL.SDL_TextureAccess.SDL_TEXTUREACCESS_STREAMING, frameSize.Width, frameSize.Height);
SDL.SDL_SetTextureBlendMode(texId, SDL.SDL_BlendMode.SDL_BLENDMODE_BLEND); SDL.SDL_SetTextureBlendMode(texId, SDL.SDL_BlendMode.SDL_BLENDMODE_BLEND);
@ -371,10 +369,7 @@ namespace OpenDiablo2.SDL2_
UInt32* data = (UInt32*)pixels; UInt32* data = (UInt32*)pixels;
var pitchChange = pitch / 4; var pitchChange = pitch / 4;
var colors = getGameState().CurrentPalette.Colors;
for (var i = 0; i < frameSize.Height * pitchChange; i++)
data[i] = 0x0;
foreach (var block in mapCell.Blocks) foreach (var block in mapCell.Blocks)
{ {
@ -387,7 +382,7 @@ namespace OpenDiablo2.SDL2_
{ {
if (colorIndex == 0) if (colorIndex == 0)
continue; continue;
var color = getGameState().CurrentPalette.Colors[colorIndex]; var color = colors[colorIndex];
if (color > 0) if (color > 0)
data[index] = color; data[index] = color;
@ -399,8 +394,7 @@ namespace OpenDiablo2.SDL2_
xx++; xx++;
if (xx == 32) if (xx == 32)
{ {
index -= 32; index += pitchChange - 32;
index += pitchChange;
xx = 0; xx = 0;
yy++; yy++;
} }
@ -428,7 +422,7 @@ namespace OpenDiablo2.SDL2_
public void DrawMapCell(MapCellInfo mapCellInfo, int xPixel, int yPixel) public void DrawMapCell(MapCellInfo mapCellInfo, int xPixel, int yPixel)
{ {
var srcRect = new SDL.SDL_Rect { x = 0, y = 0, w = mapCellInfo.FrameWidth, h = Math.Abs(mapCellInfo.FrameHeight) }; var srcRect = new SDL.SDL_Rect { x = 0, y = 0, w = mapCellInfo.FrameWidth, h = Math.Abs(mapCellInfo.FrameHeight) };
var destRect = new SDL.SDL_Rect { x = xPixel - mapCellInfo.OffX, y = yPixel - mapCellInfo.OffY, w = mapCellInfo.FrameWidth, h = mapCellInfo.FrameHeight }; var destRect = new SDL.SDL_Rect { x = xPixel + mapCellInfo.Rect.X, y = yPixel + mapCellInfo.Rect.Y, w = mapCellInfo.FrameWidth, h = mapCellInfo.FrameHeight };
SDL.SDL_RenderCopy(renderer, (mapCellInfo.Texture as SDL2Texture).Pointer, ref srcRect, ref destRect); SDL.SDL_RenderCopy(renderer, (mapCellInfo.Texture as SDL2Texture).Pointer, ref srcRect, ref destRect);
} }

View File

@ -43,6 +43,8 @@ namespace OpenDiablo2.Scenes
private bool showEntryUi = false; private bool showEntryUi = false;
private eHero? selectedHero = null; private eHero? selectedHero = null;
private float secondTimer; private float secondTimer;
private int sfxChannel = -1;
private int sfxChannel2 = -1;
private readonly ISprite backgroundSprite, campfireSprite; private readonly ISprite backgroundSprite, campfireSprite;
private readonly IFont headingFont; private readonly IFont headingFont;
private readonly IFont heroDescFont; private readonly IFont heroDescFont;
@ -242,14 +244,27 @@ namespace OpenDiablo2.Scenes
}, (path => sfxDictionary.Add(path, mpqProvider.GetBytes(path)))); }, (path => sfxDictionary.Add(path, mpqProvider.GetBytes(path))));
} }
private void StopSfx()
{
if (sfxChannel > -1)
soundProvider.StopSfx(sfxChannel);
if (sfxChannel2 > -1)
soundProvider.StopSfx(sfxChannel);
}
private void OnOkclicked() private void OnOkclicked()
{ {
StopSfx();
// TODO: Support other session types // TODO: Support other session types
gameState.Initialize(characterNameTextBox.Text, selectedHero.Value, eSessionType.Local); gameState.Initialize(characterNameTextBox.Text, selectedHero.Value, eSessionType.Local);
} }
private void OnExitClicked() private void OnExitClicked()
{ {
StopSfx();
var heros = Enum.GetValues(typeof(eHero)).Cast<eHero>(); var heros = Enum.GetValues(typeof(eHero)).Cast<eHero>();
foreach(var hero in heros) foreach(var hero in heros)
{ {
@ -449,6 +464,7 @@ namespace OpenDiablo2.Scenes
if (ri.Value.Stance != eHeroStance.Selected) if (ri.Value.Stance != eHeroStance.Selected)
continue; continue;
PlayHeroDeselected(ri.Key);
ri.Value.Stance = eHeroStance.Retreating; ri.Value.Stance = eHeroStance.Retreating;
ri.Value.SpecialFrameTime = 0; ri.Value.SpecialFrameTime = 0;
break; break;
@ -476,25 +492,25 @@ namespace OpenDiablo2.Scenes
switch (hero) switch (hero)
{ {
case eHero.Barbarian: case eHero.Barbarian:
soundProvider.PlaySfx(sfxDictionary[ResourcePaths.SFXBarbarianSelect]); sfxChannel = soundProvider.PlaySfx(sfxDictionary[ResourcePaths.SFXBarbarianSelect]);
break; break;
case eHero.Necromancer: case eHero.Necromancer:
soundProvider.PlaySfx(sfxDictionary[ResourcePaths.SFXNecromancerSelect]); sfxChannel = soundProvider.PlaySfx(sfxDictionary[ResourcePaths.SFXNecromancerSelect]);
break; break;
case eHero.Paladin: case eHero.Paladin:
soundProvider.PlaySfx(sfxDictionary[ResourcePaths.SFXPaladinSelect]); sfxChannel = soundProvider.PlaySfx(sfxDictionary[ResourcePaths.SFXPaladinSelect]);
break; break;
case eHero.Assassin: case eHero.Assassin:
soundProvider.PlaySfx(sfxDictionary[ResourcePaths.SFXAssassinSelect]); sfxChannel = soundProvider.PlaySfx(sfxDictionary[ResourcePaths.SFXAssassinSelect]);
break; break;
case eHero.Sorceress: case eHero.Sorceress:
soundProvider.PlaySfx(sfxDictionary[ResourcePaths.SFXSorceressSelect]); sfxChannel = soundProvider.PlaySfx(sfxDictionary[ResourcePaths.SFXSorceressSelect]);
break; break;
case eHero.Amazon: case eHero.Amazon:
soundProvider.PlaySfx(sfxDictionary[ResourcePaths.SFXAmazonSelect]); sfxChannel = soundProvider.PlaySfx(sfxDictionary[ResourcePaths.SFXAmazonSelect]);
break; break;
case eHero.Druid: case eHero.Druid:
soundProvider.PlaySfx(sfxDictionary[ResourcePaths.SFXDruidSelect]); sfxChannel = soundProvider.PlaySfx(sfxDictionary[ResourcePaths.SFXDruidSelect]);
break; break;
default: default:
break; break;
@ -506,25 +522,25 @@ namespace OpenDiablo2.Scenes
switch (hero) switch (hero)
{ {
case eHero.Barbarian: case eHero.Barbarian:
soundProvider.PlaySfx(sfxDictionary[ResourcePaths.SFXBarbarianDeselect]); sfxChannel2 = soundProvider.PlaySfx(sfxDictionary[ResourcePaths.SFXBarbarianDeselect]);
break; break;
case eHero.Necromancer: case eHero.Necromancer:
soundProvider.PlaySfx(sfxDictionary[ResourcePaths.SFXNecromancerDeselect]); sfxChannel2 = soundProvider.PlaySfx(sfxDictionary[ResourcePaths.SFXNecromancerDeselect]);
break; break;
case eHero.Paladin: case eHero.Paladin:
soundProvider.PlaySfx(sfxDictionary[ResourcePaths.SFXPaladinDeselect]); sfxChannel2 = soundProvider.PlaySfx(sfxDictionary[ResourcePaths.SFXPaladinDeselect]);
break; break;
case eHero.Assassin: case eHero.Assassin:
soundProvider.PlaySfx(sfxDictionary[ResourcePaths.SFXAssassinDeselect]); sfxChannel2 = soundProvider.PlaySfx(sfxDictionary[ResourcePaths.SFXAssassinDeselect]);
break; break;
case eHero.Sorceress: case eHero.Sorceress:
soundProvider.PlaySfx(sfxDictionary[ResourcePaths.SFXSorceressDeselect]); sfxChannel2 = soundProvider.PlaySfx(sfxDictionary[ResourcePaths.SFXSorceressDeselect]);
break; break;
case eHero.Amazon: case eHero.Amazon:
soundProvider.PlaySfx(sfxDictionary[ResourcePaths.SFXAmazonDeselect]); sfxChannel2 = soundProvider.PlaySfx(sfxDictionary[ResourcePaths.SFXAmazonDeselect]);
break; break;
case eHero.Druid: case eHero.Druid:
soundProvider.PlaySfx(sfxDictionary[ResourcePaths.SFXDruidDeselect]); sfxChannel2 = soundProvider.PlaySfx(sfxDictionary[ResourcePaths.SFXDruidDeselect]);
break; break;
default: default:
break; break;