added quit_prompt to save_prompt; proper case handling except save operation

This commit is contained in:
anyc 2014-05-24 01:00:58 +02:00
parent a83c3141a7
commit 88a0359cf6
6 changed files with 165 additions and 69 deletions

View File

@ -234,7 +234,8 @@ void osinterface_process_messages()
while (SDL_PollEvent(&e)) {
switch (e.type) {
case SDL_QUIT:
rct2_finish();
// rct2_finish();
rct2_quit();
break;
case SDL_WINDOWEVENT:
if (e.window.event == SDL_WINDOWEVENT_SIZE_CHANGED)

View File

@ -132,6 +132,11 @@ void rct2_finish()
_finished = 1;
}
void rct2_quit() {
RCT2_GLOBAL(RCT2_ADDRESS_SAVE_PROMPT_MODE, uint16) = PM_QUIT;
window_save_prompt_open();
}
void rct2_init()
{
RCT2_GLOBAL(0x00F663AC, int) = 0;

View File

@ -170,5 +170,6 @@ void get_local_time();
void *rct2_malloc(size_t numBytes);
void *rct2_realloc(void *block, size_t numBytes);
void rct2_free(void *block);
void rct2_quit();
#endif

View File

@ -285,6 +285,12 @@ enum {
WC_CHEATS = 110,
} WINDOW_CLASS;
enum PROMPT_MODE {
PM_SAVE_BEFORE_LOAD,
PM_SAVE_BEFORE_QUIT,
PM_SAVE_BEFORE_QUIT2,
PM_QUIT
};
void window_dispatch_update_all();
void window_update_all();

View File

@ -39,9 +39,9 @@ enum WINDOW_SAVE_PROMPT_WIDGET_IDX {
};
static rct_widget window_save_prompt_widgets[] = {
{ WWT_FRAME, 0, 0, 259, 0, 49, -1, STR_NONE }, // panel / background
{ WWT_FRAME, 0, 0, 259, 0, 49, STR_NONE, STR_NONE }, // panel / background
{ WWT_CAPTION, 0, 1, 258, 1, 14, 0, STR_WINDOW_TITLE_TIP }, // title bar
{ WWT_CLOSEBOX, 0, 247, 257, 2, 13, 824, STR_CLOSE_WINDOW_TIP }, // close x button
{ WWT_CLOSEBOX, 0, 247, 257, 2, 13, STR_CLOSE_X, STR_CLOSE_WINDOW_TIP }, // close x button
{ WWT_12, 0, 2, 257, 19, 30, 0, STR_NONE }, // question/label
{ WWT_DROPDOWN_BUTTON, 0, 8, 85, 35, 46, STR_SAVE_PROMPT_SAVE, STR_NONE }, // save
{ WWT_DROPDOWN_BUTTON, 0, 91, 168, 35, 46, STR_SAVE_PROMPT_DONT_SAVE, STR_NONE }, // don't save
@ -49,6 +49,23 @@ static rct_widget window_save_prompt_widgets[] = {
{ WIDGETS_END },
};
enum WINDOW_QUIT_PROMPT_WIDGET_IDX {
WQIDX_BACKGROUND,
WQIDX_TITLE,
WQIDX_CLOSE,
WQIDX_OK,
WQIDX_CANCEL
};
static rct_widget window_quit_prompt_widgets[] = {
{ WWT_FRAME, 0, 0, 176, 0, 33, STR_NONE, STR_NONE }, // panel / background
{ WWT_CAPTION, 0, 1, 175, 1, 14, STR_QUIT_GAME, STR_WINDOW_TITLE_TIP }, // title bar
{ WWT_CLOSEBOX, 0, 164, 174, 2, 13, STR_CLOSE_X, STR_CLOSE_WINDOW_TIP }, // close x button
{ WWT_DROPDOWN_BUTTON, 0, 8, 85, 19, 30, STR_OK, STR_NONE }, // ok
{ WWT_DROPDOWN_BUTTON, 0, 91, 168, 19, 30, STR_CANCEL, STR_NONE }, // cancel
{ WIDGETS_END },
};
static void window_save_prompt_emptysub() { }
static void window_save_prompt_close();
static void window_save_prompt_mouseup();
@ -91,28 +108,48 @@ static void* window_save_prompt_events[] = {
*/
void window_save_prompt_open()
{
int stringId;
int stringId, x, y;
rct_window* window;
unsigned short prompt_mode;
rct_widget *widgets;
uint64 enabled_widgets;
prompt_mode = RCT2_GLOBAL(RCT2_ADDRESS_SAVE_PROMPT_MODE, uint16);
// Check if window is already open
window = window_bring_to_front_by_id(WC_SAVE_PROMPT, 0);
if (window == NULL) {
if (prompt_mode == PM_QUIT) {
widgets = window_quit_prompt_widgets;
enabled_widgets =
(1 << WQIDX_CLOSE) |
(1 << WQIDX_OK) |
(1 << WQIDX_CANCEL);
x = 177;
y = 34;
} else {
widgets = window_save_prompt_widgets;
enabled_widgets =
(1 << WIDX_CLOSE) |
(1 << WIDX_SAVE) |
(1 << WIDX_DONT_SAVE) |
(1 << WIDX_CANCEL);
x = 260;
y = 50;
}
window = window_create(
(RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_WIDTH, sint16) / 2) - 130,
max(28, (RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_HEIGHT, sint16) / 2) - 25),
260,
50,
(RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_WIDTH, sint16) / 2) - x/2,
max(28, (RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_HEIGHT, sint16) / 2) - y/2),
x,
y,
(uint32*)window_save_prompt_events,
WC_SAVE_PROMPT,
0
);
window->widgets = window_save_prompt_widgets;
window->enabled_widgets =
(1 << WIDX_CLOSE) |
(1 << WIDX_SAVE) |
(1 << WIDX_DONT_SAVE) |
(1 << WIDX_CANCEL);
window->widgets = widgets;
window->enabled_widgets = enabled_widgets;
window_init_scroll_widgets(window);
window->colours[0] = 154;
window->flags |= WF_TRANSPARENT;
@ -123,14 +160,111 @@ void window_save_prompt_open()
window_invalidate_by_id(0x80 | WC_TOP_TOOLBAR, 0);
}
stringId = RCT2_GLOBAL(RCT2_ADDRESS_SAVE_PROMPT_MODE, uint16) + STR_LOAD_GAME;
stringId = prompt_mode + STR_LOAD_GAME;
if (stringId == STR_LOAD_GAME && RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) & 2)
stringId = STR_LOAD_LANDSCAPE;
if (stringId == STR_QUIT_GAME && RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) & 2)
stringId = STR_QUIT_SCENARIO_EDITOR;
window_save_prompt_widgets[WIDX_TITLE].image = stringId;
window_save_prompt_widgets[WIDX_LABEL].image =
RCT2_GLOBAL(RCT2_ADDRESS_SAVE_PROMPT_MODE, uint16) + STR_SAVE_BEFORE_LOADING;
window_save_prompt_widgets[WIDX_LABEL].image = prompt_mode + STR_SAVE_BEFORE_LOADING;
/* the following doesn't make sense here,
* game_load_or_quit_no_save_prompt() will close the window immediately
* => moved to mouseup()
*/
// if (RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) & 0x0D) {
// game_load_or_quit_no_save_prompt();
// return;
// }
//
// if (RCT2_GLOBAL(RCT2_ADDRESS_ON_TUTORIAL, uint8) != 0) {
// if (RCT2_GLOBAL(RCT2_ADDRESS_ON_TUTORIAL, uint8) != 1) {
// RCT2_CALLPROC_EBPSAFE(0x0066EE54);
// game_load_or_quit_no_save_prompt();
// return;
// } else {
// tutorial_stop();
// game_load_or_quit_no_save_prompt();
// return;
// }
// }
//
// if (RCT2_GLOBAL(0x009DEA66, uint16) < 3840) {
// game_load_or_quit_no_save_prompt();
// return;
// }
}
/**
*
* rct2: 0x0066DF17
*/
static void window_save_prompt_close()
{
// Unpause the game
RCT2_GLOBAL(0x009DEA6E, uint8) &= ~2;
unpause_sounds();
window_invalidate_by_id(0x80 | WC_TOP_TOOLBAR, 0);
}
/**
*
* rct2: 0x0066DDF2
*/
static void window_save_prompt_mouseup()
{
short widgetIndex;
rct_window *w;
short prompt_mode;
#ifdef _MSC_VER
__asm mov widgetIndex, dx
#else
__asm__ ( "mov %[widgetIndex], dx " : [widgetIndex] "+m" (widgetIndex) );
#endif
#ifdef _MSC_VER
__asm mov w, esi
#else
__asm__ ( "mov %[w], esi " : [w] "+m" (w) );
#endif
prompt_mode = RCT2_GLOBAL(RCT2_ADDRESS_SAVE_PROMPT_MODE, uint16);
if (prompt_mode == PM_QUIT) {
switch (widgetIndex) {
case WQIDX_CLOSE:
window_close(w);
window_save_prompt_close();
break;
case WQIDX_OK:
rct2_finish();
break;
case WQIDX_CANCEL:
window_close(w);
window_save_prompt_close();
break;
}
return;
} else {
switch (widgetIndex) {
case WIDX_SAVE:
// TODO to avoid data loss, treat SAVE as CANCEL
RCT2_ERROR("%s", "TODO\n");
window_close(w);
window_save_prompt_close();
return;
break;
case WIDX_DONT_SAVE:
break;
case WIDX_CLOSE:
case WIDX_CANCEL:
window_close(w);
window_save_prompt_close();
return;
}
}
if (RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) & 0x0D) {
game_load_or_quit_no_save_prompt();
@ -155,57 +289,6 @@ void window_save_prompt_open()
}
}
/**
*
* rct2: 0x0066DF17
*/
static void window_save_prompt_close()
{
// Unpause the game
RCT2_GLOBAL(0x009DEA6E, uint8) &= ~2;
unpause_sounds();
window_invalidate_by_id(0x80 | WC_TOP_TOOLBAR, 0);
}
/**
*
* rct2: 0x0066DDF2
*/
static void window_save_prompt_mouseup()
{
short widgetIndex;
rct_window *w;
#ifdef _MSC_VER
__asm mov widgetIndex, dx
#else
__asm__ ( "mov %[widgetIndex], dx " : [widgetIndex] "+m" (widgetIndex) );
#endif
#ifdef _MSC_VER
__asm mov w, esi
#else
__asm__ ( "mov %[w], esi " : [w] "+m" (w) );
#endif
// TODO
switch (widgetIndex) {
case WIDX_CLOSE:
window_close(w);
window_save_prompt_close();
break;
case WIDX_SAVE:
break;
case WIDX_DONT_SAVE:
break;
case WIDX_CANCEL:
window_close(w);
window_save_prompt_close();
break;
}
}
static void window_save_prompt_paint()
{
rct_window *w;

View File

@ -114,7 +114,7 @@ static void window_title_exit_mouseup()
return;
if (widgetIndex == 0)
game_do_command(0, 1, 0, 0, 5, 2, 0);
game_do_command(0, 1, 0, 0, 5, 3, 0);
}
/**