Skip to content

Commit

Permalink
Add per player difficulty and modifier options
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-r-elp committed Aug 2, 2024
1 parent 4c11e11 commit 0d6c8f4
Show file tree
Hide file tree
Showing 10 changed files with 478 additions and 0 deletions.
3 changes: 3 additions & 0 deletions assets/MpDifficultySelector.bsml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<vertical id='segmentVert' bg='panel-top' anchor-pos-y='-25' pref-width='60' min-height='10' vertical-fit='MinSize' pad='2' active='false'>
<text-segments id='difficultyControl' select-cell='SetSelectedDifficulty' />
</vertical>
7 changes: 7 additions & 0 deletions assets/MpPerPlayerToggles.bsml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<horizontal>
<vertical min-width='45' horizontal-fit='MinSize'> </vertical>
<vertical min-width='45' horizontal-fit='MinSize'>
<toggle-setting id='ppdt' value='per-player-diffs' apply-on-change='true' text='Per Player Difficulty' hover-hint='Allows each player to select their own difficulty!' bind-value='true'/>
<toggle-setting id='ppmt' value='per-player-modifiers' apply-on-change='true' text='Per Player Modifiers' hover-hint="Allows each player to select their own modifiers!" bind-value='true'/>
</vertical>
</horizontal>
81 changes: 81 additions & 0 deletions include/UI/MpPerPlayerUI.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#pragma once

#include "custom-types/shared/macros.hpp"
#include "lapiz/shared/macros.hpp"

#include "GlobalNamespace/GameServerLobbyFlowCoordinator.hpp"
#include "GlobalNamespace/BeatmapLevelsModel.hpp"


#include "System/Object.hpp"
#include "System/IDisposable.hpp"
#include "Zenject/IInitializable.hpp"

#include "UnityEngine/UI/VerticalLayoutGroup.hpp"
#include "UnityEngine/CanvasGroup.hpp"

#include "HMUI/TextSegmentedControl.hpp"

#include "bsml/shared/BSML/Components/Settings/ToggleSetting.hpp"

#include "Beatmaps/Providers/MpBeatmapLevelProvider.hpp"
#include "Networking/MpPacketSerializer.hpp"

#include "Players/Packets/MpPerPlayerPacket.hpp"
#include "Players/Packets/GetMpPerPlayerPacket.hpp"

DECLARE_CLASS_CODEGEN_INTERFACES(MultiplayerCore::UI, MpPerPlayerUI, System::Object, std::vector<Il2CppClass*>({ classof(::Zenject::IInitializable*), classof(::System::IDisposable*)}),

DECLARE_INSTANCE_FIELD(GlobalNamespace::GameServerLobbyFlowCoordinator*, _gameServerLobbyFlowCoordinator);
DECLARE_INSTANCE_FIELD(GlobalNamespace::LobbySetupViewController*, _lobbyViewController);
DECLARE_INSTANCE_FIELD(GlobalNamespace::ILobbyGameStateController*, _gameStateController);
DECLARE_INSTANCE_FIELD(GlobalNamespace::BeatmapLevelsModel*, _beatmapLevelsModel);
DECLARE_INSTANCE_FIELD(GlobalNamespace::IMultiplayerSessionManager*, _multiplayerSessionManager);
DECLARE_INSTANCE_FIELD(MultiplayerCore::Beatmaps::Providers::MpBeatmapLevelProvider*, _beatmapLevelProvider);
DECLARE_INSTANCE_FIELD(MultiplayerCore::Networking::MpPacketSerializer*, _packetSerializer);

// Values
DECLARE_INSTANCE_FIELD(GlobalNamespace::BeatmapKey, _currentBeatmapKey);
DECLARE_INSTANCE_FIELD(ListW<StringW>, _allowedDifficulties);

DECLARE_OVERRIDE_METHOD_MATCH(void, Initialize, &::Zenject::IInitializable::Initialize);
DECLARE_OVERRIDE_METHOD_MATCH(void, Dispose, &::System::IDisposable::Dispose);

DECLARE_INSTANCE_METHOD(void, DidActivate, bool firstActivation, bool addedToHierarchy, bool screenSystemEnabling);
DECLARE_INSTANCE_METHOD(void, DidDeactivate, bool removedFromHierarchy, bool screenSystemDisabling);
DECLARE_INSTANCE_METHOD(void, SetLobbyState, GlobalNamespace::MultiplayerLobbyState state);
DECLARE_INSTANCE_METHOD(void, LocalSelectedBeatmap, GlobalNamespace::LevelSelectionFlowCoordinator::State* state);
DECLARE_INSTANCE_METHOD(void, UpdateDifficultyListWithBeatmapKey, GlobalNamespace::BeatmapKey beatmapKey);
DECLARE_INSTANCE_METHOD(void, UpdateDifficultyList, ListW<StringW> difficulties);
DECLARE_INSTANCE_METHOD(void, ClearLocalSelectedBeatmap);
DECLARE_INSTANCE_METHOD(void, HandleMpPerPlayerPacket, MultiplayerCore::Players::Packets::MpPerPlayerPacket* packet, GlobalNamespace::IConnectedPlayer* player);
DECLARE_INSTANCE_METHOD(void, HandleGetMpPerPlayerPacket, MultiplayerCore::Players::Packets::GetMpPerPlayerPacket* packet, GlobalNamespace::IConnectedPlayer* player);
DECLARE_INSTANCE_METHOD(void, UpdateButtonsEnabled);

DECLARE_INSTANCE_METHOD(void, SetSelectedDifficulty, HMUI::SegmentedControl* control, int index);

DECLARE_CTOR(ctor,
GlobalNamespace::GameServerLobbyFlowCoordinator* gameServerLobbyFlowCoordinator,
GlobalNamespace::BeatmapLevelsModel* beatmapLevelsModel,
GlobalNamespace::IMultiplayerSessionManager* sessionManager,
MultiplayerCore::Beatmaps::Providers::MpBeatmapLevelProvider* beatmapLevelProvider,
MultiplayerCore::Networking::MpPacketSerializer* packetSerializer
);

// UI Elements
DECLARE_INSTANCE_FIELD(UnityEngine::UI::VerticalLayoutGroup*, segmentVert);
DECLARE_INSTANCE_FIELD(HMUI::TextSegmentedControl*, difficultyControl);
DECLARE_INSTANCE_FIELD(BSML::ToggleSetting*, ppdt);
DECLARE_INSTANCE_FIELD(BSML::ToggleSetting*, ppmt);
DECLARE_INSTANCE_FIELD(UnityEngine::CanvasGroup*, _difficultyCanvasGroup);

// Event Listeners
// Delegates
DECLARE_INSTANCE_FIELD(HMUI::ViewController::DidActivateDelegate*, didActivateDelegate);
DECLARE_INSTANCE_FIELD(HMUI::ViewController::DidDeactivateDelegate*, didDeactivateDelegate);
DECLARE_INSTANCE_FIELD(System::Action_1<GlobalNamespace::MultiplayerLobbyState>*, setLobbyStateDelegate);
DECLARE_INSTANCE_FIELD(System::Action_1<GlobalNamespace::LevelSelectionFlowCoordinator::State*>*, localSelectedBeatmapDelegate);
DECLARE_INSTANCE_FIELD(System::Action_1<GlobalNamespace::BeatmapKey>*, updateDifficultyListDelegate);
DECLARE_INSTANCE_FIELD(System::Action*, clearLocalSelectedBeatmapDelegate);
DECLARE_INSTANCE_FIELD(System::Action*, updateButtonsEnabledDelegate);
)
2 changes: 2 additions & 0 deletions include/assets.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ DECLARE_FILE(_binary_LoadingIndicator_bsml, Assets, LoadingIndicator_bsml);
DECLARE_FILE(_binary_MissingReq_png, Assets, MissingReq_png);
DECLARE_FILE(_binary_MissingSprite_png, Assets, MissingSprite_png);
DECLARE_FILE(_binary_MissingSuggestion_png, Assets, MissingSuggestion_png);
DECLARE_FILE(_binary_MpDifficultySelector_bsml, Assets, MpDifficultySelector_bsml);
DECLARE_FILE(_binary_MpPerPlayerToggles_bsml, Assets, MpPerPlayerToggles_bsml);
DECLARE_FILE(_binary_RequirementsButton_bsml, Assets, RequirementsButton_bsml);
DECLARE_FILE(_binary_RequirementsUI_bsml, Assets, RequirementsUI_bsml);
DECLARE_FILE(_binary_Warning_png, Assets, Warning_png);
7 changes: 7 additions & 0 deletions shared/Players/Packets/GetMpPerPlayerPacket.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include "../../Networking/Abstractions/MpPacket.hpp"

#include "custom-types/shared/macros.hpp"

DECLARE_CLASS_CUSTOM(MultiplayerCore::Players::Packets, GetMpPerPlayerPacket, MultiplayerCore::Networking::Abstractions::MpPacket,
DECLARE_DEFAULT_CTOR();
)
13 changes: 13 additions & 0 deletions shared/Players/Packets/MpPerPlayerPacket.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "../../Networking/Abstractions/MpPacket.hpp"

#include "custom-types/shared/macros.hpp"

DECLARE_CLASS_CUSTOM(MultiplayerCore::Players::Packets, MpPerPlayerPacket, MultiplayerCore::Networking::Abstractions::MpPacket,
DECLARE_INSTANCE_FIELD(bool, PPDEnabled);
DECLARE_INSTANCE_FIELD(bool, PPMEnabled);

DECLARE_OVERRIDE_METHOD_MATCH(void, Serialize, &LiteNetLib::Utils::INetSerializable::Serialize, LiteNetLib::Utils::NetDataWriter* writer);
DECLARE_OVERRIDE_METHOD_MATCH(void, Deserialize, &LiteNetLib::Utils::INetSerializable::Deserialize, LiteNetLib::Utils::NetDataReader* reader);
public:
DECLARE_DEFAULT_CTOR();
)
2 changes: 2 additions & 0 deletions src/Installers/MpMenuInstaller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "UI/MpColorsUI.hpp"
#include "UI/MpLoadingIndicator.hpp"
#include "UI/MpRequirementsUI.hpp"
#include "UI/MpPerPlayerUI.hpp"
#include "Patchers/BeatmapSelectionViewPatcher.hpp"

#include "Zenject/DiContainer.hpp"
Expand All @@ -19,6 +20,7 @@ namespace MultiplayerCore::Installers {

container->BindInterfacesAndSelfTo<MpColorsUI*>()->AsSingle();
container->BindInterfacesAndSelfTo<MpRequirementsUI*>()->AsSingle();
container->BindInterfacesAndSelfTo<MpPerPlayerUI*>()->AsSingle();
container->BindInterfacesAndSelfTo<MpLoadingIndicator*>()->AsSingle();
container->BindInterfacesAndSelfTo<BeatmapSelectionViewPatcher*>()->AsSingle();
}
Expand Down
4 changes: 4 additions & 0 deletions src/Players/Packets/GetMpPerPlayerPacket.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#include "Players/Packets/GetMpPerPlayerPacket.hpp"

// This packet has no data to serialize
DEFINE_TYPE(MultiplayerCore::Players::Packets, GetMpPerPlayerPacket);
15 changes: 15 additions & 0 deletions src/Players/Packets/MpPerPlayerPacket.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "Players/Packets/MpPerPlayerPacket.hpp"

DEFINE_TYPE(MultiplayerCore::Players::Packets, MpPerPlayerPacket);

namespace MultiplayerCore::Players::Packets {
void MpPerPlayerPacket::Serialize(LiteNetLib::Utils::NetDataWriter* writer) {
writer->Put(PPDEnabled);
writer->Put(PPMEnabled);
}

void MpPerPlayerPacket::Deserialize(LiteNetLib::Utils::NetDataReader* reader) {
PPDEnabled = reader->GetBool();
PPMEnabled = reader->GetBool();
}
}
Loading

0 comments on commit 0d6c8f4

Please sign in to comment.