diff options
author | yexo <yexo@openttd.org> | 2012-08-20 21:03:50 +0000 |
---|---|---|
committer | yexo <yexo@openttd.org> | 2012-08-20 21:03:50 +0000 |
commit | 053770d4a6827e73aea5074015dc2764f5099f12 (patch) | |
tree | 96a52d0905c9b76231f7f82d1cb0ab9a27d2c974 | |
parent | fe31aa28c422f1fab32ab3b72d8369d539c8496e (diff) | |
download | openttd-053770d4a6827e73aea5074015dc2764f5099f12.tar.xz |
(svn r24488) -Feature [FS#5236]: add buttons to view textfiles from the online content window (LordAro)
-rw-r--r-- | src/network/core/tcp_content.cpp | 51 | ||||
-rw-r--r-- | src/network/core/tcp_content.h | 1 | ||||
-rw-r--r-- | src/network/network_content_gui.cpp | 58 | ||||
-rw-r--r-- | src/script/api/script_window.hpp | 1 | ||||
-rw-r--r-- | src/widgets/network_content_widget.h | 5 |
5 files changed, 115 insertions, 1 deletions
diff --git a/src/network/core/tcp_content.cpp b/src/network/core/tcp_content.cpp index 131501a5c..7d8a898ef 100644 --- a/src/network/core/tcp_content.cpp +++ b/src/network/core/tcp_content.cpp @@ -14,6 +14,13 @@ #ifdef ENABLE_NETWORK #include "../../stdafx.h" +#include "../../textfile_gui.h" +#include "../../fileio_func.h" +#include "../../newgrf_config.h" +#include "../../base_media_base.h" +#include "../../ai/ai.hpp" +#include "../../game/game.hpp" +#include "../../fios.h" #include "tcp_content.h" /** Clear everything in the struct */ @@ -86,6 +93,50 @@ bool ContentInfo::IsValid() const return this->state < ContentInfo::INVALID && this->type >= CONTENT_TYPE_BEGIN && this->type < CONTENT_TYPE_END; } +/** + * Search a textfile file next to this file in the content list. + * @param type The type of the textfile to search for. + * @return The filename for the textfile, \c NULL otherwise. + */ +const char *ContentInfo::GetTextfile(TextfileType type) const +{ + if (this->state == INVALID) return NULL; + const char *tmp; + switch (this->type) { + default: NOT_REACHED(); + case CONTENT_TYPE_AI: + tmp = AI::GetScannerInfo()->FindMainScript(this, true); + break; + case CONTENT_TYPE_AI_LIBRARY: + tmp = AI::GetScannerLibrary()->FindMainScript(this, true); + break; + case CONTENT_TYPE_GAME: + tmp = Game::GetScannerInfo()->FindMainScript(this, true); + break; + case CONTENT_TYPE_GAME_LIBRARY: + tmp = Game::GetScannerLibrary()->FindMainScript(this, true); + break; + case CONTENT_TYPE_NEWGRF: + tmp = FindGRFConfig(BSWAP32(this->unique_id), FGCM_EXACT, this->md5sum)->filename; + break; + case CONTENT_TYPE_BASE_GRAPHICS: + tmp = TryGetBaseSetFile(this, true, BaseGraphics::GetAvailableSets()); + break; + case CONTENT_TYPE_BASE_SOUNDS: + tmp = TryGetBaseSetFile(this, true, BaseSounds::GetAvailableSets()); + break; + case CONTENT_TYPE_BASE_MUSIC: + tmp = TryGetBaseSetFile(this, true, BaseMusic::GetAvailableSets()); + break; + case CONTENT_TYPE_SCENARIO: + case CONTENT_TYPE_HEIGHTMAP: + tmp = FindScenario(this, true); + break; + } + if (tmp == NULL) return NULL; + return ::GetTextfile(type, GetContentInfoSubDir(this->type), tmp); +} + void NetworkContentSocketHandler::Close() { CloseConnection(); diff --git a/src/network/core/tcp_content.h b/src/network/core/tcp_content.h index 8e06bedb0..57e02d2a7 100644 --- a/src/network/core/tcp_content.h +++ b/src/network/core/tcp_content.h @@ -91,6 +91,7 @@ struct ContentInfo { size_t Size() const; bool IsSelected() const; bool IsValid() const; + const char *GetTextfile(TextfileType type) const; }; /** Base socket handler for all Content TCP sockets */ diff --git a/src/network/network_content_gui.cpp b/src/network/network_content_gui.cpp index 6b6e796df..ca1cfdab6 100644 --- a/src/network/network_content_gui.cpp +++ b/src/network/network_content_gui.cpp @@ -22,12 +22,55 @@ #include "../stringfilter_type.h" #include "../querystring_gui.h" #include "../core/geometry_func.hpp" +#include "../textfile_gui.h" #include "network_content_gui.h" #include "table/strings.h" #include "../table/sprites.h" +/** Window for displaying the textfile of an item in the content list. */ +struct ContentTextfileWindow : public TextfileWindow { + const ContentInfo *ci; ///< View the textfile of this ContentInfo. + + ContentTextfileWindow(TextfileType file_type, const ContentInfo *ci) : TextfileWindow(file_type), ci(ci) + { + const char *textfile = this->ci->GetTextfile(file_type); + this->LoadTextfile(textfile, GetContentInfoSubDir(this->ci->type)); + } + + StringID GetTypeString() const + { + switch (this->ci->type) { + case CONTENT_TYPE_NEWGRF: return STR_CONTENT_TYPE_NEWGRF; + case CONTENT_TYPE_BASE_GRAPHICS: return STR_CONTENT_TYPE_BASE_GRAPHICS; + case CONTENT_TYPE_BASE_SOUNDS: return STR_CONTENT_TYPE_BASE_SOUNDS; + case CONTENT_TYPE_BASE_MUSIC: return STR_CONTENT_TYPE_BASE_MUSIC; + case CONTENT_TYPE_AI: return STR_CONTENT_TYPE_AI; + case CONTENT_TYPE_AI_LIBRARY: return STR_CONTENT_TYPE_AI_LIBRARY; + case CONTENT_TYPE_GAME: return STR_CONTENT_TYPE_GAME_SCRIPT; + case CONTENT_TYPE_GAME_LIBRARY: return STR_CONTENT_TYPE_GS_LIBRARY; + case CONTENT_TYPE_SCENARIO: return STR_CONTENT_TYPE_SCENARIO; + case CONTENT_TYPE_HEIGHTMAP: return STR_CONTENT_TYPE_HEIGHTMAP; + default: NOT_REACHED(); + } + } + + /* virtual */ void SetStringParameters(int widget) const + { + if (widget == WID_TF_CAPTION) { + SetDParam(0, this->GetTypeString()); + SetDParamStr(1, this->ci->name); + } + } +}; + +void ShowContentTextfileWindow(TextfileType file_type, const ContentInfo *ci) +{ + DeleteWindowByClass(WC_TEXTFILE); + new ContentTextfileWindow(file_type, ci); +} + /** Nested widgets for the download window. */ static const NWidgetPart _nested_network_content_download_status_window_widgets[] = { NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_CONTENT_DOWNLOAD_TITLE, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS), @@ -611,6 +654,13 @@ public: virtual void OnClick(Point pt, int widget, int click_count) { + if (widget >= WID_NCL_TEXTFILE && widget < WID_NCL_TEXTFILE + TFT_END) { + if (this->selected == NULL || this->selected->state != ContentInfo::ALREADY_HERE) return; + + ShowContentTextfileWindow((TextfileType)(widget - WID_NCL_TEXTFILE), this->selected); + return; + } + switch (widget) { case WID_NCL_MATRIX: { uint id_v = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_NCL_MATRIX); @@ -820,6 +870,9 @@ public: this->SetWidgetDisabledState(WID_NCL_SELECT_ALL, !show_select_all); this->SetWidgetDisabledState(WID_NCL_SELECT_UPDATE, !show_select_upgrade); this->SetWidgetDisabledState(WID_NCL_OPEN_URL, this->selected == NULL || StrEmpty(this->selected->url)); + for (TextfileType tft = TFT_BEGIN; tft < TFT_END; tft++) { + this->SetWidgetDisabledState(WID_NCL_TEXTFILE + tft, this->selected == NULL || this->selected->state != ContentInfo::ALREADY_HERE || this->selected->GetTextfile(tft) == NULL); + } this->GetWidget<NWidgetCore>(WID_NCL_CANCEL)->widget_data = this->filesize_sum == 0 ? STR_AI_SETTINGS_CLOSE : STR_AI_LIST_CANCEL; } @@ -873,6 +926,11 @@ static const NWidgetPart _nested_network_content_list_widgets[] = { /* Right side. */ NWidget(NWID_VERTICAL), NWidget(WWT_PANEL, COLOUR_LIGHT_BLUE, WID_NCL_DETAILS), SetResize(1, 1), SetFill(1, 1), EndContainer(), + NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(7, 0, 7), + NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NCL_TEXTFILE + TFT_README), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_README, STR_NULL), + NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NCL_TEXTFILE + TFT_CHANGELOG), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_CHANGELOG, STR_NULL), + NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NCL_TEXTFILE + TFT_LICENSE), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_LICENCE, STR_NULL), + EndContainer(), EndContainer(), EndContainer(), NWidget(NWID_SPACER), SetMinimalSize(0, 7), SetResize(1, 0), diff --git a/src/script/api/script_window.hpp b/src/script/api/script_window.hpp index 23882e919..75583c0d2 100644 --- a/src/script/api/script_window.hpp +++ b/src/script/api/script_window.hpp @@ -1523,6 +1523,7 @@ public: WID_NCL_SELECT_ALL = ::WID_NCL_SELECT_ALL, ///< 'Select all' button. WID_NCL_SELECT_UPDATE = ::WID_NCL_SELECT_UPDATE, ///< 'Select updates' button. WID_NCL_UNSELECT = ::WID_NCL_UNSELECT, ///< 'Unselect all' button. + WID_NCL_TEXTFILE = ::WID_NCL_TEXTFILE, ///< Open textfile (readme, changelog (+1) or license (+2)) of some content. WID_NCL_OPEN_URL = ::WID_NCL_OPEN_URL, ///< 'Open url' button. WID_NCL_CANCEL = ::WID_NCL_CANCEL, ///< 'Cancel' button. WID_NCL_DOWNLOAD = ::WID_NCL_DOWNLOAD, ///< 'Download' button. diff --git a/src/widgets/network_content_widget.h b/src/widgets/network_content_widget.h index 383cf725e..d90afb3d4 100644 --- a/src/widgets/network_content_widget.h +++ b/src/widgets/network_content_widget.h @@ -12,6 +12,8 @@ #ifndef WIDGETS_NETWORK_CONTENT_WIDGET_H #define WIDGETS_NETWORK_CONTENT_WIDGET_H +#include "../textfile_type.h" + /** Widgets of the #NetworkContentDownloadStatusWindow class. */ enum NetworkContentDownloadStatusWidgets { WID_NCDS_BACKGROUND, ///< Background of the window. @@ -33,8 +35,9 @@ enum NetworkContentListWidgets { WID_NCL_SCROLLBAR, ///< Scrollbar of matrix. WID_NCL_DETAILS, ///< Panel with content details. + WID_NCL_TEXTFILE, ///< Open readme, changelog (+1) or license (+2) of a file in the content window. - WID_NCL_SELECT_ALL, ///< 'Select all' button. + WID_NCL_SELECT_ALL = WID_NCL_TEXTFILE + TFT_END, ///< 'Select all' button. WID_NCL_SELECT_UPDATE, ///< 'Select updates' button. WID_NCL_UNSELECT, ///< 'Unselect all' button. WID_NCL_OPEN_URL, ///< 'Open url' button. |