2011-11-17 21:17:17 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
|
|
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** @file bootstrap_gui.cpp Barely used user interface for bootstrapping OpenTTD, i.e. downloading the required content. */
|
|
|
|
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "base_media_base.h"
|
|
|
|
#include "blitter/factory.hpp"
|
2023-04-19 20:47:36 +00:00
|
|
|
#include "error_func.h"
|
2011-11-17 21:29:15 +00:00
|
|
|
|
2021-02-13 21:51:18 +00:00
|
|
|
#if defined(WITH_FREETYPE) || defined(WITH_UNISCRIBE) || defined(WITH_COCOA)
|
2011-11-17 21:29:15 +00:00
|
|
|
|
2011-11-17 21:17:17 +00:00
|
|
|
#include "core/geometry_func.hpp"
|
2021-03-13 11:26:06 +00:00
|
|
|
#include "error.h"
|
2011-11-17 21:17:17 +00:00
|
|
|
#include "fontcache.h"
|
|
|
|
#include "gfx_func.h"
|
|
|
|
#include "network/network.h"
|
|
|
|
#include "network/network_content_gui.h"
|
|
|
|
#include "openttd.h"
|
|
|
|
#include "strings_func.h"
|
|
|
|
#include "video/video_driver.hpp"
|
|
|
|
#include "window_func.h"
|
|
|
|
|
2011-12-15 22:22:55 +00:00
|
|
|
#include "widgets/bootstrap_widget.h"
|
|
|
|
|
2011-11-17 21:17:17 +00:00
|
|
|
#include "table/strings.h"
|
|
|
|
|
2014-04-23 20:13:33 +00:00
|
|
|
#include "safeguards.h"
|
|
|
|
|
2011-11-17 21:17:17 +00:00
|
|
|
/** Widgets for the background window to prevent smearing. */
|
2024-01-15 22:49:24 +00:00
|
|
|
static constexpr NWidgetPart _background_widgets[] = {
|
2011-12-19 20:46:17 +00:00
|
|
|
NWidget(WWT_PANEL, COLOUR_DARK_BLUE, WID_BB_BACKGROUND), SetResize(1, 1),
|
2023-11-03 08:17:26 +00:00
|
|
|
EndContainer(),
|
2011-11-17 21:17:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Window description for the background window to prevent smearing.
|
|
|
|
*/
|
2023-11-02 19:33:01 +00:00
|
|
|
static WindowDesc _background_desc(__FILE__, __LINE__,
|
2019-04-10 21:07:06 +00:00
|
|
|
WDP_MANUAL, nullptr, 0, 0,
|
2011-11-17 21:17:17 +00:00
|
|
|
WC_BOOTSTRAP, WC_NONE,
|
2023-06-14 16:24:14 +00:00
|
|
|
WDF_NO_CLOSE,
|
2023-09-03 20:54:13 +00:00
|
|
|
std::begin(_background_widgets), std::end(_background_widgets)
|
2011-11-17 21:17:17 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
/** The background for the game. */
|
|
|
|
class BootstrapBackground : public Window {
|
|
|
|
public:
|
2013-05-26 19:23:42 +00:00
|
|
|
BootstrapBackground() : Window(&_background_desc)
|
2011-11-17 21:17:17 +00:00
|
|
|
{
|
2013-05-26 19:23:42 +00:00
|
|
|
this->InitNested(0);
|
2011-12-15 19:54:23 +00:00
|
|
|
CLRBITS(this->flags, WF_WHITE_BORDER);
|
2011-11-17 21:17:17 +00:00
|
|
|
ResizeWindow(this, _screen.width, _screen.height);
|
|
|
|
}
|
|
|
|
|
2023-12-29 19:11:59 +00:00
|
|
|
void DrawWidget(const Rect &r, WidgetID) const override
|
2011-11-17 21:17:17 +00:00
|
|
|
{
|
|
|
|
GfxFillRect(r.left, r.top, r.right, r.bottom, 4, FILLRECT_OPAQUE);
|
|
|
|
GfxFillRect(r.left, r.top, r.right, r.bottom, 0, FILLRECT_CHECKER);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-03-13 11:26:06 +00:00
|
|
|
/** Nested widgets for the error window. */
|
2024-01-15 22:49:24 +00:00
|
|
|
static constexpr NWidgetPart _nested_bootstrap_errmsg_widgets[] = {
|
2021-03-13 11:26:06 +00:00
|
|
|
NWidget(NWID_HORIZONTAL),
|
|
|
|
NWidget(WWT_CAPTION, COLOUR_GREY, WID_BEM_CAPTION), SetDataTip(STR_MISSING_GRAPHICS_ERROR_TITLE, STR_NULL),
|
|
|
|
EndContainer(),
|
2023-10-25 21:12:39 +00:00
|
|
|
NWidget(WWT_PANEL, COLOUR_GREY, WID_BEM_MESSAGE), EndContainer(),
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_BEM_QUIT), SetDataTip(STR_MISSING_GRAPHICS_ERROR_QUIT, STR_NULL), SetFill(1, 0),
|
2021-03-13 11:26:06 +00:00
|
|
|
EndContainer(),
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Window description for the error window. */
|
2023-11-02 19:33:01 +00:00
|
|
|
static WindowDesc _bootstrap_errmsg_desc(__FILE__, __LINE__,
|
2021-03-13 11:26:06 +00:00
|
|
|
WDP_CENTER, nullptr, 0, 0,
|
|
|
|
WC_BOOTSTRAP, WC_NONE,
|
2023-06-14 16:24:14 +00:00
|
|
|
WDF_MODAL | WDF_NO_CLOSE,
|
2023-09-03 20:54:13 +00:00
|
|
|
std::begin(_nested_bootstrap_errmsg_widgets), std::end(_nested_bootstrap_errmsg_widgets)
|
2021-03-13 11:26:06 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
/** The window for a failed bootstrap. */
|
|
|
|
class BootstrapErrorWindow : public Window {
|
|
|
|
public:
|
|
|
|
BootstrapErrorWindow() : Window(&_bootstrap_errmsg_desc)
|
|
|
|
{
|
|
|
|
this->InitNested(1);
|
|
|
|
}
|
|
|
|
|
2023-10-13 11:59:15 +00:00
|
|
|
void Close([[maybe_unused]] int data = 0) override
|
2021-03-13 11:26:06 +00:00
|
|
|
{
|
|
|
|
_exit_game = true;
|
2021-05-15 21:12:25 +00:00
|
|
|
this->Window::Close();
|
2021-03-13 11:26:06 +00:00
|
|
|
}
|
|
|
|
|
2023-12-29 19:11:59 +00:00
|
|
|
void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override
|
2021-03-13 11:26:06 +00:00
|
|
|
{
|
|
|
|
if (widget == WID_BEM_MESSAGE) {
|
|
|
|
*size = GetStringBoundingBox(STR_MISSING_GRAPHICS_ERROR);
|
2023-05-14 15:32:45 +00:00
|
|
|
size->width += WidgetDimensions::scaled.frametext.Horizontal();
|
|
|
|
size->height += WidgetDimensions::scaled.frametext.Vertical();
|
2021-03-13 11:26:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-29 19:11:59 +00:00
|
|
|
void DrawWidget(const Rect &r, WidgetID widget) const override
|
2021-03-13 11:26:06 +00:00
|
|
|
{
|
|
|
|
if (widget == WID_BEM_MESSAGE) {
|
2022-09-23 08:36:22 +00:00
|
|
|
DrawStringMultiLine(r.Shrink(WidgetDimensions::scaled.frametext), STR_MISSING_GRAPHICS_ERROR, TC_FROMSTRING, SA_CENTER);
|
2021-03-13 11:26:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-29 19:11:59 +00:00
|
|
|
void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
|
2021-03-13 11:26:06 +00:00
|
|
|
{
|
|
|
|
if (widget == WID_BEM_QUIT) {
|
|
|
|
_exit_game = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-11-17 21:17:17 +00:00
|
|
|
/** Nested widgets for the download window. */
|
2024-01-15 22:49:24 +00:00
|
|
|
static constexpr NWidgetPart _nested_bootstrap_download_status_window_widgets[] = {
|
2011-11-17 21:17:17 +00:00
|
|
|
NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_CONTENT_DOWNLOAD_TITLE, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
|
2022-11-04 12:32:59 +00:00
|
|
|
NWidget(WWT_PANEL, COLOUR_GREY),
|
|
|
|
NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_wide, 0), SetPadding(WidgetDimensions::unscaled.modalpopup),
|
|
|
|
NWidget(WWT_EMPTY, INVALID_COLOUR, WID_NCDS_PROGRESS_BAR), SetFill(1, 0),
|
|
|
|
NWidget(WWT_EMPTY, INVALID_COLOUR, WID_NCDS_PROGRESS_TEXT), SetFill(1, 0), SetMinimalSize(350, 0),
|
|
|
|
EndContainer(),
|
2011-11-17 21:17:17 +00:00
|
|
|
EndContainer(),
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Window description for the download window */
|
2023-11-02 19:33:01 +00:00
|
|
|
static WindowDesc _bootstrap_download_status_window_desc(__FILE__, __LINE__,
|
2019-04-10 21:07:06 +00:00
|
|
|
WDP_CENTER, nullptr, 0, 0,
|
2011-11-17 21:17:17 +00:00
|
|
|
WC_NETWORK_STATUS_WINDOW, WC_NONE,
|
2023-06-14 16:24:14 +00:00
|
|
|
WDF_MODAL | WDF_NO_CLOSE,
|
2023-09-03 20:54:13 +00:00
|
|
|
std::begin(_nested_bootstrap_download_status_window_widgets), std::end(_nested_bootstrap_download_status_window_widgets)
|
2011-11-17 21:17:17 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
/** Window for showing the download status of content */
|
|
|
|
struct BootstrapContentDownloadStatusWindow : public BaseNetworkContentDownloadStatusWindow {
|
|
|
|
public:
|
|
|
|
/** Simple call the constructor of the superclass. */
|
|
|
|
BootstrapContentDownloadStatusWindow() : BaseNetworkContentDownloadStatusWindow(&_bootstrap_download_status_window_desc)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-10-13 11:59:15 +00:00
|
|
|
void Close([[maybe_unused]] int data = 0) override
|
2021-03-13 11:26:06 +00:00
|
|
|
{
|
|
|
|
/* If we are not set to exit the game, it means the bootstrap failed. */
|
|
|
|
if (!_exit_game) {
|
|
|
|
new BootstrapErrorWindow();
|
|
|
|
}
|
2021-05-15 21:12:25 +00:00
|
|
|
this->BaseNetworkContentDownloadStatusWindow::Close();
|
2021-03-13 11:26:06 +00:00
|
|
|
}
|
|
|
|
|
2023-09-16 20:20:53 +00:00
|
|
|
void OnDownloadComplete(ContentID) override
|
2011-11-17 21:17:17 +00:00
|
|
|
{
|
|
|
|
/* We have completed downloading. We can trigger finding the right set now. */
|
|
|
|
BaseGraphics::FindSets();
|
|
|
|
|
|
|
|
/* And continue going into the menu. */
|
|
|
|
_game_mode = GM_MENU;
|
|
|
|
|
|
|
|
/* _exit_game is used to break out of the outer video driver's MainLoop. */
|
|
|
|
_exit_game = true;
|
2021-05-15 21:12:25 +00:00
|
|
|
this->Close();
|
2011-11-17 21:17:17 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/** The widgets for the query. It has no close box as that sprite does not exist yet. */
|
2024-01-15 22:49:24 +00:00
|
|
|
static constexpr NWidgetPart _bootstrap_query_widgets[] = {
|
2011-11-17 21:17:17 +00:00
|
|
|
NWidget(NWID_HORIZONTAL),
|
|
|
|
NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_MISSING_GRAPHICS_SET_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
|
|
|
|
EndContainer(),
|
2023-10-25 21:12:39 +00:00
|
|
|
NWidget(WWT_PANEL, COLOUR_GREY, WID_BAFD_QUESTION), EndContainer(),
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_BAFD_YES), SetDataTip(STR_MISSING_GRAPHICS_YES_DOWNLOAD, STR_NULL),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_BAFD_NO), SetDataTip(STR_MISSING_GRAPHICS_NO_QUIT, STR_NULL),
|
2011-11-17 21:17:17 +00:00
|
|
|
EndContainer(),
|
|
|
|
};
|
|
|
|
|
|
|
|
/** The window description for the query. */
|
2023-11-02 19:33:01 +00:00
|
|
|
static WindowDesc _bootstrap_query_desc(__FILE__, __LINE__,
|
2019-04-10 21:07:06 +00:00
|
|
|
WDP_CENTER, nullptr, 0, 0,
|
2011-11-17 21:17:17 +00:00
|
|
|
WC_CONFIRM_POPUP_QUERY, WC_NONE,
|
2023-06-14 16:24:14 +00:00
|
|
|
WDF_NO_CLOSE,
|
2023-09-03 20:54:13 +00:00
|
|
|
std::begin(_bootstrap_query_widgets), std::end(_bootstrap_query_widgets)
|
2011-11-17 21:17:17 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
/** The window for the query. It can't use the generic query window as that uses sprites that don't exist yet. */
|
|
|
|
class BootstrapAskForDownloadWindow : public Window, ContentCallback {
|
|
|
|
Dimension button_size; ///< The dimension of the button
|
|
|
|
|
|
|
|
public:
|
|
|
|
/** Start listening to the content client events. */
|
2013-05-26 19:23:42 +00:00
|
|
|
BootstrapAskForDownloadWindow() : Window(&_bootstrap_query_desc)
|
2011-11-17 21:17:17 +00:00
|
|
|
{
|
2013-05-26 19:23:42 +00:00
|
|
|
this->InitNested(WN_CONFIRM_POPUP_QUERY_BOOTSTRAP);
|
2011-11-17 21:17:17 +00:00
|
|
|
_network_content_client.AddCallback(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Stop listening to the content client events. */
|
2023-10-13 11:59:15 +00:00
|
|
|
void Close([[maybe_unused]] int data = 0) override
|
2011-11-17 21:17:17 +00:00
|
|
|
{
|
|
|
|
_network_content_client.RemoveCallback(this);
|
2021-05-15 21:12:25 +00:00
|
|
|
this->Window::Close();
|
2011-11-17 21:17:17 +00:00
|
|
|
}
|
|
|
|
|
2023-12-29 19:11:59 +00:00
|
|
|
void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override
|
2011-11-17 21:17:17 +00:00
|
|
|
{
|
|
|
|
/* We cache the button size. This is safe as no reinit can happen here. */
|
|
|
|
if (this->button_size.width == 0) {
|
|
|
|
this->button_size = maxdim(GetStringBoundingBox(STR_MISSING_GRAPHICS_YES_DOWNLOAD), GetStringBoundingBox(STR_MISSING_GRAPHICS_NO_QUIT));
|
2022-09-23 08:36:22 +00:00
|
|
|
this->button_size.width += WidgetDimensions::scaled.frametext.Horizontal();
|
|
|
|
this->button_size.height += WidgetDimensions::scaled.frametext.Vertical();
|
2011-11-17 21:17:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (widget) {
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_BAFD_QUESTION:
|
2011-11-17 21:17:17 +00:00
|
|
|
/* The question is twice as wide as the buttons, and determine the height based on the width. */
|
|
|
|
size->width = this->button_size.width * 2;
|
2022-09-23 08:36:22 +00:00
|
|
|
size->height = GetStringHeight(STR_MISSING_GRAPHICS_SET_MESSAGE, size->width - WidgetDimensions::scaled.frametext.Horizontal()) + WidgetDimensions::scaled.frametext.Vertical();
|
2011-11-17 21:17:17 +00:00
|
|
|
break;
|
|
|
|
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_BAFD_YES:
|
|
|
|
case WID_BAFD_NO:
|
2011-11-17 21:17:17 +00:00
|
|
|
*size = this->button_size;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-29 19:11:59 +00:00
|
|
|
void DrawWidget(const Rect &r, WidgetID widget) const override
|
2011-11-17 21:17:17 +00:00
|
|
|
{
|
2023-09-20 19:25:37 +00:00
|
|
|
if (widget != WID_BAFD_QUESTION) return;
|
2011-11-17 21:17:17 +00:00
|
|
|
|
2022-09-23 08:36:22 +00:00
|
|
|
DrawStringMultiLine(r.Shrink(WidgetDimensions::scaled.frametext), STR_MISSING_GRAPHICS_SET_MESSAGE, TC_FROMSTRING, SA_CENTER);
|
2011-11-17 21:17:17 +00:00
|
|
|
}
|
|
|
|
|
2023-12-29 19:11:59 +00:00
|
|
|
void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
|
2011-11-17 21:17:17 +00:00
|
|
|
{
|
|
|
|
switch (widget) {
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_BAFD_YES:
|
2011-11-17 21:17:17 +00:00
|
|
|
/* We got permission to connect! Yay! */
|
|
|
|
_network_content_client.Connect();
|
|
|
|
break;
|
|
|
|
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_BAFD_NO:
|
2011-11-17 21:17:17 +00:00
|
|
|
_exit_game = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-04 07:49:37 +00:00
|
|
|
void OnConnect(bool success) override
|
2011-11-17 21:17:17 +00:00
|
|
|
{
|
2023-07-08 14:54:39 +00:00
|
|
|
if (!success) {
|
|
|
|
UserError("Failed to connect to content server. Please acquire a graphics set for OpenTTD. See section 1.4 of README.md.");
|
|
|
|
/* _exit_game is used to break out of the outer video driver's MainLoop. */
|
|
|
|
_exit_game = true;
|
|
|
|
this->Close();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-11-17 21:17:17 +00:00
|
|
|
/* Once connected, request the metadata. */
|
|
|
|
_network_content_client.RequestContentList(CONTENT_TYPE_BASE_GRAPHICS);
|
|
|
|
}
|
|
|
|
|
2019-03-04 07:49:37 +00:00
|
|
|
void OnReceiveContentInfo(const ContentInfo *ci) override
|
2011-11-17 21:17:17 +00:00
|
|
|
{
|
|
|
|
/* And once the meta data is received, start downloading it. */
|
|
|
|
_network_content_client.Select(ci->id);
|
|
|
|
new BootstrapContentDownloadStatusWindow();
|
2021-05-15 21:12:25 +00:00
|
|
|
this->Close();
|
2011-11-17 21:17:17 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
Remove: ENABLE_NETWORK switch
This switch has been a pain for years. Often disabling broke
compilation, as no developer compiles OpenTTD without, neither do
any of our official binaries.
Additionaly, it has grown so hugely in our codebase, that it
clearly shows that the current solution was a poor one. 350+
instances of "#ifdef ENABLE_NETWORK" were in the code, of which
only ~30 in the networking code itself. The rest were all around
the code to do the right thing, from GUI to NewGRF.
A more proper solution would be to stub all the functions, and
make sure the rest of the code can simply assume network is
available. This was also partially done, and most variables were
correct if networking was disabled. Despite that, often the #ifdefs
were still used.
With the recent removal of DOS, there is also no platform anymore
which we support where networking isn't working out-of-the-box.
All in all, it is time to remove the ENABLE_NETWORK switch. No
replacement is planned, but if you feel we really need this option,
we welcome any Pull Request which implements this in a way that
doesn't crawl through the code like this diff shows we used to.
2019-03-20 16:01:13 +00:00
|
|
|
#endif /* defined(WITH_FREETYPE) */
|
2011-11-17 21:29:15 +00:00
|
|
|
|
2023-07-06 16:20:33 +00:00
|
|
|
#if defined(__EMSCRIPTEN__)
|
|
|
|
# include <emscripten.h>
|
|
|
|
# include "network/network.h"
|
|
|
|
# include "network/network_content.h"
|
|
|
|
# include "openttd.h"
|
|
|
|
# include "video/video_driver.hpp"
|
|
|
|
|
|
|
|
class BootstrapEmscripten : public ContentCallback {
|
|
|
|
bool downloading{false};
|
|
|
|
uint total_files{0};
|
|
|
|
uint total_bytes{0};
|
|
|
|
uint downloaded_bytes{0};
|
|
|
|
|
|
|
|
public:
|
|
|
|
BootstrapEmscripten()
|
|
|
|
{
|
|
|
|
_network_content_client.AddCallback(this);
|
|
|
|
_network_content_client.Connect();
|
|
|
|
}
|
|
|
|
|
|
|
|
~BootstrapEmscripten()
|
|
|
|
{
|
|
|
|
_network_content_client.RemoveCallback(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnConnect(bool success) override
|
|
|
|
{
|
|
|
|
if (!success) {
|
|
|
|
EM_ASM({ if (window["openttd_bootstrap_failed"]) openttd_bootstrap_failed(); });
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Once connected, request the metadata. */
|
|
|
|
_network_content_client.RequestContentList(CONTENT_TYPE_BASE_GRAPHICS);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnReceiveContentInfo(const ContentInfo *ci) override
|
|
|
|
{
|
|
|
|
if (this->downloading) return;
|
|
|
|
|
|
|
|
/* And once the metadata is received, start downloading it. */
|
|
|
|
_network_content_client.Select(ci->id);
|
|
|
|
_network_content_client.DownloadSelectedContent(this->total_files, this->total_bytes);
|
|
|
|
this->downloading = true;
|
|
|
|
|
|
|
|
EM_ASM({ if (window["openttd_bootstrap"]) openttd_bootstrap($0, $1); }, this->downloaded_bytes, this->total_bytes);
|
|
|
|
}
|
|
|
|
|
2023-09-16 20:20:53 +00:00
|
|
|
void OnDownloadProgress(const ContentInfo *, int bytes) override
|
2023-07-06 16:20:33 +00:00
|
|
|
{
|
|
|
|
/* A negative value means we are resetting; for example, when retrying or using a fallback. */
|
|
|
|
if (bytes < 0) {
|
|
|
|
this->downloaded_bytes = 0;
|
|
|
|
} else {
|
|
|
|
this->downloaded_bytes += bytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
EM_ASM({ if (window["openttd_bootstrap"]) openttd_bootstrap($0, $1); }, this->downloaded_bytes, this->total_bytes);
|
|
|
|
}
|
|
|
|
|
2023-09-16 20:20:53 +00:00
|
|
|
void OnDownloadComplete(ContentID) override
|
2023-07-06 16:20:33 +00:00
|
|
|
{
|
|
|
|
/* _exit_game is used to break out of the outer video driver's MainLoop. */
|
|
|
|
_exit_game = true;
|
|
|
|
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
#endif /* __EMSCRIPTEN__ */
|
|
|
|
|
2011-11-17 21:17:17 +00:00
|
|
|
/**
|
2013-01-08 22:46:42 +00:00
|
|
|
* Handle all procedures for bootstrapping OpenTTD without a base graphics set.
|
2011-11-17 21:17:17 +00:00
|
|
|
* This requires all kinds of trickery that is needed to avoid the use of
|
|
|
|
* sprites from the base graphics set which are pretty interwoven.
|
|
|
|
* @return True if a base set exists, otherwise false.
|
|
|
|
*/
|
|
|
|
bool HandleBootstrap()
|
|
|
|
{
|
2019-04-10 21:07:06 +00:00
|
|
|
if (BaseGraphics::GetUsedSet() != nullptr) return true;
|
2011-11-17 21:17:17 +00:00
|
|
|
|
|
|
|
/* No user interface, bail out with an error. */
|
2014-01-02 22:41:58 +00:00
|
|
|
if (BlitterFactory::GetCurrentBlitter()->GetScreenDepth() == 0) goto failure;
|
2011-11-17 21:17:17 +00:00
|
|
|
|
2022-09-15 17:21:27 +00:00
|
|
|
/* If there is no network or no non-sprite font, then there is nothing we can do. Go straight to failure. */
|
2023-07-06 16:20:33 +00:00
|
|
|
#if defined(__EMSCRIPTEN__) || (defined(_WIN32) && defined(WITH_UNISCRIBE)) || (defined(WITH_FREETYPE) && (defined(WITH_FONTCONFIG) || defined(__APPLE__))) || defined(WITH_COCOA)
|
2011-11-17 21:17:17 +00:00
|
|
|
if (!_network_available) goto failure;
|
|
|
|
|
|
|
|
/* First tell the game we're bootstrapping. */
|
|
|
|
_game_mode = GM_BOOTSTRAP;
|
|
|
|
|
2023-07-06 16:20:33 +00:00
|
|
|
#if defined(__EMSCRIPTEN__)
|
|
|
|
new BootstrapEmscripten();
|
|
|
|
#else
|
2022-09-15 17:21:27 +00:00
|
|
|
/* Initialise the font cache. */
|
2011-11-17 21:17:17 +00:00
|
|
|
InitializeUnicodeGlyphMap();
|
2022-09-15 17:21:27 +00:00
|
|
|
/* Next "force" finding a suitable non-sprite font as the local font is missing. */
|
2011-11-20 11:52:11 +00:00
|
|
|
CheckForMissingGlyphs(false);
|
2011-11-17 21:17:17 +00:00
|
|
|
|
|
|
|
/* Initialise the palette. The biggest step is 'faking' some recolour sprites.
|
|
|
|
* This way the mauve and gray colours work and we can show the user interface. */
|
|
|
|
GfxInitPalettes();
|
|
|
|
static const int offsets[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x80, 0, 0, 0, 0x04, 0x08 };
|
|
|
|
for (uint i = 0; i != 16; i++) {
|
|
|
|
for (int j = 0; j < 8; j++) {
|
|
|
|
_colour_gradient[i][j] = offsets[i] + j;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Finally ask the question. */
|
|
|
|
new BootstrapBackground();
|
|
|
|
new BootstrapAskForDownloadWindow();
|
2023-07-06 16:20:33 +00:00
|
|
|
#endif /* __EMSCRIPTEN__ */
|
2011-11-17 21:17:17 +00:00
|
|
|
|
|
|
|
/* Process the user events. */
|
2014-04-28 21:06:51 +00:00
|
|
|
VideoDriver::GetInstance()->MainLoop();
|
2011-11-17 21:17:17 +00:00
|
|
|
|
|
|
|
/* _exit_game is used to get out of the video driver's main loop.
|
|
|
|
* In case GM_BOOTSTRAP is still set we did not exit it via the
|
|
|
|
* "download complete" event, so it was a manual exit. Obey it. */
|
|
|
|
_exit_game = _game_mode == GM_BOOTSTRAP;
|
|
|
|
if (_exit_game) return false;
|
|
|
|
|
|
|
|
/* Try to probe the graphics. Should work this time. */
|
2020-12-05 14:03:16 +00:00
|
|
|
if (!BaseGraphics::SetSet({})) goto failure;
|
2011-11-17 21:17:17 +00:00
|
|
|
|
|
|
|
/* Finally we can continue heading for the menu. */
|
|
|
|
_game_mode = GM_MENU;
|
|
|
|
return true;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Failure to get enough working to get a graphics set. */
|
|
|
|
failure:
|
2023-04-19 20:47:36 +00:00
|
|
|
UserError("Failed to find a graphics set. Please acquire a graphics set for OpenTTD. See section 1.4 of README.md.");
|
2011-11-17 21:17:17 +00:00
|
|
|
return false;
|
|
|
|
}
|