mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-06 22:28:56 +00:00
(svn r24041) [1.2] -Backport from trunk:
- Fix: After opening a text window with the monospaced font, all other text started glitching (r24038) - Feature: Allow display of baseset textfiles (r24037)
This commit is contained in:
parent
d5e69ff1fa
commit
9c36498695
@ -15,6 +15,8 @@
|
||||
#include "fileio_func.h"
|
||||
#include "core/smallmap_type.hpp"
|
||||
#include "gfx_type.h"
|
||||
#include "textfile_type.h"
|
||||
#include "textfile_gui.h"
|
||||
|
||||
/* Forward declare these; can't do 'struct X' in functions as older GCCs barf on that */
|
||||
struct IniFile;
|
||||
@ -143,6 +145,22 @@ struct BaseSet {
|
||||
{
|
||||
return file->CheckMD5(subdir, SIZE_MAX);
|
||||
}
|
||||
|
||||
/**
|
||||
* Search a textfile file next to this base media.
|
||||
* @param type The type of the textfile to search for.
|
||||
* @return The filename for the textfile, \c NULL otherwise.
|
||||
*/
|
||||
const char *GetTextfile(TextfileType type) const
|
||||
{
|
||||
for (uint i = 0; i < NUM_FILES; i++) {
|
||||
const char *textfile = ::GetTextfile(type, BASESET_DIR, this->files[i].filename);
|
||||
if (textfile != NULL) {
|
||||
return textfile;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
22
src/gfx.cpp
22
src/gfx.cpp
@ -45,6 +45,7 @@ SwitchMode _switch_mode; ///< The next mainloop command.
|
||||
PauseModeByte _pause_mode;
|
||||
Palette _cur_palette;
|
||||
|
||||
static Dimension _max_char_size[FS_END]; ///< Cache of the maximum size of any character of a font.
|
||||
static int _max_char_height; ///< Cache of the height of the largest font
|
||||
static int _max_char_width; ///< Cache of the width of the largest font
|
||||
static byte _stringwidth_table[FS_END][224]; ///< Cache containing width of often used characters. @see GetCharacterWidth()
|
||||
@ -1551,20 +1552,25 @@ void DoPaletteAnimations()
|
||||
*/
|
||||
void LoadStringWidthTable(bool monospace)
|
||||
{
|
||||
_max_char_height = 0;
|
||||
_max_char_width = 0;
|
||||
|
||||
for (FontSize fs = monospace ? FS_MONO : FS_BEGIN; fs < (monospace ? FS_END : FS_MONO); fs++) {
|
||||
_max_char_height = max<int>(_max_char_height, GetCharacterHeight(fs));
|
||||
_max_char_size[fs].width = 0;
|
||||
_max_char_size[fs].height = GetCharacterHeight(fs);
|
||||
for (uint i = 0; i != 224; i++) {
|
||||
_stringwidth_table[fs][i] = GetGlyphWidth(fs, i + 32);
|
||||
_max_char_width = max<int>(_max_char_width, _stringwidth_table[fs][i]);
|
||||
_max_char_size[fs].width = max<int>(_max_char_size[fs].width, _stringwidth_table[fs][i]);
|
||||
}
|
||||
|
||||
/* Needed because they need to be 1 more than the widest. */
|
||||
_max_char_size[fs].width++;
|
||||
_max_char_size[fs].height++;
|
||||
}
|
||||
|
||||
/* Needed because they need to be 1 more than the widest. */
|
||||
_max_char_height++;
|
||||
_max_char_width++;
|
||||
_max_char_width = 0;
|
||||
_max_char_height = 0;
|
||||
for (FontSize fs = FS_BEGIN; fs < FS_END; fs++) {
|
||||
_max_char_width = max<int>(_max_char_width, _max_char_size[fs].width);
|
||||
_max_char_height = max<int>(_max_char_height, _max_char_size[fs].height);
|
||||
}
|
||||
|
||||
ReInitAllWindows();
|
||||
}
|
||||
|
@ -34,6 +34,7 @@
|
||||
#include "ai/ai.hpp"
|
||||
#include "blitter/factory.hpp"
|
||||
#include "language.h"
|
||||
#include "textfile_gui.h"
|
||||
|
||||
|
||||
|
||||
@ -118,6 +119,42 @@ static DropDownList *BuiltSetDropDownList(int *selected_index)
|
||||
return list;
|
||||
}
|
||||
|
||||
/** Window for displaying the textfile of a BaseSet. */
|
||||
template <class TBaseSet>
|
||||
struct BaseSetTextfileWindow : public TextfileWindow {
|
||||
const TBaseSet* baseset; ///< View the textfile of this BaseSet.
|
||||
StringID content_type; ///< STR_CONTENT_TYPE_xxx for title.
|
||||
|
||||
BaseSetTextfileWindow(TextfileType file_type, const TBaseSet* baseset, StringID content_type) : TextfileWindow(file_type), baseset(baseset), content_type(content_type)
|
||||
{
|
||||
this->GetWidget<NWidgetCore>(WID_TF_CAPTION)->SetDataTip(STR_TEXTFILE_README_CAPTION + file_type, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS);
|
||||
|
||||
const char *textfile = this->baseset->GetTextfile(file_type);
|
||||
this->LoadTextfile(textfile, BASESET_DIR);
|
||||
}
|
||||
|
||||
/* virtual */ void SetStringParameters(int widget) const
|
||||
{
|
||||
if (widget == WID_TF_CAPTION) {
|
||||
SetDParam(0, content_type);
|
||||
SetDParamStr(1, this->baseset->name);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Open the BaseSet version of the textfile window.
|
||||
* @param file_type The type of textfile to display.
|
||||
* @param baseset The BaseSet to use.
|
||||
* @param content_type STR_CONTENT_TYPE_xxx for title.
|
||||
*/
|
||||
template <class TBaseSet>
|
||||
void ShowBaseSetTextfileWindow(TextfileType file_type, const TBaseSet* baseset, StringID content_type)
|
||||
{
|
||||
DeleteWindowByClass(WC_TEXTFILE);
|
||||
new BaseSetTextfileWindow<TBaseSet>(file_type, baseset, content_type);
|
||||
}
|
||||
|
||||
struct GameOptionsWindow : Window {
|
||||
GameSettings *opt;
|
||||
bool reload;
|
||||
@ -395,6 +432,24 @@ struct GameOptionsWindow : Window {
|
||||
|
||||
virtual void OnClick(Point pt, int widget, int click_count)
|
||||
{
|
||||
if (widget >= WID_GO_BASE_GRF_TEXTFILE && widget < WID_GO_BASE_GRF_TEXTFILE + TFT_END) {
|
||||
if (BaseGraphics::GetUsedSet() == NULL) return;
|
||||
|
||||
ShowBaseSetTextfileWindow((TextfileType)(widget - WID_GO_BASE_GRF_TEXTFILE), BaseGraphics::GetUsedSet(), STR_CONTENT_TYPE_BASE_GRAPHICS);
|
||||
return;
|
||||
}
|
||||
if (widget >= WID_GO_BASE_SFX_TEXTFILE && widget < WID_GO_BASE_SFX_TEXTFILE + TFT_END) {
|
||||
if (BaseSounds::GetUsedSet() == NULL) return;
|
||||
|
||||
ShowBaseSetTextfileWindow((TextfileType)(widget - WID_GO_BASE_SFX_TEXTFILE), BaseSounds::GetUsedSet(), STR_CONTENT_TYPE_BASE_SOUNDS);
|
||||
return;
|
||||
}
|
||||
if (widget >= WID_GO_BASE_MUSIC_TEXTFILE && widget < WID_GO_BASE_MUSIC_TEXTFILE + TFT_END) {
|
||||
if (BaseMusic::GetUsedSet() == NULL) return;
|
||||
|
||||
ShowBaseSetTextfileWindow((TextfileType)(widget - WID_GO_BASE_MUSIC_TEXTFILE), BaseMusic::GetUsedSet(), STR_CONTENT_TYPE_BASE_MUSIC);
|
||||
return;
|
||||
}
|
||||
switch (widget) {
|
||||
case WID_GO_FULLSCREEN_BUTTON: // Click fullscreen on/off
|
||||
/* try to toggle full-screen on/off */
|
||||
@ -517,6 +572,12 @@ struct GameOptionsWindow : Window {
|
||||
bool missing_files = BaseGraphics::GetUsedSet()->GetNumMissing() == 0;
|
||||
this->GetWidget<NWidgetCore>(WID_GO_BASE_GRF_STATUS)->SetDataTip(missing_files ? STR_EMPTY : STR_GAME_OPTIONS_BASE_GRF_STATUS, STR_NULL);
|
||||
|
||||
for (TextfileType tft = TFT_BEGIN; tft < TFT_END; tft++) {
|
||||
this->SetWidgetDisabledState(WID_GO_BASE_GRF_TEXTFILE + tft, BaseGraphics::GetUsedSet() == NULL || BaseGraphics::GetUsedSet()->GetTextfile(tft) == NULL);
|
||||
this->SetWidgetDisabledState(WID_GO_BASE_SFX_TEXTFILE + tft, BaseSounds::GetUsedSet() == NULL || BaseSounds::GetUsedSet()->GetTextfile(tft) == NULL);
|
||||
this->SetWidgetDisabledState(WID_GO_BASE_MUSIC_TEXTFILE + tft, BaseMusic::GetUsedSet() == NULL || BaseMusic::GetUsedSet()->GetTextfile(tft) == NULL);
|
||||
}
|
||||
|
||||
missing_files = BaseMusic::GetUsedSet()->GetNumInvalid() == 0;
|
||||
this->GetWidget<NWidgetCore>(WID_GO_BASE_MUSIC_STATUS)->SetDataTip(missing_files ? STR_EMPTY : STR_GAME_OPTIONS_BASE_MUSIC_STATUS, STR_NULL);
|
||||
}
|
||||
@ -570,7 +631,12 @@ static const NWidgetPart _nested_game_options_widgets[] = {
|
||||
NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_BASE_GRF_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_RAW_STRING, STR_GAME_OPTIONS_BASE_GRF_TOOLTIP),
|
||||
NWidget(WWT_TEXT, COLOUR_GREY, WID_GO_BASE_GRF_STATUS), SetMinimalSize(150, 12), SetDataTip(STR_EMPTY, STR_NULL), SetFill(1, 0),
|
||||
EndContainer(),
|
||||
NWidget(WWT_TEXT, COLOUR_GREY, WID_GO_BASE_GRF_DESCRIPTION), SetMinimalSize(330, 0), SetDataTip(STR_EMPTY, STR_GAME_OPTIONS_BASE_GRF_DESCRIPTION_TOOLTIP), SetFill(1, 0), SetPadding(6, 0, 0, 0),
|
||||
NWidget(WWT_TEXT, COLOUR_GREY, WID_GO_BASE_GRF_DESCRIPTION), SetMinimalSize(330, 0), SetDataTip(STR_EMPTY, STR_GAME_OPTIONS_BASE_GRF_DESCRIPTION_TOOLTIP), SetFill(1, 0), SetPadding(6, 0, 6, 0),
|
||||
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(7, 0, 7),
|
||||
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_GO_BASE_GRF_TEXTFILE + TFT_README), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_README, STR_NULL),
|
||||
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_GO_BASE_GRF_TEXTFILE + TFT_CHANGELOG), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_CHANGELOG, STR_NULL),
|
||||
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_GO_BASE_GRF_TEXTFILE + TFT_LICENSE), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_LICENCE, STR_NULL),
|
||||
EndContainer(),
|
||||
EndContainer(),
|
||||
|
||||
NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_BASE_SFX, STR_NULL), SetPadding(0, 10, 0, 10),
|
||||
@ -578,7 +644,12 @@ static const NWidgetPart _nested_game_options_widgets[] = {
|
||||
NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_BASE_SFX_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_RAW_STRING, STR_GAME_OPTIONS_BASE_SFX_TOOLTIP),
|
||||
NWidget(NWID_SPACER), SetFill(1, 0),
|
||||
EndContainer(),
|
||||
NWidget(WWT_TEXT, COLOUR_GREY, WID_GO_BASE_SFX_DESCRIPTION), SetMinimalSize(330, 0), SetDataTip(STR_EMPTY, STR_GAME_OPTIONS_BASE_SFX_DESCRIPTION_TOOLTIP), SetFill(1, 0), SetPadding(6, 0, 0, 0),
|
||||
NWidget(WWT_TEXT, COLOUR_GREY, WID_GO_BASE_SFX_DESCRIPTION), SetMinimalSize(330, 0), SetDataTip(STR_EMPTY, STR_GAME_OPTIONS_BASE_SFX_DESCRIPTION_TOOLTIP), SetFill(1, 0), SetPadding(6, 0, 6, 0),
|
||||
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(7, 0, 7),
|
||||
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_GO_BASE_SFX_TEXTFILE + TFT_README), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_README, STR_NULL),
|
||||
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_GO_BASE_SFX_TEXTFILE + TFT_CHANGELOG), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_CHANGELOG, STR_NULL),
|
||||
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_GO_BASE_SFX_TEXTFILE + TFT_LICENSE), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_LICENCE, STR_NULL),
|
||||
EndContainer(),
|
||||
EndContainer(),
|
||||
|
||||
NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_BASE_MUSIC, STR_NULL), SetPadding(0, 10, 0, 10),
|
||||
@ -586,7 +657,12 @@ static const NWidgetPart _nested_game_options_widgets[] = {
|
||||
NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_BASE_MUSIC_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_RAW_STRING, STR_GAME_OPTIONS_BASE_MUSIC_TOOLTIP),
|
||||
NWidget(WWT_TEXT, COLOUR_GREY, WID_GO_BASE_MUSIC_STATUS), SetMinimalSize(150, 12), SetDataTip(STR_EMPTY, STR_NULL), SetFill(1, 0),
|
||||
EndContainer(),
|
||||
NWidget(WWT_TEXT, COLOUR_GREY, WID_GO_BASE_MUSIC_DESCRIPTION), SetMinimalSize(330, 0), SetDataTip(STR_EMPTY, STR_GAME_OPTIONS_BASE_MUSIC_DESCRIPTION_TOOLTIP), SetFill(1, 0), SetPadding(6, 0, 0, 0),
|
||||
NWidget(WWT_TEXT, COLOUR_GREY, WID_GO_BASE_MUSIC_DESCRIPTION), SetMinimalSize(330, 0), SetDataTip(STR_EMPTY, STR_GAME_OPTIONS_BASE_MUSIC_DESCRIPTION_TOOLTIP), SetFill(1, 0), SetPadding(6, 0, 6, 0),
|
||||
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(7, 0, 7),
|
||||
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_GO_BASE_MUSIC_TEXTFILE + TFT_README), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_README, STR_NULL),
|
||||
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_GO_BASE_MUSIC_TEXTFILE + TFT_CHANGELOG), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_CHANGELOG, STR_NULL),
|
||||
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_GO_BASE_MUSIC_TEXTFILE + TFT_LICENSE), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_LICENCE, STR_NULL),
|
||||
EndContainer(),
|
||||
EndContainer(),
|
||||
EndContainer(),
|
||||
};
|
||||
|
@ -26,12 +26,15 @@ enum GameOptionsWidgets {
|
||||
WID_GO_SCREENSHOT_DROPDOWN, ///< Select the screenshot type... please use PNG!.
|
||||
WID_GO_BASE_GRF_DROPDOWN, ///< Use to select a base GRF.
|
||||
WID_GO_BASE_GRF_STATUS, ///< Info about missing files etc.
|
||||
WID_GO_BASE_GRF_DESCRIPTION, ///< Description of selected base GRF.
|
||||
WID_GO_BASE_GRF_TEXTFILE, ///< Open base GRF readme, changelog (+1) or license (+2).
|
||||
WID_GO_BASE_GRF_DESCRIPTION = WID_GO_BASE_GRF_TEXTFILE + TFT_END, ///< Description of selected base GRF.
|
||||
WID_GO_BASE_SFX_DROPDOWN, ///< Use to select a base SFX.
|
||||
WID_GO_BASE_SFX_DESCRIPTION, ///< Description of selected base SFX.
|
||||
WID_GO_BASE_SFX_TEXTFILE, ///< Open base SFX readme, changelog (+1) or license (+2).
|
||||
WID_GO_BASE_SFX_DESCRIPTION = WID_GO_BASE_SFX_TEXTFILE + TFT_END, ///< Description of selected base SFX.
|
||||
WID_GO_BASE_MUSIC_DROPDOWN, ///< Use to select a base music set.
|
||||
WID_GO_BASE_MUSIC_STATUS, ///< Info about corrupted files etc.
|
||||
WID_GO_BASE_MUSIC_DESCRIPTION, ///< Description of selected base music set.
|
||||
WID_GO_BASE_MUSIC_TEXTFILE, ///< Open base music readme, changelog (+1) or license (+2).
|
||||
WID_GO_BASE_MUSIC_DESCRIPTION = WID_GO_BASE_MUSIC_TEXTFILE + TFT_END, ///< Description of selected base music set.
|
||||
};
|
||||
|
||||
/** Widgets of the #GameDifficultyWindow class. */
|
||||
|
Loading…
Reference in New Issue
Block a user