summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--misc_gui.c26
-rw-r--r--network_gui.c55
-rw-r--r--openttd.c13
3 files changed, 34 insertions, 60 deletions
diff --git a/misc_gui.c b/misc_gui.c
index 0aa0140ab..eb15a7069 100644
--- a/misc_gui.c
+++ b/misc_gui.c
@@ -1163,7 +1163,7 @@ void BuildFileList(void)
_fios_list = FiosGetSavegameList(&_fios_num, _saveload_mode);
}
-static void DrawFiosTexts(void)
+static void DrawFiosTexts(uint maxw)
{
static const char *path = NULL;
static StringID str = STR_4006_UNABLE_TO_READ_DRIVE;
@@ -1176,7 +1176,7 @@ static void DrawFiosTexts(void)
if (str != STR_4006_UNABLE_TO_READ_DRIVE) SetDParam(0, tot);
DrawString(2, 37, str, 0);
- DoDrawString(path, 2, 27, 16);
+ DoDrawStringTruncated(path, 2, 27, 16, 5);
}
static void MakeSortedSaveGameList(void)
@@ -1231,7 +1231,7 @@ static void SaveLoadDlgWndProc(Window *w, WindowEvent *e)
SetVScrollCount(w, _fios_num);
DrawWindowWidgets(w);
- DrawFiosTexts();
+ DrawFiosTexts(w->width);
if (_savegame_sort_dirty) {
_savegame_sort_dirty = false;
@@ -1245,7 +1245,7 @@ static void SaveLoadDlgWndProc(Window *w, WindowEvent *e)
pos = w->vscroll.pos;
while (pos < _fios_num) {
item = _fios_list + pos;
- DoDrawString(item->title[0] ? item->title : item->name, 4, y, _fios_colors[item->type] );
+ DoDrawString(item->title, 4, y, _fios_colors[item->type]);
pos++;
y+=10;
if (y >= w->vscroll.cap*10+w->widget[6].top+1)
@@ -1282,19 +1282,17 @@ static void SaveLoadDlgWndProc(Window *w, WindowEvent *e)
file = _fios_list + y;
if ((name = FiosBrowseTo(file)) != NULL) {
- if (_saveload_mode == SLD_LOAD_GAME) {
- _switch_mode = SM_LOAD;
- SetFiosType(file->type);
- strcpy(_file_to_saveload.name, name);
- DeleteWindow(w);
- } else if (_saveload_mode == SLD_LOAD_SCENARIO) {
- _switch_mode = (_game_mode == GM_MENU) ? SM_LOAD : SM_LOAD_SCENARIO;
+ if (_saveload_mode == SLD_LOAD_GAME || _saveload_mode == SLD_LOAD_SCENARIO) {
+ _switch_mode = (_game_mode == GM_EDITOR) ? SM_LOAD_SCENARIO : SM_LOAD;
+
SetFiosType(file->type);
- strcpy(_file_to_saveload.name, name);
+ ttd_strlcpy(_file_to_saveload.name, name, sizeof(_file_to_saveload.name));
+ ttd_strlcpy(_file_to_saveload.title, file->title, sizeof(_file_to_saveload.title));
+
DeleteWindow(w);
} else {
// SLD_SAVE_GAME, SLD_SAVE_SCENARIO copy clicked name to editbox
- ttd_strlcpy(WP(w, querystr_d).text.buf, (file->title[0] != '\0') ? file->title : file->name, WP(w, querystr_d).text.maxlength);
+ ttd_strlcpy(WP(w, querystr_d).text.buf, file->title, WP(w, querystr_d).text.maxlength);
UpdateTextBufferSize(&WP(w, querystr_d).text);
InvalidateWidget(w, 9);
}
@@ -1485,7 +1483,7 @@ static void SelectScenarioWndProc(Window *w, WindowEvent *e) {
pos = w->vscroll.pos;
while (pos < _fios_num) {
item = _fios_list + pos;
- DoDrawString(item->title[0] ? item->title : item->name, 4, y, _fios_colors[item->type] );
+ DoDrawString(item->title, 4, y, _fios_colors[item->type] );
pos++;
y+=10;
if (y >= w->vscroll.cap*10+list_start)
diff --git a/network_gui.c b/network_gui.c
index 5c7daa06f..cccba0d19 100644
--- a/network_gui.c
+++ b/network_gui.c
@@ -53,30 +53,9 @@ enum {
static NetworkGameList *_selected_item = NULL;
static int8 _selected_company_item = -1;
-// Truncates a string to max_width (via GetStringWidth) and adds 3 dots
-// at the end of the name.
-static void NetworkTruncateString(char *name, const int max_width)
-{
- char temp[NETWORK_NAME_LENGTH];
- char internal_name[NETWORK_NAME_LENGTH];
-
- ttd_strlcpy(internal_name, name, sizeof(internal_name));
-
- if (GetStringWidth(internal_name) > max_width) {
- // Servername is too long, trunc it!
- snprintf(temp, sizeof(temp), "%s...", internal_name);
- // Continue to delete 1 char of the string till it is in range
- while (GetStringWidth(temp) > max_width) {
- internal_name[strlen(internal_name) - 1] = '\0';
- snprintf(temp, sizeof(temp), "%s...", internal_name);
- }
- ttd_strlcpy(name, temp, sizeof(temp));
- }
-}
-
extern const char _openttd_revision[];
-static FiosItem *selected_map = NULL; // to highlight slected map
+static FiosItem *_selected_map = NULL; // to highlight slected map
// called when a new server is found on the network
void UpdateNetworkGameWindow(bool unselect)
@@ -132,7 +111,6 @@ static void NetworkGameWindowWndProc(Window *w, WindowEvent *e)
uint16 y = NET_PRC__OFFSET_TOP_WIDGET + 3;
int32 n = 0;
int32 pos = w->vscroll.pos;
- char servername[NETWORK_NAME_LENGTH];
const NetworkGameList *cur_item = _network_game_list;
while (pos > 0 && cur_item != NULL) {
@@ -148,9 +126,8 @@ static void NetworkGameWindowWndProc(Window *w, WindowEvent *e)
if (cur_item == sel)
GfxFillRect(11, y - 2, 218, y + 9, 10); // show highlighted item with a different colour
- snprintf(servername, sizeof(servername), "%s", cur_item->info.server_name);
- NetworkTruncateString(servername, 110);
- DoDrawString(servername, 15, y, 16); // server name
+ SetDParamStr(0, cur_item->info.server_name);
+ DrawStringTruncated(15, y, STR_02BD, 16, 110);
SetDParam(0, cur_item->info.clients_on);
SetDParam(1, cur_item->info.clients_max);
@@ -192,10 +169,10 @@ static void NetworkGameWindowWndProc(Window *w, WindowEvent *e)
SetDParamStr(0, sel->info.server_name);
- DrawStringMultiCenter(365, 42, STR_ORANGE, 2); // game name
+ DrawStringCenteredTruncated(365, 42, STR_ORANGE, 16, 220); // game name
SetDParamStr(0, sel->info.map_name);
- DrawStringMultiCenter(365, 54, STR_02BD, 2); // map name
+ DrawStringCenteredTruncated(365, 54, STR_02BD, 16, 220); // map name
SetDParam(0, sel->info.clients_on);
SetDParam(1, sel->info.clients_max);
@@ -495,11 +472,11 @@ static void NetworkStartServerWindowWndProc(Window *w, WindowEvent *e)
pos = w->vscroll.pos;
while (pos < _fios_num + 1) {
item = _fios_list + pos - 1;
- if (item == selected_map || (pos == 0 && selected_map == NULL))
+ if (item == _selected_map || (pos == 0 && _selected_map == NULL))
GfxFillRect(11, y - 1, 259, y + 10, 155); // show highlighted item with a different colour
if (pos == 0) DrawString(14, y, STR_4010_GENERATE_RANDOM_NEW_GAME, 9);
- else DoDrawString(item->title[0] ? item->title : item->name, 14, y, _fios_colors[item->type] );
+ else DoDrawString(item->title, 14, y, _fios_colors[item->type] );
pos++;
y += NSSWND_ROWSIZE;
@@ -521,8 +498,8 @@ static void NetworkStartServerWindowWndProc(Window *w, WindowEvent *e)
int y = (e->click.pt.y - NSSWND_START) / NSSWND_ROWSIZE;
if ((y += w->vscroll.pos) >= w->vscroll.count)
return;
- if (y == 0) selected_map = NULL;
- else selected_map = _fios_list + y-1;
+
+ _selected_map = (y == 0) ? NULL : _fios_list + y - 1;
SetWindowDirty(w);
} break;
case 7: case 8: /* Connection type */
@@ -538,14 +515,15 @@ static void NetworkStartServerWindowWndProc(Window *w, WindowEvent *e)
_is_network_server = true;
ttd_strlcpy(_network_server_name, WP(w, querystr_d).text.buf, sizeof(_network_server_name));
UpdateTextBufferSize(&WP(w, querystr_d).text);
- if (selected_map == NULL) { // start random new game
+ if (_selected_map == NULL) { // start random new game
GenRandomNewGame(Random(), InteractiveRandom());
} else { // load a scenario
- char *name;
- if ((name = FiosBrowseTo(selected_map)) != NULL) {
- SetFiosType(selected_map->type);
- strcpy(_file_to_saveload.name, name);
- snprintf(_network_game_info.map_name, sizeof(_network_game_info.map_name), "Loaded scenario");
+ char *name = FiosBrowseTo(_selected_map);
+ if (name != NULL) {
+ SetFiosType(_selected_map->type);
+ ttd_strlcpy(_file_to_saveload.name, name, sizeof(_file_to_saveload.name));
+ ttd_strlcpy(_file_to_saveload.title, _selected_map->title, sizeof(_file_to_saveload.title));
+
DeleteWindow(w);
StartScenarioEditor(Random(), InteractiveRandom());
}
@@ -555,7 +533,6 @@ static void NetworkStartServerWindowWndProc(Window *w, WindowEvent *e)
_is_network_server = true;
ttd_strlcpy(_network_server_name, WP(w, querystr_d).text.buf, sizeof(_network_server_name));
UpdateTextBufferSize(&WP(w, querystr_d).text);
- snprintf(_network_game_info.map_name, sizeof(_network_game_info.map_name), "Loaded game");
/* XXX - WC_NETWORK_WINDOW should stay, but if it stays, it gets
* copied all the elements of 'load game' and upon closing that, it segfaults */
DeleteWindowById(WC_NETWORK_WINDOW, 0);
diff --git a/openttd.c b/openttd.c
index 8a88789ad..8cef88613 100644
--- a/openttd.c
+++ b/openttd.c
@@ -907,12 +907,16 @@ void SwitchMode(int new_mode)
case SM_NEWGAME: /* New Game --> 'Random game' */
#ifdef ENABLE_NETWORK
if (_network_server)
- snprintf(_network_game_info.map_name, 40, "Random");
+ snprintf(_network_game_info.map_name, NETWORK_NAME_LENGTH, "Random Map");
#endif /* ENABLE_NETWORK */
MakeNewGame();
break;
case SM_START_SCENARIO: /* New Game --> Choose one of the preset scenarios */
+ #ifdef ENABLE_NETWORK
+ if (_network_server)
+ snprintf(_network_game_info.map_name, NETWORK_NAME_LENGTH, "%s (Loaded scenario)", _file_to_saveload.title);
+ #endif /* ENABLE_NETWORK */
StartScenario();
break;
@@ -928,7 +932,7 @@ void SwitchMode(int new_mode)
DoCommandP(0, 0, 0, NULL, CMD_PAUSE); // decrease pause counter (was increased from opening load dialog)
#ifdef ENABLE_NETWORK
if (_network_server)
- snprintf(_network_game_info.map_name, 40, "Loaded game");
+ snprintf(_network_game_info.map_name, NETWORK_NAME_LENGTH, "%s (Loaded game)", _file_to_saveload.title);
#endif /* ENABLE_NETWORK */
}
break;
@@ -950,11 +954,6 @@ void SwitchMode(int new_mode)
_generating_world = false;
// delete all stations owned by a player
DeleteAllPlayerStations();
-
-#ifdef ENABLE_NETWORK
- if (_network_server)
- snprintf(_network_game_info.map_name, 40, "Loaded scenario");
-#endif /* ENABLE_NETWORK */
} else
ShowErrorMessage(INVALID_STRING_ID, STR_4009_GAME_LOAD_FAILED, 0, 0);