2018-11-22 14:30:37 -05:00
|
|
|
|
using OpenDiablo2.Common;
|
|
|
|
|
using OpenDiablo2.Common.Attributes;
|
2018-11-22 22:53:05 -05:00
|
|
|
|
using OpenDiablo2.Common.Enums;
|
2018-11-22 00:18:42 -05:00
|
|
|
|
using OpenDiablo2.Common.Interfaces;
|
|
|
|
|
using OpenDiablo2.Common.Models;
|
2018-11-22 18:06:15 -05:00
|
|
|
|
using OpenDiablo2.Core.UI;
|
2018-11-22 00:18:42 -05:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
2018-11-22 02:24:55 -05:00
|
|
|
|
using System.Threading;
|
2018-11-22 00:18:42 -05:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace OpenDiablo2.Scenes
|
|
|
|
|
{
|
|
|
|
|
[Scene("Main Menu")]
|
|
|
|
|
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;
|
2018-11-22 00:56:36 -05:00
|
|
|
|
private readonly IMouseInfoProvider mouseInfoProvider;
|
2018-11-22 02:24:55 -05:00
|
|
|
|
private readonly IMusicProvider musicProvider;
|
2018-11-22 20:23:00 -05:00
|
|
|
|
private readonly ISceneManager sceneManager;
|
2018-11-22 00:18:42 -05:00
|
|
|
|
|
|
|
|
|
private float logoFrame;
|
2018-11-22 17:00:22 -05:00
|
|
|
|
private ISprite backgroundSprite, diabloLogoLeft, diabloLogoRight, diabloLogoLeftBlack, diabloLogoRightBlack;
|
2018-11-22 16:22:39 -05:00
|
|
|
|
private IFont labelFont;
|
|
|
|
|
private ILabel versionLabel, urlLabel;
|
2018-11-22 22:53:05 -05:00
|
|
|
|
private Button btnSinglePlayer, btnExit, btnWebsite;
|
2018-11-22 00:18:42 -05:00
|
|
|
|
|
|
|
|
|
public MainMenu(
|
|
|
|
|
IRenderWindow renderWindow,
|
|
|
|
|
IPaletteProvider paletteProvider,
|
2018-11-22 00:56:36 -05:00
|
|
|
|
IMPQProvider mpqProvider,
|
2018-11-22 02:24:55 -05:00
|
|
|
|
IMouseInfoProvider mouseInfoProvider,
|
2018-11-22 18:06:15 -05:00
|
|
|
|
IMusicProvider musicProvider,
|
2018-11-22 20:23:00 -05:00
|
|
|
|
ISceneManager sceneManager,
|
2018-11-23 11:43:21 -05:00
|
|
|
|
Func<eButtonType, Button> createButton,
|
|
|
|
|
Func<string, IScene> getScene // Temporary until SDL load functions are sped up
|
2018-11-22 00:18:42 -05:00
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
this.renderWindow = renderWindow;
|
|
|
|
|
this.paletteProvider = paletteProvider;
|
|
|
|
|
this.mpqProvider = mpqProvider;
|
2018-11-22 00:56:36 -05:00
|
|
|
|
this.mouseInfoProvider = mouseInfoProvider;
|
2018-11-22 20:23:00 -05:00
|
|
|
|
this.sceneManager = sceneManager;
|
2018-11-22 00:18:42 -05:00
|
|
|
|
|
2018-11-22 14:30:37 -05:00
|
|
|
|
backgroundSprite = renderWindow.LoadSprite(ResourcePaths.GameSelectScreen, Palettes.Sky);
|
|
|
|
|
diabloLogoLeft = renderWindow.LoadSprite(ResourcePaths.Diablo2LogoFireLeft, Palettes.Units, new Point(400, 120));
|
2018-11-22 18:06:15 -05:00
|
|
|
|
diabloLogoLeft.Blend = true;
|
2018-11-22 14:30:37 -05:00
|
|
|
|
diabloLogoRight = renderWindow.LoadSprite(ResourcePaths.Diablo2LogoFireRight, Palettes.Units, new Point(400, 120));
|
2018-11-22 18:06:15 -05:00
|
|
|
|
diabloLogoRight.Blend = true;
|
2018-11-22 14:30:37 -05:00
|
|
|
|
diabloLogoLeftBlack = renderWindow.LoadSprite(ResourcePaths.Diablo2LogoBlackLeft, Palettes.Units, new Point(400, 120));
|
|
|
|
|
diabloLogoRightBlack = renderWindow.LoadSprite(ResourcePaths.Diablo2LogoBlackRight, Palettes.Units, new Point(400, 120));
|
2018-11-22 00:18:42 -05:00
|
|
|
|
|
2018-11-22 22:53:05 -05:00
|
|
|
|
btnSinglePlayer = createButton(eButtonType.Wide);
|
2018-11-22 18:06:15 -05:00
|
|
|
|
btnSinglePlayer.Text = "Single Player".ToUpper();
|
|
|
|
|
btnSinglePlayer.Location = new Point(264, 290);
|
2018-11-22 18:46:24 -05:00
|
|
|
|
btnSinglePlayer.OnActivate = OnSinglePlayerClicked;
|
|
|
|
|
|
2018-11-22 22:53:05 -05:00
|
|
|
|
btnWebsite = createButton(eButtonType.Wide);
|
|
|
|
|
btnWebsite.Text = "Visit Github".ToUpper();
|
2018-11-22 18:46:24 -05:00
|
|
|
|
btnWebsite.Location = new Point(264, 460);
|
|
|
|
|
btnWebsite.OnActivate = OnVisitWebsiteClicked;
|
|
|
|
|
|
2018-11-22 22:53:05 -05:00
|
|
|
|
btnExit = createButton(eButtonType.Wide);
|
2018-11-22 18:46:24 -05:00
|
|
|
|
btnExit.Text = "Exit Diablo II".ToUpper();
|
|
|
|
|
btnExit.Location = new Point(264, 500);
|
|
|
|
|
btnExit.OnActivate = OnExitClicked;
|
2018-11-22 00:56:36 -05:00
|
|
|
|
|
2018-11-22 16:22:39 -05:00
|
|
|
|
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;
|
2018-11-22 00:56:36 -05:00
|
|
|
|
|
2018-11-22 14:30:37 -05:00
|
|
|
|
var loadingSprite = renderWindow.LoadSprite(ResourcePaths.LoadingScreen, Palettes.Loading, new Point(300, 400));
|
2018-11-22 00:56:36 -05:00
|
|
|
|
|
2018-11-23 11:43:21 -05:00
|
|
|
|
|
|
|
|
|
// Pre-load all the scenes for now until we fix the sdl load problem
|
|
|
|
|
var scenesToLoad = new string[] {"Select Hero Class" };
|
|
|
|
|
for (int i = 0; i < scenesToLoad.Count(); i++)
|
|
|
|
|
{
|
|
|
|
|
renderWindow.Clear();
|
|
|
|
|
renderWindow.Draw(loadingSprite, (int)((float)loadingSprite.TotalFrames * ((float)i / (float)scenesToLoad.Count())));
|
|
|
|
|
renderWindow.Sync();
|
|
|
|
|
getScene(scenesToLoad[i]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2018-11-22 02:24:55 -05:00
|
|
|
|
|
2018-11-22 20:23:00 -05:00
|
|
|
|
/*
|
2018-11-22 02:24:55 -05:00
|
|
|
|
musicProvider.LoadSong(mpqProvider.GetStream("data\\global\\music\\introedit.wav"));
|
|
|
|
|
|
|
|
|
|
musicProvider.PlaySong();
|
2018-11-22 20:23:00 -05:00
|
|
|
|
*/
|
2018-11-22 00:18:42 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-22 18:46:24 -05:00
|
|
|
|
private void OnVisitWebsiteClicked()
|
|
|
|
|
=> System.Diagnostics.Process.Start("https://github.com/essial/OpenDiablo2/");
|
|
|
|
|
|
2018-11-22 00:18:42 -05:00
|
|
|
|
public void Render()
|
|
|
|
|
{
|
2018-11-22 16:22:39 -05:00
|
|
|
|
// Render the background
|
2018-11-22 12:35:21 -05:00
|
|
|
|
renderWindow.Draw(backgroundSprite, 4, 3, 0);
|
2018-11-22 12:19:38 -05:00
|
|
|
|
|
2018-11-22 16:22:39 -05:00
|
|
|
|
// Render the flaming diablo 2 logo
|
2018-11-22 17:00:22 -05:00
|
|
|
|
renderWindow.Draw(diabloLogoLeftBlack, (int)(diabloLogoLeftBlack.TotalFrames * logoFrame));
|
|
|
|
|
renderWindow.Draw(diabloLogoRightBlack, (int)(diabloLogoRightBlack.TotalFrames * logoFrame));
|
|
|
|
|
renderWindow.Draw(diabloLogoLeft, (int)(diabloLogoLeft.TotalFrames * logoFrame));
|
|
|
|
|
renderWindow.Draw(diabloLogoRight, (int)(diabloLogoRight.TotalFrames * logoFrame));
|
2018-11-22 00:18:42 -05:00
|
|
|
|
|
2018-11-22 16:22:39 -05:00
|
|
|
|
// Render the text
|
|
|
|
|
renderWindow.Draw(versionLabel);
|
|
|
|
|
renderWindow.Draw(urlLabel);
|
|
|
|
|
|
|
|
|
|
// Render the UI buttons
|
2018-11-22 18:06:15 -05:00
|
|
|
|
btnSinglePlayer.Render();
|
2018-11-22 18:46:24 -05:00
|
|
|
|
btnWebsite.Render();
|
|
|
|
|
btnExit.Render();
|
2018-11-22 18:06:15 -05:00
|
|
|
|
|
2018-11-22 17:00:22 -05:00
|
|
|
|
//wideButton.Location = new Point(264, 290);
|
|
|
|
|
//renderWindow.Draw(wideButton, 2, 1, 0);
|
2018-11-22 00:18:42 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Update(long ms)
|
|
|
|
|
{
|
|
|
|
|
float seconds = ((float)ms / 1000f);
|
|
|
|
|
logoFrame += seconds;
|
|
|
|
|
while (logoFrame >= 1f)
|
|
|
|
|
logoFrame -= 1f;
|
|
|
|
|
|
2018-11-22 18:06:15 -05:00
|
|
|
|
btnSinglePlayer.Update();
|
2018-11-22 18:46:24 -05:00
|
|
|
|
btnWebsite.Update();
|
|
|
|
|
btnExit.Update();
|
2018-11-22 18:06:15 -05:00
|
|
|
|
|
2018-11-22 00:18:42 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
2018-11-22 22:53:05 -05:00
|
|
|
|
backgroundSprite.Dispose();
|
|
|
|
|
diabloLogoLeft.Dispose();
|
|
|
|
|
diabloLogoRight.Dispose();
|
|
|
|
|
diabloLogoLeftBlack.Dispose();
|
|
|
|
|
diabloLogoRightBlack.Dispose();
|
|
|
|
|
labelFont.Dispose();
|
|
|
|
|
versionLabel.Dispose();
|
|
|
|
|
urlLabel.Dispose();
|
|
|
|
|
btnSinglePlayer.Dispose();
|
|
|
|
|
btnExit.Dispose();
|
|
|
|
|
btnWebsite.Dispose();
|
2018-11-22 00:18:42 -05:00
|
|
|
|
}
|
2018-11-22 18:06:15 -05:00
|
|
|
|
|
|
|
|
|
private void OnSinglePlayerClicked()
|
2018-11-22 20:23:00 -05:00
|
|
|
|
=> sceneManager.ChangeScene("Select Hero Class");
|
2018-11-22 18:46:24 -05:00
|
|
|
|
|
|
|
|
|
private void OnExitClicked()
|
|
|
|
|
{
|
|
|
|
|
renderWindow.Quit();
|
|
|
|
|
}
|
2018-11-22 00:18:42 -05:00
|
|
|
|
}
|
|
|
|
|
}
|