Improved support for multiplayer kart selection (fixed crash + added eye candy)
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@4157 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
@@ -26,6 +26,7 @@ ModelViewWidget::ModelViewWidget()
|
||||
{
|
||||
m_type = WTYPE_MODEL_VIEW;
|
||||
m_rtt_provider = NULL;
|
||||
m_rotation_mode = ROTATE_OFF;
|
||||
}
|
||||
// -----------------------------------------------------------------------------
|
||||
ModelViewWidget::~ModelViewWidget()
|
||||
@@ -90,8 +91,26 @@ void ModelViewWidget::addModel(irr::scene::IMesh* mesh, const Vec3& location)
|
||||
// -----------------------------------------------------------------------------
|
||||
void ModelViewWidget::update(float delta)
|
||||
{
|
||||
angle += delta*35;
|
||||
if (angle > 360) angle -= 360;
|
||||
if (m_rotation_mode == ROTATE_CONTINUOUSLY)
|
||||
{
|
||||
angle += delta*m_rotation_speed;
|
||||
if (angle > 360) angle -= 360;
|
||||
}
|
||||
else if (m_rotation_mode == ROTATE_TO)
|
||||
{
|
||||
// TODO : doesn't handle warp-arounds, which may be faster (e.g. we're at 300 and target is 10, better use warp-around)
|
||||
if (angle < m_rotation_target)
|
||||
{
|
||||
angle += delta*m_rotation_speed;
|
||||
}
|
||||
else
|
||||
{
|
||||
angle -= delta*m_rotation_speed;
|
||||
}
|
||||
|
||||
// stop rotating when target reached
|
||||
if (fabsf(angle - m_rotation_target) < 2.0f) m_rotation_mode = ROTATE_OFF;
|
||||
}
|
||||
|
||||
if (m_rtt_provider == NULL)
|
||||
{
|
||||
@@ -109,3 +128,20 @@ void ModelViewWidget::update(float delta)
|
||||
((IGUIImage*)m_element)->setImage(m_texture);
|
||||
}
|
||||
|
||||
|
||||
void ModelViewWidget::setRotateOff()
|
||||
{
|
||||
m_rotation_mode = ROTATE_OFF;
|
||||
}
|
||||
void ModelViewWidget::setRotateContinuously(float speed)
|
||||
{
|
||||
m_rotation_mode = ROTATE_CONTINUOUSLY;
|
||||
m_rotation_speed = speed;
|
||||
}
|
||||
void ModelViewWidget::setRotateTo(float targetAngle, float speed)
|
||||
{
|
||||
m_rotation_mode = ROTATE_TO;
|
||||
m_rotation_speed = speed;
|
||||
m_rotation_target = targetAngle;
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,15 @@ namespace GUIEngine
|
||||
/** A model view widget. See guiengine/engine.hpp for a detailed overview */
|
||||
class ModelViewWidget : public Widget
|
||||
{
|
||||
enum RotationMode
|
||||
{
|
||||
ROTATE_OFF,
|
||||
ROTATE_CONTINUOUSLY,
|
||||
ROTATE_TO
|
||||
};
|
||||
RotationMode m_rotation_mode;
|
||||
float m_rotation_speed;
|
||||
float m_rotation_target;
|
||||
|
||||
ptr_vector<scene::IMesh, REF> m_models;
|
||||
std::vector<Vec3> m_model_location;
|
||||
@@ -48,6 +57,15 @@ namespace GUIEngine
|
||||
void clearModels();
|
||||
void addModel(irr::scene::IMesh* mesh, const Vec3& location = Vec3(0,0,0));
|
||||
void update(float delta);
|
||||
|
||||
/** Disables any model rotation */
|
||||
void setRotateOff();
|
||||
|
||||
/** Makes the model rotate at given speed (in degrees per second) */
|
||||
void setRotateContinuously(float speed);
|
||||
|
||||
/** Rotate to 'targetAngle' in degrees at given speed (in degrees per second) */
|
||||
void setRotateTo(float targetAngle, float speed);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -189,6 +189,7 @@ ptr_vector<PlayerKartWidget, REF> g_player_karts;
|
||||
this->modelView->addModel( kartModel->getWheelModel(1), kartModel->getWheelGraphicsPosition(1) );
|
||||
this->modelView->addModel( kartModel->getWheelModel(2), kartModel->getWheelGraphicsPosition(2) );
|
||||
this->modelView->addModel( kartModel->getWheelModel(3), kartModel->getWheelGraphicsPosition(3) );
|
||||
this->modelView->setRotateContinuously( 35.0f );
|
||||
|
||||
kartName = new LabelWidget();
|
||||
kartName->m_text = props->getName();
|
||||
@@ -282,19 +283,25 @@ ptr_vector<PlayerKartWidget, REF> g_player_karts;
|
||||
stringw playerNameString = playerName->getStringValue();
|
||||
playerIDLabel->setText( StringUtils::insertValues( _("%s is ready"), playerNameString ) );
|
||||
|
||||
m_children.remove(playerName);
|
||||
playerName->getIrrlichtElement()->remove();
|
||||
playerName->elementRemoved();
|
||||
|
||||
modelView->setRotateTo(30.0f, 150.0f);
|
||||
|
||||
player_id_w *= 2;
|
||||
player_name_w = 0;
|
||||
|
||||
/*
|
||||
LabelWidget* playerIDLabel;
|
||||
PlayerNameSpinner* playerName;
|
||||
ModelViewWidget* modelView;
|
||||
LabelWidget* kartName;
|
||||
*/
|
||||
irr::video::ITexture* texture = irr_driver->getTexture( file_manager->getTextureFile("green_check.png").c_str() ) ;
|
||||
const int check_size = 128; // TODO: reduce size on smaller resolutions?
|
||||
const int check_x = model_x + model_w - check_size;
|
||||
const int check_y = model_y + model_h - check_size;
|
||||
core::rect< s32 > green_check_area(check_x, check_y, check_x + check_size, check_y + check_size);
|
||||
irr::gui::IGUIImage* greenCheckWidget = GUIEngine::getGUIEnv()->addImage( green_check_area );
|
||||
greenCheckWidget->setImage(texture);
|
||||
greenCheckWidget->setScaleImage(true);
|
||||
greenCheckWidget->setTabStop(false);
|
||||
greenCheckWidget->setUseAlphaChannel(true);
|
||||
}
|
||||
bool isReady()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user