Skip to content

Commit

Permalink
Quick match
Browse files Browse the repository at this point in the history
  • Loading branch information
devo1929 committed Oct 7, 2022
1 parent 602b83b commit 145f9cf
Show file tree
Hide file tree
Showing 61 changed files with 2,798 additions and 141 deletions.
2 changes: 2 additions & 0 deletions ClientCore/ClientConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,8 @@ public string GetThemePath(string themeName)

public string MPMapsIniPath => SafePath.CombineFilePath(clientDefinitionsIni.GetStringValue(SETTINGS, "MPMapsPath", SafePath.CombineFilePath("INI", "MPMaps.ini")));

public string QuickMatchPath => clientDefinitionsIni.GetStringValue(SETTINGS, "QuickMatchPath", "INI/QuickMatch.ini");

public string KeyboardINI => clientDefinitionsIni.GetStringValue(SETTINGS, "KeyboardINI", "Keyboard.ini");

public int MinimumIngameWidth => clientDefinitionsIni.GetIntValue(SETTINGS, "MinimumIngameWidth", 640);
Expand Down
11 changes: 11 additions & 0 deletions ClientCore/Exceptions/ClientException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;

namespace ClientCore.Exceptions
{
public class ClientException : Exception
{
public ClientException(string message, Exception innerException = null) : base(message, innerException)
{
}
}
}
14 changes: 14 additions & 0 deletions ClientCore/Exceptions/ClientRequestException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Net;

namespace ClientCore.Exceptions
{
public class ClientRequestException : ClientException
{
public HttpStatusCode? StatusCode { get; }

public ClientRequestException(string message, HttpStatusCode? statusCode = null) : base(message)
{
StatusCode = statusCode;
}
}
}
8 changes: 5 additions & 3 deletions ClientGUI/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
using Rampastring.XNAUI.XNAControls;
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;

namespace ClientGUI
{
Expand Down Expand Up @@ -69,6 +70,9 @@ private XNAControl GetControl(string controlName)
if (controlName == primaryControl.Name)
return primaryControl;

if (controlName == primaryControl.Parent.Name)
return primaryControl.Parent;

var control = Find(primaryControl.Children, controlName);
if (control == null)
throw new KeyNotFoundException($"Control '{controlName}' not found while parsing input '{Input}'");
Expand Down Expand Up @@ -104,7 +108,7 @@ public void SetPrimaryControl(XNAControl primaryControl)
public int GetExprValue(string input, XNAControl parsingControl)
{
this.parsingControl = parsingControl;
Input = input;
Input = Regex.Replace(input, @"\s", "");
tokenPlace = 0;
return GetExprValue();
}
Expand All @@ -115,8 +119,6 @@ private int GetExprValue()

while (true)
{
SkipWhitespace();

if (IsEndOfInput())
return value;

Expand Down
14 changes: 13 additions & 1 deletion ClientGUI/XNAClientDropDown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ public class XNAClientDropDown : XNADropDown
{
public ToolTip ToolTip { get; set; }

public bool DisabledMouseScroll { get; set; }

public XNAClientDropDown(WindowManager windowManager) : base(windowManager)
{
}
Expand Down Expand Up @@ -46,6 +48,16 @@ public override void OnMouseLeftDown()
UpdateToolTipBlock();
}

public override void OnMouseScrolled()
{
if (DisabledMouseScroll)
return;

base.OnMouseScrolled();
}

public void Close() => CloseDropDown();

protected override void CloseDropDown()
{
base.CloseDropDown();
Expand All @@ -60,4 +72,4 @@ protected void UpdateToolTipBlock()
ToolTip.Blocked = true;
}
}
}
}
74 changes: 74 additions & 0 deletions ClientGUI/XNAClientProgressBar.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using System;
using Microsoft.Xna.Framework;
using Rampastring.Tools;
using Rampastring.XNAUI;
using Rampastring.XNAUI.XNAControls;

namespace ClientGUI;

public class XNAClientProgressBar : XNAProgressBar
{
public int Speed { get; set; } = 4;

public double WidthRatio { get; set; } = 0.25;

public bool IndeterminateMode { get; set; }

private int _left { get; set; }

public XNAClientProgressBar(WindowManager windowManager) : base(windowManager)
{
}

public override void Update(GameTime gameTime)
{
_left = (_left + Speed) % Width;
}

public override void Draw(GameTime gameTime)
{
if (!IndeterminateMode)
{
base.Draw(gameTime);
return;
}

Rectangle wrect = RenderRectangle();
var filledWidth = (int)(wrect.Width * WidthRatio);

for (int i = 0; i < BorderWidth; i++)
{
var rect = new Rectangle(wrect.X + i, wrect.Y + i, wrect.Width - i, wrect.Height - i);

Renderer.DrawRectangle(rect, BorderColor);
}

Renderer.FillRectangle(new Rectangle(wrect.X + BorderWidth, wrect.Y + BorderWidth, wrect.Width - BorderWidth * 2, wrect.Height - BorderWidth * 2), UnfilledColor);

if (_left + filledWidth > wrect.Width - BorderWidth * 2)
{
Renderer.FillRectangle(new Rectangle(wrect.X + BorderWidth, wrect.Y + BorderWidth, (_left + filledWidth) - (wrect.Width - (BorderWidth * 2)), wrect.Height - BorderWidth * 2), FilledColor);
}

Renderer.FillRectangle(new Rectangle(wrect.X + BorderWidth + _left, wrect.Y + BorderWidth, Math.Min(filledWidth, wrect.Width - (BorderWidth * 2) - _left), wrect.Height - BorderWidth * 2), FilledColor);
}

public override void ParseAttributeFromINI(IniFile iniFile, string key, string value)
{
switch (key)
{
case "WidthRatio":
WidthRatio = double.Parse(value);
return;
case "IndeterminateMode":
IndeterminateMode = bool.Parse(value);
return;
case "Speed":
Speed = int.Parse(value);
return;
default:
base.ParseAttributeFromINI(iniFile, key, value);
return;
}
}
}
7 changes: 6 additions & 1 deletion ClientGUI/XNAMessageBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,10 @@ private static void MsgBox_OKClicked(XNAMessageBox messageBox)
/// <param name="caption">The caption of the message box.</param>
/// <param name="description">The description in the message box.</param>
/// <returns>The XNAMessageBox instance that is created.</returns>
public static XNAMessageBox ShowYesNoDialog(WindowManager windowManager, string caption, string description)
public static XNAMessageBox ShowYesNoDialog(WindowManager windowManager, string caption, string description)
=> ShowYesNoDialog(windowManager, caption, description, null);

public static XNAMessageBox ShowYesNoDialog(WindowManager windowManager, string caption, string description, Action<XNAMessageBox> yesAction)
{
var panel = new DarkeningPanel(windowManager);
windowManager.AddAndInitializeControl(panel);
Expand All @@ -274,6 +277,8 @@ public static XNAMessageBox ShowYesNoDialog(WindowManager windowManager, string

panel.AddChild(msgBox);
msgBox.YesClickedAction = MsgBox_YesClicked;
if (yesAction != null)
msgBox.YesClickedAction += yesAction;
msgBox.NoClickedAction = MsgBox_NoClicked;

return msgBox;
Expand Down
12 changes: 12 additions & 0 deletions ClientGUI/XNAScrollablePanel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Rampastring.XNAUI;
using Rampastring.XNAUI.XNAControls;

namespace ClientGUI;

public class XNAScrollablePanel : XNAPanel
{
public XNAScrollablePanel(WindowManager windowManager) : base(windowManager)
{
DrawMode = ControlDrawMode.UNIQUE_RENDER_TARGET;
}
}
48 changes: 35 additions & 13 deletions DXMainClient/DXGUI/Generic/LoadingScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
using DTAClient.DXGUI.Multiplayer;
using DTAClient.DXGUI.Multiplayer.CnCNet;
using DTAClient.DXGUI.Multiplayer.GameLobby;
using DTAClient.DXGUI.Multiplayer.QuickMatch;
using DTAClient.Online;
using DTAConfig;
using Microsoft.Xna.Framework;
using Rampastring.XNAUI;
using System.Threading.Tasks;
using Rampastring.Tools;
using ClientUpdater;
using Rampastring.XNAUI.XNAControls;
using SkirmishLobby = DTAClient.DXGUI.Multiplayer.GameLobby.SkirmishLobby;

namespace DTAClient.DXGUI.Generic
Expand Down Expand Up @@ -79,26 +81,20 @@ private void LogGameClientVersion()

private void LoadMaps()
{
mapLoader = new MapLoader();
mapLoader = MapLoader.GetInstance();
mapLoader.LoadMaps();
}

private void Finish()
{
ProgramConstants.GAME_VERSION = ClientConfiguration.Instance.ModMode ?
ProgramConstants.GAME_VERSION = ClientConfiguration.Instance.ModMode ?
"N/A" : Updater.GameVersion;

DiscordHandler discordHandler = null;
if (!string.IsNullOrEmpty(ClientConfiguration.Instance.DiscordAppId))
discordHandler = new DiscordHandler(WindowManager);

ClientGUICreator.Instance.AddControl(typeof(GameLobbyCheckBox));
ClientGUICreator.Instance.AddControl(typeof(GameLobbyDropDown));
ClientGUICreator.Instance.AddControl(typeof(MapPreviewBox));
ClientGUICreator.Instance.AddControl(typeof(GameLaunchButton));
ClientGUICreator.Instance.AddControl(typeof(ChatListBox));
ClientGUICreator.Instance.AddControl(typeof(XNAChatTextBox));
ClientGUICreator.Instance.AddControl(typeof(PlayerExtraOptionsPanel));
DeclareCustomControls();

var gameCollection = new GameCollection();
gameCollection.Initialize();
Expand All @@ -109,7 +105,7 @@ private void Finish()
var cncnetManager = new CnCNetManager(WindowManager, gameCollection, cncnetUserData);
var tunnelHandler = new TunnelHandler(WindowManager, cncnetManager);
var privateMessageHandler = new PrivateMessageHandler(cncnetManager, cncnetUserData);

var topBar = new TopBar(WindowManager, cncnetManager, privateMessageHandler);

var optionsWindow = new OptionsWindow(WindowManager, gameCollection, topBar);
Expand All @@ -120,23 +116,26 @@ private void Finish()

var cncnetGameLobby = new CnCNetGameLobby(WindowManager,
"MultiplayerGameLobby", topBar, cncnetManager, tunnelHandler, gameCollection, cncnetUserData, mapLoader, discordHandler, pmWindow);
var cncnetGameLoadingLobby = new CnCNetGameLoadingLobby(WindowManager,
var cncnetGameLoadingLobby = new CnCNetGameLoadingLobby(WindowManager,
topBar, cncnetManager, tunnelHandler, mapLoader.GameModes, gameCollection, discordHandler);
var cncnetLobby = new CnCNetLobby(WindowManager, cncnetManager,
var cncnetLobby = new CnCNetLobby(WindowManager, cncnetManager,
cncnetGameLobby, cncnetGameLoadingLobby, topBar, pmWindow, tunnelHandler,
gameCollection, cncnetUserData, optionsWindow);
var gipw = new GameInProgressWindow(WindowManager);

var skirmishLobby = new SkirmishLobby(WindowManager, topBar, mapLoader, discordHandler);
var quickMatchWindow = new QuickMatchWindow(WindowManager);

topBar.SetSecondarySwitch(cncnetLobby);

var mainMenu = new MainMenu(WindowManager, skirmishLobby, lanLobby,
var mainMenu = new MainMenu(WindowManager, skirmishLobby, quickMatchWindow, lanLobby,
topBar, optionsWindow, cncnetLobby, cncnetManager, discordHandler);
WindowManager.AddAndInitializeControl(mainMenu);

DarkeningPanel.AddAndInitializeWithControl(WindowManager, skirmishLobby);

DarkeningPanel.AddAndInitializeWithControl(WindowManager, quickMatchWindow);

DarkeningPanel.AddAndInitializeWithControl(WindowManager, cncnetGameLoadingLobby);

DarkeningPanel.AddAndInitializeWithControl(WindowManager, cncnetGameLobby);
Expand All @@ -152,9 +151,11 @@ private void Finish()

topBar.SetTertiarySwitch(pmWindow);
topBar.SetOptionsWindow(optionsWindow);
topBar.SetQuickMatchWindow(quickMatchWindow);

WindowManager.AddAndInitializeControl(gipw);
skirmishLobby.Disable();
quickMatchWindow.Disable();
cncnetLobby.Disable();
cncnetGameLobby.Disable();
cncnetGameLoadingLobby.Disable();
Expand Down Expand Up @@ -183,6 +184,27 @@ private void Finish()
Cursor.Visible = visibleSpriteCursor;
}

private static void DeclareCustomControls()
{
ClientGUICreator.Instance.AddControl(typeof(GameLobbyCheckBox));
ClientGUICreator.Instance.AddControl(typeof(GameLobbyDropDown));
ClientGUICreator.Instance.AddControl(typeof(MapPreviewBox));
ClientGUICreator.Instance.AddControl(typeof(GameLaunchButton));
ClientGUICreator.Instance.AddControl(typeof(ChatListBox));
ClientGUICreator.Instance.AddControl(typeof(XNAChatTextBox));
ClientGUICreator.Instance.AddControl(typeof(XNAScrollBar));
ClientGUICreator.Instance.AddControl(typeof(XNAPasswordBox));
ClientGUICreator.Instance.AddControl(typeof(PlayerExtraOptionsPanel));
ClientGUICreator.Instance.AddControl(typeof(QuickMatchLoginPanel));
ClientGUICreator.Instance.AddControl(typeof(QuickMatchLobbyPanel));
ClientGUICreator.Instance.AddControl(typeof(QuickMatchLobbyFooterPanel));
ClientGUICreator.Instance.AddControl(typeof(QuickMatchMapList));
ClientGUICreator.Instance.AddControl(typeof(QuickMatchStatusOverlay));
ClientGUICreator.Instance.AddControl(typeof(XNAClientTabControl));
ClientGUICreator.Instance.AddControl(typeof(XNAClientProgressBar));
ClientGUICreator.Instance.AddControl(typeof(XNAScrollablePanel));
}

public override void Update(GameTime gameTime)
{
base.Update(gameTime);
Expand Down
Loading

0 comments on commit 145f9cf

Please sign in to comment.