summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/fios.h7
-rw-r--r--src/fios_gui.cpp132
-rw-r--r--src/lang/english.txt1
-rw-r--r--src/widgets/fios_widget.h1
4 files changed, 127 insertions, 14 deletions
diff --git a/src/fios.h b/src/fios.h
index 5e17e8ee1..24c9f370e 100644
--- a/src/fios.h
+++ b/src/fios.h
@@ -18,6 +18,13 @@
#include "network/core/tcp_content.h"
+/** Special values for save-load window for the data parameter of #InvalidateWindowData. */
+enum SaveLoadInvalidateWindowData {
+ SLIWD_RESCAN_FILES, ///< Rescan all files (when changed directory, ...)
+ SLIWD_SELECTION_CHANGES, ///< File selection has changed (user click, ...)
+ SLIWD_FILTER_CHANGES, ///< The filename filter has changed (via the editbox)
+};
+
typedef SmallMap<uint, CompanyProperties *> CompanyPropertiesMap;
/**
diff --git a/src/fios_gui.cpp b/src/fios_gui.cpp
index 9aa5277ac..e149d07b4 100644
--- a/src/fios_gui.cpp
+++ b/src/fios_gui.cpp
@@ -28,6 +28,7 @@
#include "date_func.h"
#include "core/geometry_func.hpp"
#include "gamelog.h"
+#include "stringfilter_type.h"
#include "widgets/fios_widget.h"
@@ -76,9 +77,20 @@ static const NWidgetPart _nested_load_dialog_widgets[] = {
NWidget(WWT_CAPTION, COLOUR_GREY, WID_SL_CAPTION),
NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
EndContainer(),
+ /* Current directory and free space */
NWidget(WWT_PANEL, COLOUR_GREY, WID_SL_BACKGROUND), SetFill(1, 0), SetResize(1, 0), EndContainer(),
+
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
- NWidget(NWID_VERTICAL),
+ /* Left side : filter box and available files */
+ NWidget(WWT_PANEL, COLOUR_GREY), SetFill(1, 1), SetResize(1, 1),
+ /* Filter box with label */
+ NWidget(NWID_HORIZONTAL), SetPadding(WD_FRAMERECT_TOP, 0, WD_FRAMERECT_BOTTOM, 0),
+ SetPIP(WD_FRAMETEXT_LEFT, WD_FRAMETEXT_RIGHT, 0),
+ NWidget(WWT_TEXT, COLOUR_GREY), SetFill(0, 1), SetDataTip(STR_SAVELOAD_FILTER_TITLE , STR_NULL),
+ NWidget(WWT_EDITBOX, COLOUR_GREY, WID_SL_FILTER), SetFill(1, 0), SetMinimalSize(50, 12), SetResize(1, 0),
+ SetDataTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
+ EndContainer(),
+ /* Sort buttons */
NWidget(NWID_HORIZONTAL),
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SL_SORT_BYNAME), SetDataTip(STR_SORT_BY_CAPTION_NAME, STR_TOOLTIP_SORT_ORDER), SetFill(1, 0), SetResize(1, 0),
@@ -86,6 +98,7 @@ static const NWidgetPart _nested_load_dialog_widgets[] = {
EndContainer(),
NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_SL_HOME_BUTTON), SetMinimalSize(12, 12), SetDataTip(SPR_HOUSE_ICON, STR_SAVELOAD_HOME_BUTTON),
EndContainer(),
+ /* Files */
NWidget(WWT_PANEL, COLOUR_GREY, WID_SL_FILE_BACKGROUND),
NWidget(NWID_HORIZONTAL),
NWidget(WWT_INSET, COLOUR_GREY, WID_SL_DRIVES_DIRECTORIES_LIST), SetFill(1, 1), SetPadding(2, 1, 2, 2),
@@ -98,6 +111,8 @@ static const NWidgetPart _nested_load_dialog_widgets[] = {
EndContainer(),
EndContainer(),
EndContainer(),
+
+ /* Right side : game details */
NWidget(WWT_PANEL, COLOUR_GREY),
NWidget(WWT_EMPTY, INVALID_COLOUR, WID_SL_DETAILS), SetResize(1, 1), SetFill(1, 1),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SL_MISSING_NEWGRFS), SetDataTip(STR_NEWGRF_SETTINGS_FIND_MISSING_CONTENT_BUTTON, STR_NEWGRF_SETTINGS_FIND_MISSING_CONTENT_TOOLTIP), SetFill(1, 0), SetResize(1, 0),
@@ -119,8 +134,18 @@ static const NWidgetPart _nested_load_heightmap_dialog_widgets[] = {
NWidget(WWT_CAPTION, COLOUR_GREY, WID_SL_CAPTION),
NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
EndContainer(),
+ /* Current directory and free space */
NWidget(WWT_PANEL, COLOUR_GREY, WID_SL_BACKGROUND), SetFill(1, 0), SetResize(1, 0), EndContainer(),
- NWidget(NWID_VERTICAL),
+
+ NWidget(WWT_PANEL, COLOUR_GREY), SetFill(1, 1), SetResize(1, 1),
+ /* Filter box with label */
+ NWidget(NWID_HORIZONTAL), SetPadding(WD_FRAMERECT_TOP, 0, WD_FRAMERECT_BOTTOM, 0),
+ SetPIP(WD_FRAMETEXT_LEFT, WD_FRAMETEXT_RIGHT, 0),
+ NWidget(WWT_TEXT, COLOUR_GREY), SetFill(0, 1), SetDataTip(STR_SAVELOAD_FILTER_TITLE , STR_NULL),
+ NWidget(WWT_EDITBOX, COLOUR_GREY, WID_SL_FILTER), SetFill(1, 0), SetMinimalSize(50, 12), SetResize(1, 0),
+ SetDataTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
+ EndContainer(),
+ /* Sort Buttons */
NWidget(NWID_HORIZONTAL),
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SL_SORT_BYNAME), SetDataTip(STR_SORT_BY_CAPTION_NAME, STR_TOOLTIP_SORT_ORDER), SetFill(1, 0), SetResize(1, 0),
@@ -128,6 +153,7 @@ static const NWidgetPart _nested_load_heightmap_dialog_widgets[] = {
EndContainer(),
NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_SL_HOME_BUTTON), SetMinimalSize(12, 12), SetDataTip(SPR_HOUSE_ICON, STR_SAVELOAD_HOME_BUTTON),
EndContainer(),
+ /* Files */
NWidget(WWT_PANEL, COLOUR_GREY, WID_SL_FILE_BACKGROUND),
NWidget(NWID_HORIZONTAL),
NWidget(WWT_INSET, COLOUR_GREY, WID_SL_DRIVES_DIRECTORIES_LIST), SetFill(1, 1), SetPadding(2, 1, 2, 2),
@@ -152,9 +178,19 @@ static const NWidgetPart _nested_save_dialog_widgets[] = {
NWidget(WWT_CAPTION, COLOUR_GREY, WID_SL_CAPTION),
NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
EndContainer(),
+ /* Current directory and free space */
NWidget(WWT_PANEL, COLOUR_GREY, WID_SL_BACKGROUND), SetFill(1, 0), SetResize(1, 0), EndContainer(),
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
- NWidget(NWID_VERTICAL),
+ /* Left side : filter box and available files */
+ NWidget(WWT_PANEL, COLOUR_GREY), SetFill(1, 1), SetResize(1, 1),
+ /* Filter box with label */
+ NWidget(NWID_HORIZONTAL), SetPadding(WD_FRAMERECT_TOP, 0, WD_FRAMERECT_BOTTOM, 0),
+ SetPIP(WD_FRAMETEXT_LEFT, WD_FRAMETEXT_RIGHT, 0),
+ NWidget(WWT_TEXT, COLOUR_GREY), SetFill(0, 1), SetDataTip(STR_SAVELOAD_FILTER_TITLE , STR_NULL),
+ NWidget(WWT_EDITBOX, COLOUR_GREY, WID_SL_FILTER), SetFill(1, 0), SetMinimalSize(50, 12), SetResize(1, 0),
+ SetDataTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
+ EndContainer(),
+ /* Sort buttons */
NWidget(NWID_HORIZONTAL),
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SL_SORT_BYNAME), SetDataTip(STR_SORT_BY_CAPTION_NAME, STR_TOOLTIP_SORT_ORDER), SetFill(1, 0), SetResize(1, 0),
@@ -162,6 +198,7 @@ static const NWidgetPart _nested_save_dialog_widgets[] = {
EndContainer(),
NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_SL_HOME_BUTTON), SetMinimalSize(12, 12), SetDataTip(SPR_HOUSE_ICON, STR_SAVELOAD_HOME_BUTTON),
EndContainer(),
+ /* Files */
NWidget(WWT_PANEL, COLOUR_GREY, WID_SL_FILE_BACKGROUND),
NWidget(NWID_HORIZONTAL),
NWidget(WWT_INSET, COLOUR_GREY, WID_SL_DRIVES_DIRECTORIES_LIST), SetPadding(2, 1, 0, 2),
@@ -171,11 +208,14 @@ static const NWidgetPart _nested_save_dialog_widgets[] = {
NWidget(WWT_EDITBOX, COLOUR_GREY, WID_SL_SAVE_OSK_TITLE), SetPadding(3, 2, 2, 2), SetFill(1, 0), SetResize(1, 0),
SetDataTip(STR_SAVELOAD_OSKTITLE, STR_SAVELOAD_EDITBOX_TOOLTIP),
EndContainer(),
+ /* Save/delete buttons */
NWidget(NWID_HORIZONTAL),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SL_DELETE_SELECTION), SetDataTip(STR_SAVELOAD_DELETE_BUTTON, STR_SAVELOAD_DELETE_TOOLTIP), SetFill(1, 0), SetResize(1, 0),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SL_SAVE_GAME), SetDataTip(STR_SAVELOAD_SAVE_BUTTON, STR_SAVELOAD_SAVE_TOOLTIP), SetFill(1, 0), SetResize(1, 0),
EndContainer(),
EndContainer(),
+
+ /* Right side : game details */
NWidget(WWT_PANEL, COLOUR_GREY),
NWidget(WWT_EMPTY, INVALID_COLOUR, WID_SL_DETAILS), SetResize(1, 1), SetFill(1, 1),
NWidget(NWID_HORIZONTAL),
@@ -227,6 +267,8 @@ static void SortSaveGameList(FileList &file_list)
struct SaveLoadWindow : public Window {
private:
+ static const uint EDITBOX_MAX_SIZE = 50;
+
QueryString filename_editbox; ///< Filename editbox.
AbstractFileType abstract_filetype; /// Type of file to select.
SaveLoadOperation fop; ///< File operation to perform.
@@ -234,6 +276,11 @@ private:
FiosItem o_dir;
const FiosItem *selected; ///< Selected game in #fios_items, or \c NULL.
Scrollbar *vscroll;
+
+ StringFilter string_filter; ///< Filter for available games.
+ QueryString filter_editbox; ///< Filter editbox;
+ SmallVector<bool, 32> fios_items_shown; ///< Map of the filtered out fios items
+
public:
/** Generate a default save filename. */
@@ -244,7 +291,7 @@ public:
}
SaveLoadWindow(WindowDesc *desc, AbstractFileType abstract_filetype, SaveLoadOperation fop)
- : Window(desc), filename_editbox(64), abstract_filetype(abstract_filetype), fop(fop)
+ : Window(desc), filename_editbox(64), abstract_filetype(abstract_filetype), fop(fop), filter_editbox(EDITBOX_MAX_SIZE)
{
assert(this->fop == SLO_SAVE || this->fop == SLO_LOAD);
@@ -296,6 +343,8 @@ public:
this->FinishInitNested(0);
this->LowerWidget(WID_SL_DRIVES_DIRECTORIES_LIST);
+ this->querystrings[WID_SL_FILTER] = &this->filter_editbox;
+ this->filter_editbox.cancel_button = QueryString::ACTION_CLEAR;
/* pause is only used in single-player, non-editor mode, non-menu mode. It
* will be unpaused in the WE_DESTROY event handler. */
@@ -304,7 +353,7 @@ public:
}
SetObjectToPlace(SPR_CURSOR_ZZZ, PAL_NONE, HT_NONE, WC_MAIN_WINDOW, 0);
- this->OnInvalidateData(0);
+ this->OnInvalidateData(SLIWD_RESCAN_FILES);
ResetObjectToPlace();
@@ -327,8 +376,15 @@ public:
strecpy(o_dir.name, _personal_dir, lastof(o_dir.name));
}
- /* Focus the edit box by default in the save windows */
- if (this->fop == SLO_SAVE) this->SetFocusedWidget(WID_SL_SAVE_OSK_TITLE);
+ switch (this->fop) {
+ case SLO_SAVE:
+ /* Focus the edit box by default in the save window */
+ this->SetFocusedWidget(WID_SL_SAVE_OSK_TITLE);
+ break;
+
+ default:
+ this->SetFocusedWidget(WID_SL_FILTER);
+ }
}
virtual ~SaveLoadWindow()
@@ -370,6 +426,10 @@ public:
uint y = r.top + WD_FRAMERECT_TOP;
for (uint pos = this->vscroll->GetPosition(); pos < this->fios_items.Length(); pos++) {
+ if (!this->fios_items_shown[pos]) {
+ /* The current item is filtered out : we do not show it */
+ continue;
+ }
const FiosItem *item = this->fios_items.Get(pos);
if (item == this->selected) {
@@ -507,7 +567,6 @@ public:
SortSaveGameList(this->fios_items);
}
- this->vscroll->SetCount(this->fios_items.Length());
this->DrawWidgets();
}
@@ -530,7 +589,7 @@ public:
case WID_SL_HOME_BUTTON: // OpenTTD 'button', jumps to OpenTTD directory
FiosBrowseTo(&o_dir);
- this->InvalidateData();
+ this->InvalidateData(SLIWD_RESCAN_FILES);
break;
case WID_SL_LOAD_BUTTON:
@@ -572,6 +631,12 @@ public:
int y = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_SL_DRIVES_DIRECTORIES_LIST, WD_FRAMERECT_TOP);
if (y == INT_MAX) return;
+ /* Get the corresponding non-filtered out item from the list */
+ int i = 0;
+ while (i <= y) {
+ if (!this->fios_items_shown[i]) y++;
+ i++;
+ }
const FiosItem *file = this->fios_items.Get(y);
const char *name = FiosBrowseTo(file);
@@ -586,7 +651,7 @@ public:
SaveOrLoad(name, SLO_CHECK, DFT_GAME_FILE, NO_DIRECTORY, false);
}
- this->InvalidateData(1);
+ this->InvalidateData(SLIWD_SELECTION_CHANGES);
}
if (this->fop == SLO_SAVE) {
/* Copy clicked name to editbox */
@@ -611,7 +676,7 @@ public:
}
} else {
/* Changed directory, need refresh. */
- this->InvalidateData();
+ this->InvalidateData(SLIWD_RESCAN_FILES);
}
break;
}
@@ -660,7 +725,7 @@ public:
if (!FiosDelete(this->filename_editbox.text.buf)) {
ShowErrorMessage(STR_ERROR_UNABLE_TO_DELETE_FILE, INVALID_STRING_ID, WL_ERROR);
} else {
- this->InvalidateData();
+ this->InvalidateData(SLIWD_RESCAN_FILES);
/* Reset file name to current date on successful delete */
if (this->abstract_filetype == FT_SAVEGAME) GenerateFileName();
}
@@ -691,7 +756,7 @@ public:
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{
switch (data) {
- case 0:
+ case SLIWD_RESCAN_FILES:
/* Rescan files */
this->selected = NULL;
_load_check_data.Clear();
@@ -702,9 +767,13 @@ public:
this->vscroll->SetCount(this->fios_items.Length());
this->selected = NULL;
_load_check_data.Clear();
+
+ /* We reset the files filtered */
+ this->OnInvalidateData(SLIWD_FILTER_CHANGES);
+
FALLTHROUGH;
- case 1:
+ case SLIWD_SELECTION_CHANGES:
/* Selection changes */
if (!gui_scope) break;
@@ -732,6 +801,41 @@ public:
NOT_REACHED();
}
break;
+
+ case SLIWD_FILTER_CHANGES:
+ /* Filter changes */
+ this->fios_items_shown.Resize(this->fios_items.Length());
+ uint items_shown_count = 0; ///< The number of items shown in the list
+ /* We pass through every fios item */
+ for (uint i = 0; i < this->fios_items.Length(); i++) {
+ if (this->string_filter.IsEmpty()) {
+ /* We don't filter anything out if the filter editbox is empty */
+ this->fios_items_shown[i] = true;
+ items_shown_count++;
+ } else {
+ this->string_filter.ResetState();
+ this->string_filter.AddLine(this->fios_items[i].title);
+ /* We set the vector to show this fios element as filtered depending on the result of the filter */
+ this->fios_items_shown[i] = this->string_filter.GetState();
+ if (this->fios_items_shown[i]) items_shown_count++;
+
+ if (&(this->fios_items[i]) == this->selected && this->fios_items_shown[i] == false) {
+ /* The selected element has been filtered out */
+ this->selected = NULL;
+ this->OnInvalidateData(SLIWD_SELECTION_CHANGES);
+ }
+ }
+ }
+ this->vscroll->SetCount(items_shown_count);
+ break;
+ }
+ }
+
+ virtual void OnEditboxChanged(int wid)
+ {
+ if (wid == WID_SL_FILTER) {
+ this->string_filter.SetFilterTerm(this->filter_editbox.text.buf);
+ this->InvalidateData(SLIWD_FILTER_CHANGES);
}
}
};
diff --git a/src/lang/english.txt b/src/lang/english.txt
index fa2ba0e6f..1cfe14921 100644
--- a/src/lang/english.txt
+++ b/src/lang/english.txt
@@ -2772,6 +2772,7 @@ STR_SAVELOAD_DETAIL_CAPTION :{BLACK}Game Det
STR_SAVELOAD_DETAIL_NOT_AVAILABLE :{BLACK}No information available
STR_SAVELOAD_DETAIL_COMPANY_INDEX :{SILVER}{COMMA}: {WHITE}{STRING1}
STR_SAVELOAD_DETAIL_GRFSTATUS :{SILVER}NewGRF: {WHITE}{STRING}
+STR_SAVELOAD_FILTER_TITLE :{BLACK}Filter string:
STR_SAVELOAD_OSKTITLE :{BLACK}Enter a name for the savegame
diff --git a/src/widgets/fios_widget.h b/src/widgets/fios_widget.h
index c94655d76..2351f8035 100644
--- a/src/widgets/fios_widget.h
+++ b/src/widgets/fios_widget.h
@@ -17,6 +17,7 @@ enum SaveLoadWidgets {
WID_SL_CAPTION, ///< Caption of the window.
WID_SL_SORT_BYNAME, ///< Sort by name button.
WID_SL_SORT_BYDATE, ///< Sort by date button.
+ WID_SL_FILTER, ///< Filter list of files
WID_SL_BACKGROUND, ///< Background of window.
WID_SL_FILE_BACKGROUND, ///< Background of file selection.
WID_SL_HOME_BUTTON, ///< Home button.