Example #1
0
GUI_status InputDialog::KeyDown(SDL_keysym key) {
	KeyBinder *keybinder = Game::get_game()->get_keybinder();
	ActionType a = keybinder->get_ActionType(key);

	switch(keybinder->GetActionKeyType(a))
	{
		case NORTH_KEY:
		case WEST_KEY:
			if(b_index_num != -1)
				button_index[b_index_num]->set_highlighted(false);

			if(b_index_num <= 0)
				b_index_num = last_index;
			else
				b_index_num = b_index_num - 1;
			button_index[b_index_num]->set_highlighted(true); break;
		case SOUTH_KEY:
		case EAST_KEY:
			if(b_index_num != -1)
				button_index[b_index_num]->set_highlighted(false);

			if(b_index_num == last_index)
				b_index_num = 0;
			else
				b_index_num += 1;
			button_index[b_index_num]->set_highlighted(true); break;
		case DO_ACTION_KEY: if(b_index_num != -1) return button_index[b_index_num]->Activate_button(); break;
		case CANCEL_ACTION_KEY: return close_dialog();
		default: keybinder->handle_always_available_keys(a); break;
	}
	return GUI_YUM;
}
Example #2
0
/* Move the cursor around and use command icons.
 */
GUI_status ActorView::KeyDown(SDL_keysym key)
{
	if(!show_cursor) // FIXME: don't rely on show_cursor to get/pass focus
		return(GUI_PASS);
	KeyBinder *keybinder = Game::get_game()->get_keybinder();
	ActionType a = keybinder->get_ActionType(key);

	switch(keybinder->GetActionKeyType(a))
	{
		case SOUTH_WEST_KEY:
		case NORTH_WEST_KEY:
		case WEST_KEY:
			moveCursorToButton(cursor_pos.x - 1);
			break;
		case NORTH_EAST_KEY:
		case SOUTH_EAST_KEY:
		case EAST_KEY:
			moveCursorToButton(cursor_pos.x + 1);
			break;
		case DO_ACTION_KEY:
			select_button();
			break;
		case NORTH_KEY: // would otherwise move invisible mapwindow cursor
		case SOUTH_KEY:
			break;
		default:
//			set_show_cursor(false); // newAction() can move cursor here
			return GUI_PASS;
	}
	return(GUI_YUM);
}
Example #3
0
void create_stuff()
{
    KeyBinder binder;
    KeyRule *rule;
    rule = binder.add_rule();
    rule->add_key("a");
    rule->add_modifier("control");
    rule->print();
}
Example #4
0
/* Move the cursor around
 */
GUI_status SpellView::KeyDown(SDL_keysym key)
{
    KeyBinder *keybinder = Game::get_game()->get_keybinder();
    ActionType a = keybinder->get_ActionType(key);

    switch(keybinder->GetActionKeyType(a))
    {
        case NORTH_KEY:
            return move_up();
        case SOUTH_KEY:
            return move_down();
        case WEST_KEY:
        case PREVIOUS_PARTY_MEMBER_KEY:
        	move_left();
            break;
        case EAST_KEY:
        case NEXT_PARTY_MEMBER_KEY:
            move_right();
            break;
        case HOME_KEY:
// TODO - add going to first viable page
            break;
        case END_KEY:
// TODO - add going to last viable page
            break;
        case DO_ACTION_KEY:
        	if(Game::get_game()->get_event()->is_looking_at_spellbook())
        	{
        		show_spell_description();
        		return GUI_YUM;
        	}
        	if(event_mode)
        	{
        		event_mode_select_spell();
        		return GUI_YUM;
        	}

        	return GUI_PASS;
        case CANCEL_ACTION_KEY:
            return cancel_spell();
        case TOGGLE_CURSOR_KEY :

        	break;

        default:
            return GUI_PASS;
    }
    return(GUI_YUM);
}
Example #5
0
GUI_status ScrollWidgetGump::KeyDown(SDL_keysym key)
{
	ScrollEventType event = SCROLL_ESCAPE;

	KeyBinder *keybinder = Game::get_game()->get_keybinder();
	ActionType a = keybinder->get_ActionType(key);

	switch(keybinder->GetActionKeyType(a))
	{
	case MSGSCROLL_DOWN_KEY: event = SCROLL_PAGE_DOWN; break;
	case SOUTH_KEY: event = SCROLL_DOWN; break;
	case MSGSCROLL_UP_KEY: event = SCROLL_PAGE_UP; break;
	case NORTH_KEY: event = SCROLL_UP; break;
	case HOME_KEY: event = SCROLL_TO_BEGINNING; break;
	case END_KEY: event = SCROLL_TO_END; break;
	default : break;
	}

	if(scroll_movement_event(event) == GUI_YUM)
		return GUI_YUM;

    return MsgScroll::KeyDown(key);
}
Example #6
0
GUI_status ContainerViewGump::KeyDown(SDL_Keysym key)
{
	if(left_arrow_button && left_arrow_button->Status() == WIDGET_VISIBLE) // okay to change member number
	{
		KeyBinder *keybinder = Game::get_game()->get_keybinder();
		ActionType a = keybinder->get_ActionType(key);

		switch(keybinder->GetActionKeyType(a))
		{
			case NEXT_PARTY_MEMBER_KEY:
				right_arrow(); return GUI_YUM;
			case PREVIOUS_PARTY_MEMBER_KEY:
				left_arrow(); return GUI_YUM;
			case HOME_KEY:
				set_actor(party->get_actor(0));
				force_full_redraw_if_needed();
				return GUI_YUM;
			case END_KEY:
				set_actor(party->get_actor(party->get_party_size() - 1));
				force_full_redraw_if_needed();
				return GUI_YUM;
			default: break;
		}
	}
	/* moved into container widget
	switch(key.sym)
	    {
	        case SDLK_RETURN:
	        case SDLK_KP_ENTER:

	        	return GUI_YUM;
	        default:
	        	break;
	    }
	*/
	return container_widget->KeyDown(key);
}
Example #7
0
GUI_status JoystickDialog::callback(uint16 msg, GUI_CallBack *caller, void *data) {
	if(caller == (GUI_CallBack *)cancel_button) {
		return close_dialog();
	} else if(caller == (GUI_CallBack *)save_button) {
		Configuration *config = Game::get_game()->get_config();
		KeyBinder *kb = Game::get_game()->get_keybinder();
// enable joystick
		uint8 enabled_setting;
		if(enable_button->GetSelection() == 5)
			enabled_setting = kb->get_enable_joystick();
		else if(enable_button->GetSelection() == 4) {
			enabled_setting = 255;
			config->set("config/joystick/enable_joystick", "no");
		} else {
			enabled_setting = enable_button->GetSelection();
			config->set("config/joystick/enable_joystick", enabled_setting);
		}
		kb->init_joystick(enabled_setting == 255 ? -1 : enabled_setting); // will close and NULL joystick and open again if enabled
// hat repeating
		kb->set_hat_repeating(hat_repeating_b->GetSelection() == 1);
		config->set("config/joystick/repeat_hat", hat_repeating_b->GetSelection() == 1 ? "yes" : "no");
// Axes Pairs
		std::string axes_str[] = { "axes_pair1/x_axis", "axes_pair1/y_axis", "axes_pair2/x_axis", "axes_pair2/y_axis", 
		                           "axes_pair3/x_axis", "axes_pair3/y_axis", "axes_pair4/x_axis", "axes_pair4/y_axis" };
		for(int i=0; i < 8; i++) {
			uint8 val = axes_index[i]->GetSelection();
			if(val != kb->get_axis(i) && val != 11 && (val != 10 || kb->get_axis(i) != 255)) {
				val = val == 10 ? 255 : val;
				config->set("config/joystick/" + axes_str[i], val);
				kb->set_axis(i, val);
			}
		}

		config->write();
		return close_dialog();
	}

	return GUI_PASS;
}
Example #8
0
GUI_status GUI_TextInput::KeyDown(SDL_keysym key)
{
// char ascii;
 char ascii = 0;

 if(!focused)
   return GUI_PASS;
 if((key.unicode & 0xFF80) == 0) // high 9bits 0 == ascii code
   ascii = (char)(key.unicode & 0x7F); // (in low 7bits)

 if(!isprint(ascii) && key.sym != SDLK_BACKSPACE)
 {
    KeyBinder *keybinder = Game::get_game()->get_keybinder();
    ActionType a = keybinder->get_ActionType(key);
    switch(keybinder->GetActionKeyType(a))
    {
      case NORTH_KEY: key.sym = SDLK_UP; break;
      case SOUTH_KEY: key.sym = SDLK_DOWN; break;
      case WEST_KEY: key.sym = SDLK_LEFT; break;
      case EAST_KEY: key.sym = SDLK_RIGHT; break;
      case TOGGLE_CURSOR_KEY: release_focus(); return GUI_PASS; // can tab through to SaveDialog
      case DO_ACTION_KEY: key.sym = SDLK_RETURN; break;
      case CANCEL_ACTION_KEY: key.sym = SDLK_ESCAPE; break;
      case HOME_KEY: key.sym = SDLK_HOME;
      case END_KEY: key.sym = SDLK_END;
      default : if(keybinder->handle_always_available_keys(a)) return GUI_YUM; break;
    }
 }

 switch(key.sym)
   {
    case SDLK_LSHIFT   :
    case SDLK_RSHIFT   :
    case SDLK_LCTRL    :
    case SDLK_RCTRL    :
    case SDLK_CAPSLOCK : break;

    case SDLK_KP_ENTER:
    case SDLK_RETURN : if(callback_object)
                         callback_object->callback(TEXTINPUT_CB_TEXT_READY, this, text);
    case SDLK_ESCAPE : release_focus(); break;

    case SDLK_HOME : pos = 0; break;
    case SDLK_END  : pos = length; break;

    case SDLK_KP4  :
    case SDLK_LEFT : if(pos > 0)
                       pos--;
                     break;

    case SDLK_KP6   :
    case SDLK_RIGHT : if(pos < length)
                       pos++;
                      break;

    case SDLK_DELETE    : if(pos < length) //delete the character to the right of the cursor
                            {
                             pos++;
                             remove_char(); break;
                            }
                          break;

    case SDLK_BACKSPACE : remove_char(); break; //delete the character to the left of the cursor

    case SDLK_UP :
    case SDLK_KP8 :
                    if(pos == length)
                    {
                        if(length+1 > max_width * max_height)
                            break;
                        length++;
                        if(pos == 0 || text[pos-1] == ' ')
                            text[pos] = 'A';
                        else
                            text[pos] = 'a';
                        break;
                    }
                    text[pos]++;
                    // We want alphanumeric characters or space
                    if(text[pos] < ' ' || text[pos] > 'z')
                    {
                        text[pos] = ' ';
                        break;
                    }
                    while(!isalnum(text[pos]))
                        text[pos]++;
                    break;

    case SDLK_KP2 :
    case SDLK_DOWN : if(pos == length)
                     {
                         if(length+1 > max_width * max_height)
                             break;
                         length++;
                         if(pos == 0 || text[pos-1] == ' ')
                             text[pos] = 'Z';
                         else
                             text[pos] = 'z';
                         break;
                     }
                     text[pos]--;
                     // We want alphanumeric characters or space
                     if(text[pos] < ' ' || text[pos] > 'z')
                     {
                         text[pos] = 'z';
                         break;
                     }
                     else if(text[pos] < '0')
                     {
                         text[pos] = ' ';
                         break;
                     }
                     while(!isalnum(text[pos]))
                         text[pos]--;
                     break;

    default :
              if(isprint(ascii))
                  add_char(ascii); break;
   }



 return(GUI_YUM);
}
Example #9
0
bool JoystickDialog::init() {
	int height = 12;
	int buttonX[] = { 128, 142, 183};
	int textX[] = { 9, 115, 170 };
	int textY = 11;
	int buttonY = 9;
	uint8 sub_h = 4;
	uint8 row_h = 13;
	uint8 axis_w = 40;
	b_index_num = -1;
	last_index = 0;
//	uint8 yesno_width = 32;

	GUI_Widget *widget;
	GUI_Font * font = GUI::get_gui()->get_font();



//	Configuration *config = Game::get_game()->get_config();
	KeyBinder *kb = Game::get_game()->get_keybinder();

	uint8 enable_selection; /*index*/;
	char enable_buff[11], axis_buff[4];

	if(kb->get_enable_joystick() == -1)
		enable_selection = 4;
#if SDL_VERSION_ATLEAST(2,0,0) // haven't considered this in the saving loop
	else if(kb->get_enable_joystick() == 127)
	{
		enable_selection = 5;
		sprintf(enable_buff, "%s", "auto detect");
	}
#endif
	else if(kb->get_enable_joystick() < 4)
		enable_selection = kb->get_enable_joystick();
	else
	{
		enable_selection = 5;
		sprintf(enable_buff, "Joystick %i", kb->get_enable_joystick());
	}

// enable_button
	widget = (GUI_Widget *) new GUI_Text(textX[0], textY, 0, 0, 0, "Enable joystick:", font);
	AddWidget(widget);
	const char* const enabled_text[] = { "Joystick 0", "Joystick 1", "Joystick 2", "joystick 3", "Disabled", enable_buff };
	enable_button = new GUI_TextToggleButton(this, buttonX[1], buttonY, 93, height, enabled_text, enable_selection == 5 ? 6 : 5, enable_selection, font, BUTTON_TEXTALIGN_CENTER, this, 0);
	AddWidget(enable_button); 
	button_index[last_index] = enable_button;
// hat_repeating_b
	widget = (GUI_Widget *) new GUI_Text(textX[0], textY += row_h, 0, 0, 0, "Repeat when held:", font);
	AddWidget(widget);
	const char* const hat_repeating_text[] = { "axes pair 1", "hat" };
	hat_repeating_b = new GUI_TextToggleButton(this, buttonX[1], buttonY += row_h, 93, height, hat_repeating_text, 2, kb->is_hat_repeating(), font, BUTTON_TEXTALIGN_CENTER, this, 0);
	AddWidget(hat_repeating_b); 
	button_index[last_index+= 1] = hat_repeating_b;
// Axes Pairs
	int str_i = 0; // used in loop
	const char* axis_text[] = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "none", "" };
	const char* const axes_str[] = { "Axes pair 1:", "Axes pair 2:", "Axes pair 3:", "Axes pair 4:" };
	for(int i=0; i < 8; i++) {
		if(i%2 == 0) { // pairs text
			widget = (GUI_Widget *) new GUI_Text(textX[0], textY += row_h, 0, 0, 0, axes_str[str_i++], font);
			AddWidget(widget);
		} // x and y text
		widget = (GUI_Widget *) new GUI_Text(i%2 ? textX[2] : textX[1], textY += i%2 ? 0 : sub_h, 0, 0, 0, i%2 ? "Y:" : "X:", font);
		AddWidget(widget);
	// x and y  button
		uint8 index = get_axis_index(kb->get_axis(i));
		if(index == 11) {
			sprintf(axis_buff, "%i", kb->get_axis(i));
			axis_text[11] = axis_buff;
		}
		axes_index[i] = new GUI_TextToggleButton(this, i%2 ? buttonX[2] : buttonX[0], buttonY += i%2 ? 0 : row_h + sub_h, axis_w, height, axis_text, index == 11 ? 12 : 11, index, font, BUTTON_TEXTALIGN_CENTER, this, 0);
		AddWidget(axes_index[i]); 
		button_index[last_index+= 1] = axes_index[i];
	}
// cancel_button
	cancel_button = new GUI_Button(this, 59, JD_HEIGHT - 20, 54, height, "Cancel", font, BUTTON_TEXTALIGN_CENTER, 0, this, 0);
	AddWidget(cancel_button);
	button_index[last_index += 1] = cancel_button;
// save_button
	save_button = new GUI_Button(this, 124, JD_HEIGHT - 20, 60, height, "Save", font, BUTTON_TEXTALIGN_CENTER, 0, this, 0);
	AddWidget(save_button);
	button_index[last_index += 1] = save_button;

 return true;
}
Example #10
0
GUI_status CommandBarNewUI::KeyDown(SDL_keysym key)
{
    KeyBinder *keybinder = Game::get_game()->get_keybinder();
    ActionType a = keybinder->get_ActionType(key);

    switch(keybinder->GetActionKeyType(a))
    {
        case NORTH_KEY:
        	do
        	{
				if(cur_pos - icon_w < 0)
					cur_pos = icon_w * icon_h - (icon_w - cur_pos%icon_w);
				else
					cur_pos -= icon_w;
        	} while(cur_pos >= num_icons);
            break;
        case SOUTH_KEY:
        	do
        	{
        		cur_pos = (cur_pos + icon_w) % (icon_w * icon_h);
        	} while(cur_pos >= num_icons);
            break;
        case WEST_KEY:
        	do
        	{
				if(cur_pos%icon_w == 0)
					cur_pos = (cur_pos/icon_w)*icon_w+icon_w-1;
				else
					cur_pos--;
        	} while(cur_pos >= num_icons);
            break;
        case EAST_KEY:
        	do
        	{
        		cur_pos = (cur_pos/icon_w)*icon_w + (cur_pos+1) % icon_w;
        	} while(cur_pos >= num_icons);
            break;
        case DO_ACTION_KEY:
        	if(cur_pos < num_icons)
        	{
				hit((sint8)cur_pos);
#ifdef HAVE_JOYSTICK_SUPPORT
				keybinder->set_enable_joy_repeat(true);
#endif
				Hide();
        	}
        	break;
        case CANCEL_ACTION_KEY:
        case NEW_COMMAND_BAR_KEY:
#ifdef HAVE_JOYSTICK_SUPPORT
        	keybinder->set_enable_joy_repeat(true);
#endif
        	Hide();
        	break;

        default : keybinder->handle_always_available_keys(a);
        	break;
    }

    return GUI_YUM;
}