-
Notifications
You must be signed in to change notification settings - Fork 117
Expand file tree
/
Copy pathmain.cpp
More file actions
1125 lines (957 loc) · 28.2 KB
/
main.cpp
File metadata and controls
1125 lines (957 loc) · 28.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
*
* Attract-Mode frontend
* Copyright (C) 2013-17 Andrew Mickelson
*
* This file is part of Attract-Mode.
*
* Attract-Mode is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Attract-Mode is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Attract-Mode. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "fe_settings.hpp"
#include "fe_present.hpp"
#include "fe_overlay.hpp"
#include "fe_util.hpp"
#include "fe_image.hpp"
#include "fe_sound.hpp"
#include "fe_text.hpp"
#include "fe_window.hpp"
#include "fe_vm.hpp"
#include "fe_blend.hpp"
#include <iostream>
#include <cmath>
#include <cstdlib>
#include "nowide/args.hpp"
#ifdef USE_LIBCURL
#include <curl/curl.h>
#endif
#ifndef NO_MOVIE
#include <Audio/AudioDevice.hpp>
#endif
#ifdef SFML_SYSTEM_ANDROID
#include "fe_util_android.hpp"
#endif
#ifdef SFML_SYSTEM_WINDOWS
#include <windows.h>
#include "nvapi.hpp"
extern "C"
{
// Request more powerful GPU (Nvidea,AMD)
__declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001;
__declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1;
}
#endif
void process_args( int argc, char *argv[],
std::string &config_path,
std::string &cmdln_font,
bool &process_console,
std::string &log_file,
FeLogLevel &log_level );
int main(int argc, char *argv[])
{
std::string config_path, cmdln_font, log_file;
bool launch_game = false;
bool process_console = false;
FeInputMap::Command c = FeInputMap::LAST_COMMAND;
FeLogLevel log_level = FeLog_Info;
#ifdef USE_LIBCURL
curl_global_init( CURL_GLOBAL_ALL );
#endif
nowide::args a( argc, argv );
process_args( argc, argv, config_path, cmdln_font, process_console, log_file, log_level );
FeSettings feSettings( config_path, cmdln_font );
//
// Setup logging
//
#if defined(SFML_SYSTEM_WINDOWS) && !defined(WINDOWS_CONSOLE)
if ( log_file.empty() ) // on windows non-console version, write log to "last_run.log" by default
{
log_file = feSettings.get_config_dir();
log_file += "last_run.log";
}
#endif
//
// If a log file was supplied at the command line, write to that log file
// If no file is supplied, logging is to stdout
//
if ( !log_file.empty() )
fe_set_log_file( clean_path( log_file ) );
// The following call also initializes the log callback for ffmpeg and gameswf
//
fe_set_log_level( log_level );
//
// Run the front-end
//
fe_print_version();
FeLog() << std::endl;
#ifdef SFML_SYSTEM_WINDOWS
// Detect an nvidia card and if it's found create an nvidia profile
// for Attract Mode with optimizations
if ( nvapi_init() > 0 )
FeLog() << "Nvidia GPU detected. Attract Mode profile was not found so it has been created.\n"
<< "In order for the changes to take effect, please restart Attract Mode\n" << std::endl;
FeDebug() << std::endl;
#endif
feSettings.load();
std::string def_font_path, def_font_file;
if ( feSettings.get_font_file( def_font_path, def_font_file ) == false )
{
FeLog() << "Error, could not find default font." << std::endl;
return 1;
}
FeFontContainer def_font;
def_font.set_font( def_font_path, def_font_file );
//
// Set up music/sound playing objects
//
#ifndef NO_MOVIE
sf::AudioDevice audio_device;
#endif
FeSoundSystem soundsys( &feSettings );
soundsys.update_volumes();
soundsys.play_ambient();
FeWindow window( feSettings );
window.initial_create();
#ifdef WINDOWS_CONSOLE
if ( feSettings.get_hide_console() )
hide_console();
#endif
FeVM feVM( feSettings, def_font, window, soundsys.get_ambient_sound(), process_console );
FeOverlay feOverlay( window, feSettings, feVM );
feVM.set_overlay( &feOverlay );
bool exit_selected=false;
if ( feSettings.get_info( FeSettings::Language ).empty() )
{
#ifdef SFML_SYSTEM_ANDROID
android_copy_assets();
#endif
// If our language isn't set at this point, we want to prompt the user for the language
// they wish to use
//
if ( feOverlay.languages_dialog() < 0 )
exit_selected = true;
// Font may change depending on the language selected
feSettings.get_font_file( def_font_path, def_font_file );
def_font.set_font( def_font_path, def_font_file );
if ( !exit_selected )
{
FeLog() << "Performing some initial configuration" << std::endl;
feVM.setup_wizard();
FeLog() << "Done initial configuration" << std::endl;
}
}
soundsys.sound_event( FeInputMap::EventStartup );
bool redraw=true, has_focus=true;
int guard_joyid=-1, guard_axis=-1;
// variables used to track movement when a key is held down
FeInputMap::Command move_state( FeInputMap::LAST_COMMAND ); // command mapped to the move
FeInputMap::Command move_triggered( FeInputMap::LAST_COMMAND ); // "repeatable" command triggered on move (if any)
sf::Clock move_timer;
sf::Event move_event;
int move_last_triggered( 0 );
sf::Vector2i last_mouse_pos;
// go straight into config mode if there are no lists configured for
// display
//
bool config_mode = ( feSettings.displays_count() < 1 );
if ( !config_mode )
{
// start the intro now
if ( !feVM.load_intro() )
{
switch ( feSettings.get_startup_mode() )
{
case FeSettings::LaunchLastGame:
feVM.load_layout( true );
feSettings.select_last_launch();
launch_game=true;
break;
case FeSettings::ShowDisplaysMenu:
// we do a double load of the layout on startup if there is custom display menu
// so we suppress the extra transition signals that get triggered here
feVM.load_layout( true, !feSettings.get_info( FeSettings::MenuLayout ).empty() );
FeVM::cb_signal( "displays_menu" );
break;
default:
feVM.load_layout( true );
break;
}
}
}
while (window.isOpen() && (!exit_selected))
{
if ( config_mode )
{
//
// Enter config mode
//
int old_mode = feSettings.get_window_mode();
if ( feOverlay.config_dialog() )
{
// Settings changed, reload
//
if ( feSettings.get_font_file( def_font_path, def_font_file ) )
def_font.set_font( def_font_path, def_font_file );
feSettings.set_display(
feSettings.get_current_display_index() );
feSettings.on_joystick_connect(); // update joystick mappings
soundsys.stop();
soundsys.update_volumes();
soundsys.play_ambient();
// Recreate window if the window mode changed
if ( feSettings.get_window_mode() != old_mode )
{
window.on_exit();
window.initial_create();
feVM.init_monitors();
}
feVM.load_layout();
}
feVM.reset_screen_saver();
config_mode=false;
redraw=true;
}
else if (( launch_game )
&& ( !soundsys.is_sound_event_playing( FeInputMap::Select ) ))
{
const std::string &emu_name = feSettings.get_rom_info( 0, 0, FeRomInfo::Emulator );
if ( emu_name.compare( 0, 1, "@" ) == 0 )
{
if ( emu_name.size() > 1 )
{
// If emu name size >1 and starts with a "@", then we treat the rest of the
// string as the signal we have to send
//
FeVM::cb_signal( emu_name.substr( 1 ).c_str() );
}
else
{
// If emu name is just "@", then this is a shortcut to another display, so instead
// of running a game we switch to the display specified in the rom_info's Romname field
//
std::string name = feSettings.get_rom_info( 0, 0, FeRomInfo::Romname );
int index = feSettings.get_display_index_from_name( name );
// if index not found or if we are already in the specified display, then
// jump to the altromname display instead
//
if (( index < 0 ) || ( index == feSettings.get_current_display_index() ))
{
name = feSettings.get_rom_info( 0, 0, FeRomInfo::AltRomname );
if ( !name.empty() )
index = feSettings.get_display_index_from_name( name );
}
if ( index < 0 )
{
FeLog() << "Error resolving shortcut, Display `" << name << "' not found." << std::endl;
}
else
{
if ( feSettings.set_display( index, true ) )
feVM.load_layout();
else
feVM.update_to_new_list( 0, true );
}
}
launch_game=false;
}
if ( launch_game && feSettings.switch_to_clone_group() )
{
feVM.update_to_new_list( 0, true );
launch_game=false;
}
if ( launch_game )
{
soundsys.stop();
soundsys.release_audio( true );
feVM.pre_run();
// window.run() returns true if our window has been closed while
// the other program was running
if ( !window.run() )
exit_selected = true;
feVM.post_run();
soundsys.release_audio( false );
soundsys.update_volumes();
soundsys.sound_event( FeInputMap::EventGameReturn );
soundsys.play_ambient();
if ( feSettings.switch_from_clone_group() )
feVM.update_to_new_list( 0, true );
has_focus=true;
}
launch_game=false;
redraw=true;
}
sf::Event ev;
bool from_ui;
while ( feVM.poll_command( c, ev, from_ui ) )
{
//
// Special case handling based on event type
//
switch ( ev.type )
{
case sf::Event::Closed:
exit_selected = true;
break;
case sf::Event::MouseMoved:
if ( (( ev.mouseMove.x != last_mouse_pos.x ) || ( ev.mouseMove.y != last_mouse_pos.y ))
&& ( feSettings.test_mouse_reset( ev.mouseMove.x, ev.mouseMove.y )) )
{
// We reset the mouse if we are capturing it and it has moved
// outside of its bounding box
//
last_mouse_pos = sf::Vector2i( ev.mouseMove.x, ev.mouseMove.y );
sf::Vector2u s = window.get_win().getSize();
sf::Mouse::setPosition( sf::Vector2i( s.x / 2, s.y / 2 ), window.get_win() );
}
break;
case sf::Event::KeyReleased:
case sf::Event::MouseButtonReleased:
case sf::Event::JoystickButtonReleased:
//
// We always want to reset the screen saver on these events,
// even if they aren't mapped otherwise (mapped events cause
// a reset too)
//
if (( c == FeInputMap::LAST_COMMAND )
&& ( feVM.reset_screen_saver() ))
redraw = true;
break;
case sf::Event::GainedFocus:
case sf::Event::Resized:
redraw = true;
break;
case sf::Event::JoystickMoved:
if ( c != FeInputMap::LAST_COMMAND )
{
// Only allow one mapped "Joystick Moved" input through at a time
//
if ( guard_joyid != -1 )
continue;
guard_joyid = ev.joystickMove.joystickId;
guard_axis = ev.joystickMove.axis;
}
break;
case sf::Event::JoystickConnected:
case sf::Event::JoystickDisconnected:
feSettings.on_joystick_connect();
break;
case sf::Event::Count:
default:
break;
}
// Test if we need to keep the joystick axis guard up
//
if (( guard_joyid >= 0 )
&& ( std::abs( sf::Joystick::getAxisPosition(
guard_joyid, (sf::Joystick::Axis)guard_axis ))
< feSettings.get_joy_thresh() ))
{
guard_joyid = -1;
guard_axis = -1;
}
// Nothing further to do if there is no command or if we are in the process
// of launching a game already
//
if (( c == FeInputMap::LAST_COMMAND ) || ( launch_game ))
continue;
//
// Special case: handle the reload signal now
//
if ( c == FeInputMap::Reload )
{
feVM.load_layout();
continue;
}
//
// KEY REPEAT LOGIC (1 of 2)
//
// if 'move_state' is set, we typically bail here and let the move timer trigger
// the next action
//
// Special case: If we didn't get a move_triggered value set when the move state was first
// set, then capture the next fe.signal() command after the move state started, as the
// user's scripts may be remapping the signal to another value. If that is the case, we
// let the signal proceed (and set move_triggered below... at step 2 of 2)
//
if (( move_state != FeInputMap::LAST_COMMAND )
&& ( from_ui || ( move_triggered != FeInputMap::LAST_COMMAND )))
continue;
if ( from_ui )
{
// setup variables to test for when the navigation keys are held down
move_state = c;
move_timer.restart();
move_event = ev;
move_triggered = FeInputMap::LAST_COMMAND;
}
//
// Map Up/Down/Left/Right/Back to their default action now
//
if ( FeInputMap::is_ui_command( c ) )
{
//
// Give the script the option to handle the (pre-map) action.
//
if ( feVM.script_handle_event( c ) )
{
FeDebug() << "Command intercepted by script handler: "
<< FeInputMap::commandStrings[c] << std::endl;
redraw=true;
continue;
}
//
// Handle special case Back UI button behaviour
//
if ( c == FeInputMap::Back )
{
//
// If a display shortcut was used previously, then the "Back" UI
// button goes back to the previous display accordingly...
//
if ( feSettings.back_displays_available() )
{
if ( feSettings.set_display( -1, true ) )
feVM.load_layout();
else
feVM.update_to_new_list( 0, true );
redraw=true;
continue;
}
//
// If FE is configured to show displays menu on startup, then the "Back" UI
// button goes back to that menu accordingly...
//
if (( feSettings.get_startup_mode() == FeSettings::ShowDisplaysMenu )
&& ( feSettings.get_present_state() == FeSettings::Layout_Showing )
&& ( feSettings.get_current_display_index() >= 0 ))
{
FeVM::cb_signal( "displays_menu" );
redraw=true;
continue;
}
//
// If FE is configured to group clones and is presently showing a group,
// then the "Back" UI button goes back to the main romlist...
//
if (( feSettings.get_info_bool( FeSettings::GroupClones ) )
&& ( feSettings.switch_from_clone_group() ))
{
feVM.update_to_new_list( 0, true );
continue;
}
}
c = feSettings.get_default_command( c );
if ( c == FeInputMap::LAST_COMMAND )
{
redraw=true;
continue;
}
}
//
// Give the script the option to handle the command.
//
if ( feVM.script_handle_event( c ) )
{
FeDebug() << "Command intercepted by script handler: "
<< FeInputMap::commandStrings[c] << std::endl;
redraw=true;
continue;
}
//
// Check if we need to get out of intro mode
//
if ( feSettings.get_present_state() == FeSettings::Intro_Showing )
{
move_state = FeInputMap::LAST_COMMAND;
move_triggered = FeInputMap::LAST_COMMAND;
move_last_triggered = 0;
switch ( feSettings.get_startup_mode() )
{
case FeSettings::LaunchLastGame:
feVM.load_layout( true );
feSettings.select_last_launch();
launch_game=true;
break;
case FeSettings::ShowDisplaysMenu:
// we do a double load of the layout on startup if there is custom display menu
// so we suppress the extra transition signals that get triggered here
feVM.load_layout( true, !feSettings.get_info( FeSettings::MenuLayout ).empty() );
FeVM::cb_signal( "displays_menu" );
break;
default:
feVM.load_layout( true );
break;
}
redraw=true;
continue;
}
//
// KEY REPEAT LOGIC (2 of 2)
//
// If we get here then this is the first pass through input potentially being held down
// (i.e. repeat navigation). Since we now know what the ultimate value of c is now, record
// it in move_triggered
//
// ( !from_ui && ( move_triggered == LAST_COMMAND ) ) will catch where remapping by script
//
// ( move_state == LAST_COMMAND ) will catch the regular case with no remapping
//
if (( !from_ui && ( move_triggered == FeInputMap::LAST_COMMAND ))
|| ( move_state != FeInputMap::LAST_COMMAND ))
{
if ( FeInputMap::is_repeatable_command( c ) )
move_triggered = c;
}
//
// Default command handling
//
FeDebug() << "Handling command: " << FeInputMap::commandStrings[c] << std::endl;
soundsys.sound_event( c );
if ( feVM.handle_event( c ) )
redraw = true;
else
{
// handle the things that fePresent doesn't do
switch ( c )
{
case FeInputMap::Exit:
{
if ( feOverlay.common_exit() )
exit_selected=true;
redraw=true;
}
break;
case FeInputMap::ExitToDesktop:
exit_selected = true;
break;
case FeInputMap::ReplayLastGame:
if ( feSettings.select_last_launch() )
feVM.load_layout();
else
feVM.update_to_new_list();
launch_game=true;
redraw=true;
break;
case FeInputMap::Select:
launch_game=true;
break;
case FeInputMap::ToggleMute:
feSettings.set_mute( !feSettings.get_mute() );
soundsys.update_volumes();
feVM.toggle_mute();
break;
case FeInputMap::ScreenShot:
{
std::string filename;
get_available_filename( feSettings.get_config_dir(),
"screen", ".png", filename );
sf::RenderWindow &w = window.get_win();
#if ( SFML_VERSION_INT >= FE_VERSION_INT( 2, 4, 0 ) )
sf::Texture texture;
texture.create( w.getSize().x, w.getSize().y );
texture.update( w );
sf::Image sshot_img = texture.copyToImage();
#else
sf::Image sshot_img = w.capture();
#endif
sshot_img.saveToFile( filename );
}
break;
case FeInputMap::Configure:
config_mode = true;
break;
case FeInputMap::InsertGame:
{
std::vector< std::string > options;
std::string temp;
// 0
feSettings.get_resource( "Insert Game Entry", temp );
options.push_back( temp );
// 1
feSettings.get_resource( "Insert Display Shortcut", temp );
options.push_back( temp );
// 2
feSettings.get_resource( "Insert Command Shortcut", temp );
options.push_back( temp );
feSettings.get_resource( "Insert Menu Entry", temp );
int sel = feOverlay.common_list_dialog(
temp, options, 0, 0 );
std::string emu_name;
std::string def_name;
switch ( sel )
{
case 0:
{
std::vector<std::string> tl;
feSettings.get_list_of_emulators( tl );
if ( !tl.empty() )
emu_name = tl[0];
feSettings.get_resource( "Blank Game", def_name );
}
break;
case 1:
{
emu_name = "@";
feSettings.get_resource( "Display Shortcut", def_name );
if ( feSettings.displays_count() > 0 )
def_name = feSettings.get_display( 0 )
->get_info( FeDisplayInfo::Name );
}
break;
case 2:
emu_name = "@exit";
feSettings.get_resource( "Exit", def_name );
break;
default:
break;
};
FeRomInfo new_entry( def_name );
new_entry.set_info( FeRomInfo::Title, def_name );
new_entry.set_info( FeRomInfo::Emulator, emu_name );
int f_idx = feSettings.get_current_filter_index();
FeRomInfo dummy;
FeRomInfo *r = feSettings.get_rom_absolute(
f_idx, feSettings.get_rom_index( f_idx, 0 ) );
if ( !r )
r = &dummy;
feSettings.update_romlist_after_edit( *r,
new_entry,
FeSettings::InsertEntry );
// initial update shows new entry behind config
// dialog
feVM.update_to_new_list();
if ( feOverlay.edit_game_dialog() )
feVM.update_to_new_list();
redraw=true;
}
break;
case FeInputMap::EditGame:
if ( feOverlay.edit_game_dialog() )
feVM.update_to_new_list();
redraw=true;
break;
case FeInputMap::LayoutOptions:
if ( feOverlay.layout_options_dialog() )
feVM.load_layout();
redraw=true;
break;
case FeInputMap::DisplaysMenu:
{
if ( !feSettings.get_info( FeSettings::MenuLayout ).empty() )
{
//
// If user has configured a custom layout for the display
// menu, then setting display to -1 and loading will
// bring up the displays menu using that layout
//
feSettings.set_display(-1);
feVM.load_layout( true );
redraw=true;
break;
}
//
// If no custom layout is configured, then we simply show the
// displays menu the same way as any other popup menu...
//
std::vector<std::string> disp_names;
std::vector<int> disp_indices;
int current_idx;
std::string title;
feSettings.get_displays_menu( title, disp_names, disp_indices, current_idx );
int exit_opt=-999;
if ( feSettings.get_info_bool( FeSettings::DisplaysMenuExit ) )
{
//
// Add an exit option at the end of the lists menu
//
std::string exit_str;
feSettings.get_exit_message( exit_str );
disp_names.push_back( exit_str );
exit_opt = disp_names.size() - 1;
}
if ( !disp_names.empty() )
{
int sel_idx = feOverlay.common_list_dialog(
title,
disp_names,
current_idx,
-1,
FeInputMap::DisplaysMenu );
if ( sel_idx == exit_opt )
{
if ( feOverlay.common_exit() )
exit_selected = true;
}
else if ( sel_idx >= 0 )
{
if ( feSettings.set_display( disp_indices[sel_idx] ) )
feVM.load_layout();
else
feVM.update_to_new_list( 0, true );
}
redraw=true;
}
}
break;
case FeInputMap::FiltersMenu:
{
std::vector<std::string> names_list;
feSettings.get_current_display_filter_names( names_list );
std::string title;
feSettings.get_resource( "Filters", title );
int filter_index = feOverlay.common_list_dialog(
title,
names_list,
feSettings.get_current_filter_index(),
-1,
FeInputMap::FiltersMenu );
if ( filter_index >= 0 )
{
feSettings.set_current_selection( filter_index, -1 );
feVM.update_to_new_list();
}
redraw=true;
}
break;
case FeInputMap::ToggleFavourite:
{
bool new_state = !feSettings.get_current_fav();
if ( feSettings.get_info_bool( FeSettings::ConfirmFavourites ) )
{
std::string msg = ( new_state )
? "Add '$1' to Favourites?"
: "Remove '$1' from Favourites?";
// returns 0 if user confirmed toggle
if ( feOverlay.confirm_dialog(
msg,
feSettings.get_rom_info( 0, 0, FeRomInfo::Title ),
false,
FeInputMap::ToggleFavourite ) == 0 )
{
if ( feSettings.set_current_fav( new_state ) )
{
feVM.update_to_new_list( 0, true ); // our current display might have changed, so update
feVM.on_transition( ChangedTag, FeRomInfo::Favourite );
}
}
}
else
{
if ( feSettings.set_current_fav( new_state ) )
{
feVM.update_to_new_list( 0, true ); // our current display might have changed, so update
feVM.on_transition( ChangedTag, FeRomInfo::Favourite );
}
}
redraw = true;
}
break;
case FeInputMap::ToggleTags:
if ( feOverlay.tags_dialog() < 0 )
exit_selected = true;
redraw = true;
break;
default:
break;
}
}
}
//
// Determine if we have to do anything because a key is being held down
//
if ( move_state != FeInputMap::LAST_COMMAND )
{
bool cont=false;
switch ( move_event.type )
{
case sf::Event::KeyPressed:
if ( sf::Keyboard::isKeyPressed( move_event.key.code ) )
cont=true;
break;
case sf::Event::MouseButtonPressed:
if ( sf::Mouse::isButtonPressed( move_event.mouseButton.button ) )
cont=true;
break;
case sf::Event::JoystickButtonPressed:
if ( sf::Joystick::isButtonPressed(
move_event.joystickButton.joystickId,
move_event.joystickButton.button ) )
cont=true;
break;
case sf::Event::JoystickMoved:
{
sf::Joystick::update();
float pos = sf::Joystick::getAxisPosition(
move_event.joystickMove.joystickId,
move_event.joystickMove.axis );
if ( std::abs( pos ) > feSettings.get_joy_thresh() )
cont=true;
}
break;
default:
break;
}
if ( cont )
{
const int TRIG_CHANGE_MS = 400;
int t = move_timer.getElapsedTime().asMilliseconds();
if (( t > TRIG_CHANGE_MS ) && ( t - move_last_triggered > feSettings.selection_speed() ))
{
if (( move_triggered == FeInputMap::LAST_COMMAND )
|| feVM.script_handle_event( move_triggered ))
{
redraw=true;
move_triggered = FeInputMap::LAST_COMMAND;
}
else
{
move_last_triggered = t;
int step = 1;
int max_step = feSettings.selection_max_step();
if ( max_step > 1 )
{
int s = t / TRIG_CHANGE_MS;
if ( s < 8 )
step = 1;
else if ( s < 15 )
step = 2;
else if ( s < 20 )
step = 4;
else if ( s < 22 )
step = 6;
else
{
int shift = s - 19;
if ( shift > 11 ) // sanity check - don't go above 2^11 (2048)
shift = 11;
step = 1 << ( shift );
}
if ( step > max_step ) // make sure we don't go over user specified max
step = max_step;
}
switch ( move_triggered )
{
case FeInputMap::PrevGame: step = -step; break;
case FeInputMap::NextGame: break; // do nothing
case FeInputMap::PrevPage: step *= -feVM.get_page_size(); break;
case FeInputMap::NextPage: step *= feVM.get_page_size(); break;
case FeInputMap::PrevFavourite:
{