Exemple #1
0
state menu_execute(void* data, void*) {
	menu_t* menu = (menu_t*)data;
	menu_show(menu);

	do {
		switch (get_code()) {
		case KEY_ENTER:
			if (menu->selected->action->cb) {
				menu->menu_state = menu->selected->action->cb(menu->selected->action->data, menu->selected->action->params);
			}
			break;
		case ARROW_UP:
			if (menu->head != menu->selected) {
				menu_item_t* current = menu->head;
				while (current->next != menu->selected) {
					current = current->next;
				}
				menu->selected = current;
				menu->menu_state = REDRAW;
			}
			break;
		case ARROW_DOWN:
			if (menu->selected->next) {
				menu->selected = menu->selected->next;
				menu->menu_state = REDRAW;
			}
			break;
		}
		menu_show(menu);
	} while (menu->menu_state);
	return REDRAW;
}
Exemple #2
0
void do_state_1( int keypress )
{
	int i;

	if (!keyd_pressed[KEY_LALT] && !keyd_pressed[KEY_RALT] )
	{
		//state = 2;
		//state2_alt_down = 0;
		//Menu[0].ShowBar = 1;
		//Menu[0].Active = 1;
		//menu_show( &Menu[0] );
		state = 0;
		menu_hide_all();
  	}

	i = menu_match_keypress( &Menu[0], keypress );
	
	if (i > -1 )
	{
		Menu[0].CurrentItem = i;
		Menu[0].Active = 0;
		state = 3;	
		Menu[ CMENU ].ShowBar = 1;
		Menu[ CMENU ].Active = 1;
		Menu[0].ShowBar = 1;

		menu_show( &Menu[ CMENU ] );
		menu_show( &Menu[0] );
	}

	i = menu_check_mouse_item( &Menu[0] );

	if ( (i == -1) && B1_JUST_RELEASED )
	{
		state = 0;
		menu_hide_all();
	}

	if ( B1_PRESSED && (i > -1))
	{
		Menu[0].CurrentItem = i;
		state = 3;	
		Menu[ CMENU ].ShowBar = 1;
		Menu[ CMENU ].Active = 1;
		Menu[0].ShowBar = 1;
		Menu[0].Active = 0;
		menu_show( &Menu[ CMENU ] );
		menu_show( &Menu[0] );
	}
}
Exemple #3
0
/* @brief Called when a file, document or url is to be opened by the application
 *
 * Application (callee) should create and realise, or reuse an existing window 
 * for the given file and return the X window id in the method reply. The X window 
 * can be obtained using GDK_WINDOW_XID(widget->window). When the file is already 
 * opened by the callee, it may just return its X window id. This call implies that
 * the window is activated (set to the foreground) so callee should also set its 
 * context for the given window and set the Popupmenu menu context. 
 * System Daemon adds a task to Task Manager of Popupmenu, or replaces the task 
 * when an existing window is returned.
 */
static void on_file_open ( eripc_context_t          *context,
                           const eripc_event_info_t *info,
                           void                     *user_data )
{
    LOGPRINTF("entry");
    gchar             *error_msg  = NULL;
    gint              my_xid      = -1; 

    const eripc_arg_t *arg_array  = info->args;
    
    if (arg_array[0].type == ERIPC_TYPE_STRING)
    {
        const char *file = arg_array[0].value.s;
        if (file)
        {
            menu_show();
            my_xid = GDK_WINDOW_XID(g_main_window->window);
            view_open_uri(file);
        }
    }
    
    // return result to caller
    eripc_reply_varargs(context, info->message_id, 
                        ERIPC_TYPE_INT, my_xid,
                        ERIPC_TYPE_STRING, error_msg,
                        ERIPC_TYPE_INVALID);
    g_free(error_msg);
}
Exemple #4
0
int game_sel_lost_focus( void ) {
	game_sel_hide(HIDE_TARGET_START);
	snap_hide();

	if( config_get()->iface.theme.menu.auto_hide ) {
		menu_show();
	}

	return 0;
}
Exemple #5
0
void menu_hide_all()
{
 	int i;

	for (i=1; i<num_menus; i++) 
		menu_hide( &Menu[i] );
	
	Menu[0].ShowBar = 0;
	Menu[0].Active = 0;
	menu_show( &Menu[0] );

}
Exemple #6
0
static void menu_hide_all()
{
	range_for (auto &i, partial_range(Menu, 1u, num_menus))
		menu_hide(&i);
	
	Menu[0].ShowBar = 0;
	Menu[0].Active = 0;
	if (Menu[0].wind)
		window_set_modal(Menu[0].wind, 0);
	menu_show( &Menu[0] );

}
Exemple #7
0
void menu_hide_all()
{
 	int i;

	for (i=1; i<num_menus; i++) 
		menu_hide( &Menu[i] );
	
	Menu[0].ShowBar = 0;
	Menu[0].Active = 0;
	if (Menu[0].wind)
		window_set_modal(Menu[0].wind, 0);
	menu_show( &Menu[0] );

}
Exemple #8
0
/* @brief Called after a window was activated (set to the foreground)
 *
 * Application (callee) should set its context for the given window and set the 
 * Popupmenu menu context.
 */
static void on_window_activated( eripc_context_t          *context,
                                 const eripc_event_info_t *info,
                                 void                     *user_data )
{
    LOGPRINTF("entry");
    gboolean          result      = FALSE; 
    const eripc_arg_t *arg_array  = info->args;

    if (arg_array[0].type == ERIPC_TYPE_INT)
    {
        menu_show();
        result = TRUE;
    }

    // return result to caller
    eripc_reply_bool(context, info->message_id, result);
}
int main(void) 
{
	menu_init();
	settings_init();
	pokedex_init();
	  ///game1_init();

	menu_show();
	
	app_event_loop();
	
	menu_deinit();
	settings_deinit();
	pokedex_deinit();
	  ///game1_deinit();
	
	return 0;
}
Exemple #10
0
int menu_wait()
{
  menu_show();

  int chosen_option;
  while ((get_int_input("Insira a sua opção: ", &chosen_option)) == 1)
  {
    printf("Opção não válida.\n");
  }

  if (chosen_option > 0 && chosen_option <= N_OPTIONS)
  {
    return chosen_option;
  }

  clear_screen();

  return -1;
}
Exemple #11
0
/* Always return FALSE because its not interactive */
static gboolean run_func(ObActionsData *data, gpointer options)
{
    Options *o = options;
    GravityPoint position = { { 0, }, };
    gint monitor = -1;

    if (o->use_position) {
        if (o->monitor >= 0)
            monitor = o->monitor;
        else switch (o->monitor_type) {
            case OB_PLACE_MONITOR_ANY:
            case OB_PLACE_MONITOR_PRIMARY:
                monitor = screen_monitor_primary(FALSE);
                break;
            case OB_PLACE_MONITOR_MOUSE:
                monitor = screen_monitor_pointer();
                break;
            case OB_PLACE_MONITOR_ACTIVE:
                monitor = screen_monitor_active();
                break;
            case OB_PLACE_MONITOR_ALL:
                monitor = screen_num_monitors;
                break;
            default:
                g_assert_not_reached();
        }

        position = o->position;
    } else {
        const Rect *allmon;
        monitor = screen_num_monitors;
        allmon = screen_physical_area_monitor(monitor);
        position.x.pos = data->x - allmon->x;
        position.y.pos = data->y - allmon->y;
    }

    /* you cannot call ShowMenu from inside a menu */
    if (data->uact != OB_USER_ACTION_MENU_SELECTION && o->name)
        menu_show(o->name, &position, monitor,
                  data->button != 0, o->use_position, data->client);

    return FALSE;
}
Exemple #12
0
bool menu_run(int m)
{
    while (1) {
        switch (menu_show(m))
        {
            case MENU_SELECTED_EXIT:
                return false;

            case MENU_ATTACHED_USB:
                return true;

            default:
                if ((menus[m].items[menus[m].cursor].function) &&
                    (menus[m].items[menus[m].cursor].function()))
                    return true;
        }
    }
    return false;
}
int main(int argc, char *argv[])
{
	int choice;

	if (argc != 2)
	{
		fprintf(stderr, "Usage: [%s] + num_process\n", argv[0]);
	}

	while (true)
	{
		menu_show();
		scanf("%d", &choice);

		switch(choice)
		{
			case 1:
				priority_create(atoi(argv[1]));
				priority();
				break;
			case 2:
				fcfs_create(atoi(argv[1]));
				fcfs();
				break;
			case 3:
				sjf_create(atoi(argv[1]));
				sjf();
				break;
			case 0:
				printf("退出程序...\n");
				break;
			default:
				printf("选择错误,请重新选择!\n");
				break;
		}	
		if (choice == 0)
			break;
	}
	return EXIT_SUCCESS;
}
void PuyoCommander::backLoop(Menu *menu, PuyoDrawable *starter)
{

    if (menu == aboutMenu) {
    //    corona = corona32_new();
    //    corona32_resize(corona, 320, CORONA_HEIGHT);
    //    corona_screen = (int*)calloc(320 * CORONA_HEIGHT + 64, sizeof(int));
    }

    menu_show(menu);
    while (1) {
        SDL_Event e;

        while (SDL_PollEvent (&e)) {
            GameControlEvent controlEvent;
            getControlEvent(e, &controlEvent);

            switch (controlEvent.cursorEvent) {
                case GameControlEvent::kQuit:
                    exit(0);
                    goto mml_fin;
                case GameControlEvent::kStart:
                case GameControlEvent::kBack:
                    goto mml_fin;
                    break;
            }
        }
        updateAll(starter);
    }
mml_fin:
    menu_hide (menu);
    if (corona)
    {
    //    corona32_delete(corona);
    //    free(corona_screen);
    //    corona = NULL;
    }
}
Exemple #15
0
Fichier : dvb.c Projet : Limsik/e17
void
dvb_shutdown(void)
{
   if (!o_dvb_bg) return;
   if (!_hide_timer)
     {
	menu_show();
	background_show();
	mini_pause_set(0);
     }
   else
     {
	ecore_timer_del(_hide_timer);
	_hide_timer = NULL;
     }
   
   evas_object_del(o_dvb_bg);
   evas_object_del(o_dvb);
   if (dvb_stopped_job) ecore_job_del(dvb_stopped_job);
   o_dvb = NULL;
   o_dvb_bg = NULL;
   dvb_stopped_job = NULL;
}
Exemple #16
0
void menubar_show()
{
	menubar_hid = 0;
	menu_show( &Menu[0] );
}
void PuyoCommander::startSingleGameLoop()
{
  char playerName[256];

    char * defaultName = getenv("USER");
    if (defaultName == NULL)
      defaultName = "Player";
    if (!(defaultName[0]>=32))
      defaultName = "Player";
    if ((defaultName[0]>='a') && (defaultName[0]<='z'))
      defaultName[0] += 'A' - 'a';

  GetStrPreference("Player Name", playerName, defaultName);
  menu_set_value(singleGameMenu, kPlayerName, playerName, 0);

  while (!menu_active_is(singleGameMenu,kLevelMedium))
    menu_next_item(singleGameMenu);

  menu_show(singleGameMenu);
  while (1) {
    SDL_Event e;

    while (SDL_PollEvent (&e)) {
      GameControlEvent controlEvent;
        getControlEvent(e, &controlEvent);
        switch (controlEvent.cursorEvent) {
            case GameControlEvent::kQuit:
                exit(0);
                break;
            case GameControlEvent::kDown:
                menu_next_item (singleGameMenu);
                break;
            case GameControlEvent::kUp:
                menu_prev_item (singleGameMenu);
                break;
            case GameControlEvent::kStart:
                menu_validate (singleGameMenu);
                if (menu_active_is(singleGameMenu,kPlayerName))
                  enterStringLoop(singleGameMenu,kPlayerName,playerName);
                else
                  goto mml_play;
                break;
            case GameControlEvent::kBack:
                menu_hide(singleGameMenu);
                return;
                break;
        }
    }
    updateAll(NULL);
  }

mml_play:
  menu_hide (singleGameMenu);

  SelIA ia1[] = { {RANDOM, 350}, {FLOBO, 350}, {FLOBO, 250}, {FLOBO, 180}, {FLOBO,  90}, {JEKO, 350}, {TANIA, 320}, {FLOBO, 62}, {RANDOM,0} };
  SelIA ia2[] = { {FLOBO,  190}, {JEKO , 180}, {TANIA, 160}, {FLOBO,  90}, {GYOM , 210}, {TANIA, 90}, {JEKO,   80}, {GYOM,  90}, {RANDOM,0} };
  SelIA ia3[] = { {TANIA,  130}, {JEKO , 100}, {GYOM ,  90}, {JEKO,   80}, {TANIA,  60}, {GYOM,  60}, {GYOM,   40}, {GYOM,  30}, {RANDOM,0} };

  SelIA *ia = &(ia1[0]);

  gameLevel = 1;
  GAME_ACCEL = 2000;
  if (menu_active_is (singleGameMenu, kLevelMedium)) {
    ia = &(ia2[0]);
    GAME_ACCEL = 1500;
    gameLevel = 2;
  }
  else if (menu_active_is (singleGameMenu, kLevelHard)) {
    ia = &(ia3[0]);
    GAME_ACCEL = 1000;
    gameLevel = 3;
  }

  int score1 = 0;
  int score2 = 0;
  int lives  = 3;
  if (menu_active_is(finishedMenu,  "NO"))
    menu_next_item(finishedMenu);
  if (menu_active_is(looserMenu   ,  "NO"))
    menu_next_item(looserMenu);
  if (menu_active_is(nextLevelMenu,  "NO"))
    menu_next_item(nextLevelMenu);
  if (menu_active_is(gameOver2PMenu, "NO"))
    menu_next_item(gameOver2PMenu);
  gameOverMenu = nextLevelMenu;

  int lastPoints = 0;
  int currentMusicTheme = 0;

  int fini = 0;
  while (!fini)
  {
    PuyoStory myStory(this, score2+1);
    myStory.loop();
    PuyoStarter myStarter(this, true, ia[score2].level, ia[score2].type, currentMusicTheme);
    p1name = playerName;
    p2name = AI_NAMES[score2];
    doom_melt_start(melt, menuBGImage);
    audio_music_switch_theme(currentMusicTheme);
    myStarter.run(score1, score2, lives, lastPoints, 0);
    lastPoints = myStarter.rightPlayerPoints();
    score1 += myStarter.leftPlayerWin();
    score2 += myStarter.rightPlayerWin();
    if (!myStarter.rightPlayerWin())
      lives--;
    else {
      currentMusicTheme = (currentMusicTheme + 1) % NB_MUSIC_THEME;
    }

    if (ia[score2].level == 0) {
      lastPoints += 100000;
      if (menu_active_is (singleGameMenu, kLevelMedium))
        lastPoints += 150000;
      if (menu_active_is (singleGameMenu, kLevelHard))
        lastPoints += 250000;
      fini = 1;
    }

    if (!(menu_active_is(gameOverMenu, "YES") && (lives >= 0)))
      fini = 1;

    if (fini)
    {
      audio_music_start(0);
      doom_melt_start(melt, gameScreen);
      int newOne = setHiScore(lastPoints, p1name);
      if (newOne >= 0)
      {
        updateHighScoresMenu(newOne);
        backLoop(highScoresMenu, NULL);
      }
    }
  }
  SetStrPreference("Player Name", playerName);
}
Exemple #18
0
void do_state_2(int keypress)
{
	int i;

	if (keyd_pressed[KEY_LALT] || keyd_pressed[KEY_RALT] )
 		state2_alt_down = 1;

	if (!keyd_pressed[KEY_LALT] && !keyd_pressed[KEY_RALT] && state2_alt_down )
	{
		state = 0;
		menu_hide_all();
	}			

	switch( keypress )
	{
	case KEY_ESC:
		state = 0;
		menu_hide_all();
		break;
	case KEY_LEFT:
	case KEY_PAD4:
		i = Menu[0].CurrentItem-1;
		if (i < 0 ) i = Menu[0].NumItems-1;
		menu_move_bar_to( &Menu[0], i );
		break;
	case KEY_RIGHT:
	case KEY_PAD6:
		i = Menu[0].CurrentItem+1;
		if (i >= Menu[0].NumItems ) i = 0;
		menu_move_bar_to( &Menu[0], i );
		break;
	case KEY_ENTER:
	case KEY_PADENTER:
	case KEY_DOWN:
	case KEY_PAD2:
		state = 3;	
		Menu[ CMENU ].ShowBar = 1;
		Menu[ CMENU ].Active = 1;
		Menu[0].Active = 0;
		menu_show( &Menu[ 0 ] );
		menu_show( &Menu[ CMENU ] );
		break;
	
	default:
		i = menu_match_keypress( &Menu[0], keypress );
	
		if (i > -1 )
		{
			Menu[0].CurrentItem = i;
			Menu[0].Active = 0;
			state = 3;	
			Menu[ CMENU ].ShowBar = 1;
			Menu[ CMENU ].Active = 1;
			Menu[0].ShowBar = 1;
			menu_show( &Menu[ CMENU ] );
			menu_show( &Menu[0] );
			break;
		}

		i = menu_check_mouse_item( &Menu[0] );

		if ( (i == -1) && B1_JUST_RELEASED )
		{
			state = 0;
			menu_hide_all();
			break;
		}

		if ( B1_PRESSED && (i > -1))
		{
			Menu[0].CurrentItem = i;
			Menu[0].Active = 0;
			state = 3;	
			Menu[ CMENU ].ShowBar = 1;
			Menu[ CMENU ].Active = 1;
			Menu[0].ShowBar = 1;
			menu_show( &Menu[ CMENU ] );
			menu_show( &Menu[0] );
			break;
		}


	}
}
Exemple #19
0
void do_state_3( int keypress )
{
	int i;
	
	switch( keypress )
	{
	case KEY_ESC:
		state = 0;
		menu_hide_all();
		break;
	case KEY_DOWN:
	case KEY_PAD2:
		i = Menu[ CMENU ].CurrentItem;
		do {
			i++;		
			if ( i >= Menu[ CMENU ].NumItems )
				i = 0;
		} while( Menu[CMENU].Item[i].Text[0] == '-');
		menu_move_bar_to( &Menu[ CMENU ], i );
		break;
	case KEY_UP:
	case KEY_PAD8:
		i = Menu[ CMENU ].CurrentItem;
		do 
		{
			i--;
			if ( i < 0 )
				i = Menu[ CMENU ].NumItems-1;
		} while( Menu[CMENU].Item[i].Text[0] == '-');
		menu_move_bar_to( &Menu[ CMENU ], i );
		break;
	case KEY_RIGHT:
	case KEY_PAD6:
		menu_hide( &Menu[ CMENU ] );
		i = Menu[0].CurrentItem+1;
		if (i >= Menu[0].NumItems ) i = 0;
		menu_move_bar_to( &Menu[0], i );
		Menu[CMENU].ShowBar = 1;
		Menu[CMENU].Active = 1;
		menu_show( &Menu[CMENU] );
		break;
	case KEY_LEFT:
	case KEY_PAD4:
		menu_hide( &Menu[ CMENU ] );
		i = Menu[0].CurrentItem-1;
		if (i < 0 ) i = Menu[0].NumItems-1;
		menu_move_bar_to( &Menu[0], i );
		Menu[ CMENU ].ShowBar = 1;
		Menu[CMENU].Active = 1;
		menu_show( &Menu[ CMENU ] );
		break;
	case KEY_ENTER:
	case KEY_PADENTER:
		state = 0;
		menu_hide_all();

		if (Menu[CMENU].Item[ Menu[CMENU].CurrentItem ].user_function)
			Menu[CMENU].Item[ Menu[CMENU].CurrentItem ].user_function();
		
		break;
		
	default:
		i = menu_match_keypress( &Menu[ CMENU ], keypress );

		if (i > -1 )
		{
			menu_move_bar_to( &Menu[ CMENU ], i );
			state = 0;
			menu_hide_all();
							
			if (Menu[CMENU].Item[ Menu[CMENU].CurrentItem ].user_function)
				Menu[CMENU].Item[ Menu[CMENU].CurrentItem ].user_function();
			break;
		}
		i = menu_check_mouse_item( &Menu[CMENU] );
			
		if (i > -1 )
		{
			if ( B1_PRESSED )
				menu_move_bar_to( &Menu[ CMENU ], i );
			else if ( B1_JUST_RELEASED )
			{
				menu_move_bar_to( &Menu[ CMENU ], i );
				state = 0;
				menu_hide_all();
								
				if (Menu[CMENU].Item[ Menu[CMENU].CurrentItem ].user_function)
					Menu[CMENU].Item[ Menu[CMENU].CurrentItem ].user_function();
				break;
			}
		} else {
			i = menu_check_mouse_item( &Menu[0] );

			if ( B1_PRESSED && (i > -1))
			{
				if ( Menu[0].CurrentItem != i)	{
					menu_hide( &Menu[ CMENU ] );
					menu_move_bar_to( &Menu[0], i );
					Menu[ CMENU ].ShowBar = 1;
					Menu[CMENU].Active = 1;
					menu_show( &Menu[ CMENU ] );
					break;
				}
			}

			if ( B1_JUST_RELEASED )
			{
				state = 0;
				menu_hide_all();
				break;
			}

		}

	}
}
Exemple #20
0
void do_state_0( int keypress )
{
	int i, j;
	
	Menu[0].Active = 0;
	Menu[0].ShowBar = 0;
	if (Menu[0].Displayed==0)
		menu_show( &Menu[0] );

	if ( keypress & KEY_ALTED )	{
		i = menu_match_keypress( &Menu[0], keypress );
		if (i > -1 )
		{
			Menu[0].CurrentItem = i;
			Menu[0].Active = 0;
			state = 3;	
			Menu[ CMENU ].ShowBar = 1;
			Menu[ CMENU ].Active = 1;
			Menu[0].ShowBar = 1;
	
			menu_show( &Menu[ CMENU ] );
			menu_show( &Menu[0] );
		}
	}
	
	for (i=0; i<num_menus; i++ )
		for (j=0; j< Menu[i].NumItems; j++ )
		{
			if ( Menu[i].Item[j].Hotkey == keypress )
			{
				if (Menu[i].Item[j].user_function)
					Menu[i].Item[j].user_function();
				last_keypress = 0;
				return;
			}
		}
		
	if (keyd_pressed[KEY_LALT] || keyd_pressed[KEY_RALT] || ((keypress & 0xFF) == KEY_LALT) )
	//if ( (keypress & 0xFF) == KEY_LALT )
	{
		state = 1;
		Menu[0].Active = 1;
		menu_show( &Menu[0] );
		return;
	}

	i = menu_check_mouse_item( &Menu[0] );

	if ( B1_PRESSED && (i > -1))
	{
		Menu[0].CurrentItem = i;
		state = 3;	
		Menu[ CMENU ].ShowBar = 1;
		Menu[0].ShowBar = 1;
		Menu[ CMENU ].Active = 1;
		Menu[0].Active = 0;
		menu_show( &Menu[ CMENU ] );
		menu_show( &Menu[0] );
		return;
	}
}
Exemple #21
0
static window_event_result do_state_1(const d_event &event)
{
	int i;
	int keypress = 0;
	window_event_result rval = window_event_result::ignored;
	
	if (event.type == EVENT_KEY_COMMAND)
		keypress = event_key_get(event);
	
	if ((event.type == EVENT_KEY_RELEASE) && !(event_key_get(event) & KEY_ALTED))
	{
		state = 2;
		state2_alt_down = 0;
		Menu[0].ShowBar = 1;
		Menu[0].Active = 1;
		menu_show( &Menu[0] );
		rval = window_event_result::handled;
  	}

	i = menu_match_keypress( &Menu[0], keypress );
	
	if (i > -1 )
	{
		Menu[0].CurrentItem = i;
		Menu[0].Active = 0;
		window_set_modal(Menu[0].wind, 0);
		state = 3;	
		Menu[ CMENU ].ShowBar = 1;
		Menu[ CMENU ].Active = 1;
		Menu[0].ShowBar = 1;

		menu_show( &Menu[ CMENU ] );
		menu_show( &Menu[0] );
		rval = window_event_result::handled;
	}

	i = menu_check_mouse_item( &Menu[0] );

	if ( (i == -1) && B1_JUST_RELEASED )
	{
		state = 0;
		menu_hide_all();
		return window_event_result::handled;
	}

	if ( B1_JUST_PRESSED && (i > -1))
	{
		Menu[0].CurrentItem = i;
		state = 3;	
		Menu[ CMENU ].ShowBar = 1;
		Menu[ CMENU ].Active = 1;
		Menu[0].ShowBar = 1;
		Menu[0].Active = 0;
		window_set_modal(Menu[0].wind, 0);
		menu_show( &Menu[ CMENU ] );
		menu_show( &Menu[0] );
		return window_event_result::handled;
	}
	
	return rval;
}
void 
GameSession::update()
{
  int delta_wait = static_cast<int>(1000/args->fps);
  float delta = delta_wait/1000.0f;;

  deltas += delta;
  ++loops;

  if (CL_Keyboard::get_keycode(CL_KEY_D))
    Guile::enter_repl();

  unsigned int last_time = CL_System::get_time ();

  // Update stuff
  if (!do_pause)
    {
      collision_mgr->clear();
      AIManager::instance()->update(delta);
      world->update(delta);
      collision_mgr->run();
      view->update(delta);
    }

  GameWorld::current()->draw(*view);
  GameWorld::current()->draw_energie(*view);
  view->get_sc().render();
  view->get_sc().light().fill_screen(CL_Color(50, 50, 100));

  if (draw_colmap)
    collision_mgr->draw(*view);

  if (!do_pause)
    DisplayManager::current()->update(delta);
      
  DisplayManager::current()->draw(*(CL_Display::get_current_window()->get_gc()));

  if (CL_Mouse::get_keycode(CL_MOUSE_MIDDLE))
    world->add(new ExplosionParticle(view->screen_to_world(FloatVector2d(CL_Mouse::get_x (),
                                                                         CL_Mouse::get_y ())),
                                     FloatVector2d(), 3.0f));

  // Comment out for variable frame rate
  int sleep_time = (last_time + delta_wait) - CL_System::get_time();
  if (sleep_time > 0)
    CL_System::sleep (sleep_time);

  // Flip front and backbuffer. This makes the changes visible:
  CL_Display::flip ();

  if (!args->video_record_directory.empty())
    {
      std::stringstream filename;
      filename << args->video_record_directory;
      filename.width(8);
      filename.fill('0');
      filename << frames;
      filename << ".ppm";
      Screenshot::write_screenshot_pnm(filename.str());
    }

  ++frames;
	    
  // Update keyboard input and handle system events:
  // Exits the loop if ClanLib requests shutdown - for instance if
  // someone closes the window.
  CL_System::keep_alive();
  clanlib_call_post_keep_alive_func();
  InputManager::update(delta);

  InputEventLst lst = InputManager::get_controller().get_events();
  for(InputEventLst::iterator i = lst.begin(); i != lst.end(); ++i)
    {
      if (i->type == BUTTON_EVENT)
        {
          if (i->button.name == MENU_BUTTON && i->button.is_down())
            {
              if (control_state == MENU_CONTROL)
                {
                  menu_hide();
                  control_state = UNIT_CONTROL;
                }
              else 
                {
                  menu_show(0);
                  control_state = MENU_CONTROL;
                }
            }
          else if (i->button.name == USE_BUTTON && i->button.is_down())
            {
              // FIXME: Unclean hack
              gh_call0(gh_lookup("join-nearest-vehicle"));
            }
        }
    }

  switch (control_state)
    {
    case MENU_CONTROL:
      if (DisplayManager::current()->get_menu())
        DisplayManager::current()->get_menu()->process_events(InputManager::get_controller().get_events());
      else
        {
          std::cout << "Error: Menu not available, fallback to unit" << std::endl;
          control_state = UNIT_CONTROL;
        }
      break;

    case UNIT_CONTROL:
      player->get_current_unit()->update_controlls(InputManager::get_controller());
      break;
      
    default: 
      std::cout << "Unknown ControlState, switching back to UNIT_CONTROL" << std::endl;
      control_state = UNIT_CONTROL;
      break;
    }

  InputManager::clear();
}
Exemple #23
0
static window_event_result do_state_2(const d_event &event)
{
	int i;
	int keypress = 0;
	window_event_result rval = window_event_result::ignored;
	if (event.type == EVENT_KEY_COMMAND)
		keypress = event_key_get(event);
		
	if (keypress & KEY_ALTED)
	{
 		state2_alt_down = 1;
		rval = window_event_result::handled;
	}

	if ((event.type == EVENT_KEY_RELEASE) && !(event_key_get(event) & KEY_ALTED) && state2_alt_down)
	{
		state = 0;
		menu_hide_all();
		rval = window_event_result::handled;
	}			

	switch( keypress )
	{
	case KEY_ESC:
		state = 0;
		menu_hide_all();
		return window_event_result::handled;
	case KEY_LEFT:
	case KEY_PAD4:
		i = Menu[0].CurrentItem-1;
		if (i < 0 ) i = Menu[0].NumItems-1;
		menu_move_bar_to( &Menu[0], i );
		return window_event_result::handled;
	case KEY_RIGHT:
	case KEY_PAD6:
		i = Menu[0].CurrentItem+1;
		if (i >= Menu[0].NumItems ) i = 0;
		menu_move_bar_to( &Menu[0], i );
		return window_event_result::handled;
	case KEY_ENTER:
	case KEY_PADENTER:
	case KEY_DOWN:
	case KEY_PAD2:
		state = 3;	
		Menu[ CMENU ].ShowBar = 1;
		Menu[ CMENU ].Active = 1;
		Menu[0].Active = 0;
		window_set_modal(Menu[0].wind, 0);
		menu_show( &Menu[ 0 ] );
		menu_show( &Menu[ CMENU ] );
		return window_event_result::handled;
	
	default:
		i = menu_match_keypress( &Menu[0], keypress );
	
		if (i > -1 )
		{
			Menu[0].CurrentItem = i;
			Menu[0].Active = 0;
			window_set_modal(Menu[0].wind, 0);
			state = 3;	
			Menu[ CMENU ].ShowBar = 1;
			Menu[ CMENU ].Active = 1;
			Menu[0].ShowBar = 1;
			menu_show( &Menu[ CMENU ] );
			menu_show( &Menu[0] );
			return window_event_result::handled;
		}

		i = menu_check_mouse_item( &Menu[0] );

		if ( (i == -1) && B1_JUST_RELEASED )
		{
			state = 0;
			menu_hide_all();
			return window_event_result::handled;
		}

		if (i > -1)
		{
			Menu[0].CurrentItem = i;
			Menu[0].Active = 0;
			window_set_modal(Menu[0].wind, 0);
			state = 3;	
			Menu[ CMENU ].ShowBar = 1;
			Menu[ CMENU ].Active = 1;
			Menu[0].ShowBar = 1;
			menu_show( &Menu[ CMENU ] );
			menu_show( &Menu[0] );
			return window_event_result::handled;
		}
	}
	
	return rval;
}
Exemple #24
0
int main( int argc, char *arvg[] ) {
	int quit = 0;
	int config_status = 0;
	int event;

#ifdef __WIN32__
	freopen( "cabrio.out", "w", stdout );
	freopen( "cabrio.err", "w", stderr );
#endif

	config_status = config_open( NULL );
	if( config_status == -1 )
		return -1;

	if( sdl_init() != 0 )
		bail();

	if( ogl_init() != 0 )
		bail();
	
	/* Clear the screen as soon as we can. This avoids graphics
	 * glitches which can occur with some SDL implementations. */
	ogl_clear();
	sdl_swap();

	if( event_init() != 0 )
		bail();

	if( font_init() != 0 )
		bail();

	if( config_status == 1 ) {
		/* Config file didn't exist, so run the setup utility */
		if( setup() != 0 )
			return -1;
		config_update();
		if( config_create() != 0 )
			return -1;
	}

	location_init();

	/* If config or location results in a new font, it'll be loaded here. */
	font_free();
	font_init();

	/* Large game lists take a while to initialise,
	 * so show the background while we wait... */
	bg_init();
	bg_clear();
	bg_draw();
	sdl_swap();

	if( platform_init() != 0 )
		bail();

	if( category_init() != 0 )
		bail();

	if( game_sel_init() != 0 )
		bail();

	if( hint_init() != 0 )
		bail();

	if( snap_init() != 0 )
		bail();
	
	if( game_list_create() != 0 )
		bail();

	if( menu_init() != 0 )
		bail();

	if( submenu_init() != 0 )
		bail();

	sound_init();
	video_init();
	
	event_flush();

	if( !config_get()->iface.theme.menu.auto_hide )
		menu_show();
		
	focus_set( FOCUS_GAMESEL );

	while( !quit ) {
		ogl_clear();
		bg_draw();
		snap_draw();
		if (!config_get()->iface.hide_buttons)
			hint_draw();
		menu_draw();
		submenu_draw();
		game_sel_draw();
		sdl_swap();
		if (Mix_PlayingMusic() != 1 && config_get()->iface.theme_sound && reader_running == 0) 
			playmusic();
		if (( event = event_poll() )) {
			if( supress_wait == 0 ) {
				if( event == EVENT_QUIT ) {
					quit = 1;
				}
				else {
					supress();
					event_process( event );
				}
			}
		}
		if( supress_wait > 0 )
			supress_wait--;
		
		sdl_frame_delay();
	}
	clean_up();
	return 0;
}
Exemple #25
0
static window_event_result menu_handler(window *, const d_event &event, MENU *menu)
{
	int i;
	int keypress = 0;
	
	if (state != 3)
		return window_event_result::ignored;
	
	if (event.type == EVENT_KEY_COMMAND)
		keypress = event_key_get(event);
	else if (event.type == EVENT_WINDOW_CLOSE)	// quitting
	{
		state = 0;
		menu_hide_all();
		menu->wind = nullptr;
		return window_event_result::ignored;
	}
	window_event_result rval = window_event_result::ignored;
	switch( keypress )
	{
		case 0:
			break;
		case KEY_ESC:
			state = 0;
			menu_hide_all();
			rval = window_event_result::handled;
			break;
		case KEY_DOWN:
		case KEY_PAD2:
			i = Menu[ CMENU ].CurrentItem;
			do {
				i++;		
				if ( i >= Menu[ CMENU ].NumItems )
					i = 0;
			} while( Menu[CMENU].Item[i].Text[0] == '-');
			menu_move_bar_to( &Menu[ CMENU ], i );
			rval = window_event_result::handled;
			break;
		case KEY_UP:
		case KEY_PAD8:
			i = Menu[ CMENU ].CurrentItem;
			do 
			{
				i--;
				if ( i < 0 )
					i = Menu[ CMENU ].NumItems-1;
			} while( Menu[CMENU].Item[i].Text[0] == '-');
			menu_move_bar_to( &Menu[ CMENU ], i );
			rval = window_event_result::handled;
			break;
		case KEY_RIGHT:
		case KEY_PAD6:
			menu_hide( &Menu[ CMENU ] );
			i = Menu[0].CurrentItem+1;
			if (i >= Menu[0].NumItems ) i = 0;
			menu_move_bar_to( &Menu[0], i );
			Menu[CMENU].ShowBar = 1;
			Menu[CMENU].Active = 1;
			menu_show( &Menu[CMENU] );
			rval = window_event_result::handled;
			break;
		case KEY_LEFT:
		case KEY_PAD4:
			menu_hide( &Menu[ CMENU ] );
			i = Menu[0].CurrentItem-1;
			if (i < 0 ) i = Menu[0].NumItems-1;
			menu_move_bar_to( &Menu[0], i );
			Menu[ CMENU ].ShowBar = 1;
			Menu[CMENU].Active = 1;
			menu_show( &Menu[ CMENU ] );
			rval = window_event_result::handled;
			break;
		case KEY_ENTER:
		case KEY_PADENTER:
			state = 0;
			menu_hide_all();

			if (Menu[CMENU].Item[ Menu[CMENU].CurrentItem ].user_function)
				Menu[CMENU].Item[ Menu[CMENU].CurrentItem ].user_function();
			
			rval = window_event_result::handled;
			break;
			
		default:
			i = menu_match_keypress( &Menu[ CMENU ], keypress );

			if (i > -1 )
			{
				menu_move_bar_to( &Menu[ CMENU ], i );
				state = 0;
				menu_hide_all();
								
				if (Menu[CMENU].Item[ Menu[CMENU].CurrentItem ].user_function)
					Menu[CMENU].Item[ Menu[CMENU].CurrentItem ].user_function();
				rval = window_event_result::handled;
				break;
			}
	}
	
	if (event.type == EVENT_MOUSE_MOVED || B1_JUST_RELEASED)
	{
		i = menu_check_mouse_item( &Menu[CMENU] );
			
		if (i > -1 )
		{
			if ( B1_JUST_RELEASED )
			{
				menu_move_bar_to( &Menu[ CMENU ], i );
				state = 0;
				menu_hide_all();
								
				if (Menu[CMENU].Item[ Menu[CMENU].CurrentItem ].user_function)
					Menu[CMENU].Item[ Menu[CMENU].CurrentItem ].user_function();
				rval = window_event_result::handled;
			}
			else
			{
				menu_move_bar_to( &Menu[ CMENU ], i );
				rval = window_event_result::handled;
			}
		} else {
			i = menu_check_mouse_item( &Menu[0] );

			if (i > -1)
			{
				if ( Menu[0].CurrentItem != i)	{
					menu_hide( &Menu[ CMENU ] );
					menu_move_bar_to( &Menu[0], i );
					Menu[ CMENU ].ShowBar = 1;
					Menu[CMENU].Active = 1;
					menu_show( &Menu[ CMENU ] );
				}

				rval = window_event_result::handled;
			}

			if ( B1_JUST_RELEASED )
			{
				state = 0;
				menu_hide_all();
				rval = window_event_result::handled;
			}
		}
	}
	
	if (event.type == EVENT_WINDOW_DRAW)
	{
		menu_draw(&Menu[CMENU]);
		return window_event_result::handled;
	}
	
	return rval;
}
Exemple #26
0
/* this is the important one */
void handle_key(struct key_event *k)
{
	if (_handle_ime(k))
		return;

	/* okay... */
	if (!(status.flags & DISKWRITER_ACTIVE) && ACTIVE_PAGE.pre_handle_key) {
		if (ACTIVE_PAGE.pre_handle_key(k)) return;
	}

	if (handle_key_global(k)) return;
	if (!(status.flags & DISKWRITER_ACTIVE) && menu_handle_key(k)) return;
	if (widget_handle_key(k)) return;

	/* now check a couple other keys. */
	switch (k->sym) {
	case SDLK_LEFT:
		if (k->state == KEY_RELEASE) return;
		if (status.flags & DISKWRITER_ACTIVE) return;
		if ((k->mod & KMOD_CTRL) && status.current_page != PAGE_PATTERN_EDITOR) {
			_mp_finish(NULL);
			if (song_get_mode() == MODE_PLAYING)
				song_set_current_order(song_get_current_order() - 1);
			return;
		}
		break;
	case SDLK_RIGHT:
		if (k->state == KEY_RELEASE) return;
		if (status.flags & DISKWRITER_ACTIVE) return;
		if ((k->mod & KMOD_CTRL) && status.current_page != PAGE_PATTERN_EDITOR) {
			_mp_finish(NULL);
			if (song_get_mode() == MODE_PLAYING)
				song_set_current_order(song_get_current_order() + 1);
			return;
		}
		break;
	case SDLK_ESCAPE:
		/* TODO | Page key handlers should return true/false depending on if the key was handled
		   TODO | (same as with other handlers), and the escape key check should go *after* the
		   TODO | page gets a chance to grab it. This way, the load sample page can switch back
		   TODO | to the sample list on escape like it's supposed to. (The status.current_page
		   TODO | checks above won't be necessary, either.) */
		if (NO_MODIFIER(k->mod) && status.dialog_type == DIALOG_NONE
		    && status.current_page != PAGE_LOAD_SAMPLE
		    && status.current_page != PAGE_LOAD_INSTRUMENT) {
			if (k->state == KEY_RELEASE) return;
			if (_mp_active) {
				_mp_finish(NULL);
				return;
			}
			menu_show();
			return;
		}
		break;
	case SDLK_SLASH:
		if (k->state == KEY_RELEASE) return;
		if (status.flags & DISKWRITER_ACTIVE) return;
		if (k->orig_sym == SDLK_KP_DIVIDE) {
			kbd_set_current_octave(kbd_get_current_octave() - 1);
		}
		return;
	case SDLK_ASTERISK:
		if (k->state == KEY_RELEASE) return;
		if (status.flags & DISKWRITER_ACTIVE) return;
		if (k->orig_sym == SDLK_KP_MULTIPLY) {
			kbd_set_current_octave(kbd_get_current_octave() + 1);
		}
		return;
	case SDLK_LEFTBRACKET:
		if (k->state == KEY_RELEASE) break;
		if (status.flags & DISKWRITER_ACTIVE) return;
		if (k->mod & KMOD_SHIFT) {
			song_set_current_speed(song_get_current_speed() - 1);
			status_text_flash("Speed set to %d frames per row", song_get_current_speed());
			if (!(song_get_mode() & (MODE_PLAYING | MODE_PATTERN_LOOP))) {
				song_set_initial_speed(song_get_current_speed());
			}
		} else if ((k->mod & KMOD_CTRL) && !(status.flags & CLASSIC_MODE)) {
			song_set_current_tempo(song_get_current_tempo() - 1);
			status_text_flash("Tempo set to %d frames per row", song_get_current_tempo());
			if (!(song_get_mode() & (MODE_PLAYING | MODE_PATTERN_LOOP))) {
				song_set_initial_tempo(song_get_current_tempo());
			}
		} else if (NO_MODIFIER(k->mod)) {
			song_set_current_global_volume(song_get_current_global_volume() - 1);
			status_text_flash("Global volume set to %d", song_get_current_global_volume());
			if (!(song_get_mode() & (MODE_PLAYING | MODE_PATTERN_LOOP))) {
				song_set_initial_global_volume(song_get_current_global_volume());
			}
		}
		return;
	case SDLK_RIGHTBRACKET:
		if (k->state == KEY_RELEASE) break;
		if (status.flags & DISKWRITER_ACTIVE) return;
		if (k->mod & KMOD_SHIFT) {
			song_set_current_speed(song_get_current_speed() + 1);
			status_text_flash("Speed set to %d frames per row", song_get_current_speed());
			if (!(song_get_mode() & (MODE_PLAYING | MODE_PATTERN_LOOP))) {
				song_set_initial_speed(song_get_current_speed());
			}
		} else if ((k->mod & KMOD_CTRL) && !(status.flags & CLASSIC_MODE)) {
			song_set_current_tempo(song_get_current_tempo() + 1);
			status_text_flash("Tempo set to %d frames per row", song_get_current_tempo());
			if (!(song_get_mode() & (MODE_PLAYING | MODE_PATTERN_LOOP))) {
				song_set_initial_tempo(song_get_current_tempo());
			}
		} else if (NO_MODIFIER(k->mod)) {
			song_set_current_global_volume(song_get_current_global_volume() + 1);
			status_text_flash("Global volume set to %d", song_get_current_global_volume());
			if (!(song_get_mode() & (MODE_PLAYING | MODE_PATTERN_LOOP))) {
				song_set_initial_global_volume(song_get_current_global_volume());
			}
		}
		return;

	default:
		break;
	}

	/* and if we STILL didn't handle the key, pass it to the page.
	 * (or dialog, if one's active) */
	if (status.dialog_type & DIALOG_BOX) {
		dialog_handle_key(k);
	} else {
		if (status.flags & DISKWRITER_ACTIVE) return;
		if (ACTIVE_PAGE.handle_key) ACTIVE_PAGE.handle_key(k);
	}
}
void PuyoCommander::optionMenuLoop(PuyoDrawable *d)
{
  menu_show(optionMenu);
  while (1) {
    SDL_Event e;

    while (SDL_PollEvent (&e)) {
      GameControlEvent controlEvent;
      getControlEvent(e, &controlEvent);

      switch (controlEvent.cursorEvent) {
        case GameControlEvent::kQuit:
          exit(0);
          goto mml_fin;
          break;
        case GameControlEvent::kUp:
          menu_prev_item (optionMenu);
          break;
        case GameControlEvent::kDown:
          menu_next_item (optionMenu);
          break;
        case GameControlEvent::kStart:
          menu_validate (optionMenu);
          if (menu_active_is (optionMenu, "Back"))
            goto mml_fin;
          if (menu_active_is (optionMenu, kFullScreen)) {
            fullscreen  = menu_switch_on_off(optionMenu, kFullScreen);
            SetBoolPreference(kFullScreen,fullscreen);
            if (useGL)
            {
              menu_hide(optionMenu);
              backLoop(mustRestartMenu,d);
              menu_show(optionMenu);
            }
            else
            {
#ifdef _WIN32
                menu_hide(optionMenu);
                backLoop(mustRestartMenu,d);
                menu_show(optionMenu);
#else
                SDL_QuitSubSystem(SDL_INIT_VIDEO);
                SDL_InitSubSystem(SDL_INIT_VIDEO);
                display = SDL_SetVideoMode(320, 240, 0,
                                           SDL_SWSURFACE
                                           |(fullscreen?SDL_FULLSCREEN:0));
#endif
              /* IIM_ReConvertAll();
              SoFont_Refresh(menuFont);
              SoFont_Refresh(smallFont);
              SoFont_Refresh(darkFont); */
            }
          }
          if (menu_active_is (optionMenu, kOpenGL)) {
            bool useGL2 = menu_switch_on_off(optionMenu, kOpenGL);
            SetBoolPreference(kOpenGL,useGL2);
            menu_hide(optionMenu);
            backLoop(mustRestartMenu,d);
            menu_show(optionMenu);
          }
          if (menu_active_is (optionMenu, kMusic)) {
            sound = menu_switch_on_off(optionMenu, kMusic);
            SetBoolPreference(kMusic,sound);
            audio_set_music_on_off(sound);
            if (sound) audio_music_start(0);
          }
          if (menu_active_is (optionMenu, kAudioFX)) {
            fx = menu_switch_on_off(optionMenu, kAudioFX);
            SetBoolPreference(kAudioFX,fx);
            audio_set_sound_on_off(fx);
          }
          if (menu_active_is (optionMenu, kControls)) {
            menu_hide (optionMenu);
            controlsMenuLoop(d);
            menu_show(optionMenu);
          }
          break;
        case GameControlEvent::kBack:
          goto mml_fin;
          break;
        default:
          break;
      }
    }

    updateAll(d);
  }
mml_fin:
  menu_hide (optionMenu);
}
void PuyoCommander::controlsMenuLoop(PuyoDrawable *d)
{
  char newKeyName[250];

  getKeyName(kPlayer1LeftControl, newKeyName);
  menu_set_value(controlsMenu, kPlayer1Left, newKeyName,0);
  getKeyName(kPlayer1RightControl, newKeyName);
  menu_set_value(controlsMenu, kPlayer1Right, newKeyName,0);
  getKeyName(kPlayer1DownControl, newKeyName);
  menu_set_value(controlsMenu, kPlayer1Down, newKeyName,0);
  getKeyName(kPlayer1ClockwiseControl, newKeyName);
  menu_set_value(controlsMenu, kPlayer1Clockwise, newKeyName,0);
  getKeyName(kPlayer1CounterclockwiseControl, newKeyName);
  menu_set_value(controlsMenu, kPlayer1Counterclockwise, newKeyName,0);


  getKeyName(kPlayer2LeftControl, newKeyName);
  menu_set_value(controlsMenu, kPlayer2Left, newKeyName,0);
  getKeyName(kPlayer2RightControl, newKeyName);
  menu_set_value(controlsMenu, kPlayer2Right, newKeyName,0);
  getKeyName(kPlayer2DownControl, newKeyName);
  menu_set_value(controlsMenu, kPlayer2Down, newKeyName,0);
  getKeyName(kPlayer2ClockwiseControl, newKeyName);
  menu_set_value(controlsMenu, kPlayer2Clockwise, newKeyName,0);
  getKeyName(kPlayer2CounterclockwiseControl, newKeyName);
  menu_set_value(controlsMenu, kPlayer2Counterclockwise, newKeyName,1);


  menu_show(controlsMenu);
  while (1) {
    SDL_Event e;

    while (SDL_PollEvent (&e)) {
      char *chosenControl = NULL;
      int chosenControlIndex;
      GameControlEvent controlEvent;
      getControlEvent(e, &controlEvent);

      switch (controlEvent.cursorEvent) {
        case GameControlEvent::kQuit:
          exit(0);
          goto mml_fin;
          break;
        case GameControlEvent::kUp:
          menu_prev_item (controlsMenu);
          break;
        case GameControlEvent::kDown:
          menu_next_item (controlsMenu);
          break;
        case GameControlEvent::kStart:
          menu_validate (controlsMenu);
          if (menu_active_is (controlsMenu, "Back"))
            goto mml_fin;

          if (menu_active_is (controlsMenu, kPlayer1Left)) {
            chosenControl = kPlayer1Left;
            chosenControlIndex = kPlayer1LeftControl;
          }
          if (menu_active_is (controlsMenu, kPlayer1Right)) {
            chosenControl = kPlayer1Right;
            chosenControlIndex = kPlayer1RightControl;
          }
          if (menu_active_is (controlsMenu, kPlayer1Down)) {
            chosenControl = kPlayer1Down;
            chosenControlIndex = kPlayer1DownControl;
          }
          if (menu_active_is (controlsMenu, kPlayer1Clockwise)) {
            chosenControl = kPlayer1Clockwise;
            chosenControlIndex = kPlayer1ClockwiseControl;
          }
          if (menu_active_is (controlsMenu, kPlayer1Counterclockwise)) {
            chosenControl = kPlayer1Counterclockwise;
            chosenControlIndex = kPlayer1CounterclockwiseControl;
          }

          if (menu_active_is (controlsMenu, kPlayer2Left)) {
            chosenControl = kPlayer2Left;
            chosenControlIndex = kPlayer2LeftControl;
          }
          if (menu_active_is (controlsMenu, kPlayer2Right)) {
            chosenControl = kPlayer2Right;
            chosenControlIndex = kPlayer2RightControl;
          }
          if (menu_active_is (controlsMenu, kPlayer2Down)) {
            chosenControl = kPlayer2Down;
            chosenControlIndex = kPlayer2DownControl;
          }
          if (menu_active_is (controlsMenu, kPlayer2Clockwise)) {
            chosenControl = kPlayer2Clockwise;
            chosenControlIndex = kPlayer2ClockwiseControl;
          }
          if (menu_active_is (controlsMenu, kPlayer2Counterclockwise)) {
            chosenControl = kPlayer2Counterclockwise;
            chosenControlIndex = kPlayer2CounterclockwiseControl;
          }

          if (chosenControl != NULL) {
            char prevValue[255];
            strcpy(prevValue, menu_get_value (controlsMenu, chosenControl));
            menu_set_value(controlsMenu, chosenControl, "<Choose>");
            if (changeControlLoop(chosenControlIndex, d)) {
              getKeyName(chosenControlIndex, newKeyName);
              menu_set_value(controlsMenu, chosenControl, newKeyName);
              menu_next_item (controlsMenu);
            }
            else {
              menu_set_value(controlsMenu, chosenControl, prevValue);
            }
          }
          break;
        case GameControlEvent::kBack:
          goto mml_fin;
          break;
        default:
          break;
      }
    }

    updateAll(d);
  }
mml_fin:
  saveControls();
  menu_hide (controlsMenu);
}
void PuyoCommander::run()
{
    Menu   *menu = mainMenu;

    cycle = 0;
    lastRenderedCycle = 0;
    maxFrameDrop = 10;

    start_time = SDL_GetTicks ();

    audio_music_start (0);

    /*  PuyoStory *introStory = new PuyoStory(this, 0);
    introStory->loop();
    delete introStory; */

    menu_show (menu);

    while (1) {
        SDL_Event e;

        while (SDL_PollEvent (&e)) {
            GameControlEvent controlEvent;
            getControlEvent(e, &controlEvent);

            switch (controlEvent.cursorEvent) {
                case GameControlEvent::kQuit:
                    goto mml_fin;
                    break;
                case GameControlEvent::kDown:
                    menu_next_item (menu);
                    break;
                case GameControlEvent::kUp:
                    menu_prev_item (menu);
                    break;
                case GameControlEvent::kStart:
                    menu_validate (menu);
                    if (menu_active_is (menu, "Quit"))
                        goto mml_fin;
                    if (menu_active_is (menu, "Options")) {
                        menu_hide (menu);
                        optionMenuLoop(NULL);
                        menu_show (menu);
                    }
                    if (menu_active_is (menu, kHighScores)) {
                        menu_hide(menu);
                        updateHighScoresMenu();
                        backLoop(highScoresMenu);
                        menu_show(menu);
                    }
                    if (menu_active_is (menu, "Rules")) {
                        menu_hide(menu);
                        backLoop(rulesMenu);
                        menu_show(menu);
                    }
                    if (menu_active_is (menu, "About FloboPuyo")) {
                        menu_hide(menu);
                        backLoop(aboutMenu);
                        menu_show(menu);
                    }
                    if (menu_active_is (menu, SINGLE_PLAYER_GAME)) {
                        menu_hide (menu);
                        startSingleGameLoop();
                        menu_show (menu);
                    }
                    if (menu_active_is (menu, TWO_PLAYERS_GAME)) {
                        menu_hide (menu);
                        startTwoPlayerGameLoop();
                        menu_show (menu);
                        audio_music_start(0);
                    }
                    break;
                case GameControlEvent::kBack:
                    goto mml_fin;
                    break;
                default:
                    break;
            }
        }
    updateAll(NULL);
  }
mml_fin:
  menu_hide (menu);
}
void PuyoCommander::startTwoPlayerGameLoop()
{
  char player1Name[256];
  char player2Name[256];

  GetStrPreference("Player1 Name", player1Name, "Player 1");
  GetStrPreference("Player2 Name", player2Name, "Player 2");
  menu_set_value(twoPlayerGameMenu, kPlayer1Name, player1Name, 0);
  menu_set_value(twoPlayerGameMenu, kPlayer2Name, player2Name, 0);

  while (!menu_active_is(twoPlayerGameMenu,kLevelMedium))
    menu_next_item(twoPlayerGameMenu);

  menu_show(twoPlayerGameMenu);
  while (1) {
    SDL_Event e;

    while (SDL_PollEvent (&e)) {
      GameControlEvent controlEvent;
        getControlEvent(e, &controlEvent);
        switch (controlEvent.cursorEvent) {
            case GameControlEvent::kQuit:
                exit(0);
                break;
            case GameControlEvent::kDown:
                menu_next_item (twoPlayerGameMenu);
                break;
            case GameControlEvent::kUp:
                menu_prev_item (twoPlayerGameMenu);
                break;
            case GameControlEvent::kStart:
                menu_validate (twoPlayerGameMenu);
                if (menu_active_is(twoPlayerGameMenu,kPlayer2Name)) {
                  enterStringLoop(twoPlayerGameMenu,kPlayer2Name,player2Name);
                  menu_next_item (twoPlayerGameMenu);
                }
                else if (menu_active_is(twoPlayerGameMenu,kPlayer1Name)) {
                  enterStringLoop(twoPlayerGameMenu,kPlayer1Name,player1Name);
                  menu_next_item (twoPlayerGameMenu);
                }
                else
                  goto mml_play;
                break;
            case GameControlEvent::kBack:
                menu_hide(twoPlayerGameMenu);
                return;
                break;
        }
    }
    updateAll(NULL);
  }

mml_play:
  menu_hide (twoPlayerGameMenu);

  GAME_ACCEL = 2000;
  gameLevel = 1;
  if (menu_active_is (twoPlayerGameMenu, kLevelMedium)) {
    GAME_ACCEL = 1500;
    gameLevel = 2;
  }
  else if (menu_active_is (twoPlayerGameMenu, kLevelHard)) {
    GAME_ACCEL = 1000;
    gameLevel = 3;
  }

  int score1 = 0;
  int score2 = 0;
  gameOverMenu = gameOver2PMenu;
  int currentMusicTheme = 0;
  if (menu_active_is(gameOverMenu, "NO"))
    menu_next_item(gameOverMenu);
  while (menu_active_is(gameOverMenu, "YES")) {
    menu_next_item(gameOverMenu);
    PuyoStarter myStarter(this,false,0,RANDOM,currentMusicTheme);
    audio_music_switch_theme(currentMusicTheme);
    p1name = player1Name;
    p2name = player2Name;
    GAME_ACCEL = 1500;
    doom_melt_start(melt, menuBGImage);
    myStarter.run(score1, score2, 0, 0, 0);
    score1 += myStarter.leftPlayerWin();
    score2 += myStarter.rightPlayerWin();
    currentMusicTheme = (currentMusicTheme + 1) % NB_MUSIC_THEME;
  }

  SetStrPreference("Player1 Name", player1Name);
  SetStrPreference("Player2 Name", player2Name);
  doom_melt_start(melt, gameScreen);
}