Forbid players from changing their selected kart after confirming (while other players choose theirs)
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@4168 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
@@ -604,36 +604,7 @@ void DynamicRibbonWidget::updateItemDisplay()
|
||||
} // next row
|
||||
}
|
||||
// -----------------------------------------------------------------------------
|
||||
void DynamicRibbonWidget::setSelection(int item_id)
|
||||
{
|
||||
//printf("****DynamicRibbonWidget::setSelection()****\n");
|
||||
|
||||
if (m_rows.size() > 1)
|
||||
{
|
||||
std::cout << "\n/!\\ Warning, DynamicRibbonWidget::setSelection only makes sense on 1-row ribbons " <<
|
||||
"(since there can't logically be a permanent with more than one row)\n\n";
|
||||
return;
|
||||
}
|
||||
|
||||
// FIXME: don't hardcode player 0 ?
|
||||
const int PLAYER_ID = 0;
|
||||
|
||||
m_selected_item[PLAYER_ID] = item_id;
|
||||
if (m_selected_item[PLAYER_ID] >= (int)m_items.size()) m_selected_item[PLAYER_ID] -= m_items.size();
|
||||
|
||||
// scroll so selection is visible
|
||||
m_scroll_offset = m_selected_item[PLAYER_ID]; // works because in this case there is a single row
|
||||
updateItemDisplay();
|
||||
|
||||
// set selection
|
||||
RibbonWidget* ribbon = m_rows.get(0); // there is a single row when we can select items
|
||||
int id = m_selected_item[PLAYER_ID] - m_scroll_offset;
|
||||
if (id < 0) id += m_items.size();
|
||||
ribbon->setSelection(id, PLAYER_ID);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
void DynamicRibbonWidget::setSelection(int item_id, const int playerID)
|
||||
bool DynamicRibbonWidget::setSelection(int item_id, const int playerID)
|
||||
{
|
||||
//printf("****DynamicRibbonWidget::setSelection()****\n");
|
||||
|
||||
@@ -659,12 +630,26 @@ void DynamicRibbonWidget::setSelection(int item_id, const int playerID)
|
||||
if (row == -1)
|
||||
{
|
||||
std::cerr << "DynamicRibbonWidget::setSelection cannot find item " << item_id << " (" << name.c_str() << ")\n";
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
std::cout << "Player " << playerID << " has kart " << item_id << " (" << name.c_str() << ") in row " << row << std::endl;
|
||||
//std::cout << "Player " << playerID << " has item " << item_id << " (" << name.c_str() << ") in row " << row << std::endl;
|
||||
m_rows[row].setSelection(id, playerID);
|
||||
m_rows[row].setFocusForPlayer(playerID);
|
||||
|
||||
propagateSelection();
|
||||
return true;
|
||||
}
|
||||
// -----------------------------------------------------------------------------
|
||||
bool DynamicRibbonWidget::setSelection(const std::string item_codename, const int playerID)
|
||||
{
|
||||
const int item_count = m_items.size();
|
||||
for (int n=0; n<item_count; n++)
|
||||
{
|
||||
if (m_items[n].m_code_name == item_codename)
|
||||
{
|
||||
return setSelection(n, playerID);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -138,6 +138,7 @@ namespace GUIEngine
|
||||
EventPropagation mouseHovered(Widget* child);
|
||||
EventPropagation transmitEvent(Widget* w, std::string& originator, const int playerID);
|
||||
|
||||
|
||||
public:
|
||||
DynamicRibbonWidget(const bool combo=false, const int max_rows=4);
|
||||
|
||||
@@ -172,14 +173,17 @@ namespace GUIEngine
|
||||
/** Get the user-visible text of the selected item */
|
||||
const irr::core::stringw& getSelectionText(const int playerID);
|
||||
|
||||
/** Select an item from its numerical ID. Only for [1-row] combo ribbons.
|
||||
ID ranges from {0} to {number of items added through 'addItem' - 1} */
|
||||
void setSelection(int item_id);
|
||||
|
||||
/** Returns a read-only list of items added to this ribbon */
|
||||
const std::vector<ItemDescription>& getItems() const { return m_items; }
|
||||
|
||||
void setSelection(int item_id, const int playerID);
|
||||
/** Select an item from its numerical ID. Only for [1-row] combo ribbons.
|
||||
ID ranges from {0} to {number of items added through 'addItem' - 1}
|
||||
\return Whether setting the selection was successful (whether the item exists) */
|
||||
bool setSelection(int item_id, const int playerID);
|
||||
|
||||
/** Select an item from its codename.
|
||||
\return Whether setting the selection was successful (whether the item exists) */
|
||||
bool setSelection(const std::string item_codename, const int playerID);
|
||||
|
||||
/**
|
||||
* Called when irrLicht widgets cleared. Forget all references to them, they're no more valid.
|
||||
|
||||
@@ -497,43 +497,64 @@ ptr_vector<PlayerKartWidget, REF> g_player_karts;
|
||||
#endif
|
||||
|
||||
class KartHoverListener : public DynamicRibbonHoverListener
|
||||
{
|
||||
KartSelectionScreen* m_parent;
|
||||
public:
|
||||
KartHoverListener(KartSelectionScreen* parent)
|
||||
{
|
||||
public:
|
||||
void onSelectionChanged(DynamicRibbonWidget* theWidget, const std::string& selectionID,
|
||||
const irr::core::stringw& selectionText, const int playerID)
|
||||
m_parent = parent;
|
||||
}
|
||||
|
||||
void onSelectionChanged(DynamicRibbonWidget* theWidget, const std::string& selectionID,
|
||||
const irr::core::stringw& selectionText, const int playerID)
|
||||
{
|
||||
// Don't allow changing the selection after confirming it
|
||||
if (g_player_karts[playerID].isReady())
|
||||
{
|
||||
ModelViewWidget* w3 = g_player_karts[playerID].modelView;
|
||||
assert( w3 != NULL );
|
||||
// discard events sent when putting back to the right kart
|
||||
if (selectionID == g_player_karts[playerID].m_kartInternalName) return;
|
||||
|
||||
if (selectionID == "gui/track_random.png")
|
||||
{
|
||||
scene::IMesh* model = item_manager->getItemModel(Item::ITEM_BONUS_BOX);
|
||||
w3->clearModels();
|
||||
w3->addModel( model, Vec3(0.0f, 0.0f, -12.0f) );
|
||||
w3->update(0);
|
||||
g_player_karts[playerID].kartName->setText( _("Random Kart") );
|
||||
}
|
||||
else
|
||||
{
|
||||
//printf("%s\n", selectionID.c_str());
|
||||
const KartProperties* kart = kart_properties_manager->getKart(selectionID);
|
||||
if (kart == NULL) return;
|
||||
KartModel* kartModel = kart->getKartModel();
|
||||
|
||||
w3->clearModels();
|
||||
w3->addModel( kartModel->getModel() );
|
||||
w3->addModel( kartModel->getWheelModel(0), kartModel->getWheelGraphicsPosition(0) );
|
||||
w3->addModel( kartModel->getWheelModel(1), kartModel->getWheelGraphicsPosition(1) );
|
||||
w3->addModel( kartModel->getWheelModel(2), kartModel->getWheelGraphicsPosition(2) );
|
||||
w3->addModel( kartModel->getWheelModel(3), kartModel->getWheelGraphicsPosition(3) );
|
||||
w3->update(0);
|
||||
|
||||
g_player_karts[playerID].kartName->setText( selectionText.c_str() );
|
||||
}
|
||||
|
||||
g_player_karts[playerID].setKartInternalName(selectionID);
|
||||
DynamicRibbonWidget* w = m_parent->getWidget<DynamicRibbonWidget>("karts");
|
||||
assert(w != NULL);
|
||||
|
||||
w->setSelection(g_player_karts[playerID].m_kartInternalName, playerID);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
// Update the displayed model
|
||||
ModelViewWidget* w3 = g_player_karts[playerID].modelView;
|
||||
assert( w3 != NULL );
|
||||
|
||||
if (selectionID == "gui/track_random.png")
|
||||
{
|
||||
// Random kart
|
||||
scene::IMesh* model = item_manager->getItemModel(Item::ITEM_BONUS_BOX);
|
||||
w3->clearModels();
|
||||
w3->addModel( model, Vec3(0.0f, 0.0f, -12.0f) );
|
||||
w3->update(0);
|
||||
g_player_karts[playerID].kartName->setText( _("Random Kart") );
|
||||
}
|
||||
else
|
||||
{
|
||||
//printf("%s\n", selectionID.c_str());
|
||||
const KartProperties* kart = kart_properties_manager->getKart(selectionID);
|
||||
if (kart == NULL) return;
|
||||
KartModel* kartModel = kart->getKartModel();
|
||||
|
||||
w3->clearModels();
|
||||
w3->addModel( kartModel->getModel() );
|
||||
w3->addModel( kartModel->getWheelModel(0), kartModel->getWheelGraphicsPosition(0) );
|
||||
w3->addModel( kartModel->getWheelModel(1), kartModel->getWheelGraphicsPosition(1) );
|
||||
w3->addModel( kartModel->getWheelModel(2), kartModel->getWheelGraphicsPosition(2) );
|
||||
w3->addModel( kartModel->getWheelModel(3), kartModel->getWheelGraphicsPosition(3) );
|
||||
w3->update(0);
|
||||
|
||||
g_player_karts[playerID].kartName->setText( selectionText.c_str() );
|
||||
}
|
||||
|
||||
g_player_karts[playerID].setKartInternalName(selectionID);
|
||||
}
|
||||
};
|
||||
KartHoverListener* karthoverListener = NULL;
|
||||
|
||||
#if 0
|
||||
@@ -702,7 +723,7 @@ void KartSelectionScreen::init()
|
||||
|
||||
if (karthoverListener == NULL)
|
||||
{
|
||||
karthoverListener = new KartHoverListener();
|
||||
karthoverListener = new KartHoverListener(this);
|
||||
w->registerHoverListener(karthoverListener);
|
||||
}
|
||||
|
||||
|
||||
@@ -126,7 +126,8 @@ void OptionsScreenAV::init()
|
||||
{
|
||||
//std::cout << "************* Detected right resolution!!! " << n << "\n";
|
||||
// that's the current one
|
||||
res->setSelection(n);
|
||||
const int playerID = 0; // FIXME: don't hardcode player 0 ?
|
||||
res->setSelection(n, playerID);
|
||||
break;
|
||||
}
|
||||
} // end for
|
||||
|
||||
Reference in New Issue
Block a user