Skip to content

Commit

Permalink
Reworked computer menu UI (CleverRaven#36427)
Browse files Browse the repository at this point in the history
* Reworked computer menu to use uilist

* Added fourth security reminder for HWS computer
  • Loading branch information
Night-Pryanik authored and ZhilkinSerg committed Dec 26, 2019
1 parent 76ecb0e commit d18fc5d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 43 deletions.
2 changes: 1 addition & 1 deletion data/json/mapgen/hazardous_waste_sarcophagus.json
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@
{ "monster": "mon_hazmatbot", "x": 26, "y": 37 },
{ "monster": "mon_hazmatbot", "x": 22, "y": 29 }
],
"//": "There is 4th security reminder with name 'Security Reminder [1058]' and action 'sr4_mess'. Add it when our computer UI will support more than 9 options.",
"computers": {
"5": {
"name": "SRCF Security Terminal",
Expand All @@ -164,6 +163,7 @@
{ "name": "Security Reminder [1055]", "action": "sr1_mess" },
{ "name": "Security Reminder [1056]", "action": "sr2_mess" },
{ "name": "Security Reminder [1057]", "action": "sr3_mess" },
{ "name": "Security Reminder [1058]", "action": "sr4_mess" },
{ "name": "EPA: Report All Potential Containment Breaches [3873643]", "action": "srcf_1_mess" },
{ "name": "SRCF: Internal Memo, EPA [2918024]", "action": "srcf_2_mess" },
{ "name": "CDC: Internal Memo, Standby [2918115]", "action": "srcf_3_mess" },
Expand Down
76 changes: 34 additions & 42 deletions src/computer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,54 +206,46 @@ void computer::use()
}

// Main computer loop
int sel = 0;
while( true ) {
//reset_terminal();
size_t options_size = options.size();
print_newline();
print_line( "%s - %s", _( name ), _( "Root Menu" ) );
#if defined(__ANDROID__)
input_context ctxt( "COMPUTER_MAINLOOP" );
#endif

uilist computer_menu;
computer_menu.text = string_format( _( "%s - Root Menu" ), name );
computer_menu.selected = sel;
computer_menu.fselected = sel;

for( size_t i = 0; i < options_size; i++ ) {
print_line( "%d - %s", i + 1, _( options[i].name ) );
#if defined(__ANDROID__)
ctxt.register_manual_key( '1' + i, options[i].name );
#endif
computer_menu.addentry( i, true, MENU_AUTOASSIGN, options[i].name );
}
print_line( "Q - %s", _( "Quit and Shut Down" ) );
print_newline();
#if defined(__ANDROID__)
ctxt.register_manual_key( 'Q', _( "Quit and Shut Down" ) );
#endif
char ch;
do {
// TODO: use input context
ch = inp_mngr.get_input_event().get_first_input();
} while( ch != 'q' && ch != 'Q' && ( ch < '1' || ch - '1' >= static_cast<char>( options_size ) ) );
if( ch == 'q' || ch == 'Q' ) {
break; // Exit from main computer loop
} else { // We selected an option other than quit.
ch -= '1'; // So '1' -> 0; index in options.size()
computer_option current = options[ch];
// Once you trip the security, you have to roll every time you want to do something
if( ( current.security + ( alerts ) ) > 0 ) {
print_error( _( "Password required." ) );
if( query_bool( _( "Hack into system?" ) ) ) {
if( !hack_attempt( g->u, current.security ) ) {
activate_random_failure();
shutdown_terminal();
return;
} else {
// Successfully hacked function
options[ch].security = 0;
activate_function( current.action );
}

computer_menu.query();
if( computer_menu.ret < 0 || static_cast<size_t>( computer_menu.ret ) >= options.size() ) {
break;
}

sel = computer_menu.ret;
computer_option current = options[sel];
reset_terminal();
// Once you trip the security, you have to roll every time you want to do something
if( current.security + alerts > 0 ) {
print_error( _( "Password required." ) );
if( query_bool( _( "Hack into system?" ) ) ) {
if( !hack_attempt( g->u, current.security ) ) {
activate_random_failure();
shutdown_terminal();
return;
} else {
// Successfully hacked function
options[sel].security = 0;
activate_function( current.action );
}
} else { // No need to hack, just activate
activate_function( current.action );
}
reset_terminal();
} // Done processing a selected option.
} else { // No need to hack, just activate
activate_function( current.action );
}
reset_terminal();
// Done processing a selected option.
}

shutdown_terminal(); // This should have been done by now, but just in case.
Expand Down

0 comments on commit d18fc5d

Please sign in to comment.