mirror of https://github.com/OpenRCT2/OpenRCT2.git
Added buttons for "up" and "new file" and fixed #2233
This commit is contained in:
parent
4d50c362ba
commit
b5c04a79e5
|
@ -43,6 +43,8 @@ enum {
|
|||
WIDX_BACKGROUND,
|
||||
WIDX_TITLE,
|
||||
WIDX_CLOSE,
|
||||
WIDX_UP,
|
||||
WIDX_NEW,
|
||||
WIDX_SORT_NAME,
|
||||
WIDX_SORT_DATE,
|
||||
WIDX_SCROLL,
|
||||
|
@ -53,10 +55,12 @@ enum {
|
|||
static rct_widget window_loadsave_widgets[] = {
|
||||
{ WWT_FRAME, 0, 0, WW - 1, 0, WH - 1, STR_NONE, STR_NONE },
|
||||
{ WWT_CAPTION, 0, 1, WW - 2, 1, 14, STR_NONE, STR_WINDOW_TITLE_TIP },
|
||||
{ WWT_CLOSEBOX, 0, WW - 13, WW - 3, 2, 13, STR_CLOSE_X, STR_CLOSE_WINDOW_TIP },
|
||||
{ WWT_CLOSEBOX, 0, 4, (WW - 5) / 2, 36, 47, STR_NONE, STR_NONE },
|
||||
{ WWT_CLOSEBOX, 0, (WW - 5) / 2 + 1, WW - 5 - 1, 36, 47, STR_NONE, STR_NONE },
|
||||
{ WWT_SCROLL, 0, 4, WW - 5, 47, WH - 40, 2, STR_NONE },
|
||||
{ WWT_CLOSEBOX, 0, WW - 13, WW - 3, 2, 13, STR_CLOSE_X, STR_CLOSE_WINDOW_TIP }, //Window close button
|
||||
{ WWT_CLOSEBOX, 0, 4, 104, 36, 47, 2718, STR_NONE}, // Up
|
||||
{ WWT_CLOSEBOX, 0, 105, 205, 36, 47, 2719, STR_NONE}, // New
|
||||
{ WWT_CLOSEBOX, 0, 4, (WW - 5) / 2, 50, 61, STR_NONE, STR_NONE }, // Name
|
||||
{ WWT_CLOSEBOX, 0, (WW - 5) / 2 + 1, WW - 5 - 1, 50, 61, STR_NONE, STR_NONE }, // Date
|
||||
{ WWT_SCROLL, 0, 4, WW - 5, 61, WH - 40, 2, STR_NONE }, // File list
|
||||
{ WWT_CLOSEBOX, 0, 4, 200, WH - 36, WH - 18, 2707, STR_NONE }, // Use native browser
|
||||
{ WIDGETS_END }
|
||||
};
|
||||
|
@ -111,8 +115,6 @@ static rct_window_event_list window_loadsave_events = {
|
|||
#pragma endregion
|
||||
|
||||
enum {
|
||||
TYPE_UP,
|
||||
TYPE_NEW_FILE,
|
||||
TYPE_DIRECTORY,
|
||||
TYPE_FILE,
|
||||
};
|
||||
|
@ -130,12 +132,13 @@ int _listItemsCount = 0;
|
|||
loadsave_list_item *_listItems = NULL;
|
||||
char _directory[MAX_PATH];
|
||||
char _shortenedDirectory[MAX_PATH];
|
||||
static char _parentDirectory[MAX_PATH];
|
||||
char _extension[32];
|
||||
char _defaultName[MAX_PATH];
|
||||
int _loadsaveType;
|
||||
int _type;
|
||||
|
||||
static void window_loadsave_populate_list(int includeNewItem, bool browsable, const char *directory, const char *extension);
|
||||
static void window_loadsave_populate_list(rct_window *w, int includeNewItem, const char *directory, const char *extension);
|
||||
static void window_loadsave_select(rct_window *w, const char *path);
|
||||
static void window_loadsave_sort_list(int index, int endIndex);
|
||||
|
||||
|
@ -164,7 +167,7 @@ rct_window *window_loadsave_open(int type, char *defaultName)
|
|||
if (w == NULL) {
|
||||
w = window_create_centred(WW, WH, &window_loadsave_events, WC_LOADSAVE, WF_STICK_TO_FRONT);
|
||||
w->widgets = window_loadsave_widgets;
|
||||
w->enabled_widgets = (1 << WIDX_CLOSE) | (1 << WIDX_SORT_NAME) | (1 << WIDX_SORT_DATE) | (1 << WIDX_BROWSE);
|
||||
w->enabled_widgets = (1 << WIDX_CLOSE) | (1 << WIDX_UP) | (1 << WIDX_NEW) | (1 << WIDX_SORT_NAME) | (1 << WIDX_SORT_DATE) | (1 << WIDX_BROWSE);
|
||||
w->colours[0] = 7;
|
||||
w->colours[1] = 7;
|
||||
w->colours[2] = 7;
|
||||
|
@ -205,7 +208,7 @@ rct_window *window_loadsave_open(int type, char *defaultName)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
window_loadsave_populate_list(includeNewItem, true, path, ".sv6");
|
||||
window_loadsave_populate_list(w, includeNewItem, path, ".sv6");
|
||||
break;
|
||||
case LOADSAVETYPE_LANDSCAPE:
|
||||
platform_get_user_directory(path, "landscape");
|
||||
|
@ -215,7 +218,7 @@ rct_window *window_loadsave_open(int type, char *defaultName)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
window_loadsave_populate_list(includeNewItem, true, path, ".sc6");
|
||||
window_loadsave_populate_list(w, includeNewItem, path, ".sc6");
|
||||
break;
|
||||
case LOADSAVETYPE_SCENARIO:
|
||||
/*
|
||||
|
@ -234,7 +237,7 @@ rct_window *window_loadsave_open(int type, char *defaultName)
|
|||
if (ch != NULL)
|
||||
*ch = 0;
|
||||
|
||||
window_loadsave_populate_list(includeNewItem, true, path, ".sc6");
|
||||
window_loadsave_populate_list(w, includeNewItem, path, ".sc6");
|
||||
break;
|
||||
case LOADSAVETYPE_TRACK:
|
||||
/*
|
||||
|
@ -253,7 +256,7 @@ rct_window *window_loadsave_open(int type, char *defaultName)
|
|||
if (ch != NULL)
|
||||
*ch = 0;
|
||||
|
||||
window_loadsave_populate_list(includeNewItem, true, path, ".td?");
|
||||
window_loadsave_populate_list(w, includeNewItem, path, ".td?");
|
||||
break;
|
||||
}
|
||||
w->no_list_items = _listItemsCount;
|
||||
|
@ -280,6 +283,27 @@ static void window_loadsave_mouseup(rct_window *w, int widgetIndex)
|
|||
case WIDX_CLOSE:
|
||||
window_close(w);
|
||||
break;
|
||||
case WIDX_UP:
|
||||
{
|
||||
char directory[MAX_PATH];
|
||||
int includeNewItem = (_type & 1) == LOADSAVETYPE_SAVE;
|
||||
|
||||
safe_strncpy(directory, _parentDirectory, sizeof(directory));
|
||||
window_loadsave_populate_list(w, includeNewItem, directory, _extension);
|
||||
window_init_scroll_widgets(w);
|
||||
w->no_list_items = _listItemsCount;
|
||||
break;
|
||||
}
|
||||
case WIDX_NEW:
|
||||
{
|
||||
rct_string_id templateStringId = 3165;
|
||||
char *templateString;
|
||||
|
||||
templateString = (char *)language_get_string(templateStringId);
|
||||
strcpy(templateString, _defaultName);
|
||||
window_text_input_open(w, WIDX_NEW, STR_NONE, 2710, templateStringId, 0, 64);
|
||||
break;
|
||||
}
|
||||
case WIDX_BROWSE:
|
||||
safe_strncpy(filename, _directory, MAX_PATH);
|
||||
if (_type & LOADSAVETYPE_SAVE)
|
||||
|
@ -363,40 +387,28 @@ static void window_loadsave_scrollmousedown(rct_window *w, int scrollIndex, int
|
|||
selectedItem = y / 10;
|
||||
if (selectedItem >= w->no_list_items)
|
||||
return;
|
||||
if (_listItems[selectedItem].type == TYPE_DIRECTORY){
|
||||
// The selected item is a folder
|
||||
int includeNewItem;
|
||||
|
||||
if (_listItems[selectedItem].type == TYPE_NEW_FILE) {
|
||||
rct_string_id templateStringId = 3165;
|
||||
char *templateString;
|
||||
w->no_list_items = 0;
|
||||
w->selected_list_item = -1;
|
||||
includeNewItem = (_type & 1) == LOADSAVETYPE_SAVE;
|
||||
|
||||
templateString = (char*)language_get_string(templateStringId);
|
||||
strcpy(templateString, _defaultName);
|
||||
char directory[MAX_PATH];
|
||||
safe_strncpy(directory, _listItems[selectedItem].path, sizeof(directory));
|
||||
|
||||
window_text_input_open(w, WIDX_SCROLL, STR_NONE, 2710, templateStringId, 0, 64);
|
||||
window_loadsave_populate_list(w, includeNewItem, directory, _extension);
|
||||
window_init_scroll_widgets(w);
|
||||
|
||||
w->no_list_items = _listItemsCount;
|
||||
} else {
|
||||
if (_listItems[selectedItem].type == TYPE_DIRECTORY || _listItems[selectedItem].type == TYPE_UP){
|
||||
// The selected item is a folder
|
||||
int includeNewItem;
|
||||
|
||||
w->no_list_items = 0;
|
||||
w->selected_list_item = -1;
|
||||
|
||||
includeNewItem = (_type & 1) == LOADSAVETYPE_SAVE;
|
||||
|
||||
char directory[MAX_PATH];
|
||||
safe_strncpy(directory, _listItems[selectedItem].path, sizeof(directory));
|
||||
|
||||
window_loadsave_populate_list(includeNewItem, true, directory, _extension);
|
||||
window_init_scroll_widgets(w);
|
||||
|
||||
w->no_list_items = _listItemsCount;
|
||||
} else {
|
||||
// TYPE_FILE
|
||||
// Load or overwrite
|
||||
if ((_loadsaveType & 0x01) == LOADSAVETYPE_SAVE)
|
||||
window_overwrite_prompt_open(_listItems[selectedItem].name, _listItems[selectedItem].path);
|
||||
else
|
||||
window_loadsave_select(w, _listItems[selectedItem].path);
|
||||
}
|
||||
// TYPE_FILE
|
||||
// Load or overwrite
|
||||
if ((_loadsaveType & 0x01) == LOADSAVETYPE_SAVE)
|
||||
window_overwrite_prompt_open(_listItems[selectedItem].name, _listItems[selectedItem].path);
|
||||
else
|
||||
window_loadsave_select(w, _listItems[selectedItem].path);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -482,18 +494,20 @@ static void window_loadsave_paint(rct_window *w, rct_drawpixelinfo *dpi)
|
|||
// Draw shadow
|
||||
gfx_draw_string(dpi, buffer, 0, w->x + 4, w->y + 20);
|
||||
rct_string_id id = STR_NONE;
|
||||
// Name button text
|
||||
if (gConfigGeneral.load_save_sort == SORT_NAME_ASCENDING)
|
||||
id = STR_UP;
|
||||
else if (gConfigGeneral.load_save_sort == SORT_NAME_DESCENDING)
|
||||
id = STR_DOWN;
|
||||
gfx_draw_string_centred_clipped(dpi, STR_NAME, &id, 1, w->x + 4 + (w->width - 8) / 4, w->y + 36, (w->width - 8) / 2);
|
||||
gfx_draw_string_centred_clipped(dpi, STR_NAME, &id, 1, w->x + 4 + (w->width - 8) / 4, w->y + 50, (w->width - 8) / 2);
|
||||
// Date button text
|
||||
if (gConfigGeneral.load_save_sort == SORT_DATE_ASCENDING)
|
||||
id = STR_UP;
|
||||
else if (gConfigGeneral.load_save_sort == SORT_DATE_DESCENDING)
|
||||
id = STR_DOWN;
|
||||
else
|
||||
id = STR_NONE;
|
||||
gfx_draw_string_centred_clipped(dpi, STR_DATE, &id, 1, w->x + 4 + (w->width - 8) * 3 / 4, w->y + 36, (w->width - 8) / 2);
|
||||
gfx_draw_string_centred_clipped(dpi, STR_DATE, &id, 1, w->x + 4 + (w->width - 8) * 3 / 4, w->y + 50, (w->width - 8) / 2);
|
||||
}
|
||||
|
||||
static void shorten_path(char* path, char* buffer, int available_width){
|
||||
|
@ -599,14 +613,14 @@ static void window_loadsave_sort_list(int index, int endIndex)
|
|||
qsort(_listItems + index, count, sizeof(loadsave_list_item), list_item_sort);
|
||||
}
|
||||
|
||||
static void window_loadsave_populate_list(int includeNewItem, bool browsable, const char *directory, const char *extension)
|
||||
static void window_loadsave_populate_list(rct_window *w, int includeNewItem, const char *directory, const char *extension)
|
||||
{
|
||||
int i, listItemCapacity, fileEnumHandle;
|
||||
file_info fileInfo;
|
||||
int i;
|
||||
int sortStartIndex = 0;
|
||||
int listItemCapacity = 8;
|
||||
loadsave_list_item *listItem;
|
||||
const char *src;
|
||||
char *dst, *last_dot_in_filename, filter[MAX_PATH], subDir[MAX_PATH];
|
||||
|
||||
char filter[MAX_PATH];
|
||||
|
||||
safe_strncpy(_directory, directory, sizeof(_directory));
|
||||
if (_extension != extension) {
|
||||
safe_strncpy(_extension, extension, sizeof(_extension));
|
||||
|
@ -620,58 +634,55 @@ static void window_loadsave_populate_list(int includeNewItem, bool browsable, co
|
|||
|
||||
if (_listItems != NULL)
|
||||
free(_listItems);
|
||||
|
||||
listItemCapacity = 8;
|
||||
_listItems = (loadsave_list_item*)malloc(listItemCapacity * sizeof(loadsave_list_item));
|
||||
_listItemsCount = 0;
|
||||
|
||||
window_loadsave_widgets[WIDX_NEW].type = includeNewItem?WWT_CLOSEBOX:WWT_EMPTY; // Hide/Show "new" button
|
||||
if(directory[0]=='\0' && platform_get_drives()!=0) // List Windows drives
|
||||
{
|
||||
w->disabled_widgets |= (1<<WIDX_NEW) | (1<<WIDX_UP);
|
||||
for (int x = 0; x < 32; x++){
|
||||
if (listItemCapacity <= _listItemsCount) {
|
||||
listItemCapacity *= 2;
|
||||
_listItems = realloc(_listItems, listItemCapacity * sizeof(loadsave_list_item));
|
||||
}
|
||||
|
||||
bool drivesList = false;
|
||||
|
||||
if (browsable) {
|
||||
int directoryLength = strlen(directory);
|
||||
int topLevel = 1;
|
||||
int lastSlash = directoryLength;
|
||||
for (int index = directoryLength; index >= 0; index--) {
|
||||
if (directory[index] == platform_get_path_separator()) {
|
||||
if (lastSlash != directoryLength){
|
||||
// The last slash has been changed before, we're now one up
|
||||
lastSlash = index;
|
||||
topLevel = 0;
|
||||
break;
|
||||
} else {
|
||||
// The last slash, after the whole path
|
||||
lastSlash = index;
|
||||
}
|
||||
if (platform_get_drives() & (1 << (x))){
|
||||
listItem = &_listItems[_listItemsCount];
|
||||
memset(listItem->path, '\0', MAX_PATH);
|
||||
listItem->path[0] = 'A' + x;
|
||||
listItem->path[1] = ':';
|
||||
listItem->path[2] = platform_get_path_separator();
|
||||
strcpy(listItem->name, listItem->path);
|
||||
listItem->type = TYPE_DIRECTORY;
|
||||
_listItemsCount++;
|
||||
}
|
||||
}
|
||||
if (!topLevel){
|
||||
listItem = &_listItems[_listItemsCount];
|
||||
safe_strncpy(listItem->name, language_get_string(2718), sizeof(listItem->name));
|
||||
memset(listItem->path, '\0', sizeof(listItem->path));
|
||||
strncpy(listItem->path, directory, lastSlash + 1);
|
||||
listItem->type = TYPE_UP;
|
||||
_listItemsCount++;
|
||||
} else if (platform_get_drives() != 0 && directory[0] != '\0'){
|
||||
includeNewItem = false;
|
||||
listItem = &_listItems[_listItemsCount];
|
||||
safe_strncpy(listItem->name, language_get_string(2718), sizeof(listItem->name));
|
||||
memset(listItem->path, '\0', sizeof(listItem->path));
|
||||
listItem->type = TYPE_UP;
|
||||
_listItemsCount++;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Get parent directory
|
||||
int directoryLength = strlen(directory);
|
||||
char separator = platform_get_path_separator();
|
||||
for(i = directoryLength-2; i>=0; i--)
|
||||
{
|
||||
if(directory[i]==separator)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (includeNewItem) {
|
||||
listItem = &_listItems[_listItemsCount];
|
||||
safe_strncpy(listItem->name, language_get_string(2719), sizeof(listItem->name));
|
||||
listItem->path[0] = '\0';
|
||||
listItem->type = TYPE_NEW_FILE;
|
||||
_listItemsCount++;
|
||||
}
|
||||
|
||||
int sortStartIndex = _listItemsCount;
|
||||
|
||||
if (directory[0] != '\0'){
|
||||
safe_strncpy(_parentDirectory, directory, sizeof(_parentDirectory));
|
||||
_parentDirectory[i+1] = '\0';
|
||||
if(_parentDirectory[0]=='\0' && platform_get_drives()==0)
|
||||
w->disabled_widgets |= (1<<WIDX_UP);
|
||||
else
|
||||
w->disabled_widgets &= ~(1<<WIDX_UP);
|
||||
w->disabled_widgets &= ~(1<<WIDX_NEW);
|
||||
file_info fileInfo;
|
||||
int fileEnumHandle;
|
||||
const char *src;
|
||||
char *dst;
|
||||
char *last_dot_in_filename;
|
||||
char subDir[MAX_PATH];
|
||||
|
||||
fileEnumHandle = platform_enumerate_directories_begin(directory);
|
||||
while (platform_enumerate_directories_next(fileEnumHandle, subDir)){
|
||||
if (listItemCapacity <= _listItemsCount) {
|
||||
|
@ -690,7 +701,6 @@ static void window_loadsave_populate_list(int includeNewItem, bool browsable, co
|
|||
platform_enumerate_files_end(fileEnumHandle);
|
||||
window_loadsave_sort_list(sortStartIndex, _listItemsCount - 1);
|
||||
|
||||
sortStartIndex = _listItemsCount;
|
||||
fileEnumHandle = platform_enumerate_files_begin(filter);
|
||||
while (platform_enumerate_files_next(fileEnumHandle, &fileInfo)) {
|
||||
if (listItemCapacity <= _listItemsCount) {
|
||||
|
@ -718,27 +728,7 @@ static void window_loadsave_populate_list(int includeNewItem, bool browsable, co
|
|||
_listItemsCount++;
|
||||
}
|
||||
platform_enumerate_files_end(fileEnumHandle);
|
||||
} else {
|
||||
for (int x = 0; x < 32; x++){
|
||||
if (listItemCapacity <= _listItemsCount) {
|
||||
listItemCapacity *= 2;
|
||||
_listItems = realloc(_listItems, listItemCapacity * sizeof(loadsave_list_item));
|
||||
}
|
||||
|
||||
if (platform_get_drives() & (1 << (x))){
|
||||
listItem = &_listItems[_listItemsCount];
|
||||
memset(listItem->path, '\0', MAX_PATH);
|
||||
listItem->path[0] = 'A' + x;
|
||||
listItem->path[1] = ':';
|
||||
listItem->path[2] = platform_get_path_separator();
|
||||
strcpy(listItem->name, listItem->path);
|
||||
listItem->type = TYPE_DIRECTORY;
|
||||
_listItemsCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
window_loadsave_sort_list(sortStartIndex, _listItemsCount - 1);
|
||||
}
|
||||
|
||||
static void window_loadsave_invoke_callback(int result)
|
||||
|
|
Loading…
Reference in New Issue