Exemplo n.º 1
0
void Dashboard::selectCard(const QString &pattern, bool forward){
    if(selected)
        selected->select(); // adjust the position

    // find all cards that match the card type
    QList<CardItem*> matches;

    foreach(CardItem *card_item, card_items){
        if(card_item->isEnabled() && card_item->getCard()->match(pattern))
            matches << card_item;
    }

    if(matches.isEmpty()){
        unselectAll();        
        return;
    }

    int index = matches.indexOf(selected);
    int n = matches.length();
    if(forward)
        index = (index + 1) % n;
    else
        index = (index - 1 + n) % n;

    CardItem *to_select = matches[index];

    if(to_select != selected){
        if(selected)
            selected->unselect();
        to_select->select();
        selected = to_select;

        emit card_selected(selected->getCard());
    }
}
Exemplo n.º 2
0
void tplay_card::discard(bool& handled, bool& halt, twindow& window, int index)
{
	tlistbox* list = find_widget<tlistbox>(&window, "card_list", false, true);

	if (!discard_->button_pressed(index)) {
		return;
	}
	list->remove_row(index);

	int size = current_team_.holded_cards().size();
	for (int i = index; i < size; i ++) {
		tgrid* grid_ptr = list->get_row_grid(i);
		tbutton& discard = *dynamic_cast<tbutton*>(grid_ptr->find("discard", false));

		disconnect_signal_mouse_left_click(
			discard
			, boost::bind(
				&tplay_card::discard
				, this
				, _3, _4
				, boost::ref(window)
				, i + 1));

		connect_signal_mouse_left_click(
			discard
			, boost::bind(
				&tplay_card::discard
				, this
				, _3, _4
				, boost::ref(window)
				, i));
	}

	if (!current_team_.holded_cards().empty()) {
		if (index == size) {
			index --;
		}
		list->select_row(index);
	} else {
		tbutton* ok = find_widget<tbutton>(&window, "ok", false, true);
		ok->set_active(false);
	}
	card_selected(window);

	handled = true;
	halt = true;
}