Allow going to a challenge in the overworld by clicking on the minimap
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@11143 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
a4994e7512
commit
db2cd01922
@ -451,6 +451,13 @@ void IrrDriver::hidePointer()
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
core::position2di IrrDriver::getMouseLocation()
|
||||
{
|
||||
return this->getDevice()->getCursorControl()->getPosition();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void IrrDriver::changeResolution(const int w, const int h,
|
||||
const bool fullscreen)
|
||||
{
|
||||
|
@ -192,6 +192,7 @@ public:
|
||||
void showPointer();
|
||||
void hidePointer();
|
||||
bool isPointerShown() const { return m_pointer_shown; }
|
||||
core::position2di getMouseLocation();
|
||||
|
||||
void printRenderStats();
|
||||
/** Returns the current real time, which might not be 0 at start of the
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include "guiengine/widgets/list_widget.hpp"
|
||||
#include "guiengine/widgets/ribbon_widget.hpp"
|
||||
#include "input/input_manager.hpp"
|
||||
#include "modes/world.hpp"
|
||||
#include "states_screens/state_manager.hpp"
|
||||
#include "utils/profiler.hpp"
|
||||
|
||||
@ -147,6 +148,13 @@ bool EventHandler::OnEvent (const SEvent &event)
|
||||
profiler.onClick(m_mouse_pos);
|
||||
}
|
||||
|
||||
if (event.EventType == EET_MOUSE_INPUT_EVENT &&
|
||||
event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN &&
|
||||
StateManager::get()->getGameState() == GAME)
|
||||
{
|
||||
World::getWorld()->onMouseClick(event.MouseInput.X, event.MouseInput.Y);
|
||||
}
|
||||
|
||||
// FIXME? it may be a bit unclean that all input events go trough the gui module
|
||||
const EventPropagation blockPropagation = input_manager->input(event);
|
||||
return blockPropagation == EVENT_BLOCK;
|
||||
|
@ -66,6 +66,8 @@ void OverWorld::enterOverWorld()
|
||||
StateManager::get()->enterGameState();
|
||||
network_manager->setupPlayerKartInfo();
|
||||
race_manager->startNew(false);
|
||||
|
||||
irr_driver->showPointer(); // the user should be able to click on the minimap
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -185,15 +187,20 @@ void OverWorld::onFirePressed(Controller* who)
|
||||
* \param kart The kart that was rescued.
|
||||
*/
|
||||
void OverWorld::moveKartAfterRescue(AbstractKart* kart)
|
||||
{
|
||||
moveKartAfterRescue(kart, 0);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
const btTransform& OverWorld::getClosestStartPoint(float currentKart_x, float currentKart_z)
|
||||
{
|
||||
// find closest point to drop kart on
|
||||
World *world = World::getWorld();
|
||||
const int start_spots_amount = world->getTrack()->getNumberOfStartPositions();
|
||||
assert(start_spots_amount > 0);
|
||||
|
||||
const float currentKart_x = kart->getXYZ().getX();
|
||||
const float currentKart_z = kart->getXYZ().getZ();
|
||||
|
||||
|
||||
int closest_id = -1;
|
||||
float closest_distance = 999999999.0f;
|
||||
|
||||
@ -215,7 +222,22 @@ void OverWorld::moveKartAfterRescue(AbstractKart* kart)
|
||||
}
|
||||
|
||||
assert(closest_id != -1);
|
||||
const btTransform &s = world->getTrack()->getStartTransform(closest_id);
|
||||
return world->getTrack()->getStartTransform(closest_id);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void OverWorld::moveKartAfterRescue(AbstractKart* kart, float angle)
|
||||
{
|
||||
// find closest point to drop kart on
|
||||
World *world = World::getWorld();
|
||||
const int start_spots_amount = world->getTrack()->getNumberOfStartPositions();
|
||||
assert(start_spots_amount > 0);
|
||||
|
||||
const float currentKart_x = kart->getXYZ().getX();
|
||||
const float currentKart_z = kart->getXYZ().getZ();
|
||||
|
||||
const btTransform& s = getClosestStartPoint(currentKart_x, currentKart_z);
|
||||
const Vec3 &xyz = s.getOrigin();
|
||||
kart->setXYZ(xyz);
|
||||
kart->setRotation(s.getRotation());
|
||||
@ -223,7 +245,7 @@ void OverWorld::moveKartAfterRescue(AbstractKart* kart)
|
||||
//position kart from same height as in World::resetAllKarts
|
||||
btTransform pos;
|
||||
pos.setOrigin(kart->getXYZ()+btVector3(0, 0.5f*kart->getKartHeight(), 0.0f));
|
||||
pos.setRotation( btQuaternion(btVector3(0.0f, 1.0f, 0.0f), 0 /* angle */) );
|
||||
pos.setRotation( btQuaternion(btVector3(0.0f, 1.0f, 0.0f), angle) );
|
||||
|
||||
kart->getBody()->setCenterOfMassTransform(pos);
|
||||
|
||||
@ -244,3 +266,44 @@ void OverWorld::moveKartAfterRescue(AbstractKart* kart)
|
||||
}
|
||||
} // moveKartAfterRescue
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
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++)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
@ -40,6 +40,10 @@ protected:
|
||||
|
||||
bool m_return_to_garage;
|
||||
|
||||
void moveKartAfterRescue(AbstractKart* kart, float angle);
|
||||
|
||||
const btTransform& getClosestStartPoint(float currentKart_x, float currentKart_z);
|
||||
|
||||
public:
|
||||
OverWorld();
|
||||
/** call just after instanciating. can't be moved to the contructor as child
|
||||
@ -77,6 +81,8 @@ public:
|
||||
void scheduleReturnToGarage() { m_return_to_garage = true; }
|
||||
// ------------------------------------------------------------------------
|
||||
virtual void moveKartAfterRescue(AbstractKart* kart);
|
||||
// ------------------------------------------------------------------------
|
||||
virtual void onMouseClick(int x, int y);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -220,10 +220,11 @@ public:
|
||||
* called) in non-laped races.
|
||||
*/
|
||||
virtual void newLap(unsigned int kart_index) {}
|
||||
// ------------------------------------------------------------------------
|
||||
// ------------------------------------------------------------------------
|
||||
/** Called when a kart was hit by a projectile. */
|
||||
virtual void kartHit(const int kart_id) {};
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
virtual void onMouseClick(int x, int y) {};
|
||||
|
||||
// Other functions
|
||||
// ===============
|
||||
|
@ -331,10 +331,20 @@ void RaceGUIOverworld::drawGlobalMiniMap()
|
||||
const core::rect<s32> source(core::position2d<s32>(0,0),
|
||||
m_icons[state]->getOriginalSize());
|
||||
|
||||
core::rect<s32> dest(m_map_left+(int)(draw_at.getX()-m_marker_challenge_size/2),
|
||||
lower_y -(int)(draw_at.getY()+m_marker_challenge_size/2),
|
||||
m_map_left+(int)(draw_at.getX()+m_marker_challenge_size/2),
|
||||
lower_y -(int)(draw_at.getY()-m_marker_challenge_size/2));
|
||||
int marker_size = m_marker_challenge_size;
|
||||
core::position2di mouse = irr_driver->getMouseLocation();
|
||||
core::rect<s32> dest(m_map_left+(int)(draw_at.getX()-marker_size/2),
|
||||
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));
|
||||
if (dest.isPointInside(mouse))
|
||||
{
|
||||
marker_size = (int)(marker_size*1.6f);
|
||||
dest = core::rect<s32>(m_map_left+(int)(draw_at.getX()-marker_size/2),
|
||||
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));
|
||||
}
|
||||
irr_driver->getVideoDriver()->draw2DImage(m_icons[state],
|
||||
dest, source, NULL, NULL, true);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user