mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r27641) -Codechange: Fold the _fios_items file list vector into its own class.
This commit is contained in:
parent
0bf3372882
commit
bc08fe7c5f
|
@ -378,7 +378,7 @@ DEF_CONSOLE_CMD(ConLoad)
|
||||||
IConsolePrintF(CC_ERROR, "%s: No such file or directory.", file);
|
IConsolePrintF(CC_ERROR, "%s: No such file or directory.", file);
|
||||||
}
|
}
|
||||||
|
|
||||||
FiosFreeSavegameList();
|
_fios_items.Clear();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -402,7 +402,7 @@ DEF_CONSOLE_CMD(ConRemove)
|
||||||
IConsolePrintF(CC_ERROR, "%s: No such file or directory.", file);
|
IConsolePrintF(CC_ERROR, "%s: No such file or directory.", file);
|
||||||
}
|
}
|
||||||
|
|
||||||
FiosFreeSavegameList();
|
_fios_items.Clear();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -421,7 +421,7 @@ DEF_CONSOLE_CMD(ConListFiles)
|
||||||
IConsolePrintF(CC_DEFAULT, "%d) %s", i, _fios_items[i].title);
|
IConsolePrintF(CC_DEFAULT, "%d) %s", i, _fios_items[i].title);
|
||||||
}
|
}
|
||||||
|
|
||||||
FiosFreeSavegameList();
|
_fios_items.Clear();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -448,7 +448,7 @@ DEF_CONSOLE_CMD(ConChangeDirectory)
|
||||||
IConsolePrintF(CC_ERROR, "%s: No such file or directory.", file);
|
IConsolePrintF(CC_ERROR, "%s: No such file or directory.", file);
|
||||||
}
|
}
|
||||||
|
|
||||||
FiosFreeSavegameList();
|
_fios_items.Clear();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -463,7 +463,7 @@ DEF_CONSOLE_CMD(ConPrintWorkingDirectory)
|
||||||
|
|
||||||
/* XXX - Workaround for broken file handling */
|
/* XXX - Workaround for broken file handling */
|
||||||
FiosGetSavegameList(SLD_LOAD_GAME);
|
FiosGetSavegameList(SLD_LOAD_GAME);
|
||||||
FiosFreeSavegameList();
|
_fios_items.Clear();
|
||||||
|
|
||||||
FiosGetDescText(&path, NULL);
|
FiosGetDescText(&path, NULL);
|
||||||
IConsolePrint(CC_DEFAULT, path);
|
IConsolePrint(CC_DEFAULT, path);
|
||||||
|
|
|
@ -256,6 +256,8 @@ public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the number of items in the list.
|
* Get the number of items in the list.
|
||||||
|
*
|
||||||
|
* @return The number of items in the list.
|
||||||
*/
|
*/
|
||||||
inline uint Length() const
|
inline uint Length() const
|
||||||
{
|
{
|
||||||
|
|
10
src/fios.cpp
10
src/fios.cpp
|
@ -29,7 +29,7 @@
|
||||||
#include "safeguards.h"
|
#include "safeguards.h"
|
||||||
|
|
||||||
/* Variables to display file lists */
|
/* Variables to display file lists */
|
||||||
SmallVector<FiosItem, 32> _fios_items;
|
FileList _fios_items;
|
||||||
static char *_fios_path;
|
static char *_fios_path;
|
||||||
static const char *_fios_path_last;
|
static const char *_fios_path_last;
|
||||||
SortingBits _savegame_sort_order = SORT_BY_DATE | SORT_DESCENDING;
|
SortingBits _savegame_sort_order = SORT_BY_DATE | SORT_DESCENDING;
|
||||||
|
@ -64,11 +64,9 @@ int CDECL CompareFiosItems(const FiosItem *da, const FiosItem *db)
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Free the list of savegames. */
|
FileList::~FileList()
|
||||||
void FiosFreeSavegameList()
|
|
||||||
{
|
{
|
||||||
_fios_items.Clear();
|
this->Clear();
|
||||||
_fios_items.Compact();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -336,7 +334,7 @@ static void FiosGetFileList(SaveLoadDialogMode mode, fios_getlist_callback_proc
|
||||||
{
|
{
|
||||||
SortingBits order = _savegame_sort_order;
|
SortingBits order = _savegame_sort_order;
|
||||||
_savegame_sort_order = SORT_BY_NAME | SORT_ASCENDING;
|
_savegame_sort_order = SORT_BY_NAME | SORT_ASCENDING;
|
||||||
QSortT(_fios_items.Begin(), _fios_items.Length(), CompareFiosItems);
|
QSortT(_fios_items.files.Begin(), _fios_items.files.Length(), CompareFiosItems);
|
||||||
_savegame_sort_order = order;
|
_savegame_sort_order = order;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
91
src/fios.h
91
src/fios.h
|
@ -115,6 +115,94 @@ struct FiosItem {
|
||||||
char name[MAX_PATH];
|
char name[MAX_PATH];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** List of file information. */
|
||||||
|
class FileList {
|
||||||
|
public:
|
||||||
|
~FileList();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct a new entry in the file list.
|
||||||
|
* @return Pointer to the new items to be initialized.
|
||||||
|
*/
|
||||||
|
inline FiosItem *Append()
|
||||||
|
{
|
||||||
|
return this->files.Append();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the number of files in the list.
|
||||||
|
* @return The number of files stored in the list.
|
||||||
|
*/
|
||||||
|
inline uint Length() const
|
||||||
|
{
|
||||||
|
return this->files.Length();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a pointer to the first file information.
|
||||||
|
* @return Address of the first file information.
|
||||||
|
*/
|
||||||
|
inline const FiosItem *Begin() const
|
||||||
|
{
|
||||||
|
return this->files.Begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a pointer behind the last file information.
|
||||||
|
* @return Address behind the last file information.
|
||||||
|
*/
|
||||||
|
inline const FiosItem *End() const
|
||||||
|
{
|
||||||
|
return this->files.End();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a pointer to the indicated file information. File information must exist.
|
||||||
|
* @return Address of the indicated existing file information.
|
||||||
|
*/
|
||||||
|
inline const FiosItem *Get(uint index) const
|
||||||
|
{
|
||||||
|
return this->files.Get(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a pointer to the indicated file information. File information must exist.
|
||||||
|
* @return Address of the indicated existing file information.
|
||||||
|
*/
|
||||||
|
inline FiosItem *Get(uint index)
|
||||||
|
{
|
||||||
|
return this->files.Get(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline const FiosItem &operator[](uint index) const
|
||||||
|
{
|
||||||
|
return this->files[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a reference to the indicated file information. File information must exist.
|
||||||
|
* @return The requested file information.
|
||||||
|
*/
|
||||||
|
inline FiosItem &operator[](uint index)
|
||||||
|
{
|
||||||
|
return this->files[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Remove all items from the list. */
|
||||||
|
inline void Clear()
|
||||||
|
{
|
||||||
|
this->files.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Compact the list down to the smallest block size boundary. */
|
||||||
|
inline void Compact()
|
||||||
|
{
|
||||||
|
this->files.Compact();
|
||||||
|
}
|
||||||
|
|
||||||
|
SmallVector<FiosItem, 32> files; ///< The list of files.
|
||||||
|
};
|
||||||
|
|
||||||
enum SortingBits {
|
enum SortingBits {
|
||||||
SORT_ASCENDING = 0,
|
SORT_ASCENDING = 0,
|
||||||
SORT_DESCENDING = 1,
|
SORT_DESCENDING = 1,
|
||||||
|
@ -124,7 +212,7 @@ enum SortingBits {
|
||||||
DECLARE_ENUM_AS_BIT_SET(SortingBits)
|
DECLARE_ENUM_AS_BIT_SET(SortingBits)
|
||||||
|
|
||||||
/* Variables to display file lists */
|
/* Variables to display file lists */
|
||||||
extern SmallVector<FiosItem, 32> _fios_items;
|
extern FileList _fios_items;
|
||||||
extern SaveLoadDialogMode _saveload_mode;
|
extern SaveLoadDialogMode _saveload_mode;
|
||||||
extern SortingBits _savegame_sort_order;
|
extern SortingBits _savegame_sort_order;
|
||||||
|
|
||||||
|
@ -134,7 +222,6 @@ void FiosGetSavegameList(SaveLoadDialogMode mode);
|
||||||
void FiosGetScenarioList(SaveLoadDialogMode mode);
|
void FiosGetScenarioList(SaveLoadDialogMode mode);
|
||||||
void FiosGetHeightmapList(SaveLoadDialogMode mode);
|
void FiosGetHeightmapList(SaveLoadDialogMode mode);
|
||||||
|
|
||||||
void FiosFreeSavegameList();
|
|
||||||
const char *FiosBrowseTo(const FiosItem *item);
|
const char *FiosBrowseTo(const FiosItem *item);
|
||||||
|
|
||||||
StringID FiosGetDescText(const char **path, uint64 *total_free);
|
StringID FiosGetDescText(const char **path, uint64 *total_free);
|
||||||
|
|
|
@ -196,7 +196,7 @@ const TextColour _fios_colours[] = {
|
||||||
void BuildFileList(SaveLoadDialogMode mode)
|
void BuildFileList(SaveLoadDialogMode mode)
|
||||||
{
|
{
|
||||||
_fios_path_changed = true;
|
_fios_path_changed = true;
|
||||||
FiosFreeSavegameList();
|
_fios_items.Clear();
|
||||||
|
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case SLD_LOAD_SCENARIO:
|
case SLD_LOAD_SCENARIO:
|
||||||
|
@ -327,7 +327,7 @@ public:
|
||||||
if (!_networking && _game_mode != GM_EDITOR && _game_mode != GM_MENU) {
|
if (!_networking && _game_mode != GM_EDITOR && _game_mode != GM_MENU) {
|
||||||
DoCommandP(0, PM_PAUSED_SAVELOAD, 0, CMD_PAUSE);
|
DoCommandP(0, PM_PAUSED_SAVELOAD, 0, CMD_PAUSE);
|
||||||
}
|
}
|
||||||
FiosFreeSavegameList();
|
_fios_items.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void DrawWidget(const Rect &r, int widget) const
|
virtual void DrawWidget(const Rect &r, int widget) const
|
||||||
|
|
Loading…
Reference in New Issue