2018-11-24 23:52:23 -05:00
|
|
|
|
using System;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using OpenDiablo2.Common;
|
|
|
|
|
using OpenDiablo2.Common.Attributes;
|
|
|
|
|
using OpenDiablo2.Common.Enums;
|
|
|
|
|
using OpenDiablo2.Common.Interfaces;
|
|
|
|
|
|
|
|
|
|
namespace OpenDiablo2.Scenes
|
|
|
|
|
{
|
|
|
|
|
[Scene("Game")]
|
|
|
|
|
public sealed class Game : IScene
|
|
|
|
|
{
|
|
|
|
|
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;
|
2018-12-01 15:22:55 -05:00
|
|
|
|
private readonly IMouseInfoProvider mouseInfoProvider;
|
2018-11-24 23:52:23 -05:00
|
|
|
|
private readonly IGameState gameState;
|
2018-12-01 15:22:55 -05:00
|
|
|
|
private readonly ISessionManager sessionManager;
|
2018-11-24 23:52:23 -05:00
|
|
|
|
private readonly IKeyboardInfoProvider keyboardInfoProvider;
|
|
|
|
|
|
|
|
|
|
//private ISprite[] testSprite;
|
|
|
|
|
|
|
|
|
|
private ISprite panelSprite, healthManaSprite, gameGlobeOverlapSprite;
|
|
|
|
|
|
2018-12-07 18:45:23 -05:00
|
|
|
|
private readonly IMiniPanel minipanel;
|
|
|
|
|
|
2018-11-26 18:18:23 -05:00
|
|
|
|
private IButton runButton, menuButton;
|
2018-12-01 15:22:55 -05:00
|
|
|
|
private eMovementType lastMovementType = eMovementType.Stopped;
|
2018-12-01 20:17:51 -05:00
|
|
|
|
private byte lastDirection = 255;
|
2018-12-01 15:22:55 -05:00
|
|
|
|
|
|
|
|
|
const double Rad2Deg = 180.0 / Math.PI;
|
2018-11-24 23:52:23 -05:00
|
|
|
|
|
|
|
|
|
public Game(
|
2018-11-24 23:33:04 -05:00
|
|
|
|
IRenderWindow renderWindow,
|
|
|
|
|
IResourceManager resourceManager,
|
|
|
|
|
IMapEngine mapEngine,
|
2018-11-24 23:52:23 -05:00
|
|
|
|
IGameState gameState,
|
2018-12-01 15:22:55 -05:00
|
|
|
|
IMouseInfoProvider mouseInfoProvider,
|
2018-11-24 23:52:23 -05:00
|
|
|
|
IKeyboardInfoProvider keyboardInfoProvider,
|
2018-12-02 16:34:00 -05:00
|
|
|
|
IItemManager itemManager,
|
2018-12-01 15:22:55 -05:00
|
|
|
|
ISessionManager sessionManager,
|
2018-11-26 18:18:23 -05:00
|
|
|
|
Func<eButtonType, IButton> createButton,
|
2018-12-07 18:45:23 -05:00
|
|
|
|
Func<IMiniPanel> createMiniPanel
|
2018-11-24 23:52:23 -05:00
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
this.renderWindow = renderWindow;
|
|
|
|
|
this.resourceManager = resourceManager;
|
|
|
|
|
this.mapEngine = mapEngine;
|
|
|
|
|
this.gameState = gameState;
|
2018-12-01 15:22:55 -05:00
|
|
|
|
this.mouseInfoProvider = mouseInfoProvider;
|
2018-11-24 23:52:23 -05:00
|
|
|
|
this.keyboardInfoProvider = keyboardInfoProvider;
|
2018-12-01 15:22:55 -05:00
|
|
|
|
this.sessionManager = sessionManager;
|
2018-11-24 23:52:23 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
panelSprite = renderWindow.LoadSprite(ResourcePaths.GamePanels, Palettes.Act1);
|
|
|
|
|
healthManaSprite = renderWindow.LoadSprite(ResourcePaths.HealthMana, Palettes.Act1);
|
|
|
|
|
gameGlobeOverlapSprite = renderWindow.LoadSprite(ResourcePaths.GameGlobeOverlap, Palettes.Act1);
|
|
|
|
|
|
2018-11-26 18:18:23 -05:00
|
|
|
|
minipanel = createMiniPanel();
|
2018-11-29 19:11:25 -05:00
|
|
|
|
|
2018-11-24 23:52:23 -05:00
|
|
|
|
runButton = createButton(eButtonType.Run);
|
|
|
|
|
runButton.Location = new Point(256, 570);
|
2018-11-24 23:33:04 -05:00
|
|
|
|
runButton.OnToggle = OnRunToggle;
|
|
|
|
|
|
2018-12-07 18:45:23 -05:00
|
|
|
|
// move to minipanel?
|
2018-11-24 23:52:23 -05:00
|
|
|
|
menuButton = createButton(eButtonType.Menu);
|
|
|
|
|
menuButton.Location = new Point(393, 561);
|
2018-12-07 18:45:23 -05:00
|
|
|
|
menuButton.OnToggle = minipanel.OnMenuToggle;
|
2018-11-24 23:52:23 -05:00
|
|
|
|
|
2018-12-02 16:34:00 -05:00
|
|
|
|
/*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));*/
|
2018-11-24 23:52:23 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnRunToggle(bool isToggled)
|
|
|
|
|
{
|
|
|
|
|
log.Debug("Run Toggle: " + isToggled);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Render()
|
|
|
|
|
{
|
2018-12-01 12:10:16 -05:00
|
|
|
|
// TODO: Maybe show some sort of connecting/loading message?
|
|
|
|
|
if (mapEngine.FocusedPlayerId == 0)
|
|
|
|
|
return;
|
2018-11-24 23:52:23 -05:00
|
|
|
|
|
|
|
|
|
mapEngine.Render();
|
|
|
|
|
DrawPanel();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DrawPanel()
|
|
|
|
|
{
|
2018-12-07 18:45:23 -05:00
|
|
|
|
minipanel.Render();
|
2018-11-29 19:11:25 -05:00
|
|
|
|
|
2018-11-24 23:52:23 -05:00
|
|
|
|
// Render the background bottom bar
|
|
|
|
|
renderWindow.Draw(panelSprite, 0, new Point(0, 600));
|
|
|
|
|
renderWindow.Draw(panelSprite, 1, new Point(166, 600));
|
|
|
|
|
renderWindow.Draw(panelSprite, 2, new Point(294, 600));
|
|
|
|
|
renderWindow.Draw(panelSprite, 3, new Point(422, 600));
|
|
|
|
|
renderWindow.Draw(panelSprite, 4, new Point(550, 600));
|
|
|
|
|
renderWindow.Draw(panelSprite, 5, new Point(685, 600));
|
|
|
|
|
|
|
|
|
|
// Render the health bar
|
|
|
|
|
renderWindow.Draw(healthManaSprite, 0, new Point(30, 587));
|
|
|
|
|
renderWindow.Draw(gameGlobeOverlapSprite, 0, new Point(28, 595));
|
|
|
|
|
|
|
|
|
|
// Render the mana bar
|
|
|
|
|
renderWindow.Draw(healthManaSprite, 1, new Point(692, 588));
|
|
|
|
|
renderWindow.Draw(gameGlobeOverlapSprite, 1, new Point(693, 591));
|
|
|
|
|
|
2018-11-29 19:11:25 -05:00
|
|
|
|
|
2018-11-25 13:13:24 -05:00
|
|
|
|
|
2018-11-24 23:52:23 -05:00
|
|
|
|
runButton.Render();
|
|
|
|
|
menuButton.Render();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Update(long ms)
|
|
|
|
|
{
|
2018-12-01 15:22:55 -05:00
|
|
|
|
var seconds = ms / 1000f;
|
|
|
|
|
|
2018-12-07 18:45:23 -05:00
|
|
|
|
minipanel.Update();
|
2018-11-29 19:11:25 -05:00
|
|
|
|
|
2018-11-24 23:52:23 -05:00
|
|
|
|
runButton.Update();
|
|
|
|
|
menuButton.Update();
|
|
|
|
|
|
2018-12-01 15:22:55 -05:00
|
|
|
|
HandleMovement();
|
|
|
|
|
|
|
|
|
|
mapEngine.Update(ms);
|
|
|
|
|
}
|
2018-11-24 23:52:23 -05:00
|
|
|
|
|
2018-12-01 15:22:55 -05:00
|
|
|
|
private void HandleMovement()
|
|
|
|
|
{
|
|
|
|
|
if (mouseInfoProvider.MouseY > 530) // 550 is what it should be, but the minipanel check needs to happent oo
|
|
|
|
|
return;
|
|
|
|
|
|
2018-12-07 18:45:23 -05:00
|
|
|
|
if (minipanel.IsRightPanelVisible && mouseInfoProvider.MouseX >= 400)
|
2018-12-01 15:22:55 -05:00
|
|
|
|
return;
|
|
|
|
|
|
2018-12-07 18:45:23 -05:00
|
|
|
|
if (minipanel.IsLeftPanelVisible && mouseInfoProvider.MouseX < 400)
|
2018-12-01 15:22:55 -05:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: Filter movement for inventory panel
|
2018-12-07 18:45:23 -05:00
|
|
|
|
var mx = (mouseInfoProvider.MouseX - 400) - gameState.CameraOffset;
|
2018-12-01 20:17:51 -05:00
|
|
|
|
var my = (mouseInfoProvider.MouseY - 300);
|
|
|
|
|
|
|
|
|
|
var tx = (mx / 60f + my / 40f) / 2f;
|
|
|
|
|
var ty = (my / 40f - (mx / 60f)) / 2f;
|
|
|
|
|
var cursorDirection = (int)Math.Round(Math.Atan2(ty, tx) * Rad2Deg);
|
|
|
|
|
if (cursorDirection < 0)
|
|
|
|
|
cursorDirection += 360;
|
|
|
|
|
var actualDirection = (byte)(cursorDirection / 22);
|
2018-12-08 01:01:30 -05:00
|
|
|
|
if (actualDirection >= 16)
|
|
|
|
|
actualDirection -= 16;
|
2018-12-01 15:22:55 -05:00
|
|
|
|
|
2018-12-01 20:17:51 -05:00
|
|
|
|
if (mouseInfoProvider.LeftMouseDown && (lastMovementType == eMovementType.Stopped || lastDirection != actualDirection))
|
2018-11-24 23:52:23 -05:00
|
|
|
|
{
|
2018-12-01 20:17:51 -05:00
|
|
|
|
lastDirection = actualDirection;
|
2018-12-01 15:22:55 -05:00
|
|
|
|
lastMovementType = runButton.Toggled ? eMovementType.Running : eMovementType.Walking;
|
2018-12-01 20:17:51 -05:00
|
|
|
|
sessionManager.MoveRequest(actualDirection, lastMovementType);
|
2018-11-24 23:52:23 -05:00
|
|
|
|
}
|
2018-12-01 15:22:55 -05:00
|
|
|
|
else if (!mouseInfoProvider.LeftMouseDown && lastMovementType != eMovementType.Stopped)
|
2018-11-28 19:28:41 -05:00
|
|
|
|
{
|
2018-12-01 20:17:51 -05:00
|
|
|
|
lastDirection = actualDirection;
|
2018-12-01 15:22:55 -05:00
|
|
|
|
lastMovementType = eMovementType.Stopped;
|
2018-12-01 20:17:51 -05:00
|
|
|
|
sessionManager.MoveRequest(actualDirection, lastMovementType);
|
2018-11-28 19:28:41 -05:00
|
|
|
|
}
|
2018-11-24 23:52:23 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-12-07 18:45:54 -05:00
|
|
|
|
}
|