Skip to content

Commit

Permalink
Tweak show disabled toggle when not party owner, fix toggle dissapear…
Browse files Browse the repository at this point in the history
…ing with ready/start button, remove some unnecessary checks
  • Loading branch information
michael-r-elp committed Aug 8, 2024
1 parent c1be5ad commit cf8b0ae
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 33 deletions.
3 changes: 2 additions & 1 deletion assets/MpPerPlayerToggles.bsml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<horizontal>
<horizontal id="ppth">
<vertical min-width='45' horizontal-fit='MinSize'> </vertical>
<vertical min-width='45' horizontal-fit='MinSize'> </vertical>
<vertical min-width='45' horizontal-fit='MinSize'>
<toggle-setting id='ppdt' value='PerPlayerDifficulty' apply-on-change='true' text='Per Player Difficulty' hover-hint='Allows each player to select their own difficulty!' bind-value='true'/>
Expand Down
2 changes: 2 additions & 0 deletions include/UI/MpPerPlayerUI.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "Zenject/IInitializable.hpp"

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

#include "HMUI/TextSegmentedControl.hpp"
Expand Down Expand Up @@ -68,6 +69,7 @@ DECLARE_CLASS_CODEGEN_INTERFACES(MultiplayerCore::UI, MpPerPlayerUI, System::Obj

// UI Elements
DECLARE_INSTANCE_FIELD(UnityEngine::UI::VerticalLayoutGroup*, segmentVert);
DECLARE_INSTANCE_FIELD(UnityEngine::UI::HorizontalLayoutGroup*, ppth);
DECLARE_INSTANCE_FIELD(HMUI::TextSegmentedControl*, difficultyControl);
DECLARE_INSTANCE_FIELD(BSML::ToggleSetting*, ppdt);
DECLARE_INSTANCE_FIELD(BSML::ToggleSetting*, ppmt);
Expand Down
63 changes: 31 additions & 32 deletions src/UI/MpPerPlayerUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ namespace MultiplayerCore::UI {
if (segmentVert) _difficultyCanvasGroup = segmentVert->gameObject->AddComponent<UnityEngine::CanvasGroup*>();

// PerPlayerToggles
BSML::parse_and_construct(Assets::MpPerPlayerToggles_bsml, _lobbyViewController->_startGameReadyButton->gameObject->transform, this);
BSML::parse_and_construct(Assets::MpPerPlayerToggles_bsml, _lobbyViewController->transform, this);

// Check if UI Elements were created
if (!segmentVert || !ppdt || !ppmt || !difficultyControl || !_difficultyCanvasGroup) {
if (!segmentVert || !ppdt || !ppmt || !difficultyControl || !_difficultyCanvasGroup || !ppth) {
CRITICAL("Failed to create UI Elements, UI will not function!");
return;
}
Expand Down Expand Up @@ -155,14 +155,13 @@ namespace MultiplayerCore::UI {
}
}

if (_lobbyViewController && _lobbyViewController->_isPartyOwner && ppdt && ppmt)
{
ppdt->gameObject->SetActive(true);
ppmt->gameObject->SetActive(true);
} else if (ppdt && ppmt) {
ppdt->gameObject->SetActive(false);
ppmt->gameObject->SetActive(false);
} else ERROR("Toggle Settings are null, returning...");
ppdt->set_interactable(_lobbyViewController->_isPartyOwner);
ppdt->text->alpha = _lobbyViewController->_isPartyOwner ? 1.0f : 0.25f;
ppmt->set_interactable(_lobbyViewController->_isPartyOwner);
ppmt->text->alpha = _lobbyViewController->_isPartyOwner ? 1.0f : 0.25f;

auto locposition = _lobbyViewController->_startGameReadyButton->gameObject->transform->localPosition;
ppth->gameObject->transform->localPosition = locposition;
}

void MpPerPlayerUI::DidDeactivate(bool removedFromHierarchy, bool screenSystemDisabling) {
Expand Down Expand Up @@ -199,44 +198,44 @@ namespace MultiplayerCore::UI {

void MpPerPlayerUI::UpdateButtonsEnabled() {
// UpdateButtonsEnabled
if (_lobbyViewController && _lobbyViewController->_isPartyOwner && ppdt && ppmt)
{
ppdt->gameObject->SetActive(true);
ppmt->gameObject->SetActive(true);

_multiplayerSessionManager->Send(Players::Packets::GetMpPerPlayerPacket::New_ctor());
} else if (ppdt && ppmt) {
ppdt->gameObject->SetActive(false);
ppmt->gameObject->SetActive(false);
} else ERROR("Toggle Settings are null, returning...");
ppdt->set_interactable(_lobbyViewController->_isPartyOwner);
ppdt->text->alpha = _lobbyViewController->_isPartyOwner ? 1.0f : 0.25f;
ppmt->set_interactable(_lobbyViewController->_isPartyOwner);
ppmt->text->alpha = _lobbyViewController->_isPartyOwner ? 1.0f : 0.25f;

// Request updated button states from server
_multiplayerSessionManager->Send(Players::Packets::GetMpPerPlayerPacket::New_ctor());
}

void MpPerPlayerUI::SetLobbyState(GlobalNamespace::MultiplayerLobbyState state) {
// SetLobbyState
DEBUG("Current Lobby State {}", Utils::EnumUtils::GetEnumName<GlobalNamespace::MultiplayerLobbyState>(state));
if (_difficultyCanvasGroup) {
_difficultyCanvasGroup->alpha = (state == GlobalNamespace::MultiplayerLobbyState::LobbySetup ||
state == GlobalNamespace::MultiplayerLobbyState::LobbyCountdown) ? 1.0f : 0.25f;
if (!_lobbyViewController || !_difficultyCanvasGroup || !difficultyControl || !ppdt || !ppmt) {
ERROR("UI was not properly initialized, returning...");
return;
}

_difficultyCanvasGroup->alpha = (state == GlobalNamespace::MultiplayerLobbyState::LobbySetup ||
state == GlobalNamespace::MultiplayerLobbyState::LobbyCountdown) ? 1.0f : 0.25f;

auto cells = ListW<::UnityW<::HMUI::TableCell>>(difficultyControl->cells);
for (auto& cell : cells) {
if (!cell) continue;
cell->set_interactable(state == GlobalNamespace::MultiplayerLobbyState::LobbySetup ||
state == GlobalNamespace::MultiplayerLobbyState::LobbyCountdown);
}

if (!_lobbyViewController)
return;

if (_lobbyViewController->_isPartyOwner)
{
if (ppdt && ppmt) {
ppdt->set_interactable(state == GlobalNamespace::MultiplayerLobbyState::LobbySetup ||
state == GlobalNamespace::MultiplayerLobbyState::LobbyCountdown);
ppmt->set_interactable(state == GlobalNamespace::MultiplayerLobbyState::LobbySetup ||
state == GlobalNamespace::MultiplayerLobbyState::LobbyCountdown);
}
ppdt->set_interactable(state == GlobalNamespace::MultiplayerLobbyState::LobbySetup ||
state == GlobalNamespace::MultiplayerLobbyState::LobbyCountdown);
ppmt->set_interactable(state == GlobalNamespace::MultiplayerLobbyState::LobbySetup ||
state == GlobalNamespace::MultiplayerLobbyState::LobbyCountdown);

ppdt->text->alpha = (state == GlobalNamespace::MultiplayerLobbyState::LobbySetup ||
state == GlobalNamespace::MultiplayerLobbyState::LobbyCountdown) ? 1.0f : 0.25f;
ppmt->text->alpha = (state == GlobalNamespace::MultiplayerLobbyState::LobbySetup ||
state == GlobalNamespace::MultiplayerLobbyState::LobbyCountdown) ? 1.0f : 0.25f;
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include "lapiz/shared/zenject/Zenjector.hpp"
#include "bsml/shared/BSML.hpp"

#define BEATSAVER_PLUSPLUS_AUTO_INIT

modloader::ModInfo modInfo{MOD_ID, VERSION, VERSION_LONG};

MPCORE_EXPORT_FUNC void setup(CModInfo* info) {
Expand Down

0 comments on commit cf8b0ae

Please sign in to comment.