static int SelectorWindowY(txt_dropdown_list_t *list) { if (ValidSelection(list)) { return list->widget.y - 1 - *list->variable; } else { return list->widget.y - 1 - (list->num_values / 2); } }
static void TXT_DropdownListDrawer(TXT_UNCAST_ARG(list), int selected) { TXT_CAST_ARG(txt_dropdown_list_t, list); unsigned int i; const char *str; // Set bg/fg text colors. if (selected) { TXT_BGColor(TXT_COLOR_GREY, 0); } else { TXT_BGColor(TXT_COLOR_BLUE, 0); } TXT_FGColor(TXT_COLOR_BRIGHT_WHITE); // Select a string to draw from the list, if the current value is // in range. Otherwise fall back to a default. if (ValidSelection(list)) { str = list->values[*list->variable]; } else { str = "???"; } // Draw the string and fill to the end with spaces TXT_DrawString(str); for (i=strlen(str); i<list->widget.w; ++i) { TXT_DrawString(" "); } }
//------------------------------------------------------------------------------ // ValidateSelection - Inform the scene to enable/disable buttons based on // whether the user's selection is valid or not. //------------------------------------------------------------------------------ void CardManager::ValidateSelection(void) { std::vector<Card*> selectedCards = GetSelection(PLAYER1); int i = 0; int j = 0; bool valid = true; Card::Suit suit; Card::Rank rank; bool cardBuckets[8] = { false }; switch ( currentPhase ) { case EXCHANGE: if ( selectedCards.size() < 1 || selectedCards.size() > 5 || (int)selectedCards.size() > talon->GetSize() ) { valid = false; } break; case POINT: if ( selectedCards.size() == 0 ) { valid = false; } else { suit = selectedCards[i]->GetSuit(); // First check it's a valid Point. while ( i < (int)selectedCards.size() && valid ) { if ( selectedCards[i++]->GetSuit() != suit ) valid = false; } if ( younger == PLAYER1 && valid ) { // Check if we are responding or not as we need to at least // match the opponents point. if ( (int)selectedCards.size() < pointDeclaration->numCards) valid = false; } } break; case SEQUENCE: if ( selectedCards.size() < 3 ) { valid = false; } else { // Perform a bucket sort then check the cards. suit = selectedCards[i]->GetSuit(); // First check the cards are of the same suit. while ( i < (int)selectedCards.size() && valid ) { // Place the card in it's bucket. cardBuckets[selectedCards[i]->GetRank()-7] = true; if ( selectedCards[i++]->GetSuit() != suit ) valid = false; } if ( valid ) { i = 0; j = 0; // Now check if the cards are in sequence. while ( i < 8 && !cardBuckets[i] ) { i++; } while ( i < 8 && cardBuckets[i] ) { i++; j++; } if ( j < (int)selectedCards.size() ) { valid = false; } else if ( younger == PLAYER1 ) { // Check if we are responding or not as we need to at // least match the opponents Sequence. if ( (int)selectedCards.size() < seqDeclaration->numCards) valid = false; } } } break; case SET: if ( selectedCards.size() < 3 || selectedCards.size() > 4 ) { valid = false; } else { rank = selectedCards[i]->GetRank(); while ( i < (int)selectedCards.size() && valid ) { if ( selectedCards[i++]->GetRank() != rank ) valid = false; } if ( younger == PLAYER1 && valid ) { // Check if we are responding or not as we need to at // least match the opponents Sequence. if ( (int)selectedCards.size() < setDeclaration->numCards) valid = false; } } break; default: break; } if ( valid ) emit ValidSelection(true); else emit ValidSelection(false); }