mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-16 00:12:51 +00:00
(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
5cb74cb049
commit
7656c683cf
10
console.c
10
console.c
@ -24,6 +24,7 @@
|
|||||||
#define ICON_MAX_ALIAS_LINES 40
|
#define ICON_MAX_ALIAS_LINES 40
|
||||||
|
|
||||||
// ** main console ** //
|
// ** main console ** //
|
||||||
|
static Window *_iconsole_win; // Pointer to console window
|
||||||
static bool _iconsole_inited;
|
static bool _iconsole_inited;
|
||||||
static char* _iconsole_buffer[ICON_BUFFER + 1];
|
static char* _iconsole_buffer[ICON_BUFFER + 1];
|
||||||
static uint16 _iconsole_cbuffer[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->height = _screen.height / 3;
|
||||||
_iconsole_win->width = _screen.width;
|
_iconsole_win->width = _screen.width;
|
||||||
_iconsole_mode = ICONSOLE_OPENED;
|
_iconsole_mode = ICONSOLE_OPENED;
|
||||||
|
SETBIT(_no_scroll, SCROLL_CON);
|
||||||
break;
|
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);
|
DeleteWindowById(WC_CONSOLE, 0);
|
||||||
_iconsole_win = NULL;
|
_iconsole_win = NULL;
|
||||||
_iconsole_mode = ICONSOLE_CLOSED;
|
_iconsole_mode = ICONSOLE_CLOSED;
|
||||||
|
CLRBIT(_no_scroll, SCROLL_CON);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
#ifndef CONSOLE_H
|
#ifndef CONSOLE_H
|
||||||
#define CONSOLE_H
|
#define CONSOLE_H
|
||||||
|
|
||||||
/* Pointer to console window */
|
|
||||||
VARDEF Window *_iconsole_win;
|
|
||||||
|
|
||||||
// ** console parser ** //
|
// ** console parser ** //
|
||||||
|
|
||||||
typedef enum _iconsole_var_types {
|
typedef enum _iconsole_var_types {
|
||||||
|
2
gui.h
2
gui.h
@ -64,7 +64,7 @@ void PlaceProc_LevelLand(uint tile);
|
|||||||
void ShowTerraformToolbar(void);
|
void ShowTerraformToolbar(void);
|
||||||
|
|
||||||
/* misc_gui.c */
|
/* misc_gui.c */
|
||||||
VARDEF Window *_editbox_win; // pointer to querystringwindow to prevent scrolling when focussed
|
|
||||||
void PlaceLandBlockInfo(void);
|
void PlaceLandBlockInfo(void);
|
||||||
void ShowAboutWindow(void);
|
void ShowAboutWindow(void);
|
||||||
void ShowBuildTreesToolbar(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[] = {
|
static const Widget _main_status_widgets[] = {
|
||||||
{ WWT_IMGBTN, RESIZE_NONE, 14, 0, 139, 0, 11, 0x0, STR_NULL},
|
{ 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},
|
{ 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
|
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);
|
extern void DebugProc(int i);
|
||||||
|
|
||||||
static void MainWindowWndProc(Window *w, WindowEvent *e) {
|
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);
|
const byte charwidth = GetCharacterWidth(key);
|
||||||
if (tb->length < tb->maxlength && (tb->maxwidth == 0 || tb->width + charwidth <= tb->maxwidth)) {
|
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->buf[tb->caretpos] = key;
|
||||||
tb->length++;
|
tb->length++;
|
||||||
tb->width += charwidth;
|
tb->width += charwidth;
|
||||||
@ -995,7 +995,6 @@ press_ok:;
|
|||||||
|
|
||||||
case WE_CREATE:
|
case WE_CREATE:
|
||||||
closed = false;
|
closed = false;
|
||||||
_editbox_win = w;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WE_DESTROY:
|
case WE_DESTROY:
|
||||||
@ -1009,7 +1008,7 @@ press_ok:;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
_query_string_active = false;
|
_query_string_active = false;
|
||||||
_editbox_win = NULL;
|
CLRBIT(_no_scroll, SCROLL_EDIT);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1046,6 +1045,7 @@ void ShowQueryString(StringID str, StringID caption, uint maxlen, uint maxwidth,
|
|||||||
DeleteWindowById(WC_SAVELOAD, 0);
|
DeleteWindowById(WC_SAVELOAD, 0);
|
||||||
|
|
||||||
w = AllocateWindowDesc(&_query_string_desc);
|
w = AllocateWindowDesc(&_query_string_desc);
|
||||||
|
SETBIT(_no_scroll, SCROLL_EDIT);
|
||||||
|
|
||||||
GetString(_edit_str_buf, str);
|
GetString(_edit_str_buf, str);
|
||||||
_edit_str_buf[realmaxlen] = '\0';
|
_edit_str_buf[realmaxlen] = '\0';
|
||||||
@ -1303,8 +1303,10 @@ static void SaveLoadDlgWndProc(Window *w, WindowEvent *e)
|
|||||||
FiosDelete(WP(w,querystr_d).text.buf);
|
FiosDelete(WP(w,querystr_d).text.buf);
|
||||||
SetWindowDirty(w);
|
SetWindowDirty(w);
|
||||||
BuildFileList();
|
BuildFileList();
|
||||||
if (_saveload_mode == SLD_SAVE_GAME)
|
if (_saveload_mode == SLD_SAVE_GAME) {
|
||||||
GenerateFileName(); /* Reset file name to current date */
|
GenerateFileName(); /* Reset file name to current date */
|
||||||
|
UpdateTextBufferSize(&WP(w, querystr_d).text);
|
||||||
|
}
|
||||||
} else if (HASBIT(w->click_state, 11)) { /* Save button clicked */
|
} else if (HASBIT(w->click_state, 11)) { /* Save button clicked */
|
||||||
_switch_mode = SM_SAVE;
|
_switch_mode = SM_SAVE;
|
||||||
FiosMakeSavegameName(_file_to_saveload.name, WP(w,querystr_d).text.buf);
|
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);
|
DoCommandP(0, 0, 0, NULL, CMD_PAUSE);
|
||||||
_query_string_active = false;
|
_query_string_active = false;
|
||||||
FiosFreeSavegameList();
|
FiosFreeSavegameList();
|
||||||
|
CLRBIT(_no_scroll, SCROLL_SAVE);
|
||||||
break;
|
break;
|
||||||
case WE_RESIZE: {
|
case WE_RESIZE: {
|
||||||
/* Widget 2 and 3 have to go with halve speed, make it so obiwan */
|
/* 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);
|
DeleteWindowById(WC_SAVELOAD, 0);
|
||||||
|
|
||||||
_saveload_mode = mode;
|
_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 = AllocateWindowDesc(_saveload_dialogs[mode]);
|
||||||
w->vscroll.cap = 24;
|
w->vscroll.cap = 24;
|
||||||
@ -1400,11 +1413,6 @@ void ShowSaveLoadDialog(int mode)
|
|||||||
WP(w,querystr_d).text.buf = _edit_str_buf;
|
WP(w,querystr_d).text.buf = _edit_str_buf;
|
||||||
UpdateTextBufferSize(&WP(w, querystr_d).text);
|
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
|
// pause is only used in single-player, non-editor mode, non-menu mode. It
|
||||||
// will be unpaused in the WE_DESTROY event handler.
|
// will be unpaused in the WE_DESTROY event handler.
|
||||||
if(_game_mode != GM_MENU && !_networking && _game_mode != GM_EDITOR)
|
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);
|
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)
|
void GameLoop(void)
|
||||||
{
|
{
|
||||||
|
10
ttd.h
10
ttd.h
@ -517,6 +517,16 @@ enum {
|
|||||||
MAX_SCREEN_HEIGHT = 1200,
|
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 "functions.h"
|
||||||
#include "variables.h"
|
#include "variables.h"
|
||||||
|
|
||||||
|
2
window.c
2
window.c
@ -669,7 +669,6 @@ Window *FindWindowFromPt(int x, int y)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void InitWindowSystem(void)
|
void InitWindowSystem(void)
|
||||||
{
|
{
|
||||||
IConsoleClose();
|
IConsoleClose();
|
||||||
@ -677,6 +676,7 @@ void InitWindowSystem(void)
|
|||||||
_last_window = _windows;
|
_last_window = _windows;
|
||||||
memset(_viewports, 0, sizeof(_viewports));
|
memset(_viewports, 0, sizeof(_viewports));
|
||||||
_active_viewports = 0;
|
_active_viewports = 0;
|
||||||
|
_no_scroll = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void DecreaseWindowCounters(void)
|
static void DecreaseWindowCounters(void)
|
||||||
|
Loading…
Reference in New Issue
Block a user