Refactor menu selection

This commit is contained in:
kichikuou
2017-04-30 18:25:46 +09:00
parent e5475f6296
commit 54bea213d3
2 changed files with 41 additions and 199 deletions
+40 -199
View File
@@ -155,23 +155,12 @@ void NACT::cmd_set_menu()
}
}
void NACT::cmd_open_menu()
int NACT::menu_select(int num_items)
{
#if defined(_DEBUG_CONSOLE)
char log[128];
sprintf_s(log, 128, "\n]");
output_console(log);
#endif
if(!menu_index) {
scenario_addr = scenario_data[0] | (scenario_data[1] << 8);
return;
}
// クリック中の間は待機
for(;;) {
if(terminate) {
return;
return -1;
}
// if(get_key() != 32) {
if(!get_key()) {
@@ -199,7 +188,7 @@ void NACT::cmd_open_menu()
int val = 0, current_mx = mx, current_my = my;
for(;;) {
if(terminate) {
return;
return -1;
}
if(val = get_key()) {
SDL_Delay(100);
@@ -214,7 +203,7 @@ void NACT::cmd_open_menu()
if(val) {
for(;;) {
if(terminate) {
return;
return -1;
}
if(!get_key()) {
break;
@@ -227,19 +216,19 @@ void NACT::cmd_open_menu()
// マウス操作
mx = current_mx; my = current_my;
int index = (my - sy) / height;
if(sx <= mx && mx <= ex && 0 <= index && index < menu_index) {
if(sx <= mx && mx <= ex && 0 <= index && index < num_items) {
current_index = index;
ags->redraw_menu_window(menu_window, current_index);
}
} else if(val == 1 || val == 2 || val == 4 || val == 8) {
if(val == 1) {
current_index = current_index ? current_index - 1 : menu_index - 1;
current_index = current_index ? current_index - 1 : num_items - 1;
} else if(val == 2) {
current_index = (current_index < menu_index - 1) ? current_index + 1 : 0;
current_index = (current_index < num_items - 1) ? current_index + 1 : 0;
} else if(val == 4) {
current_index = 0;
} else if(val == 8) {
current_index = menu_index - 1;
current_index = num_items - 1;
}
ags->redraw_menu_window(menu_window, current_index);
} else if(val == 16) {
@@ -256,8 +245,28 @@ void NACT::cmd_open_menu()
ags->clear_text_window(text_window, true);
}
if(current_index != -1) {
scenario_addr = menu_addr[current_index];
return current_index;
}
void NACT::cmd_open_menu()
{
#if defined(_DEBUG_CONSOLE)
char log[128];
sprintf_s(log, 128, "\n]");
output_console(log);
#endif
if(!menu_index) {
scenario_addr = scenario_data[0] | (scenario_data[1] << 8);
return;
}
int index = menu_select(menu_index);
if (terminate)
return;
if(index != -1) {
scenario_addr = menu_addr[index];
}
menu_index = 0;
}
@@ -337,98 +346,14 @@ void NACT::cmd_open_verb()
}
ags->draw_menu = false;
// クリック中の間は待機
for(;;) {
if(terminate) {
return;
}
// if(get_key() != 32) {
if(!get_key()) {
break;
}
SDL_Delay(10);
}
int selection = menu_select(index);
if (terminate)
return;
// メニュー表示
ags->open_menu_window(menu_window);
int current_index = 0;
// マウス移動
int sx = ags->menu_w[menu_window - 1].sx;
int sy = ags->menu_w[menu_window - 1].sy;
int ex = ags->menu_w[menu_window - 1].ex;
int mx = ex - 16;
int my = sy + 10;
int height = ags->menu_font_size + 4;
set_cursor(mx, my);
// メニュー選択
for(;;) {
// 入力待機
int val = 0, current_mx = mx, current_my = my;
for(;;) {
if(terminate) {
return;
}
if(val = get_key()) {
SDL_Delay(100);
break;
}
get_cursor(&current_mx, &current_my);
if(abs(my - current_my) > 3) {
break;
}
SDL_Delay(10);
}
if(val) {
for(;;) {
if(terminate) {
return;
}
if(!get_key()) {
break;
}
SDL_Delay(10);
}
}
if(val == 0) {
// マウス操作
mx = current_mx; my = current_my;
int mindex = (my - sy) / height;
if(sx <= mx && mx <= ex && 0 <= mindex && mindex < index) {
current_index = mindex;
ags->redraw_menu_window(menu_window, current_index);
}
} else if(val == 1 || val == 2 || val == 4 || val == 8) {
if(val == 1) {
current_index = current_index ? current_index - 1 : index - 1;
} else if(val == 2) {
current_index = (current_index < index - 1) ? current_index + 1 : 0;
} else if(val == 4) {
current_index = 0;
} else if(val == 8) {
current_index = index - 1;
}
ags->redraw_menu_window(menu_window, current_index);
} else if(val == 16) {
break;
} else if(val == 32) {
current_index = -1;
break;
}
}
// 画面更新
ags->close_menu_window(menu_window);
if(clear_text) {
ags->clear_text_window(text_window, true);
}
if(current_index == -1) {
if (selection == -1) {
scenario_addr = scenario_data[0] | (scenario_data[1] << 8);
} else {
cmd_open_obj(id[current_index]);
cmd_open_obj(id[selection]);
}
menu_index = 0;
}
@@ -481,98 +406,14 @@ void NACT::cmd_open_obj(int verb)
ags->menu_dest_y += ags->menu_font_size + 2;
ags->draw_menu = false;
// クリック中の間は待機
for(;;) {
if(terminate) {
return;
}
// if(get_key() != 32) {
if(!get_key()) {
break;
}
SDL_Delay(10);
}
int selection = menu_select(index);
if (terminate)
return;
// メニュー表示
ags->open_menu_window(menu_window);
int current_index = 0;
// マウス移動
int sx = ags->menu_w[menu_window - 1].sx;
int sy = ags->menu_w[menu_window - 1].sy;
int ex = ags->menu_w[menu_window - 1].ex;
int mx = ex - 16;
int my = sy + 10;
int height = ags->menu_font_size + 4;
set_cursor(mx, my);
// メニュー選択
for(;;) {
// 入力待機
int val = 0, current_mx = mx, current_my = my;
for(;;) {
if(terminate) {
return;
}
if(val = get_key()) {
SDL_Delay(100);
break;
}
get_cursor(&current_mx, &current_my);
if(abs(my - current_my) > 3) {
break;
}
SDL_Delay(10);
}
if(val) {
for(;;) {
if(terminate) {
return;
}
if(!get_key()) {
break;
}
SDL_Delay(10);
}
}
if(val == 0) {
// マウス操作
mx = current_mx; my = current_my;
int mindex = (my - sy) / height;
if(sx <= mx && mx <= ex && 0 <= mindex && mindex < index) {
current_index = mindex;
ags->redraw_menu_window(menu_window, current_index);
}
} else if(val == 1 || val == 2 || val == 4 || val == 8) {
if(val == 1) {
current_index = current_index ? current_index - 1 : index - 1;
} else if(val == 2) {
current_index = (current_index < index - 1) ? current_index + 1 : 0;
} else if(val == 4) {
current_index = 0;
} else if(val == 8) {
current_index = index - 1;
}
ags->redraw_menu_window(menu_window, current_index);
} else if(val == 16) {
break;
} else if(val == 32) {
current_index = -1;
break;
}
}
// 画面更新
ags->close_menu_window(menu_window);
if(clear_text) {
ags->clear_text_window(text_window, true);
}
if(current_index == -1) {
if (selection == -1) {
scenario_addr = scenario_data[0] | (scenario_data[1] << 8);
} else {
scenario_addr = addr[id[current_index]];
scenario_addr = addr[id[selection]];
}
}