Implemented model preview for all karts

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3697 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria 2009-07-03 19:06:24 +00:00
parent c08e0eaf0a
commit 58cfaa27fa
4 changed files with 129 additions and 11 deletions

View File

@ -7,7 +7,7 @@
<spinner id="player" width="40%" height="40" min_value="0" max_value="8" align="center"/>
<model id="modelview" width="40%" proportion="3" align="center"/>
<label width="100%" height="25" text="Wilber" align="center" text_align="center" />
<label id="currkartname" width="100%" height="25" text="Tux" align="center" text_align="center" />
<spacer height="15" width="25"/>

View File

@ -90,6 +90,38 @@ namespace StateManager
}
// -------------------------------------------------------------------------
class KartHoverListener : public RibbonGridHoverListener
{
public:
void onSelectionChanged(RibbonGridWidget* theWidget, const std::string& selectionID)
{
//std::cout << "hovered " << selectionID.c_str() << std::endl;
if(selectionID.size() == 0) return;
ModelViewWidget* w3 = getCurrentScreen()->getWidget<ModelViewWidget>("modelview");
assert( w3 != NULL );
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);
LabelWidget* label = getCurrentScreen()->getWidget<LabelWidget>("currkartname");
assert(label != NULL);
label->setText( kart->getName().c_str() );
}
};
KartHoverListener* karthoverListener = NULL;
/**
* Callback handling events from the kart selection menu
*/
@ -100,6 +132,12 @@ namespace StateManager
RibbonGridWidget* w = getCurrentScreen()->getWidget<RibbonGridWidget>("karts");
assert( w != NULL );
if(karthoverListener == NULL)
{
karthoverListener = new KartHoverListener();
w->registerHoverListener(karthoverListener);
}
if(!getCurrentScreen()->m_inited)
{
const int kart_amount = kart_properties_manager->getNumberOfKarts();
@ -127,7 +165,7 @@ namespace StateManager
assert( w3 != NULL );
// set kart model - FIXME - doesn't work very much
// set initial kart model
KartModel* kartModel = kart_properties_manager->getKart("tux")->getKartModel();
w3->addModel( kartModel->getModel() );

View File

@ -296,6 +296,14 @@ void LabelWidget::add()
m_element->setTabGroup(false);
}
void LabelWidget::setText(stringw newText)
{
IGUIStaticText* irrwidget = dynamic_cast<IGUIStaticText*>(m_element);
assert(irrwidget != NULL);
irrwidget->setText(newText.c_str());
}
#if 0
#pragma mark -
#pragma mark Check Box Widget
@ -488,9 +496,13 @@ bool RibbonWidget::leftPressed()
// -----------------------------------------------------------------------------
void RibbonWidget::focused()
{
if(m_event_handler != NULL) ((RibbonGridWidget*)m_event_handler)->updateLabel( this );
if(m_focus == NULL) m_focus = m_children.get(m_selection);
if(m_event_handler != NULL)
{
GUIEngine::getGUIEnv()->setFocus(m_focus->m_element);
((RibbonGridWidget*)m_event_handler)->onRowChange( this );
}
}
// -----------------------------------------------------------------------------
bool RibbonWidget::mouseHovered(Widget* child)
@ -1013,6 +1025,11 @@ void RibbonGridWidget::add()
m_children.push_back( m_left_widget );
}
// -----------------------------------------------------------------------------
void RibbonGridWidget::registerHoverListener(RibbonGridHoverListener* listener)
{
m_hover_listeners.push_back(listener);
}
// -----------------------------------------------------------------------------
bool RibbonGridWidget::rightPressed()
{
RibbonWidget* w = getSelectedRibbon();
@ -1024,6 +1041,12 @@ bool RibbonGridWidget::rightPressed()
propagateSelection();
}
const int listenerAmount = m_hover_listeners.size();
for(int n=0; n<listenerAmount; n++)
{
m_hover_listeners[n].onSelectionChanged(this, getSelectedRibbon()->getSelectionIDString());
}
if(m_rows[0].m_ribbon_type == RIBBON_TOOLBAR) return false;
return true;
@ -1040,6 +1063,12 @@ bool RibbonGridWidget::leftPressed()
propagateSelection();
}
const int listenerAmount = m_hover_listeners.size();
for(int n=0; n<listenerAmount; n++)
{
m_hover_listeners[n].onSelectionChanged(this, w->getSelectionIDString());
}
if(m_rows[0].m_ribbon_type == RIBBON_TOOLBAR) return false;
return true;
@ -1082,6 +1111,16 @@ bool RibbonGridWidget::mouseHovered(Widget* child)
{
updateLabel();
propagateSelection();
if(getSelectedRibbon() != NULL)
{
const int listenerAmount = m_hover_listeners.size();
for(int n=0; n<listenerAmount; n++)
{
m_hover_listeners[n].onSelectionChanged(this, getSelectedRibbon()->getSelectionIDString());
}
}
return false;
}
// -----------------------------------------------------------------------------
@ -1112,6 +1151,23 @@ void RibbonGridWidget::propagateSelection()
void RibbonGridWidget::focused()
{
updateLabel();
const int listenerAmount = m_hover_listeners.size();
for(int n=0; n<listenerAmount; n++)
{
m_hover_listeners[n].onSelectionChanged(this, getSelectedRibbon()->getSelectionIDString());
}
}
// -----------------------------------------------------------------------------
void RibbonGridWidget::onRowChange(RibbonWidget* row)
{
updateLabel(row);
const int listenerAmount = m_hover_listeners.size();
for(int n=0; n<listenerAmount; n++)
{
m_hover_listeners[n].onSelectionChanged(this, row->getSelectionIDString());
}
}
// -----------------------------------------------------------------------------
void RibbonGridWidget::updateLabel(RibbonWidget* from_this_ribbon)
@ -1307,6 +1363,12 @@ void ModelViewWidget::add()
m_texture = GUIEngine::getDriver()->addTexture( core::dimension2d< s32 >(512, 512), name.c_str() );
}
// -----------------------------------------------------------------------------
void ModelViewWidget::clearModels()
{
m_models.clearWithoutDeleting();
m_model_location.clear();
}
// -----------------------------------------------------------------------------
void ModelViewWidget::addModel(irr::scene::IMesh* mesh, const Vec3& location)
{
m_models.push_back(mesh);

View File

@ -178,9 +178,9 @@ namespace GUIEngine
{
public:
ButtonWidget();
virtual ~ButtonWidget() {}
void add();
virtual ~ButtonWidget() {}
void setLabel(const char* label);
};
@ -188,9 +188,10 @@ namespace GUIEngine
{
public:
LabelWidget();
virtual ~LabelWidget() {}
void add();
virtual ~LabelWidget() {}
void setText(stringw newText);
};
class CheckBoxWidget : public Widget
@ -287,6 +288,17 @@ namespace GUIEngine
};
/**
* Even if you have a ribbon that only acts on click/enter, you may wish to know which
* item is currently highlighted. In this case, create a listener and pass it to the ribbon.
*/
class RibbonGridHoverListener
{
public:
virtual ~RibbonGridHoverListener() {}
virtual void onSelectionChanged(RibbonGridWidget* theWidget, const std::string& selectionID) = 0;
};
struct ItemDescription
{
std::string m_user_name;
@ -298,6 +310,8 @@ namespace GUIEngine
{
friend class RibbonWidget;
ptr_vector<RibbonGridHoverListener> m_hover_listeners;
virtual ~RibbonGridWidget() {}
/* reference pointers only, the actual instances are owned by m_children */
@ -331,6 +345,8 @@ namespace GUIEngine
public:
RibbonGridWidget(const bool combo=false, const int max_rows=4);
void registerHoverListener(RibbonGridHoverListener* listener);
void add();
bool rightPressed();
bool leftPressed();
@ -339,6 +355,7 @@ namespace GUIEngine
void updateItemDisplay();
bool mouseHovered(Widget* child);
void onRowChange(RibbonWidget* row);
const std::string& getSelectionIDString();
const std::string& getSelectionText();
@ -360,6 +377,7 @@ namespace GUIEngine
~ModelViewWidget();
void add();
void clearModels();
void addModel(irr::scene::IMesh* mesh, const Vec3& location = Vec3(0,0,0));
void update(float delta);
};