You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
155 lines
5.8 KiB
155 lines
5.8 KiB
|
5 years ago
|
#include <fmt/format.h>
|
||
|
|
|
||
|
7 years ago
|
#include "DiabloUI/diabloui.h"
|
||
|
5 years ago
|
#include "stores.h"
|
||
|
4 years ago
|
#include "storm/storm_net.hpp"
|
||
|
5 years ago
|
#include "utils/language.h"
|
||
|
4 years ago
|
#include "utils/utf8.hpp"
|
||
|
7 years ago
|
|
||
|
5 years ago
|
namespace devilution {
|
||
|
7 years ago
|
|
||
|
5 years ago
|
int provider;
|
||
|
4 years ago
|
const char *ConnectionNames[] {
|
||
|
|
"ZeroTier",
|
||
|
|
N_("Client-Server (TCP)"),
|
||
|
|
N_("Loopback"),
|
||
|
|
};
|
||
|
|
|
||
|
5 years ago
|
namespace {
|
||
|
|
|
||
|
4 years ago
|
char selconn_MaxPlayers[64];
|
||
|
4 years ago
|
char selconn_Description[256];
|
||
|
7 years ago
|
char selconn_Gateway[129];
|
||
|
|
bool selconn_ReturnValue = false;
|
||
|
|
bool selconn_EndMenu = false;
|
||
|
5 years ago
|
GameData *selconn_GameData;
|
||
|
7 years ago
|
|
||
|
5 years ago
|
std::vector<std::unique_ptr<UiListItem>> vecConnItems;
|
||
|
|
std::vector<std::unique_ptr<UiItemBase>> vecSelConnDlg;
|
||
|
7 years ago
|
|
||
|
6 years ago
|
#define DESCRIPTION_WIDTH 205
|
||
|
|
|
||
|
5 years ago
|
void SelconnEsc();
|
||
|
|
void SelconnFocus(int value);
|
||
|
|
void SelconnSelect(int value);
|
||
|
5 years ago
|
|
||
|
5 years ago
|
void SelconnLoad()
|
||
|
6 years ago
|
{
|
||
|
4 years ago
|
LoadBackgroundArt("ui_art\\selconn");
|
||
|
6 years ago
|
|
||
|
7 years ago
|
#ifndef NONET
|
||
|
5 years ago
|
#ifndef DISABLE_ZERO_TIER
|
||
|
4 years ago
|
vecConnItems.push_back(std::make_unique<UiListItem>(ConnectionNames[SELCONN_ZT], SELCONN_ZT));
|
||
|
5 years ago
|
#endif
|
||
|
|
#ifndef DISABLE_TCP
|
||
|
4 years ago
|
vecConnItems.push_back(std::make_unique<UiListItem>(_(ConnectionNames[SELCONN_TCP]), SELCONN_TCP));
|
||
|
5 years ago
|
#endif
|
||
|
7 years ago
|
#endif
|
||
|
4 years ago
|
vecConnItems.push_back(std::make_unique<UiListItem>(_(ConnectionNames[SELCONN_LOOPBACK]), SELCONN_LOOPBACK));
|
||
|
7 years ago
|
|
||
|
6 years ago
|
UiAddBackground(&vecSelConnDlg);
|
||
|
|
UiAddLogo(&vecSelConnDlg);
|
||
|
|
|
||
|
4 years ago
|
const Point uiPosition = GetUIRectangle().position;
|
||
|
|
|
||
|
|
SDL_Rect rect1 = { (Sint16)(uiPosition.x + 24), (Sint16)(Sint16)(uiPosition.y + 161), 590, 35 };
|
||
|
4 years ago
|
vecSelConnDlg.push_back(std::make_unique<UiArtText>(_("Multi Player Game").data(), rect1, UiFlags::AlignCenter | UiFlags::FontSize30 | UiFlags::ColorUiSilver, 3));
|
||
|
6 years ago
|
|
||
|
4 years ago
|
SDL_Rect rect2 = { (Sint16)(uiPosition.x + 35), (Sint16)(uiPosition.y + 218), DESCRIPTION_WIDTH, 21 };
|
||
|
5 years ago
|
vecSelConnDlg.push_back(std::make_unique<UiArtText>(selconn_MaxPlayers, rect2, UiFlags::FontSize12 | UiFlags::ColorUiSilverDark));
|
||
|
6 years ago
|
|
||
|
4 years ago
|
SDL_Rect rect3 = { (Sint16)(uiPosition.x + 35), (Sint16)(uiPosition.y + 256), DESCRIPTION_WIDTH, 21 };
|
||
|
4 years ago
|
vecSelConnDlg.push_back(std::make_unique<UiArtText>(_("Requirements:").data(), rect3, UiFlags::FontSize12 | UiFlags::ColorUiSilverDark));
|
||
|
6 years ago
|
|
||
|
4 years ago
|
SDL_Rect rect4 = { (Sint16)(uiPosition.x + 35), (Sint16)(uiPosition.y + 275), DESCRIPTION_WIDTH, 66 };
|
||
|
5 years ago
|
vecSelConnDlg.push_back(std::make_unique<UiArtText>(selconn_Description, rect4, UiFlags::FontSize12 | UiFlags::ColorUiSilverDark, 1, 16));
|
||
|
6 years ago
|
|
||
|
4 years ago
|
SDL_Rect rect5 = { (Sint16)(uiPosition.x + 30), (Sint16)(uiPosition.y + 356), 220, 31 };
|
||
|
4 years ago
|
vecSelConnDlg.push_back(std::make_unique<UiArtText>(_("no gateway needed").data(), rect5, UiFlags::AlignCenter | UiFlags::FontSize24 | UiFlags::ColorUiSilver, 0));
|
||
|
6 years ago
|
|
||
|
4 years ago
|
SDL_Rect rect6 = { (Sint16)(uiPosition.x + 35), (Sint16)(uiPosition.y + 393), DESCRIPTION_WIDTH, 21 };
|
||
|
5 years ago
|
vecSelConnDlg.push_back(std::make_unique<UiArtText>(selconn_Gateway, rect6, UiFlags::AlignCenter | UiFlags::FontSize12 | UiFlags::ColorUiSilverDark));
|
||
|
6 years ago
|
|
||
|
4 years ago
|
SDL_Rect rect7 = { (Sint16)(uiPosition.x + 300), (Sint16)(uiPosition.y + 211), 295, 33 };
|
||
|
4 years ago
|
vecSelConnDlg.push_back(std::make_unique<UiArtText>(_("Select Connection").data(), rect7, UiFlags::AlignCenter | UiFlags::FontSize30 | UiFlags::ColorUiSilver, 3));
|
||
|
6 years ago
|
|
||
|
4 years ago
|
SDL_Rect rect8 = { (Sint16)(uiPosition.x + 16), (Sint16)(uiPosition.y + 427), 250, 35 };
|
||
|
5 years ago
|
vecSelConnDlg.push_back(std::make_unique<UiArtTextButton>(_("Change Gateway"), nullptr, rect8, UiFlags::AlignCenter | UiFlags::VerticalCenter | UiFlags::FontSize30 | UiFlags::ColorUiGold | UiFlags::ElementHidden));
|
||
|
6 years ago
|
|
||
|
4 years ago
|
vecSelConnDlg.push_back(std::make_unique<UiList>(vecConnItems, vecConnItems.size(), uiPosition.x + 305, (uiPosition.y + 256), 285, 26, UiFlags::AlignCenter | UiFlags::FontSize12 | UiFlags::VerticalCenter | UiFlags::ColorUiGoldDark));
|
||
|
6 years ago
|
|
||
|
4 years ago
|
SDL_Rect rect9 = { (Sint16)(uiPosition.x + 299), (Sint16)(uiPosition.y + 427), 140, 35 };
|
||
|
5 years ago
|
vecSelConnDlg.push_back(std::make_unique<UiArtTextButton>(_("OK"), &UiFocusNavigationSelect, rect9, UiFlags::AlignCenter | UiFlags::VerticalCenter | UiFlags::FontSize30 | UiFlags::ColorUiGold));
|
||
|
6 years ago
|
|
||
|
4 years ago
|
SDL_Rect rect10 = { (Sint16)(uiPosition.x + 454), (Sint16)(uiPosition.y + 427), 140, 35 };
|
||
|
5 years ago
|
vecSelConnDlg.push_back(std::make_unique<UiArtTextButton>(_("Cancel"), &UiFocusNavigationEsc, rect10, UiFlags::AlignCenter | UiFlags::VerticalCenter | UiFlags::FontSize30 | UiFlags::ColorUiGold));
|
||
|
6 years ago
|
|
||
|
4 years ago
|
UiInitList(SelconnFocus, SelconnSelect, SelconnEsc, vecSelConnDlg, true);
|
||
|
7 years ago
|
}
|
||
|
|
|
||
|
5 years ago
|
void SelconnFree()
|
||
|
7 years ago
|
{
|
||
|
4 years ago
|
ArtBackground = std::nullopt;
|
||
|
6 years ago
|
|
||
|
|
vecConnItems.clear();
|
||
|
|
|
||
|
|
vecSelConnDlg.clear();
|
||
|
7 years ago
|
}
|
||
|
|
|
||
|
5 years ago
|
void SelconnEsc()
|
||
|
7 years ago
|
{
|
||
|
|
selconn_ReturnValue = false;
|
||
|
|
selconn_EndMenu = true;
|
||
|
|
}
|
||
|
|
|
||
|
5 years ago
|
void SelconnFocus(int value)
|
||
|
7 years ago
|
{
|
||
|
|
int players = MAX_PLRS;
|
||
|
6 years ago
|
switch (vecConnItems[value]->m_value) {
|
||
|
7 years ago
|
case SELCONN_TCP:
|
||
|
4 years ago
|
CopyUtf8(selconn_Description, _("All computers must be connected to a TCP-compatible network."), sizeof(selconn_Description));
|
||
|
7 years ago
|
players = MAX_PLRS;
|
||
|
|
break;
|
||
|
5 years ago
|
case SELCONN_ZT:
|
||
|
4 years ago
|
CopyUtf8(selconn_Description, _("All computers must be connected to the internet."), sizeof(selconn_Description));
|
||
|
7 years ago
|
players = MAX_PLRS;
|
||
|
|
break;
|
||
|
7 years ago
|
case SELCONN_LOOPBACK:
|
||
|
4 years ago
|
CopyUtf8(selconn_Description, _("Play by yourself with no network exposure."), sizeof(selconn_Description));
|
||
|
7 years ago
|
players = 1;
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
|
||
|
4 years ago
|
CopyUtf8(selconn_MaxPlayers, fmt::format(fmt::runtime(_("Players Supported: {:d}")), players), sizeof(selconn_MaxPlayers));
|
||
|
4 years ago
|
CopyUtf8(selconn_Description, WordWrapString(selconn_Description, DESCRIPTION_WIDTH), sizeof(selconn_Description));
|
||
|
7 years ago
|
}
|
||
|
|
|
||
|
5 years ago
|
void SelconnSelect(int value)
|
||
|
7 years ago
|
{
|
||
|
6 years ago
|
provider = vecConnItems[value]->m_value;
|
||
|
7 years ago
|
|
||
|
5 years ago
|
SelconnFree();
|
||
|
5 years ago
|
selconn_EndMenu = SNetInitializeProvider(provider, selconn_GameData);
|
||
|
5 years ago
|
SelconnLoad();
|
||
|
7 years ago
|
}
|
||
|
|
|
||
|
5 years ago
|
} // namespace
|
||
|
|
|
||
|
5 years ago
|
bool UiSelectProvider(GameData *gameData)
|
||
|
7 years ago
|
{
|
||
|
5 years ago
|
selconn_GameData = gameData;
|
||
|
5 years ago
|
SelconnLoad();
|
||
|
7 years ago
|
|
||
|
|
selconn_ReturnValue = true;
|
||
|
|
selconn_EndMenu = false;
|
||
|
|
while (!selconn_EndMenu) {
|
||
|
6 years ago
|
UiClearScreen();
|
||
|
7 years ago
|
UiPollAndRender();
|
||
|
7 years ago
|
}
|
||
|
5 years ago
|
SelconnFree();
|
||
|
7 years ago
|
|
||
|
|
return selconn_ReturnValue;
|
||
|
|
}
|
||
|
|
|
||
|
5 years ago
|
} // namespace devilution
|