mirror of
https://git.neolegacy.dev/neoStudiosLCE/neoLegacy.git
synced 2026-12-02 22:18:09 +01:00
270 lines
8.2 KiB
C++
270 lines
8.2 KiB
C++
#include "stdafx.h"
|
|
#include "UI.h"
|
|
#include "UIScene_FriendMenu.h"
|
|
#include "UICustomStrings.h"
|
|
#include "SocialOnlineService.h"
|
|
#include "../../Minecraft.h"
|
|
|
|
UIScene_FriendMenu::UIScene_FriendMenu(int iPad, void *initData, UILayer *parentLayer) : UIScene(iPad, parentLayer)
|
|
{
|
|
initialiseMovie();
|
|
if (initData != nullptr)
|
|
m_data = *static_cast<FriendMenuInitData *>(initData);
|
|
else
|
|
{
|
|
m_data.friendOnline = false;
|
|
m_data.friendInWorld = false;
|
|
m_data.friendIndex = -1;
|
|
m_data.onRemove = nullptr;
|
|
m_data.onBlock = nullptr;
|
|
m_data.onInvite = nullptr;
|
|
m_data.param = nullptr;
|
|
}
|
|
m_bNeedsPopulate = true;
|
|
m_bPendingBlock = false;
|
|
m_bPendingJoin = false;
|
|
m_joinData.selectedSession = &m_joinSession;
|
|
m_joinData.iPad = iPad;
|
|
#if defined(_WINDOWS64) || defined(__linux__)
|
|
m_joinData.serverIndex = -1;
|
|
#endif
|
|
if (!isLocalPlayerInGame())
|
|
SocialOnlineService::RefreshFriendGames();
|
|
doHorizontalResizeCheck();
|
|
}
|
|
|
|
wstring UIScene_FriendMenu::getMoviePath()
|
|
{
|
|
return L"MultilistMenu";
|
|
}
|
|
|
|
bool UIScene_FriendMenu::isLocalPlayerInGame()
|
|
{
|
|
Minecraft *pMinecraft = Minecraft::GetInstance();
|
|
return pMinecraft != nullptr && pMinecraft->level != nullptr;
|
|
}
|
|
|
|
void UIScene_FriendMenu::populateList()
|
|
{
|
|
bool alreadyRegistered = false;
|
|
for (size_t i = 0; i < m_controls.size(); ++i)
|
|
{
|
|
if (m_controls[i] == &m_multiList)
|
|
alreadyRegistered = true;
|
|
}
|
|
m_multiList.setupControl(this, m_rootPath, "MultiList");
|
|
if (!alreadyRegistered)
|
|
m_controls.push_back(&m_multiList);
|
|
m_multiList.clearList();
|
|
m_multiList.init(eControl_MultiList);
|
|
|
|
int firstId = eItem_RemoveFriend;
|
|
wstring header = m_data.name;
|
|
if (!m_data.status.empty())
|
|
header += L" - " + SocialOnlineService::StatusLabel(m_data.status);
|
|
m_multiList.AddNewLabel(header);
|
|
bool canJoin = false;
|
|
if (!isLocalPlayerInGame() && !m_data.onlineId.empty())
|
|
{
|
|
canJoin = isFriendHosting();
|
|
m_multiList.AddNewButton(L"Join Game", eItem_JoinGame);
|
|
if (canJoin)
|
|
firstId = eItem_JoinGame;
|
|
}
|
|
if (isLocalPlayerInGame() && m_data.onInvite != nullptr)
|
|
{
|
|
m_multiList.AddNewButton(L"Invite", eItem_Invite);
|
|
if (firstId == eItem_RemoveFriend)
|
|
firstId = eItem_Invite;
|
|
}
|
|
m_multiList.AddNewButton(L"Remove Friend", eItem_RemoveFriend);
|
|
if (m_data.onBlock != nullptr)
|
|
m_multiList.AddNewButton(L"Block", eItem_Block);
|
|
|
|
IggyName funcDoVert = registerFastName(L"DoVerticalResizeCheck");
|
|
IggyName funcHideDesc = registerFastName(L"HideDescription");
|
|
IggyDataValue result;
|
|
IggyPlayerCallMethodRS(getMovie(), &result, m_rootPath, funcDoVert, 0, nullptr);
|
|
doHorizontalResizeCheck();
|
|
IggyPlayerCallMethodRS(getMovie(), &result, m_rootPath, funcHideDesc, 0, nullptr);
|
|
|
|
if (!isLocalPlayerInGame() && !m_data.onlineId.empty())
|
|
m_multiList.EnableItem(eItem_JoinGame, canJoin);
|
|
m_multiList.HighlightItem(firstId);
|
|
}
|
|
|
|
bool UIScene_FriendMenu::isFriendHosting()
|
|
{
|
|
if (m_data.status == L"hosting")
|
|
return true;
|
|
return SocialOnlineService::FindFriendGame(_wcstoui64(m_data.onlineId.c_str(), nullptr, 16)) != nullptr;
|
|
}
|
|
|
|
void UIScene_FriendMenu::startJoin(bool skipBlockedCheck)
|
|
{
|
|
unsigned long long hostId = _wcstoui64(m_data.onlineId.c_str(), nullptr, 16);
|
|
if (hostId == 0)
|
|
return;
|
|
const SocialOnlineService::FriendGame *game = SocialOnlineService::FindFriendGame(hostId);
|
|
if (!skipBlockedCheck && game != nullptr && !game->blockedPlayers.empty())
|
|
{
|
|
wstring names;
|
|
for (size_t i = 0; i < game->blockedPlayers.size(); ++i)
|
|
names += (i > 0 ? L", " : L"") + game->blockedPlayers[i];
|
|
wstring body = (game->blockedPlayers.size() == 1 ? L"A player you blocked is in this world: " : L"Players you blocked are in this world: ") + names + L". Join anyway?";
|
|
UINT options[2];
|
|
options[0] = UICustomStrings::Get(L"Join Anyway");
|
|
options[1] = IDS_CONFIRM_CANCEL;
|
|
ui.RequestAlertMessage(UICustomStrings::Get(L"Blocked Player"), UICustomStrings::Get(body.c_str()), options, 2, m_iPad, &UIScene_FriendMenu::BlockedWarningCallback, this);
|
|
return;
|
|
}
|
|
|
|
wstring label = m_data.name;
|
|
if (game != nullptr && !game->worldName.empty())
|
|
label += L" - " + game->worldName;
|
|
if (m_joinSession.displayLabel != nullptr)
|
|
delete[] m_joinSession.displayLabel;
|
|
m_joinSession.displayLabel = new wchar_t[label.length() + 1];
|
|
wcscpy_s(m_joinSession.displayLabel, label.length() + 1, label.c_str());
|
|
m_joinSession.displayLabelLength = static_cast<unsigned char>(label.length() > 255 ? 255 : label.length());
|
|
m_joinSession.displayLabelViewableStartIndex = 0;
|
|
m_joinSession.data.netVersion = MINECRAFT_NET_VERSION;
|
|
m_joinSession.data.isReadyToJoin = true;
|
|
m_joinSession.data.isJoinable = true;
|
|
#if defined(_WINDOWS64) || defined(__linux__)
|
|
m_joinSession.data.hostIP[0] = 0;
|
|
m_joinSession.data.hostPort = 0;
|
|
m_joinSession.isFriendGame = true;
|
|
wcsncpy_s(m_joinSession.data.hostName, XUSER_NAME_SIZE, m_data.name.c_str(), _TRUNCATE);
|
|
m_joinSession.data.playerCount = static_cast<unsigned char>(game != nullptr ? game->playerCount : 1);
|
|
m_joinSession.data.maxPlayers = static_cast<unsigned char>(game != nullptr ? game->maxPlayers : 8);
|
|
#endif
|
|
*reinterpret_cast<uint64_t *>(&m_joinSession.sessionId) = static_cast<uint64_t>(hostId);
|
|
ui.NavigateToScene(m_iPad, eUIScene_JoinMenu, &m_joinData);
|
|
}
|
|
|
|
int UIScene_FriendMenu::BlockedWarningCallback(LPVOID lpParam, int iPad, const C4JStorage::EMessageResult result)
|
|
{
|
|
UIScene_FriendMenu *pClass = static_cast<UIScene_FriendMenu *>(lpParam);
|
|
if (result == C4JStorage::EMessage_ResultAccept)
|
|
pClass->m_bPendingJoin = true;
|
|
return 0;
|
|
}
|
|
|
|
void UIScene_FriendMenu::tick()
|
|
{
|
|
if (m_bPendingJoin)
|
|
{
|
|
m_bPendingJoin = false;
|
|
startJoin(true);
|
|
}
|
|
if (m_bPendingBlock)
|
|
{
|
|
m_bPendingBlock = false;
|
|
FriendMenuInitData data = m_data;
|
|
navigateBack();
|
|
if (data.onBlock != nullptr)
|
|
data.onBlock(data.param, data.friendIndex);
|
|
return;
|
|
}
|
|
if (m_bNeedsPopulate && hasMovie() && (bHasFocus || !m_bPopulatedOnce))
|
|
{
|
|
m_bNeedsPopulate = false;
|
|
m_bPopulatedOnce = true;
|
|
populateList();
|
|
}
|
|
UIScene::tick();
|
|
}
|
|
|
|
int UIScene_FriendMenu::BlockConfirmCallback(LPVOID lpParam, int iPad, const C4JStorage::EMessageResult result)
|
|
{
|
|
UIScene_FriendMenu *pClass = static_cast<UIScene_FriendMenu *>(lpParam);
|
|
if (result == C4JStorage::EMessage_ResultAccept)
|
|
pClass->m_bPendingBlock = true;
|
|
return 0;
|
|
}
|
|
|
|
void UIScene_FriendMenu::updateTooltips()
|
|
{
|
|
ui.SetTooltips(m_iPad, IDS_TOOLTIPS_SELECT, IDS_TOOLTIPS_BACK);
|
|
}
|
|
|
|
void UIScene_FriendMenu::updateComponents()
|
|
{
|
|
m_parentLayer->showComponent(m_iPad, eUIComponent_Panorama, !isLocalPlayerInGame());
|
|
m_parentLayer->showComponent(m_iPad, eUIComponent_Logo, false);
|
|
}
|
|
|
|
void UIScene_FriendMenu::handleReload()
|
|
{
|
|
UIScene::handleReload();
|
|
m_bNeedsPopulate = true;
|
|
}
|
|
|
|
void UIScene_FriendMenu::handleGainFocus(bool navBack)
|
|
{
|
|
UIScene::handleGainFocus(navBack);
|
|
if (navBack)
|
|
m_bNeedsPopulate = true;
|
|
}
|
|
|
|
void UIScene_FriendMenu::handleInput(int iPad, int key, bool repeat, bool pressed, bool released, bool &handled)
|
|
{
|
|
ui.AnimateKeyPress(iPad, key, repeat, pressed, released);
|
|
switch (key)
|
|
{
|
|
case ACTION_MENU_CANCEL:
|
|
if (pressed)
|
|
navigateBack();
|
|
handled = true;
|
|
break;
|
|
case ACTION_MENU_OK:
|
|
case ACTION_MENU_UP:
|
|
case ACTION_MENU_DOWN:
|
|
case ACTION_MENU_PAGEUP:
|
|
case ACTION_MENU_PAGEDOWN:
|
|
sendInputToMovie(key, repeat, pressed, released);
|
|
handled = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
void UIScene_FriendMenu::handlePress(F64 controlId, F64 childId)
|
|
{
|
|
ui.PlayUISFX(eSFX_Press);
|
|
switch (static_cast<int>(childId))
|
|
{
|
|
case eItem_JoinGame:
|
|
if (isFriendHosting())
|
|
startJoin(false);
|
|
else
|
|
ui.PlayUISFX(eSFX_CraftFail);
|
|
break;
|
|
case eItem_Invite:
|
|
{
|
|
FriendMenuInitData data = m_data;
|
|
navigateBack();
|
|
if (data.onInvite != nullptr)
|
|
data.onInvite(data.param, data.friendIndex);
|
|
}
|
|
break;
|
|
case eItem_RemoveFriend:
|
|
{
|
|
FriendMenuInitData data = m_data;
|
|
navigateBack();
|
|
if (data.onRemove != nullptr)
|
|
data.onRemove(data.param, data.friendIndex);
|
|
}
|
|
break;
|
|
case eItem_Block:
|
|
{
|
|
UINT options[2];
|
|
options[0] = UICustomStrings::Get(L"Block");
|
|
options[1] = IDS_CONFIRM_CANCEL;
|
|
wstring body = L"Block " + m_data.name + L"? They'll be removed from your friends and can't send you requests. You'll be warned before joining a world they're in. You can unblock them with /friend unblock in Discord.";
|
|
ui.RequestAlertMessage(UICustomStrings::Get(L"Block Player"), UICustomStrings::Get(body.c_str()), options, 2, m_iPad, &UIScene_FriendMenu::BlockConfirmCallback, this);
|
|
}
|
|
break;
|
|
}
|
|
}
|