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
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/** 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)
|
||||
{
|
||||
//FIXME: this code is duplicated from RaceGUIOverworld
|
||||
const float scaling = irr_driver->getFrameSize().Height / 420.0f;
|
||||
int marker_challenge_size = (int)( 12.0f * scaling);
|
||||
int map_left = 20;
|
||||
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++)
|
||||
const OverworldChallenge *challenge =
|
||||
((RaceGUIOverworld*)getRaceGUI())->getCurrentChallenge();
|
||||
|
||||
if(challenge)
|
||||
{
|
||||
Vec3 draw_at;
|
||||
t->mapPoint2MiniMap(challenges[n].m_position, &draw_at);
|
||||
|
||||
int marker_size = marker_challenge_size;
|
||||
core::position2di mouse = irr_driver->getMouseLocation();
|
||||
core::rect<s32> dest(map_left +(int)(draw_at.getX()-marker_size/2),
|
||||
map_bottom-(int)(draw_at.getY()+marker_size/2),
|
||||
map_left +(int)(draw_at.getX()+marker_size/2),
|
||||
map_bottom-(int)(draw_at.getY()-marker_size/2));
|
||||
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;
|
||||
}
|
||||
AbstractKart* kart = getKart(0);
|
||||
const btTransform& s = getClosestStartPoint(challenge->m_position.X,
|
||||
challenge->m_position.Z);
|
||||
const Vec3 &xyz = s.getOrigin();
|
||||
float angle = atan2(challenge->m_position.X - xyz[0],
|
||||
challenge->m_position.Z - xyz[2]);
|
||||
kart->setXYZ(xyz);
|
||||
moveKartAfterRescue(kart, angle);
|
||||
return;
|
||||
}
|
||||
}
|
||||
} // onMouseClick
|
@ -68,6 +68,7 @@ RaceGUIOverworld::RaceGUIOverworld()
|
||||
m_enabled = true;
|
||||
m_is_first_render_call = true;
|
||||
m_close_to_a_challenge = false;
|
||||
m_current_challenge = NULL;
|
||||
m_trophy1 = irr_driver->getTexture( file_manager->getTextureFile("cup_bronze.png") );
|
||||
m_trophy2 = irr_driver->getTexture( file_manager->getTextureFile("cup_silver.png") );
|
||||
m_trophy3 = irr_driver->getTexture( file_manager->getTextureFile("cup_gold.png") );
|
||||
@ -300,7 +301,7 @@ void RaceGUIOverworld::drawGlobalMiniMap()
|
||||
const std::vector<OverworldChallenge>& challenges =
|
||||
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.
|
||||
// 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
|
||||
@ -382,7 +383,8 @@ void RaceGUIOverworld::drawGlobalMiniMap()
|
||||
NULL, NULL, true);
|
||||
} // for i<getNumKarts
|
||||
} // for only_draw_player_kart
|
||||
|
||||
|
||||
m_current_challenge = NULL;
|
||||
for (unsigned int n=0; n<challenges.size(); n++)
|
||||
{
|
||||
Vec3 draw_at;
|
||||
@ -413,6 +415,7 @@ void RaceGUIOverworld::drawGlobalMiniMap()
|
||||
lower_y -(int)(draw_at.getY()+marker_size/2),
|
||||
m_map_left+(int)(draw_at.getX()+marker_size/2),
|
||||
lower_y -(int)(draw_at.getY()-marker_size/2));
|
||||
m_current_challenge = &(challenges[n]);
|
||||
}
|
||||
irr_driver->getVideoDriver()->draw2DImage(m_icons[state],
|
||||
dest, source, NULL, NULL, true);
|
||||
|
@ -32,6 +32,7 @@ using namespace irr;
|
||||
|
||||
class AbstractKart;
|
||||
class ChallengeData;
|
||||
struct OverworldChallenge;
|
||||
class InputMap;
|
||||
class Material;
|
||||
class RaceSetup;
|
||||
@ -101,6 +102,9 @@ private:
|
||||
int m_map_bottom;
|
||||
|
||||
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. */
|
||||
void drawEnergyMeter (int x, int y, const AbstractKart *kart,
|
||||
@ -117,7 +121,16 @@ public:
|
||||
~RaceGUIOverworld();
|
||||
virtual void renderGlobal(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. */
|
||||
virtual const core::dimension2du getMiniMapSize() const
|
||||
{ return core::dimension2du(m_map_width, m_map_height); }
|
||||
|
Loading…
Reference in New Issue
Block a user