Merge remote-tracking branch 'origin/master' into game_protocol
This commit is contained in:
commit
31619aecff
@ -411,6 +411,12 @@ namespace UserConfigParams
|
||||
"A parameter in range [0, 0.5] that determines the zone that is "
|
||||
"considered as max value in steering button."));
|
||||
|
||||
PARAM_PREFIX FloatUserConfigParam m_multitouch_scale
|
||||
PARAM_DEFAULT( FloatUserConfigParam(1.0f, "multitouch_scale",
|
||||
&m_multitouch_group,
|
||||
"A parameter in range [0.5, 1.5] that determines the scale of the "
|
||||
"multitouch interface."));
|
||||
|
||||
// ---- GP start order
|
||||
PARAM_PREFIX GroupUserConfigParam m_gp_start_order
|
||||
PARAM_DEFAULT( GroupUserConfigParam("GpStartOrder",
|
||||
|
@ -94,7 +94,7 @@ void Camera::changeCamera(unsigned int camera_index, CameraType type)
|
||||
if(old_camera->getType()==type) return;
|
||||
|
||||
Camera *new_camera = createCamera(old_camera->getIndex(), type,
|
||||
old_camera->m_kart );
|
||||
old_camera->m_original_kart);
|
||||
// Replace the previous camera
|
||||
m_all_cameras[camera_index] = new_camera;
|
||||
if(s_active_camera == old_camera)
|
||||
|
@ -40,6 +40,7 @@ const core::vector3df& scale, RenderInfo* render_info, bool all_parts_colorized)
|
||||
{
|
||||
isGLInitialized = false;
|
||||
isMaterialInitialized = false;
|
||||
m_got_animated_matrix = false;
|
||||
m_mesh_render_info = render_info;
|
||||
m_all_parts_colorized = all_parts_colorized;
|
||||
#ifdef DEBUG
|
||||
@ -192,10 +193,11 @@ void STKAnimatedMesh::updateNoGL()
|
||||
{
|
||||
// Test if texture matrix needs to be updated every frame
|
||||
const core::matrix4& mat = getMaterial(i).getTextureMatrix(0);
|
||||
if (mat.isIdentity())
|
||||
if (mat.isIdentity() && !m_got_animated_matrix)
|
||||
continue;
|
||||
else
|
||||
{
|
||||
m_got_animated_matrix = true;
|
||||
GLmeshes[i].texture_trans.X = mat[8];
|
||||
GLmeshes[i].texture_trans.Y = mat[9];
|
||||
}
|
||||
|
@ -53,6 +53,7 @@ public:
|
||||
private:
|
||||
RenderInfo* m_mesh_render_info;
|
||||
bool m_all_parts_colorized;
|
||||
bool m_got_animated_matrix;
|
||||
};
|
||||
|
||||
#endif // STKANIMATEDMESH_HPP
|
||||
|
@ -61,6 +61,7 @@ STKMeshSceneNode::STKMeshSceneNode(irr::scene::IMesh* mesh, ISceneNode* parent,
|
||||
update_each_frame = false;
|
||||
m_frame_for_mesh = frame_for_mesh;
|
||||
isGlow = false;
|
||||
m_got_animated_matrix = false;
|
||||
|
||||
m_debug_name = debug_name;
|
||||
|
||||
@ -244,10 +245,11 @@ void STKMeshSceneNode::updateNoGL()
|
||||
{
|
||||
// Test if texture matrix needs to be updated every frame
|
||||
const core::matrix4& mat = getMaterial(i).getTextureMatrix(0);
|
||||
if (mat.isIdentity())
|
||||
if (mat.isIdentity() && !m_got_animated_matrix)
|
||||
continue;
|
||||
else
|
||||
{
|
||||
m_got_animated_matrix = true;
|
||||
GLmeshes[i].texture_trans.X = mat[8];
|
||||
GLmeshes[i].texture_trans.Y = mat[9];
|
||||
}
|
||||
|
@ -30,6 +30,7 @@ class STKMeshSceneNode : public irr::scene::CMeshSceneNode, public STKMeshCommon
|
||||
protected:
|
||||
PtrVector<RenderInfo> m_static_render_info;
|
||||
int m_frame_for_mesh;
|
||||
bool m_got_animated_matrix;
|
||||
std::vector<GLMesh> GLmeshes;
|
||||
core::matrix4 ModelViewProjectionMatrix;
|
||||
core::vector3df windDir;
|
||||
|
@ -100,8 +100,9 @@ bool DeviceManager::initialize()
|
||||
{
|
||||
core::stringc name = m_irrlicht_gamepads[id].Name;
|
||||
|
||||
// Some linux systems report a disk accelerometer as a gamepad, skip that
|
||||
// Some systems report a disk accelerometer as a gamepad, skip that
|
||||
if (name.find("LIS3LV02DL") != -1) continue;
|
||||
if (name == "applesmc") continue;
|
||||
|
||||
if(m_irrlicht_gamepads[id].HasGenericName)
|
||||
{
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "graphics/camera.hpp"
|
||||
#include "items/powerup_manager.hpp"
|
||||
#include "karts/abstract_kart.hpp"
|
||||
#include "karts/controller/controller.hpp"
|
||||
#include "states_screens/race_gui_base.hpp"
|
||||
#include "tracks/track.hpp"
|
||||
#include "utils/translation.hpp"
|
||||
|
@ -102,6 +102,7 @@ void ThreeStrikesBattle::reset()
|
||||
|
||||
const unsigned int kart_amount = (unsigned int)m_karts.size();
|
||||
|
||||
int idCamera = 0;
|
||||
for(unsigned int n=0; n<kart_amount; n++)
|
||||
{
|
||||
if (dynamic_cast<SpareTireAI*>(m_karts[n]->getController()) != NULL)
|
||||
|
@ -36,10 +36,6 @@ using namespace irr;
|
||||
#include "guiengine/modaldialog.hpp"
|
||||
#include "guiengine/scalable_font.hpp"
|
||||
#include "io/file_manager.hpp"
|
||||
#include "input/input.hpp"
|
||||
#include "input/input_manager.hpp"
|
||||
#include "input/device_manager.hpp"
|
||||
#include "input/multitouch_device.hpp"
|
||||
#include "items/attachment.hpp"
|
||||
#include "items/attachment_manager.hpp"
|
||||
#include "items/powerup_manager.hpp"
|
||||
@ -53,6 +49,7 @@ using namespace irr;
|
||||
#include "modes/world.hpp"
|
||||
#include "modes/soccer_world.hpp"
|
||||
#include "race/race_manager.hpp"
|
||||
#include "states_screens/race_gui_multitouch.hpp"
|
||||
#include "tracks/track.hpp"
|
||||
#include "tracks/track_object_manager.hpp"
|
||||
#include "utils/constants.hpp"
|
||||
@ -67,14 +64,42 @@ RaceGUI::RaceGUI()
|
||||
{
|
||||
m_enabled = true;
|
||||
|
||||
// Determine maximum length of the rank/lap text, in order to
|
||||
// align those texts properly on the right side of the viewport.
|
||||
gui::ScalableFont* font = GUIEngine::getHighresDigitFont();
|
||||
core::dimension2du area = font->getDimension(L"99:99:99");
|
||||
m_timer_width = area.Width;
|
||||
m_font_height = area.Height;
|
||||
|
||||
if (race_manager->getMinorMode()==RaceManager::MINOR_MODE_FOLLOW_LEADER ||
|
||||
race_manager->getMinorMode()==RaceManager::MINOR_MODE_3_STRIKES ||
|
||||
race_manager->getNumLaps() > 9)
|
||||
m_lap_width = font->getDimension(L"99/99").Width;
|
||||
else
|
||||
m_lap_width = font->getDimension(L"9/9").Width;
|
||||
|
||||
// Originally m_map_height was 100, and we take 480 as minimum res
|
||||
const float scaling = irr_driver->getFrameSize().Height / 480.0f;
|
||||
float scaling = irr_driver->getFrameSize().Height / 480.0f;
|
||||
const float map_size = 100.0f;
|
||||
const float top_margin = 3.5f * m_font_height;
|
||||
|
||||
// Check if we have enough space for minimap when touch steering is enabled
|
||||
if (UserConfigParams::m_multitouch_enabled)
|
||||
{
|
||||
const float map_bottom = (float)(m_multitouch_gui->getMinimapBottom());
|
||||
|
||||
if ((map_size + 20.0f) * scaling > map_bottom - top_margin)
|
||||
{
|
||||
scaling = (map_bottom - top_margin) / (map_size + 20.0f);
|
||||
}
|
||||
}
|
||||
|
||||
// Marker texture has to be power-of-two for (old) OpenGL compliance
|
||||
//m_marker_rendered_size = 2 << ((int) ceil(1.0 + log(32.0 * scaling)));
|
||||
m_minimap_ai_size = (int)( 14.0f * scaling);
|
||||
m_minimap_player_size = (int)( 16.0f * scaling);
|
||||
m_map_width = (int)(100.0f * scaling);
|
||||
m_map_height = (int)(100.0f * scaling);
|
||||
m_map_width = (int)(map_size * scaling);
|
||||
m_map_height = (int)(map_size * scaling);
|
||||
m_map_left = (int)( 10.0f * scaling);
|
||||
m_map_bottom = (int)( 10.0f * scaling);
|
||||
|
||||
@ -91,8 +116,10 @@ RaceGUI::RaceGUI()
|
||||
}
|
||||
else if (UserConfigParams::m_multitouch_enabled)
|
||||
{
|
||||
m_map_left = irr_driver->getActualScreenSize().Width - m_map_width;
|
||||
m_map_bottom = int(irr_driver->getActualScreenSize().Height * 0.55f);
|
||||
m_map_left = (int)((irr_driver->getActualScreenSize().Width -
|
||||
m_map_width) * 0.95f);
|
||||
m_map_bottom = (int)(irr_driver->getActualScreenSize().Height -
|
||||
top_margin - m_map_height);
|
||||
}
|
||||
|
||||
m_is_tutorial = (race_manager->getTrackName() == "tutorial");
|
||||
@ -100,37 +127,11 @@ RaceGUI::RaceGUI()
|
||||
m_speed_meter_icon = material_manager->getMaterial("speedback.png");
|
||||
m_speed_bar_icon = material_manager->getMaterial("speedfore.png");
|
||||
//createMarkerTexture();
|
||||
|
||||
// Determine maximum length of the rank/lap text, in order to
|
||||
// align those texts properly on the right side of the viewport.
|
||||
gui::ScalableFont* font = GUIEngine::getHighresDigitFont();
|
||||
core::dimension2du area = font->getDimension(L"99:99:99");
|
||||
m_timer_width = area.Width;
|
||||
m_font_height = area.Height;
|
||||
|
||||
if (race_manager->getMinorMode()==RaceManager::MINOR_MODE_FOLLOW_LEADER ||
|
||||
race_manager->getMinorMode()==RaceManager::MINOR_MODE_3_STRIKES ||
|
||||
race_manager->getNumLaps() > 9)
|
||||
m_lap_width = font->getDimension(L"99/99").Width;
|
||||
else
|
||||
m_lap_width = font->getDimension(L"9/9").Width;
|
||||
|
||||
if (UserConfigParams::m_multitouch_enabled)
|
||||
{
|
||||
initMultitouchSteering();
|
||||
}
|
||||
} // RaceGUI
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
RaceGUI::~RaceGUI()
|
||||
{
|
||||
MultitouchDevice* device = input_manager->getDeviceManager()->
|
||||
getMultitouchDevice();
|
||||
|
||||
if (device != NULL)
|
||||
{
|
||||
device->clearButtons();
|
||||
}
|
||||
} // ~Racegui
|
||||
|
||||
|
||||
@ -229,6 +230,8 @@ void RaceGUI::renderPlayerView(const Camera *camera, float dt)
|
||||
{
|
||||
if (!m_enabled) return;
|
||||
|
||||
RaceGUIBase::renderPlayerView(camera, dt);
|
||||
|
||||
const core::recti &viewport = camera->getViewport();
|
||||
|
||||
core::vector2df scaling = camera->getScaling();
|
||||
@ -240,11 +243,6 @@ void RaceGUI::renderPlayerView(const Camera *camera, float dt)
|
||||
scaling *= viewport.getWidth()/800.0f; // scale race GUI along screen size
|
||||
drawAllMessages(kart, viewport, scaling);
|
||||
|
||||
if (UserConfigParams::m_multitouch_enabled)
|
||||
{
|
||||
drawMultitouchSteering(kart, viewport, scaling);
|
||||
}
|
||||
|
||||
if(!World::getWorld()->isRacePhase()) return;
|
||||
|
||||
drawPowerupIcons(kart, viewport, scaling);
|
||||
@ -256,8 +254,6 @@ void RaceGUI::renderPlayerView(const Camera *camera, float dt)
|
||||
|
||||
if (!m_is_tutorial)
|
||||
drawLap(kart, viewport, scaling);
|
||||
|
||||
RaceGUIBase::renderPlayerView(camera, dt);
|
||||
} // renderPlayerView
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -899,160 +895,3 @@ void RaceGUI::drawLap(const AbstractKart* kart,
|
||||
font->setScale(1.0f);
|
||||
|
||||
} // drawLap
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Makes some initializations and determines the look of multitouch steering
|
||||
* interface
|
||||
*/
|
||||
void RaceGUI::initMultitouchSteering()
|
||||
{
|
||||
MultitouchDevice* device = input_manager->getDeviceManager()->
|
||||
getMultitouchDevice();
|
||||
|
||||
if (device == NULL)
|
||||
return;
|
||||
|
||||
const int w = irr_driver->getActualScreenSize().Width;
|
||||
const int h = irr_driver->getActualScreenSize().Height;
|
||||
const float btn_size = 0.1f * h;
|
||||
const float btn2_size = 0.35f * h;
|
||||
const float margin = 0.1f * h;
|
||||
const float top_margin = 0.3f * h;
|
||||
const float col_size = btn_size + margin;
|
||||
const float small_ratio = 0.6f;
|
||||
|
||||
device->addButton(BUTTON_STEERING,
|
||||
int(0.5f * margin), int(h - 0.5f * margin - btn2_size),
|
||||
int(btn2_size), int(btn2_size));
|
||||
device->addButton(BUTTON_ESCAPE,
|
||||
int(top_margin), int(small_ratio * margin),
|
||||
int(small_ratio * btn_size), int(small_ratio * btn_size));
|
||||
device->addButton(BUTTON_RESCUE,
|
||||
int(top_margin + small_ratio * col_size),
|
||||
int(small_ratio * margin),
|
||||
int(small_ratio * btn_size), int(small_ratio * btn_size));
|
||||
device->addButton(BUTTON_NITRO,
|
||||
int(w - 1 * col_size), int(h - 2 * col_size),
|
||||
int(btn_size), int(btn_size));
|
||||
device->addButton(BUTTON_SKIDDING,
|
||||
int(w - 1 * col_size), int(h - 1 * col_size),
|
||||
int(btn_size), int(btn_size));
|
||||
device->addButton(BUTTON_FIRE,
|
||||
int(w - 2 * col_size), int(h - 2 * col_size),
|
||||
int(btn_size), int(btn_size));
|
||||
device->addButton(BUTTON_LOOK_BACKWARDS,
|
||||
int(w - 2 * col_size), int(h - 1 * col_size),
|
||||
int(btn_size), int(btn_size));
|
||||
|
||||
} // initMultitouchSteering
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Draws the buttons for multitouch steering.
|
||||
* \param kart The kart for which to show the data.
|
||||
* \param viewport The viewport to use.
|
||||
* \param scaling Which scaling to apply to the buttons.
|
||||
*/
|
||||
void RaceGUI::drawMultitouchSteering(const AbstractKart* kart,
|
||||
const core::recti &viewport,
|
||||
const core::vector2df &scaling)
|
||||
{
|
||||
#ifndef SERVER_ONLY
|
||||
MultitouchDevice* device = input_manager->getDeviceManager()->
|
||||
getMultitouchDevice();
|
||||
|
||||
if (device == NULL)
|
||||
return;
|
||||
|
||||
for (unsigned int i = 0; i < device->getButtonsCount(); i++)
|
||||
{
|
||||
MultitouchButton* button = device->getButton(i);
|
||||
|
||||
core::rect<s32> pos(button->x, button->y, button->x + button->width,
|
||||
button->y + button->height);
|
||||
|
||||
if (button->type == MultitouchButtonType::BUTTON_STEERING)
|
||||
{
|
||||
video::ITexture* tex = irr_driver->getTexture(FileManager::GUI,
|
||||
"blue_plus.png");
|
||||
core::rect<s32> coords(core::position2d<s32>(0,0), tex->getSize());
|
||||
|
||||
draw2DImage(tex, pos, coords, NULL, NULL, true);
|
||||
|
||||
float x = (float)(button->x) + (float)(button->width) / 2.0f *
|
||||
(button->axis_x + 1.0f);
|
||||
float y = (float)(button->y) + (float)(button->height) / 2.0f *
|
||||
(button->axis_y + 1.0f);
|
||||
float w = (float)(button->width) / 20.0f;
|
||||
float h = (float)(button->height) / 20.0f;
|
||||
|
||||
core::rect<s32> pos2(int(round(x - w)), int(round(y - h)),
|
||||
int(round(x + w)), int(round(y + h)) );
|
||||
|
||||
draw2DImage(tex, pos2, coords, NULL, NULL, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (button->pressed)
|
||||
{
|
||||
core::rect<s32> pos2(int(button->x - button->width * 0.2f),
|
||||
int(button->y - button->height * 0.2f),
|
||||
int(button->x + button->width * 1.2f),
|
||||
int(button->y + button->height * 1.2f) );
|
||||
|
||||
video::ITexture* tex = irr_driver->getTexture(FileManager::GUI,
|
||||
"icons-frame.png");
|
||||
core::rect<s32> coords(core::position2d<s32>(0,0), tex->getSize());
|
||||
|
||||
draw2DImage(tex, pos2, coords, NULL, NULL, true);
|
||||
}
|
||||
|
||||
video::ITexture* tex;
|
||||
|
||||
if (button->type == MultitouchButtonType::BUTTON_SKIDDING)
|
||||
{
|
||||
tex = irr_driver->getTexture(FileManager::TEXTURE,
|
||||
"skid-particle1.png");
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string name = "gui_lock.png";
|
||||
|
||||
switch (button->type)
|
||||
{
|
||||
case MultitouchButtonType::BUTTON_ESCAPE:
|
||||
name = "back.png";
|
||||
break;
|
||||
case MultitouchButtonType::BUTTON_FIRE:
|
||||
name = "banana.png";
|
||||
break;
|
||||
case MultitouchButtonType::BUTTON_NITRO:
|
||||
name = "nitro.png";
|
||||
break;
|
||||
case MultitouchButtonType::BUTTON_LOOK_BACKWARDS:
|
||||
name = "down.png";
|
||||
break;
|
||||
case MultitouchButtonType::BUTTON_RESCUE:
|
||||
name = "restart.png";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
tex = irr_driver->getTexture(FileManager::GUI, name);
|
||||
}
|
||||
|
||||
core::rect<s32> coords(core::position2d<s32>(0,0), tex->getSize());
|
||||
draw2DImage(tex, pos, coords, NULL, NULL, true);
|
||||
|
||||
if (button->type == MultitouchButtonType::BUTTON_NITRO)
|
||||
{
|
||||
float scale = (float)(irr_driver->
|
||||
getActualScreenSize().Height) / 1600.0f;
|
||||
drawEnergyMeter(button->x + button->width,
|
||||
button->y + button->height,
|
||||
kart, viewport, core::vector2df(scale, scale));
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
} // drawMultitouchSteering
|
||||
|
@ -94,8 +94,6 @@ private:
|
||||
|
||||
bool m_is_tutorial;
|
||||
|
||||
void initMultitouchSteering();
|
||||
|
||||
/* Display informat for one player on the screen. */
|
||||
void drawEnergyMeter (int x, int y, const AbstractKart *kart,
|
||||
const core::recti &viewport,
|
||||
@ -110,9 +108,6 @@ private:
|
||||
const core::vector2df &offset,
|
||||
float min_ratio, int meter_width,
|
||||
int meter_height, float dt);
|
||||
void drawMultitouchSteering (const AbstractKart* kart,
|
||||
const core::recti &viewport,
|
||||
const core::vector2df &scaling);
|
||||
|
||||
/** Display items that are shown once only (for all karts). */
|
||||
void drawGlobalMiniMap ();
|
||||
|
@ -42,6 +42,7 @@
|
||||
#include "karts/rescue_animation.hpp"
|
||||
#include "modes/linear_world.hpp"
|
||||
#include "modes/world.hpp"
|
||||
#include "states_screens/race_gui_multitouch.hpp"
|
||||
#include "tracks/track.hpp"
|
||||
#include "utils/constants.hpp"
|
||||
|
||||
@ -99,6 +100,13 @@ RaceGUIBase::RaceGUIBase()
|
||||
m_icons_inertia = 2;
|
||||
|
||||
m_referee = NULL;
|
||||
m_multitouch_gui = NULL;
|
||||
|
||||
if (UserConfigParams::m_multitouch_enabled &&
|
||||
race_manager->getNumLocalPlayers() == 1)
|
||||
{
|
||||
m_multitouch_gui = new RaceGUIMultitouch(this);
|
||||
}
|
||||
} // RaceGUIBase
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -146,6 +154,7 @@ void RaceGUIBase::reset()
|
||||
|
||||
m_referee_height = 10.0f;
|
||||
m_referee->attachToSceneNode();
|
||||
m_referee->selectReadySetGo(0); // set red color
|
||||
m_plunger_move_time = 0;
|
||||
m_plunger_offset = core::vector2di(0,0);
|
||||
m_plunger_speed = core::vector2df(0,0);
|
||||
@ -163,6 +172,7 @@ RaceGUIBase::~RaceGUIBase()
|
||||
// If the referee is currently being shown,
|
||||
// remove it from the scene graph.
|
||||
delete m_referee;
|
||||
delete m_multitouch_gui;
|
||||
} // ~RaceGUIBase
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -433,7 +443,15 @@ void RaceGUIBase::preRenderCallback(const Camera *camera)
|
||||
// ----------------------------------------------------------------------------
|
||||
void RaceGUIBase::renderPlayerView(const Camera *camera, float dt)
|
||||
{
|
||||
const core::recti &viewport = camera->getViewport();
|
||||
const core::vector2df scaling = camera->getScaling();
|
||||
const AbstractKart* kart = camera->getKart();
|
||||
if(!kart) return;
|
||||
|
||||
if (m_multitouch_gui != NULL)
|
||||
{
|
||||
m_multitouch_gui->drawMultitouchSteering(kart, viewport, scaling);
|
||||
}
|
||||
} // renderPlayerView
|
||||
|
||||
|
||||
|
@ -39,6 +39,7 @@ class AbstractKart;
|
||||
class Camera;
|
||||
class Material;
|
||||
class Referee;
|
||||
class RaceGUIMultitouch;
|
||||
|
||||
/**
|
||||
* \brief An abstract base class for the two race guis (race_gui and
|
||||
@ -179,6 +180,8 @@ protected:
|
||||
/** The frame around player karts in the mini map. */
|
||||
Material *m_icons_frame;
|
||||
|
||||
RaceGUIMultitouch* m_multitouch_gui;
|
||||
|
||||
void cleanupMessages(const float dt);
|
||||
//void createMarkerTexture();
|
||||
void createRegularPolygon(unsigned int n, float radius,
|
||||
@ -238,6 +241,10 @@ public:
|
||||
|
||||
void drawGlobalPlayerIcons(int bottom_margin);
|
||||
|
||||
virtual void drawEnergyMeter(int x, int y, const AbstractKart *kart,
|
||||
const core::recti &viewport,
|
||||
const core::vector2df &scaling) {};
|
||||
|
||||
}; // RaceGUIBase
|
||||
|
||||
#endif
|
||||
|
237
src/states_screens/race_gui_multitouch.cpp
Normal file
237
src/states_screens/race_gui_multitouch.cpp
Normal file
@ -0,0 +1,237 @@
|
||||
// SuperTuxKart - a fun racing game with go-kart
|
||||
// Copyright (C) 2014-2015 SuperTuxKart-Team
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 3
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#include "states_screens/race_gui_multitouch.hpp"
|
||||
|
||||
using namespace irr;
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "config/user_config.hpp"
|
||||
#include "graphics/camera.hpp"
|
||||
#include "graphics/2dutils.hpp"
|
||||
#include "graphics/irr_driver.hpp"
|
||||
#include "input/device_manager.hpp"
|
||||
#include "input/multitouch_device.hpp"
|
||||
#include "karts/abstract_kart.hpp"
|
||||
#include "states_screens/race_gui_base.hpp"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** The multitouch GUI constructor
|
||||
*/
|
||||
RaceGUIMultitouch::RaceGUIMultitouch(RaceGUIBase* race_gui)
|
||||
{
|
||||
m_race_gui = race_gui;
|
||||
m_minimap_bottom = 0;
|
||||
|
||||
m_device = input_manager->getDeviceManager()->getMultitouchDevice();
|
||||
|
||||
if (UserConfigParams::m_multitouch_scale > 1.5f)
|
||||
{
|
||||
UserConfigParams::m_multitouch_scale = 1.5f;
|
||||
}
|
||||
else if (UserConfigParams::m_multitouch_scale < 0.5f)
|
||||
{
|
||||
UserConfigParams::m_multitouch_scale = 0.5f;
|
||||
}
|
||||
|
||||
initMultitouchSteering();
|
||||
} // RaceGUIMultitouch
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** The multitouch GUI destructor
|
||||
*/
|
||||
RaceGUIMultitouch::~RaceGUIMultitouch()
|
||||
{
|
||||
closeMultitouchSteering();
|
||||
} // ~RaceGUIMultitouch
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Clears all previously created buttons in the multitouch device
|
||||
*/
|
||||
void RaceGUIMultitouch::closeMultitouchSteering()
|
||||
{
|
||||
if (m_device != NULL)
|
||||
{
|
||||
m_device->clearButtons();
|
||||
}
|
||||
} // closeMultitouchSteering
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Makes some initializations and determines the look of multitouch steering
|
||||
* interface
|
||||
*/
|
||||
void RaceGUIMultitouch::initMultitouchSteering()
|
||||
{
|
||||
if (m_device == NULL)
|
||||
return;
|
||||
|
||||
const float scale = UserConfigParams::m_multitouch_scale;
|
||||
|
||||
const int w = irr_driver->getActualScreenSize().Width;
|
||||
const int h = irr_driver->getActualScreenSize().Height;
|
||||
const float btn_size = 0.1f * h * scale;
|
||||
const float btn2_size = 0.35f * h * scale;
|
||||
const float margin = 0.1f * h * scale;
|
||||
const float top_margin = 0.3f * h;
|
||||
const float col_size = (btn_size + margin);
|
||||
const float small_ratio = 0.6f;
|
||||
|
||||
m_minimap_bottom = (unsigned int)(h - 2 * col_size);
|
||||
|
||||
m_device->addButton(BUTTON_STEERING,
|
||||
int(0.5f * margin), int(h - 0.5f * margin - btn2_size),
|
||||
int(btn2_size), int(btn2_size));
|
||||
m_device->addButton(BUTTON_ESCAPE,
|
||||
int(top_margin), int(small_ratio * margin),
|
||||
int(small_ratio * btn_size), int(small_ratio * btn_size));
|
||||
m_device->addButton(BUTTON_RESCUE,
|
||||
int(top_margin + small_ratio * col_size),
|
||||
int(small_ratio * margin),
|
||||
int(small_ratio * btn_size), int(small_ratio * btn_size));
|
||||
m_device->addButton(BUTTON_NITRO,
|
||||
int(w - 1 * col_size), int(h - 2 * col_size),
|
||||
int(btn_size), int(btn_size));
|
||||
m_device->addButton(BUTTON_SKIDDING,
|
||||
int(w - 1 * col_size), int(h - 1 * col_size),
|
||||
int(btn_size), int(btn_size));
|
||||
m_device->addButton(BUTTON_FIRE,
|
||||
int(w - 2 * col_size), int(h - 2 * col_size),
|
||||
int(btn_size), int(btn_size));
|
||||
m_device->addButton(BUTTON_LOOK_BACKWARDS,
|
||||
int(w - 2 * col_size), int(h - 1 * col_size),
|
||||
int(btn_size), int(btn_size));
|
||||
|
||||
} // initMultitouchSteering
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Draws the buttons for multitouch steering.
|
||||
* \param kart The kart for which to show the data.
|
||||
* \param viewport The viewport to use.
|
||||
* \param scaling Which scaling to apply to the buttons.
|
||||
*/
|
||||
void RaceGUIMultitouch::drawMultitouchSteering(const AbstractKart* kart,
|
||||
const core::recti &viewport,
|
||||
const core::vector2df &scaling)
|
||||
{
|
||||
#ifndef SERVER_ONLY
|
||||
if (m_device == NULL)
|
||||
return;
|
||||
|
||||
for (unsigned int i = 0; i < m_device->getButtonsCount(); i++)
|
||||
{
|
||||
MultitouchButton* button = m_device->getButton(i);
|
||||
|
||||
core::rect<s32> pos(button->x, button->y, button->x + button->width,
|
||||
button->y + button->height);
|
||||
|
||||
if (button->type == MultitouchButtonType::BUTTON_STEERING)
|
||||
{
|
||||
video::ITexture* tex = irr_driver->getTexture(FileManager::GUI,
|
||||
"blue_plus.png");
|
||||
core::rect<s32> coords(core::position2d<s32>(0,0), tex->getSize());
|
||||
|
||||
draw2DImage(tex, pos, coords, NULL, NULL, true);
|
||||
|
||||
float x = (float)(button->x) + (float)(button->width) / 2.0f *
|
||||
(button->axis_x + 1.0f);
|
||||
float y = (float)(button->y) + (float)(button->height) / 2.0f *
|
||||
(button->axis_y + 1.0f);
|
||||
float w = (float)(button->width) / 20.0f;
|
||||
float h = (float)(button->height) / 20.0f;
|
||||
|
||||
core::rect<s32> pos2(int(round(x - w)), int(round(y - h)),
|
||||
int(round(x + w)), int(round(y + h)) );
|
||||
|
||||
draw2DImage(tex, pos2, coords, NULL, NULL, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (button->pressed)
|
||||
{
|
||||
core::rect<s32> pos2(int(button->x - button->width * 0.2f),
|
||||
int(button->y - button->height * 0.2f),
|
||||
int(button->x + button->width * 1.2f),
|
||||
int(button->y + button->height * 1.2f) );
|
||||
|
||||
video::ITexture* tex = irr_driver->getTexture(FileManager::GUI,
|
||||
"icons-frame.png");
|
||||
core::rect<s32> coords(core::position2d<s32>(0,0), tex->getSize());
|
||||
|
||||
draw2DImage(tex, pos2, coords, NULL, NULL, true);
|
||||
}
|
||||
|
||||
video::ITexture* tex;
|
||||
|
||||
if (button->type == MultitouchButtonType::BUTTON_SKIDDING)
|
||||
{
|
||||
tex = irr_driver->getTexture(FileManager::TEXTURE,
|
||||
"skid-particle1.png");
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string name = "gui_lock.png";
|
||||
|
||||
switch (button->type)
|
||||
{
|
||||
case MultitouchButtonType::BUTTON_ESCAPE:
|
||||
name = "back.png";
|
||||
break;
|
||||
case MultitouchButtonType::BUTTON_FIRE:
|
||||
name = "banana.png";
|
||||
break;
|
||||
case MultitouchButtonType::BUTTON_NITRO:
|
||||
name = "nitro.png";
|
||||
break;
|
||||
case MultitouchButtonType::BUTTON_LOOK_BACKWARDS:
|
||||
name = "down.png";
|
||||
break;
|
||||
case MultitouchButtonType::BUTTON_RESCUE:
|
||||
name = "restart.png";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
tex = irr_driver->getTexture(FileManager::GUI, name);
|
||||
}
|
||||
|
||||
core::rect<s32> coords(core::position2d<s32>(0,0), tex->getSize());
|
||||
draw2DImage(tex, pos, coords, NULL, NULL, true);
|
||||
|
||||
if (button->type == MultitouchButtonType::BUTTON_NITRO)
|
||||
{
|
||||
float scale = UserConfigParams::m_multitouch_scale *
|
||||
(float)(irr_driver->getActualScreenSize().Height) / 1600.0f;
|
||||
|
||||
if (m_race_gui != NULL)
|
||||
{
|
||||
m_race_gui->drawEnergyMeter(button->x + button->width,
|
||||
button->y + button->height,
|
||||
kart, viewport,
|
||||
core::vector2df(scale, scale));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
} // drawMultitouchSteering
|
54
src/states_screens/race_gui_multitouch.hpp
Normal file
54
src/states_screens/race_gui_multitouch.hpp
Normal file
@ -0,0 +1,54 @@
|
||||
// SuperTuxKart - a fun racing game with go-kart
|
||||
// Copyright (C) 2014-2015 SuperTuxKart-Team
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 3
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#ifndef HEADER_RACE_GUI_MULTITOUCH_HPP
|
||||
#define HEADER_RACE_GUI_MULTITOUCH_HPP
|
||||
|
||||
#include <irrString.h>
|
||||
#include <rect.h>
|
||||
#include <vector2d.h>
|
||||
using namespace irr;
|
||||
|
||||
class AbstractKart;
|
||||
class MultitouchDevice;
|
||||
class RaceGUIBase;
|
||||
|
||||
class RaceGUIMultitouch
|
||||
{
|
||||
private:
|
||||
RaceGUIBase* m_race_gui;
|
||||
MultitouchDevice* m_device;
|
||||
|
||||
unsigned int m_minimap_bottom;
|
||||
|
||||
|
||||
void initMultitouchSteering();
|
||||
void closeMultitouchSteering();
|
||||
|
||||
public:
|
||||
RaceGUIMultitouch(RaceGUIBase* race_gui);
|
||||
~RaceGUIMultitouch();
|
||||
|
||||
void drawMultitouchSteering(const AbstractKart* kart,
|
||||
const core::recti &viewport,
|
||||
const core::vector2df &scaling);
|
||||
|
||||
unsigned int getMinimapBottom() {return m_minimap_bottom;}
|
||||
|
||||
}; // RaceGUIMultitouch
|
||||
|
||||
#endif
|
@ -46,6 +46,7 @@
|
||||
#include "modes/world.hpp"
|
||||
#include "race/grand_prix_manager.hpp"
|
||||
#include "race/race_manager.hpp"
|
||||
#include "states_screens/race_gui_multitouch.hpp"
|
||||
#include "tracks/track.hpp"
|
||||
#include "tracks/track_manager.hpp"
|
||||
#include "utils/constants.hpp"
|
||||
@ -78,13 +79,26 @@ RaceGUIOverworld::RaceGUIOverworld()
|
||||
m_trophy2 = irr_driver->getTexture(FileManager::GUI, "cup_silver.png");
|
||||
m_trophy3 = irr_driver->getTexture(FileManager::GUI, "cup_gold.png" );
|
||||
|
||||
const float scaling = irr_driver->getFrameSize().Height / 420.0f;
|
||||
float scaling = irr_driver->getFrameSize().Height / 420.0f;
|
||||
const float map_size = 250.0f;
|
||||
|
||||
// Check if we have enough space for minimap when touch steering is enabled
|
||||
if (UserConfigParams::m_multitouch_enabled)
|
||||
{
|
||||
const float map_bottom = (float)(m_multitouch_gui->getMinimapBottom());
|
||||
|
||||
if ((map_size + 20.0f) * scaling > map_bottom)
|
||||
{
|
||||
scaling = map_bottom / (map_size + 20.0f);
|
||||
}
|
||||
}
|
||||
|
||||
// Marker texture has to be power-of-two for (old) OpenGL compliance
|
||||
//m_marker_rendered_size = 2 << ((int) ceil(1.0 + log(32.0 * scaling)));
|
||||
m_minimap_challenge_size = (int)( 12.0f * scaling);
|
||||
m_minimap_player_size = (int)( 24.0f * scaling);
|
||||
m_map_width = (int)(250.0f * scaling);
|
||||
m_map_height = (int)(250.0f * scaling);
|
||||
m_map_width = (int)(map_size * scaling);
|
||||
m_map_height = (int)(map_size * scaling);
|
||||
|
||||
m_map_left = 20;
|
||||
m_map_bottom = irr_driver->getActualScreenSize().Height-10;
|
||||
@ -100,6 +114,12 @@ RaceGUIOverworld::RaceGUIOverworld()
|
||||
{
|
||||
m_map_left = irr_driver->getActualScreenSize().Width - m_map_width;
|
||||
}
|
||||
else if (UserConfigParams::m_multitouch_enabled)
|
||||
{
|
||||
m_map_left = (int)((irr_driver->getActualScreenSize().Width -
|
||||
m_map_width) * 0.9f);
|
||||
m_map_bottom = m_map_height + 10 * scaling;
|
||||
}
|
||||
|
||||
m_speed_meter_icon = material_manager->getMaterial("speedback.png");
|
||||
m_speed_bar_icon = material_manager->getMaterial("speedfore.png");
|
||||
@ -169,7 +189,10 @@ void RaceGUIOverworld::renderGlobal(float dt)
|
||||
if(!world->isRacePhase()) return;
|
||||
if (!m_enabled) return;
|
||||
|
||||
if (!UserConfigParams::m_multitouch_enabled)
|
||||
{
|
||||
drawTrophyPoints();
|
||||
}
|
||||
|
||||
// minimap has no mipmaps so disable material2D
|
||||
//irr_driver->getVideoDriver()->enableMaterial2D(false);
|
||||
@ -188,6 +211,9 @@ void RaceGUIOverworld::renderGlobal(float dt)
|
||||
void RaceGUIOverworld::renderPlayerView(const Camera *camera, float dt)
|
||||
{
|
||||
if (!m_enabled) return;
|
||||
|
||||
RaceGUIBase::renderPlayerView(camera, dt);
|
||||
|
||||
const AbstractKart *kart = camera->getKart();
|
||||
if(!kart) return;
|
||||
|
||||
@ -204,8 +230,6 @@ void RaceGUIOverworld::renderPlayerView(const Camera *camera, float dt)
|
||||
if(!World::getWorld()->isRacePhase()) return;
|
||||
|
||||
drawPowerupIcons (kart, viewport, scaling);
|
||||
|
||||
RaceGUIBase::renderPlayerView(camera, dt);
|
||||
} // renderPlayerView
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -305,7 +329,6 @@ void RaceGUIOverworld::drawGlobalMiniMap()
|
||||
// arenas currently don't have a map.
|
||||
Track* track = Track::getCurrentTrack();
|
||||
if(track->isArena() || track->isSoccer()) return;
|
||||
|
||||
const std::vector<OverworldChallenge>& challenges =
|
||||
track->getChallengeList();
|
||||
|
||||
@ -317,14 +340,25 @@ void RaceGUIOverworld::drawGlobalMiniMap()
|
||||
if(m_is_first_render_call)
|
||||
{
|
||||
float left_most = 0;
|
||||
float right_most = 0;
|
||||
|
||||
for (unsigned int n=0; n<challenges.size(); n++)
|
||||
{
|
||||
Vec3 draw_at;
|
||||
track->mapPoint2MiniMap(challenges[n].m_position, &draw_at);
|
||||
if(draw_at.getX()<left_most) left_most = draw_at.getX();
|
||||
if(draw_at.getX()>right_most) right_most = draw_at.getX();
|
||||
}
|
||||
|
||||
if (UserConfigParams::m_multitouch_enabled)
|
||||
{
|
||||
m_map_left += m_map_width - (int)right_most;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_map_left -= (int)left_most;
|
||||
}
|
||||
}
|
||||
|
||||
int upper_y = m_map_bottom - m_map_height;
|
||||
int lower_y = m_map_bottom;
|
||||
@ -545,74 +579,4 @@ void RaceGUIOverworld::drawGlobalMiniMap()
|
||||
} // drawGlobalMiniMap
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Energy meter that gets filled with nitro. This function is called from
|
||||
* drawSpeedAndEnergy, which defines the correct position of the energy
|
||||
* meter.
|
||||
* \param x X position of the meter.
|
||||
* \param y Y position of the meter.
|
||||
* \param kart Kart to display the data for.
|
||||
* \param scaling Scaling applied (in case of split screen)
|
||||
*/
|
||||
void RaceGUIOverworld::drawEnergyMeter(int x, int y, const AbstractKart *kart,
|
||||
const core::recti &viewport,
|
||||
const core::vector2df &scaling)
|
||||
{
|
||||
#ifndef SERVER_ONLY
|
||||
float state = (float)(kart->getEnergy())
|
||||
/ kart->getKartProperties()->getNitroMax();
|
||||
if (state < 0.0f) state = 0.0f;
|
||||
else if (state > 1.0f) state = 1.0f;
|
||||
|
||||
int h = (int)(viewport.getHeight()/3);
|
||||
int w = h/4; // gauge image is so 1:4
|
||||
|
||||
y -= h;
|
||||
|
||||
x -= w;
|
||||
|
||||
// Background
|
||||
draw2DImage(m_gauge_empty, core::rect<s32>(x, y, x+w, y+h) /* dest rect */,
|
||||
core::rect<s32>(0, 0, 64, 256) /* source rect */,
|
||||
NULL /* clip rect */, NULL /* colors */,
|
||||
true /* alpha */);
|
||||
|
||||
// Target
|
||||
if (race_manager->getCoinTarget() > 0)
|
||||
{
|
||||
float coin_target = (float)race_manager->getCoinTarget()
|
||||
/ kart->getKartProperties()->getNitroMax();
|
||||
|
||||
const int EMPTY_TOP_PIXELS = 4;
|
||||
const int EMPTY_BOTTOM_PIXELS = 3;
|
||||
int y1 = y + (int)(EMPTY_TOP_PIXELS +
|
||||
(h - EMPTY_TOP_PIXELS - EMPTY_BOTTOM_PIXELS)
|
||||
*(1.0f - coin_target) );
|
||||
if (state >= 1.0f) y1 = y;
|
||||
|
||||
core::rect<s32> clip(x, y1, x + w, y + h);
|
||||
draw2DImage(m_gauge_goal, core::rect<s32>(x, y, x+w, y+h) /* dest rect */,
|
||||
core::rect<s32>(0, 0, 64, 256) /* source rect */,
|
||||
&clip, NULL /* colors */, true /* alpha */);
|
||||
}
|
||||
|
||||
// Filling (current state)
|
||||
if (state > 0.0f)
|
||||
{
|
||||
const int EMPTY_TOP_PIXELS = 4;
|
||||
const int EMPTY_BOTTOM_PIXELS = 3;
|
||||
int y1 = y + (int)(EMPTY_TOP_PIXELS
|
||||
+ (h - EMPTY_TOP_PIXELS - EMPTY_BOTTOM_PIXELS)
|
||||
*(1.0f - state) );
|
||||
if (state >= 1.0f) y1 = y;
|
||||
|
||||
core::rect<s32> clip(x, y1, x + w, y + h);
|
||||
draw2DImage(m_gauge_full, core::rect<s32>(x, y, x+w, y+h) /* dest rect */,
|
||||
core::rect<s32>(0, 0, 64, 256) /* source rect */,
|
||||
&clip, NULL /* colors */, true /* alpha */);
|
||||
}
|
||||
|
||||
#endif
|
||||
} // drawEnergyMeter
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
@ -109,11 +109,6 @@ private:
|
||||
/** 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,
|
||||
const core::recti &viewport,
|
||||
const core::vector2df &scaling);
|
||||
|
||||
/** Display items that are shown once only (for all karts). */
|
||||
void drawGlobalMiniMap ();
|
||||
void drawTrophyPoints ();
|
||||
|
Loading…
Reference in New Issue
Block a user