mirror of https://github.com/OpenTTD/OpenTTD.git
(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)
This commit is contained in:
parent
aa55bc1559
commit
7746c4722b
10
console.c
10
console.c
|
@ -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 @@ void IConsoleSwitch(void)
|
|||
_iconsole_win->height = _screen.height / 3;
|
||||
_iconsole_win->width = _screen.width;
|
||||
_iconsole_mode = ICONSOLE_OPENED;
|
||||
SETBIT(_no_scroll, SCROLL_CON);
|
||||
break;
|
||||
case ICONSOLE_OPENED:
|
||||
DeleteWindowById(WC_CONSOLE, 0);
|
||||
_iconsole_win = NULL;
|
||||
_iconsole_mode = ICONSOLE_CLOSED;
|
||||
break;
|
||||
case ICONSOLE_FULL:
|
||||
case ICONSOLE_OPENED: case ICONSOLE_FULL:
|
||||
DeleteWindowById(WC_CONSOLE, 0);
|
||||
_iconsole_win = NULL;
|
||||
_iconsole_mode = ICONSOLE_CLOSED;
|
||||
CLRBIT(_no_scroll, SCROLL_CON);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
2
gui.h
2
gui.h
|
@ -64,7 +64,7 @@ void PlaceProc_LevelLand(uint tile);
|
|||
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);
|
||||
|
|
39
main_gui.c
39
main_gui.c
|
@ -2204,18 +2204,6 @@ static void StatusBarWndProc(Window *w, WindowEvent *e)
|
|||
}
|
||||
}
|
||||
|
||||
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 @@ static WindowDesc _main_status_desc = {
|
|||
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) {
|
||||
|
|
26
misc_gui.c
26
misc_gui.c
|
@ -804,7 +804,7 @@ bool InsertTextBufferChar(Textbuf *tb, byte key)
|
|||
{
|
||||
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 @@ press_ok:;
|
|||
|
||||
case WE_CREATE:
|
||||
closed = false;
|
||||
_editbox_win = w;
|
||||
break;
|
||||
|
||||
case WE_DESTROY:
|
||||
|
@ -1009,7 +1008,7 @@ press_ok:;
|
|||
}
|
||||
}
|
||||
_query_string_active = false;
|
||||
_editbox_win = NULL;
|
||||
CLRBIT(_no_scroll, SCROLL_EDIT);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1046,6 +1045,7 @@ void ShowQueryString(StringID str, StringID caption, uint maxlen, uint maxwidth,
|
|||
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 @@ static void SaveLoadDlgWndProc(Window *w, WindowEvent *e)
|
|||
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 @@ static void SaveLoadDlgWndProc(Window *w, WindowEvent *e)
|
|||
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 @@ void ShowSaveLoadDialog(int mode)
|
|||
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 @@ void ShowSaveLoadDialog(int mode)
|
|||
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)
|
||||
|
|
38
ttd.c
38
ttd.c
|
@ -1036,7 +1036,43 @@ static void DoAutosave(void)
|
|||
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)
|
||||
{
|
||||
|
|
10
ttd.h
10
ttd.h
|
@ -517,6 +517,16 @@ enum {
|
|||
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"
|
||||
|
||||
|
|
2
window.c
2
window.c
|
@ -669,7 +669,6 @@ Window *FindWindowFromPt(int x, int y)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
void InitWindowSystem(void)
|
||||
{
|
||||
IConsoleClose();
|
||||
|
@ -677,6 +676,7 @@ void InitWindowSystem(void)
|
|||
_last_window = _windows;
|
||||
memset(_viewports, 0, sizeof(_viewports));
|
||||
_active_viewports = 0;
|
||||
_no_scroll = 0;
|
||||
}
|
||||
|
||||
static void DecreaseWindowCounters(void)
|
||||
|
|
Loading…
Reference in New Issue