(svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
--- a/console.c Tue Feb 22 14:37:52 2005 +0000
+++ b/console.c Tue Feb 22 14:52:20 2005 +0000
@@ -24,6 +24,7 @@
#define ICON_MAX_ALIAS_LINES 40
// ** main console ** //
+static Window *_iconsole_win; // Pointer to console window
static bool _iconsole_inited;
static char* _iconsole_buffer[ICON_BUFFER + 1];
static uint16 _iconsole_cbuffer[ICON_BUFFER + 1];
@@ -290,16 +291,13 @@
_iconsole_win->height = _screen.height / 3;
_iconsole_win->width = _screen.width;
_iconsole_mode = ICONSOLE_OPENED;
+ SETBIT(_no_scroll, SCROLL_CON);
break;
- case ICONSOLE_OPENED:
+ case ICONSOLE_OPENED: case ICONSOLE_FULL:
DeleteWindowById(WC_CONSOLE, 0);
_iconsole_win = NULL;
_iconsole_mode = ICONSOLE_CLOSED;
- break;
- case ICONSOLE_FULL:
- DeleteWindowById(WC_CONSOLE, 0);
- _iconsole_win = NULL;
- _iconsole_mode = ICONSOLE_CLOSED;
+ CLRBIT(_no_scroll, SCROLL_CON);
break;
}
--- a/console.h Tue Feb 22 14:37:52 2005 +0000
+++ b/console.h Tue Feb 22 14:52:20 2005 +0000
@@ -1,9 +1,6 @@
#ifndef CONSOLE_H
#define CONSOLE_H
-/* Pointer to console window */
-VARDEF Window *_iconsole_win;
-
// ** console parser ** //
typedef enum _iconsole_var_types {
--- a/gui.h Tue Feb 22 14:37:52 2005 +0000
+++ b/gui.h Tue Feb 22 14:52:20 2005 +0000
@@ -64,7 +64,7 @@
void ShowTerraformToolbar(void);
/* misc_gui.c */
-VARDEF Window *_editbox_win; // pointer to querystringwindow to prevent scrolling when focussed
+
void PlaceLandBlockInfo(void);
void ShowAboutWindow(void);
void ShowBuildTreesToolbar(void);
--- a/main_gui.c Tue Feb 22 14:37:52 2005 +0000
+++ b/main_gui.c Tue Feb 22 14:52:20 2005 +0000
@@ -2204,18 +2204,6 @@
}
}
-static void ScrollMainViewport(int x, int y)
-{
- if (_game_mode != GM_MENU) {
- Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
- assert(w);
-
- WP(w,vp_d).scrollpos_x += x << w->viewport->zoom;
- WP(w,vp_d).scrollpos_y += y << w->viewport->zoom;
- }
-}
-
-
static const Widget _main_status_widgets[] = {
{ WWT_IMGBTN, RESIZE_NONE, 14, 0, 139, 0, 11, 0x0, STR_NULL},
{ WWT_PUSHIMGBTN, RESIZE_NONE, 14, 140, 499, 0, 11, 0x0, STR_02B7_SHOW_LAST_MESSAGE_OR_NEWS},
@@ -2231,33 +2219,6 @@
StatusBarWndProc
};
-static const int8 scrollamt[16][2] = {
- { 0, 0},
- {-2, 0}, // 1:left
- { 0,-2}, // 2:up
- {-2,-1}, // 3:left + up
- { 2, 0}, // 4:right
- { 0, 0}, // 5:left + right
- { 2,-1}, // 6:right + up
- { 0,-2}, // 7:left + right + up = up
- { 0 ,2}, // 8:down
- {-2 ,1}, // 9:down+left
- { 0, 0}, // 10:impossible
- {-2, 0}, // 11:left + up + down = left
- { 2, 1}, // 12:down+right
- { 0, 2}, // 13:left + right + down = down
- { 0,-2}, // 14:left + right + up = up
- { 0, 0}, // 15:impossible
-};
-
-void HandleKeyScrolling(void)
-{
- if (_dirkeys && _iconsole_win == NULL && _editbox_win == NULL) {
- int factor = _shift_pressed ? 50 : 10;
- ScrollMainViewport(scrollamt[_dirkeys][0] * factor, scrollamt[_dirkeys][1] * factor);
- }
-}
-
extern void DebugProc(int i);
static void MainWindowWndProc(Window *w, WindowEvent *e) {
--- a/misc_gui.c Tue Feb 22 14:37:52 2005 +0000
+++ b/misc_gui.c Tue Feb 22 14:52:20 2005 +0000
@@ -804,7 +804,7 @@
{
const byte charwidth = GetCharacterWidth(key);
if (tb->length < tb->maxlength && (tb->maxwidth == 0 || tb->width + charwidth <= tb->maxwidth)) {
- memmove(tb->buf + tb->caretpos + 1, tb->buf + tb->caretpos, tb->length - tb->caretpos);
+ memmove(tb->buf + tb->caretpos + 1, tb->buf + tb->caretpos, (tb->length - tb->caretpos) + 1);
tb->buf[tb->caretpos] = key;
tb->length++;
tb->width += charwidth;
@@ -995,7 +995,6 @@
case WE_CREATE:
closed = false;
- _editbox_win = w;
break;
case WE_DESTROY:
@@ -1009,7 +1008,7 @@
}
}
_query_string_active = false;
- _editbox_win = NULL;
+ CLRBIT(_no_scroll, SCROLL_EDIT);
break;
}
}
@@ -1046,6 +1045,7 @@
DeleteWindowById(WC_SAVELOAD, 0);
w = AllocateWindowDesc(&_query_string_desc);
+ SETBIT(_no_scroll, SCROLL_EDIT);
GetString(_edit_str_buf, str);
_edit_str_buf[realmaxlen] = '\0';
@@ -1303,8 +1303,10 @@
FiosDelete(WP(w,querystr_d).text.buf);
SetWindowDirty(w);
BuildFileList();
- if (_saveload_mode == SLD_SAVE_GAME)
+ if (_saveload_mode == SLD_SAVE_GAME) {
GenerateFileName(); /* Reset file name to current date */
+ UpdateTextBufferSize(&WP(w, querystr_d).text);
+ }
} else if (HASBIT(w->click_state, 11)) { /* Save button clicked */
_switch_mode = SM_SAVE;
FiosMakeSavegameName(_file_to_saveload.name, WP(w,querystr_d).text.buf);
@@ -1319,6 +1321,7 @@
DoCommandP(0, 0, 0, NULL, CMD_PAUSE);
_query_string_active = false;
FiosFreeSavegameList();
+ CLRBIT(_no_scroll, SCROLL_SAVE);
break;
case WE_RESIZE: {
/* Widget 2 and 3 have to go with halve speed, make it so obiwan */
@@ -1387,6 +1390,16 @@
DeleteWindowById(WC_SAVELOAD, 0);
_saveload_mode = mode;
+ SETBIT(_no_scroll, SCROLL_SAVE);
+
+ switch (mode) {
+ case SLD_SAVE_GAME:
+ GenerateFileName();
+ break;
+ case SLD_SAVE_SCENARIO:
+ strcpy(_edit_str_buf, "UNNAMED");
+ break;
+ }
w = AllocateWindowDesc(_saveload_dialogs[mode]);
w->vscroll.cap = 24;
@@ -1400,11 +1413,6 @@
WP(w,querystr_d).text.buf = _edit_str_buf;
UpdateTextBufferSize(&WP(w, querystr_d).text);
- if (mode == SLD_SAVE_GAME) {
- GenerateFileName();
- } else if (mode == SLD_SAVE_SCENARIO)
- strcpy(_edit_str_buf, "UNNAMED");
-
// pause is only used in single-player, non-editor mode, non-menu mode. It
// will be unpaused in the WE_DESTROY event handler.
if(_game_mode != GM_MENU && !_networking && _game_mode != GM_EDITOR)
--- a/ttd.c Tue Feb 22 14:37:52 2005 +0000
+++ b/ttd.c Tue Feb 22 14:52:20 2005 +0000
@@ -1036,7 +1036,43 @@
ShowErrorMessage(INVALID_STRING_ID, STR_AUTOSAVE_FAILED, 0, 0);
}
-extern void HandleKeyScrolling(void);
+static void ScrollMainViewport(int x, int y)
+{
+ if (_game_mode != GM_MENU) {
+ Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
+ assert(w);
+
+ WP(w,vp_d).scrollpos_x += x << w->viewport->zoom;
+ WP(w,vp_d).scrollpos_y += y << w->viewport->zoom;
+ }
+}
+
+static const int8 scrollamt[16][2] = {
+ { 0, 0},
+ {-2, 0}, // 1:left
+ { 0,-2}, // 2:up
+ {-2,-1}, // 3:left + up
+ { 2, 0}, // 4:right
+ { 0, 0}, // 5:left + right
+ { 2,-1}, // 6:right + up
+ { 0,-2}, // 7:left + right + up = up
+ { 0 ,2}, // 8:down
+ {-2 ,1}, // 9:down+left
+ { 0, 0}, // 10:impossible
+ {-2, 0}, // 11:left + up + down = left
+ { 2, 1}, // 12:down+right
+ { 0, 2}, // 13:left + right + down = down
+ { 0,-2}, // 14:left + right + up = up
+ { 0, 0}, // 15:impossible
+};
+
+static void HandleKeyScrolling(void)
+{
+ if (_dirkeys && !_no_scroll) {
+ int factor = _shift_pressed ? 50 : 10;
+ ScrollMainViewport(scrollamt[_dirkeys][0] * factor, scrollamt[_dirkeys][1] * factor);
+ }
+}
void GameLoop(void)
{
--- a/ttd.h Tue Feb 22 14:37:52 2005 +0000
+++ b/ttd.h Tue Feb 22 14:52:20 2005 +0000
@@ -517,6 +517,16 @@
MAX_SCREEN_HEIGHT = 1200,
};
+/* In certain windows you navigate with the arrow keys. Do not scroll the
+ * gameview when here. Bitencoded variable that only allows scrolling if all
+ * elements are zero */
+enum {
+ SCROLL_CON = 0,
+ SCROLL_EDIT = 1,
+ SCROLL_SAVE = 2,
+};
+VARDEF byte _no_scroll;
+
#include "functions.h"
#include "variables.h"
--- a/window.c Tue Feb 22 14:37:52 2005 +0000
+++ b/window.c Tue Feb 22 14:52:20 2005 +0000
@@ -669,7 +669,6 @@
return NULL;
}
-
void InitWindowSystem(void)
{
IConsoleClose();
@@ -677,6 +676,7 @@
_last_window = _windows;
memset(_viewports, 0, sizeof(_viewports));
_active_viewports = 0;
+ _no_scroll = 0;
}
static void DecreaseWindowCounters(void)