Fixed #806: clicking on challenges in overworld did not
teleport karts anymore. git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@12068 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
dab600b5ea
commit
36a15015d8
@ -273,43 +273,26 @@ void OverWorld::moveKartAfterRescue(AbstractKart* kart, float angle)
|
|||||||
} // moveKartAfterRescue
|
} // moveKartAfterRescue
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
/** Called when a mouse click happens. If the click happened while the mouse
|
||||||
|
* was hovering on top of a challenge, the kart will be teleported to
|
||||||
|
* the challenge.
|
||||||
|
* \param x,y Mouse coordinates.
|
||||||
|
*/
|
||||||
void OverWorld::onMouseClick(int x, int y)
|
void OverWorld::onMouseClick(int x, int y)
|
||||||
{
|
{
|
||||||
//FIXME: this code is duplicated from RaceGUIOverworld
|
const OverworldChallenge *challenge =
|
||||||
const float scaling = irr_driver->getFrameSize().Height / 420.0f;
|
((RaceGUIOverworld*)getRaceGUI())->getCurrentChallenge();
|
||||||
int marker_challenge_size = (int)( 12.0f * scaling);
|
|
||||||
int map_left = 20;
|
if(challenge)
|
||||||
int map_bottom = UserConfigParams::m_height-10;
|
|
||||||
|
|
||||||
Track* t = getTrack();
|
|
||||||
|
|
||||||
const std::vector<OverworldChallenge>& challenges = t->getChallengeList();
|
|
||||||
|
|
||||||
for (unsigned int n=0; n<challenges.size(); n++)
|
|
||||||
{
|
{
|
||||||
Vec3 draw_at;
|
AbstractKart* kart = getKart(0);
|
||||||
t->mapPoint2MiniMap(challenges[n].m_position, &draw_at);
|
const btTransform& s = getClosestStartPoint(challenge->m_position.X,
|
||||||
|
challenge->m_position.Z);
|
||||||
int marker_size = marker_challenge_size;
|
const Vec3 &xyz = s.getOrigin();
|
||||||
core::position2di mouse = irr_driver->getMouseLocation();
|
float angle = atan2(challenge->m_position.X - xyz[0],
|
||||||
core::rect<s32> dest(map_left +(int)(draw_at.getX()-marker_size/2),
|
challenge->m_position.Z - xyz[2]);
|
||||||
map_bottom-(int)(draw_at.getY()+marker_size/2),
|
kart->setXYZ(xyz);
|
||||||
map_left +(int)(draw_at.getX()+marker_size/2),
|
moveKartAfterRescue(kart, angle);
|
||||||
map_bottom-(int)(draw_at.getY()-marker_size/2));
|
return;
|
||||||
if (dest.isPointInside(mouse))
|
|
||||||
{
|
|
||||||
AbstractKart* kart = getKart(0);
|
|
||||||
const btTransform& s = getClosestStartPoint(challenges[n].m_position.X,
|
|
||||||
challenges[n].m_position.Z);
|
|
||||||
const Vec3 &xyz = s.getOrigin();
|
|
||||||
printf("Kart: %f %f Challenge : %f %f\n", xyz[0], xyz[2], challenges[n].m_position.X, challenges[n].m_position.Z);
|
|
||||||
float angle = atan2(challenges[n].m_position.X - xyz[0],
|
|
||||||
challenges[n].m_position.Z - xyz[2]);
|
|
||||||
printf(" --> %f \n", angle);
|
|
||||||
kart->setXYZ(xyz);
|
|
||||||
moveKartAfterRescue(kart, angle);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
} // onMouseClick
|
@ -68,6 +68,7 @@ RaceGUIOverworld::RaceGUIOverworld()
|
|||||||
m_enabled = true;
|
m_enabled = true;
|
||||||
m_is_first_render_call = true;
|
m_is_first_render_call = true;
|
||||||
m_close_to_a_challenge = false;
|
m_close_to_a_challenge = false;
|
||||||
|
m_current_challenge = NULL;
|
||||||
m_trophy1 = irr_driver->getTexture( file_manager->getTextureFile("cup_bronze.png") );
|
m_trophy1 = irr_driver->getTexture( file_manager->getTextureFile("cup_bronze.png") );
|
||||||
m_trophy2 = irr_driver->getTexture( file_manager->getTextureFile("cup_silver.png") );
|
m_trophy2 = irr_driver->getTexture( file_manager->getTextureFile("cup_silver.png") );
|
||||||
m_trophy3 = irr_driver->getTexture( file_manager->getTextureFile("cup_gold.png") );
|
m_trophy3 = irr_driver->getTexture( file_manager->getTextureFile("cup_gold.png") );
|
||||||
@ -300,7 +301,7 @@ void RaceGUIOverworld::drawGlobalMiniMap()
|
|||||||
const std::vector<OverworldChallenge>& challenges =
|
const std::vector<OverworldChallenge>& challenges =
|
||||||
track->getChallengeList();
|
track->getChallengeList();
|
||||||
|
|
||||||
// The rophies might be to the left of the minimap on large displays
|
// The trophies might be to the left of the minimap on large displays
|
||||||
// Adjust the left side of the minimap to take this into account.
|
// Adjust the left side of the minimap to take this into account.
|
||||||
// This can't be done in the constructor of this object, since at
|
// This can't be done in the constructor of this object, since at
|
||||||
// that time the scene.xml file has not been read (so the challenges
|
// that time the scene.xml file has not been read (so the challenges
|
||||||
@ -382,7 +383,8 @@ void RaceGUIOverworld::drawGlobalMiniMap()
|
|||||||
NULL, NULL, true);
|
NULL, NULL, true);
|
||||||
} // for i<getNumKarts
|
} // for i<getNumKarts
|
||||||
} // for only_draw_player_kart
|
} // for only_draw_player_kart
|
||||||
|
|
||||||
|
m_current_challenge = NULL;
|
||||||
for (unsigned int n=0; n<challenges.size(); n++)
|
for (unsigned int n=0; n<challenges.size(); n++)
|
||||||
{
|
{
|
||||||
Vec3 draw_at;
|
Vec3 draw_at;
|
||||||
@ -413,6 +415,7 @@ void RaceGUIOverworld::drawGlobalMiniMap()
|
|||||||
lower_y -(int)(draw_at.getY()+marker_size/2),
|
lower_y -(int)(draw_at.getY()+marker_size/2),
|
||||||
m_map_left+(int)(draw_at.getX()+marker_size/2),
|
m_map_left+(int)(draw_at.getX()+marker_size/2),
|
||||||
lower_y -(int)(draw_at.getY()-marker_size/2));
|
lower_y -(int)(draw_at.getY()-marker_size/2));
|
||||||
|
m_current_challenge = &(challenges[n]);
|
||||||
}
|
}
|
||||||
irr_driver->getVideoDriver()->draw2DImage(m_icons[state],
|
irr_driver->getVideoDriver()->draw2DImage(m_icons[state],
|
||||||
dest, source, NULL, NULL, true);
|
dest, source, NULL, NULL, true);
|
||||||
|
@ -32,6 +32,7 @@ using namespace irr;
|
|||||||
|
|
||||||
class AbstractKart;
|
class AbstractKart;
|
||||||
class ChallengeData;
|
class ChallengeData;
|
||||||
|
struct OverworldChallenge;
|
||||||
class InputMap;
|
class InputMap;
|
||||||
class Material;
|
class Material;
|
||||||
class RaceSetup;
|
class RaceSetup;
|
||||||
@ -101,6 +102,9 @@ private:
|
|||||||
int m_map_bottom;
|
int m_map_bottom;
|
||||||
|
|
||||||
int m_trophy_points_width;
|
int m_trophy_points_width;
|
||||||
|
|
||||||
|
/** The current challenge over which the mouse is hovering. */
|
||||||
|
const OverworldChallenge *m_current_challenge;
|
||||||
|
|
||||||
/* Display informat for one player on the screen. */
|
/* Display informat for one player on the screen. */
|
||||||
void drawEnergyMeter (int x, int y, const AbstractKart *kart,
|
void drawEnergyMeter (int x, int y, const AbstractKart *kart,
|
||||||
@ -117,7 +121,16 @@ public:
|
|||||||
~RaceGUIOverworld();
|
~RaceGUIOverworld();
|
||||||
virtual void renderGlobal(float dt);
|
virtual void renderGlobal(float dt);
|
||||||
virtual void renderPlayerView(const AbstractKart *kart, float dt);
|
virtual void renderPlayerView(const AbstractKart *kart, float dt);
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
/** Returns the currently selected challenge data (or NULL if no is
|
||||||
|
* selected). */
|
||||||
|
const OverworldChallenge *getCurrentChallenge() const
|
||||||
|
{
|
||||||
|
return m_current_challenge;
|
||||||
|
} // getCurrentChallenge
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
/** Returns the size of the texture on which to render the minimap to. */
|
/** Returns the size of the texture on which to render the minimap to. */
|
||||||
virtual const core::dimension2du getMiniMapSize() const
|
virtual const core::dimension2du getMiniMapSize() const
|
||||||
{ return core::dimension2du(m_map_width, m_map_height); }
|
{ return core::dimension2du(m_map_width, m_map_height); }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user