12 #if defined(ENABLE_NETWORK)
13 #include "../stdafx.h"
14 #include "../strings_func.h"
15 #include "../gfx_func.h"
16 #include "../window_func.h"
18 #include "../ai/ai.hpp"
19 #include "../game/game.hpp"
20 #include "../base_media_base.h"
21 #include "../sortlist_type.h"
22 #include "../stringfilter_type.h"
23 #include "../querystring_gui.h"
24 #include "../core/geometry_func.hpp"
25 #include "../textfile_gui.h"
29 #include "table/strings.h"
30 #include "../table/sprites.h"
32 #include "../safeguards.h"
45 const char *textfile = this->ci->
GetTextfile(file_type);
62 default: NOT_REACHED();
100 _nested_network_content_download_status_window_widgets,
lengthof(_nested_network_content_download_status_window_widgets)
104 Window(desc), cur_id(UINT32_MAX)
117 void BaseNetworkContentDownloadStatusWindow::DrawWidget(
const Rect &r,
int widget)
const
122 DrawFrameRect(r.left + 20, r.top + 4, r.left + 20 + (
int)((this->width - 40LL) * this->downloaded_bytes / this->total_bytes), r.top + 14, COLOUR_MAUVE, FR_NONE);
132 str = STR_CONTENT_DOWNLOAD_COMPLETE;
137 str = STR_CONTENT_DOWNLOAD_FILE;
139 str = STR_CONTENT_DOWNLOAD_INITIALISE;
146 void BaseNetworkContentDownloadStatusWindow::OnDownloadProgress(
const ContentInfo *ci,
int bytes)
148 if (ci->
id != this->cur_id) {
259 virtual void OnClick(
Point pt,
int widget,
int click_count)
273 virtual void OnDownloadProgress(
const ContentInfo *ci,
int bytes)
275 BaseNetworkContentDownloadStatusWindow::OnDownloadProgress(ci, bytes);
324 extern void OpenBrowser(
const char *url);
327 const char *last =
lastof(url);
329 char *pos =
strecpy(url,
"http://grfsearch.openttd.org/?", last);
332 pos =
strecpy(pos,
"do=searchgrfid&q=", last);
339 if (!first) pos =
strecpy(pos,
",", last);
347 pos =
strecpy(pos,
"do=searchtext&q=", last);
350 for (
const char *search = this->
filter_editbox.text.
buf; *search !=
'\0'; search++) {
352 if (*search ==
'\'' || *search ==
'"')
continue;
355 if (*search < 0x30) {
356 pos +=
seprintf(pos, last,
"%%%02X", *search);
357 }
else if (pos < last) {
389 bool all_available =
true;
410 return strnatcmp((*a)->name, (*b)->name,
true);
417 if ((*a)->type != (*b)->type) {
427 int r = (*a)->state - (*b)->state;
449 for (
int i = 0; i < (*a)->tag_count; i++) {
460 if ((*a)->type == filter.
type)
return true;
468 bool changed =
false;
477 if (!changed)
return;
500 if (new_state != old_params.
state) {
503 return new_state != old_params.
state;
586 size->height = 10 * resize->height;
592 virtual void DrawWidget(
const Rect &r,
int widget)
const
596 DrawString(r.left, r.right, r.top, STR_CONTENT_FILTER_TITLE, TC_FROMSTRING,
SA_RIGHT);
609 virtual void OnPaint()
656 default: NOT_REACHED();
658 DrawSprite(sprite, pal, nwi_checkbox->
pos_x + (pal == PAL_NONE ? 2 : 3), y + sprite_y_offset + (pal == PAL_NONE ? 1 : 0));
661 DrawString(nwi_type->pos_x, nwi_type->pos_x + nwi_type->current_x - 1, y + text_y_offset, str, TC_BLACK,
SA_HOR_CENTER);
664 y += this->resize.step_height;
674 static const int DETAIL_LEFT = 5;
675 static const int DETAIL_RIGHT = 5;
676 static const int DETAIL_TOP = 5;
696 int y = r.top + DETAIL_TITLE_HEIGHT + DETAIL_TOP;
700 y =
DrawStringMultiLine(r.left + DETAIL_LEFT, r.right - DETAIL_RIGHT, y, max_y, STR_CONTENT_DETAIL_UPDATE);
705 y =
DrawStringMultiLine(r.left + DETAIL_LEFT, r.right - DETAIL_RIGHT, y, max_y, STR_CONTENT_DETAIL_NAME);
709 y =
DrawStringMultiLine(r.left + DETAIL_LEFT, r.right - DETAIL_RIGHT, y, max_y, STR_CONTENT_DETAIL_VERSION);
714 y =
DrawStringMultiLine(r.left + DETAIL_LEFT, r.right - DETAIL_RIGHT, y, max_y, STR_CONTENT_DETAIL_DESCRIPTION);
719 y =
DrawStringMultiLine(r.left + DETAIL_LEFT, r.right - DETAIL_RIGHT, y, max_y, STR_CONTENT_DETAIL_URL);
723 y =
DrawStringMultiLine(r.left + DETAIL_LEFT, r.right - DETAIL_RIGHT, y, max_y, STR_CONTENT_DETAIL_TYPE);
727 y =
DrawStringMultiLine(r.left + DETAIL_LEFT, r.right - DETAIL_RIGHT, y, max_y, STR_CONTENT_DETAIL_FILESIZE);
740 if (ci->
id != cid)
continue;
742 p +=
seprintf(p,
lastof(buf), p == buf ?
"%s" :
", %s", (*iter)->name);
747 y =
DrawStringMultiLine(r.left + DETAIL_LEFT, r.right - DETAIL_RIGHT, y, max_y, STR_CONTENT_DETAIL_DEPENDENCIES);
758 y =
DrawStringMultiLine(r.left + DETAIL_LEFT, r.right - DETAIL_RIGHT, y, max_y, STR_CONTENT_DETAIL_TAGS);
776 y =
DrawStringMultiLine(r.left + DETAIL_LEFT, r.right - DETAIL_RIGHT, y, max_y, STR_CONTENT_DETAIL_SELECTED_BECAUSE_OF);
781 virtual void OnClick(
Point pt,
int widget,
int click_count)
848 extern void OpenBrowser(
const char *url);
938 virtual void OnEditboxChanged(
int wid)
948 virtual void OnResize()
953 virtual void OnReceiveContentInfo(
const ContentInfo *rci)
960 virtual void OnDownloadComplete(
ContentID cid)
966 virtual void OnConnect(
bool success)
984 if (!gui_scope)
return;
989 bool show_select_all =
false;
990 bool show_select_upgrade =
false;
1000 show_select_all =
true;
1001 show_select_upgrade |= ci->
upgrade;
1015 for (
TextfileType tft = TFT_BEGIN; tft < TFT_END; tft++) {
1019 this->GetWidget<NWidgetCore>(
WID_NCL_CANCEL)->widget_data = this->
filesize_sum == 0 ? STR_AI_SETTINGS_CLOSE : STR_AI_LIST_CANCEL;
1034 &TypeOrSelectedFilter,
1045 GetString(NetworkContentListWindow::content_type_strs[i], STR_CONTENT_TYPE_BASE_GRAPHICS + i -
CONTENT_TYPE_BASE_GRAPHICS,
lastof(NetworkContentListWindow::content_type_strs[i]));
1062 SetDataTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
1073 SetDataTip(STR_CONTENT_TYPE_CAPTION, STR_CONTENT_TYPE_CAPTION_TOOLTIP),
1075 SetDataTip(STR_CONTENT_NAME_CAPTION, STR_CONTENT_NAME_CAPTION_TOOLTIP),
1077 NWidget(
WWT_MATRIX, COLOUR_LIGHT_BLUE,
WID_NCL_MATRIX),
SetResize(1, 14),
SetFill(1, 1),
SetScrollbar(
WID_NCL_SCROLLBAR),
SetMatrixDataTip(1, 0, STR_CONTENT_MATRIX_TOOLTIP),
1084 SetDataTip(STR_CONTENT_SELECT_UPDATES_CAPTION, STR_CONTENT_SELECT_UPDATES_CAPTION_TOOLTIP),
1086 SetDataTip(STR_CONTENT_SELECT_ALL_CAPTION, STR_CONTENT_SELECT_ALL_CAPTION_TOOLTIP),
1089 SetDataTip(STR_CONTENT_UNSELECT_ALL_CAPTION, STR_CONTENT_UNSELECT_ALL_CAPTION_TOOLTIP),
1109 SetDataTip(STR_CONTENT_SEARCH_EXTERNAL, STR_CONTENT_SEARCH_EXTERNAL_TOOLTIP),
1114 SetDataTip(STR_CONTENT_DOWNLOAD_CAPTION, STR_CONTENT_DOWNLOAD_CAPTION_TOOLTIP),
1131 _nested_network_content_list_widgets,
lengthof(_nested_network_content_list_widgets)
1141 #if defined(WITH_ZLIB)