diff --git a/.sbproj b/.sbproj index f6de3ac..0e6ffda 100644 --- a/.sbproj +++ b/.sbproj @@ -37,7 +37,20 @@ "GameSettings": {}, "Addons": "", "PreLaunchCommand": "", - "PostLaunchCommand": "" + "PostLaunchCommand": "lucker_minigames_per_round 1" + } + ], + "PackageSettings": [ + { + "DisplayType": "Integer", + "Choices": [], + "ConVarName": "lucker_minigames_per_round", + "DisplayName": "Minigames Per Round", + "DefaultValue": "0", + "Description": "The number of minigames played per round", + "Group": "Other", + "Minimum": 1, + "Maximum": 12 } ] } diff --git a/code/Entities/MinigameManager.cs b/code/Entities/MinigameManager.cs index 111cd39..a9f6650 100644 --- a/code/Entities/MinigameManager.cs +++ b/code/Entities/MinigameManager.cs @@ -57,8 +57,16 @@ public partial class MinigameManager : Entity FindMinigames(); } - private void cleanupPlayerPawns() + /// + /// Goes through the players included in the loaded minigame and deletes and nulls out any pawns assigned to them + /// + private void CleanupPlayerPawns() { + if ( LoadedMinigame is not { IsValid: true } || InvolvedPlayers == null) + { + Log.Warning( "Attempted to clean up players without a minigame loaded!" ); + return; + } InvolvedPlayers.ForEach( player => { player.Pawn.Delete(); diff --git a/code/Entities/RoundManager.cs b/code/Entities/RoundManager.cs index 65b21a3..5a384b6 100644 --- a/code/Entities/RoundManager.cs +++ b/code/Entities/RoundManager.cs @@ -49,7 +49,8 @@ public partial class RoundManager : Entity private const int MinigamesPerRound = 1; - private int MinigamesLeftInRound { get; set; } + [ConVar.Replicated("lucker_minigames_per_round")] + public static int MinigamesLeftInRound { get; set; } private List Players { get; set; } #endregion diff --git a/code/UI/MainMenu/ActiveLobby.razor b/code/UI/MainMenu/ActiveLobby.razor new file mode 100644 index 0000000..9f5a775 --- /dev/null +++ b/code/UI/MainMenu/ActiveLobby.razor @@ -0,0 +1,121 @@ +@using Sandbox; +@using System; +@using System.Linq; +@using System.Threading.Tasks; +@using Sandbox.Menu; +@using Sandbox.UI; + +@namespace LuckerGame.UI.MainMenu +@inherits Panel + + + + + @if ( Lobby == null ) + { +
+ Loading... + + Return +
+ } + else + { + +
+
+ + +
+ @foreach (var member in Lobby.Members) + { + + } +
+
+ + @if ( Lobby.Owner.IsMe ) + { +
+ @if ( MaxPlayersSupported > 1 ) + { + + + + + + + } + + + + + + + +
+ } + +
+ + + Leave Lobby + + Start + + Return +
+ } + + +@code +{ + Friend Owner => Lobby.Owner; + ILobby Lobby => Game.Menu.Lobby; + + int MaxPlayersSupported { get; set; } = 1; + Package MapPackage { get; set; } + + void OnMapClicked() + { + Game.Overlay.ShowPackageSelector( "type:map sort:popular", OnMapSelected ); + StateHasChanged(); + } + + void OnMapSelected( Package map ) + { + MapPackage = map; + Game.Menu.Lobby.Map = map.FullIdent; + + StateHasChanged(); + } + + public void LeaveLobby() + { + Lobby?.Leave(); + + this.Navigate( "/lobby/list" ); + } + + async Task Start() + { + await Game.Menu.StartServerAsync( Game.Menu.Lobby.MaxMembers, $"{Game.Menu.Lobby.Owner.Name}'s game", Game.Menu.Lobby.Map ); + } + + async void FetchPackage() + { + MapPackage = await Package.FetchAsync( Game.Menu.Lobby?.Map ?? "facepunch.square", true ); + } + + protected override void OnAfterTreeRender( bool firstTime ) + { + FetchPackage(); + } + + protected override void OnParametersSet() + { + MaxPlayersSupported = Game.Menu.Package.GetMeta( "MaxPlayers", 1 ); + } +} \ No newline at end of file diff --git a/code/UI/MainMenu/FrontPage.razor b/code/UI/MainMenu/FrontPage.razor new file mode 100644 index 0000000..8d9d690 --- /dev/null +++ b/code/UI/MainMenu/FrontPage.razor @@ -0,0 +1,40 @@ +@using Sandbox; +@using System.Linq; +@using System.Threading.Tasks; +@using Sandbox.Menu; +@using Sandbox.UI; +@namespace LuckerGame.UI.MainMenu + + +
+ @Game.Menu.Package.Title +
+ +
+ @if (Game.InGame) + { + Leave + } + else + { + Play + + Lobbies + + @if ( Game.Menu.Package.SupportsSavedGames && Game.Menu.SavedGames.Any()) + { + Load Save + } + } + + Quit +
+
+ +@code +{ + void LeaveGame() + { + Game.Menu.LeaveServer( "Leaving" ); + } +} \ No newline at end of file diff --git a/code/UI/MainMenu/LoadingScreen.razor b/code/UI/MainMenu/LoadingScreen.razor new file mode 100644 index 0000000..2ec5690 --- /dev/null +++ b/code/UI/MainMenu/LoadingScreen.razor @@ -0,0 +1,31 @@ +@using Sandbox; +@using Sandbox.UI; +@using System.Linq; +@using System.Threading.Tasks; +@using Sandbox.Menu; + +@inherits RootPanel +@implements Sandbox.Menu.ILoadingScreenPanel +@attribute [StyleSheet] +@namespace LuckerGame.UI.MainMenu + + +
+ +
+ + + + +@code +{ + public LoadingProgress Progress; + + public void OnLoadingProgress( LoadingProgress progress ) + { + Progress = progress; + StateHasChanged(); + } +} diff --git a/code/UI/MainMenu/LoadingScreen.razor.scss b/code/UI/MainMenu/LoadingScreen.razor.scss new file mode 100644 index 0000000..6c5893a --- /dev/null +++ b/code/UI/MainMenu/LoadingScreen.razor.scss @@ -0,0 +1,50 @@ + +LoadingScreen +{ + background-color: #262934; + padding: 128px 128px; + opacity: 1; + flex-direction: column; + font-size: 25px; + width: 100%; + height: 100%; + position: absolute; + transition: all 0.3s ease-out; + color: rgba( white, 0.8 ); + + .background + { + position: absolute; + width: 100%; + height: 100%; + background-image: url( https://files.facepunch.com/tony/1b1311b1/boxes.webm ); + opacity: 0.2; + background-size: contain; + filter: blur( 20px ); + mask: linear-gradient( 45deg, white, white, black ); + mask-scope: filter; + } + + &:intro + { + opacity: 0; + transform: scaleX( 1.1 ); + } + + .game-title + { + font-family: Roboto; + font-weight: 700; + font-size: 70px; + color: rgba( white, 1 ); + } + + .controls + { + flex-direction: column; + gap: 50px; + align-items: flex-start; + font-family: Roboto; + text-transform: uppercase; + } +} diff --git a/code/UI/MainMenu/LobbyBrowser.razor b/code/UI/MainMenu/LobbyBrowser.razor new file mode 100644 index 0000000..fae7358 --- /dev/null +++ b/code/UI/MainMenu/LobbyBrowser.razor @@ -0,0 +1,66 @@ +@using Sandbox; +@using System; +@using System.Linq; +@using System.Threading.Tasks; +@using Sandbox.Menu; +@using Sandbox.UI; +@namespace LuckerGame.UI.MainMenu +@inherits Panel + + + + +
+
+ + refresh +
+ + + + + + +@code +{ + public async void CreateLobbyAsync() + { + await Game.Menu.CreateLobbyAsync( 64, "game", true ); + Game.Menu.Lobby.Map = "facepunch.square"; + this.Navigate( "/lobby/active" ); + } + + public async void JoinLobby( ILobby lobby ) + { + if ( lobby == null ) return; + + // don't exist in two lobbies at once + Game.Menu.Lobby?.Leave(); + + await lobby.JoinAsync(); + this.Navigate( "/lobby/active" ); + } + + public async void Refresh() + { + await Game.Menu.QueryLobbiesAsync( null, 1 ); + + StateHasChanged(); + } + + protected override int BuildHash() + { + return HashCode.Combine( Game.Menu.Lobbies.Count() ); + } +} \ No newline at end of file diff --git a/code/UI/MainMenu/MainMenu.razor b/code/UI/MainMenu/MainMenu.razor new file mode 100644 index 0000000..1b9f997 --- /dev/null +++ b/code/UI/MainMenu/MainMenu.razor @@ -0,0 +1,40 @@ +@using System; +@using Sandbox; +@using Sandbox.UI; + +@inherits Sandbox.UI.NavHostPanel +@implements Sandbox.Menu.IGameMenuPanel +@attribute [StyleSheet] +@namespace LuckerGame.UI.MainMenu + + +
+