From 73ac4f165bef6450ec03481298e8b7d8aa8f379c Mon Sep 17 00:00:00 2001 From: Benau Date: Tue, 21 Aug 2018 01:31:49 +0800 Subject: [PATCH] Add indication for collected flags in GUI and map --- ...{soccer_player_blue.png => blue_arrow.png} | Bin .../{soccer_player_red.png => red_arrow.png} | Bin src/modes/capture_the_flag.cpp | 17 +++++++++++ src/modes/capture_the_flag.hpp | 22 ++++++++++++-- src/modes/world.cpp | 4 +-- src/states_screens/race_gui.cpp | 28 +++++++++++++++--- src/tracks/drive_graph.cpp | 11 +++++++ src/tracks/drive_graph.hpp | 2 +- src/tracks/graph.cpp | 16 ++++++++++ src/tracks/track.cpp | 25 +++++++++++++++- src/tracks/track.hpp | 2 +- 11 files changed, 115 insertions(+), 12 deletions(-) rename data/gui/{soccer_player_blue.png => blue_arrow.png} (100%) rename data/gui/{soccer_player_red.png => red_arrow.png} (100%) diff --git a/data/gui/soccer_player_blue.png b/data/gui/blue_arrow.png similarity index 100% rename from data/gui/soccer_player_blue.png rename to data/gui/blue_arrow.png diff --git a/data/gui/soccer_player_red.png b/data/gui/red_arrow.png similarity index 100% rename from data/gui/soccer_player_red.png rename to data/gui/red_arrow.png diff --git a/src/modes/capture_the_flag.cpp b/src/modes/capture_the_flag.cpp index b3e3fad01..0833895c5 100644 --- a/src/modes/capture_the_flag.cpp +++ b/src/modes/capture_the_flag.cpp @@ -44,6 +44,7 @@ const int g_captured_score = 10; CaptureTheFlag::CaptureTheFlag() : FreeForAll() { m_red_flag_node = m_blue_flag_node = NULL; + m_red_flag_indicator = m_blue_flag_indicator = NULL; m_red_flag_mesh = m_blue_flag_mesh = NULL; m_scored_sound = NULL; #ifndef SERVER_ONLY @@ -87,6 +88,20 @@ void CaptureTheFlag::init() "blue_flag"); assert(m_red_flag_node); assert(m_blue_flag_node); + + std::string red_path = + file_manager->getAsset(FileManager::GUI, "red_arrow.png"); + std::string blue_path = + file_manager->getAsset(FileManager::GUI, "blue_arrow.png"); + + m_red_flag_indicator = irr_driver->addBillboard( + core::dimension2df(1.5f, 1.5f), red_path, NULL); + m_red_flag_indicator->setPosition(Vec3( + m_orig_red_trans(Vec3(0.0f, 2.5f, 0.0f))).toIrrVector()); + m_blue_flag_indicator = irr_driver->addBillboard( + core::dimension2df(1.5f, 1.5f), blue_path, NULL); + m_blue_flag_indicator->setPosition(Vec3( + m_orig_blue_trans(Vec3(0.0f, 2.5f, 0.0f))).toIrrVector()); #endif } // init @@ -128,6 +143,8 @@ void CaptureTheFlag::updateGraphics(float dt) } else m_blue_flag_node->setAnimationSpeed(25.0f); + m_red_flag_indicator->setVisible(!isRedFlagInBase()); + m_blue_flag_indicator->setVisible(!isBlueFlagInBase()); } } // updateGraphics diff --git a/src/modes/capture_the_flag.hpp b/src/modes/capture_the_flag.hpp index cc1cf1748..1ce581582 100644 --- a/src/modes/capture_the_flag.hpp +++ b/src/modes/capture_the_flag.hpp @@ -27,7 +27,7 @@ namespace irr { namespace scene { - class IAnimatedMeshSceneNode; class IAnimatedMesh; + class IAnimatedMeshSceneNode; class IAnimatedMesh; class ISceneNode; } } @@ -38,9 +38,13 @@ private: scene::IAnimatedMeshSceneNode* m_blue_flag_node; - irr::scene::IAnimatedMesh* m_red_flag_mesh; + scene::IAnimatedMesh* m_red_flag_mesh; - irr::scene::IAnimatedMesh* m_blue_flag_mesh; + scene::IAnimatedMesh* m_blue_flag_mesh; + + scene::ISceneNode* m_red_flag_indicator; + + scene::ISceneNode* m_blue_flag_indicator; SFXBase* m_scored_sound; @@ -110,6 +114,18 @@ public: // ------------------------------------------------------------------------ int getBlueHolder() const { return m_blue_holder; } // ------------------------------------------------------------------------ + bool isRedFlagInBase() const + { + return m_red_holder == -1 && + m_red_trans.getOrigin() == m_orig_red_trans.getOrigin(); + } + // ------------------------------------------------------------------------ + bool isBlueFlagInBase() const + { + return m_blue_holder == -1 && + m_blue_trans.getOrigin() == m_orig_blue_trans.getOrigin(); + } + // ------------------------------------------------------------------------ const Vec3& getRedFlag() const { return (Vec3&)m_red_trans.getOrigin(); } // ------------------------------------------------------------------------ const Vec3& getBlueFlag() const { return (Vec3&)m_blue_trans.getOrigin(); } diff --git a/src/modes/world.cpp b/src/modes/world.cpp index c5a8c53bc..84cfd0c72 100644 --- a/src/modes/world.cpp +++ b/src/modes/world.cpp @@ -1512,9 +1512,9 @@ void World::initTeamArrows() //Loading the indicator textures std::string red_path = - file_manager->getAsset(FileManager::GUI, "soccer_player_red.png"); + file_manager->getAsset(FileManager::GUI, "red_arrow.png"); std::string blue_path = - file_manager->getAsset(FileManager::GUI, "soccer_player_blue.png"); + file_manager->getAsset(FileManager::GUI, "blue_arrow.png"); //Assigning indicators for(unsigned int i = 0; i < kart_amount; i++) diff --git a/src/states_screens/race_gui.cpp b/src/states_screens/race_gui.cpp index 59c6aadc2..7e5147663 100644 --- a/src/states_screens/race_gui.cpp +++ b/src/states_screens/race_gui.cpp @@ -519,11 +519,21 @@ void RaceGUI::drawGlobalMiniMap() if (ctf) { Vec3 draw_at; - track->mapPoint2MiniMap(ctf->getRedFlag(), &draw_at); - video::ITexture* icon = irr_driver->getTexture(FileManager::GUI, "red_flag.png"); + if (!ctf->isRedFlagInBase()) + { + track->mapPoint2MiniMap(Track::getCurrentTrack()->getRedFlag().getOrigin(), + &draw_at); + core::rect rs(core::position2di(0, 0), icon->getSize()); + core::rect rp(m_map_left+(int)(draw_at.getX()-(m_minimap_player_size/1.4f)), + lower_y -(int)(draw_at.getY()+(m_minimap_player_size/2.2f)), + m_map_left+(int)(draw_at.getX()+(m_minimap_player_size/1.4f)), + lower_y -(int)(draw_at.getY()-(m_minimap_player_size/2.2f))); + draw2DImage(icon, rp, rs, NULL, NULL, true, true); + } + track->mapPoint2MiniMap(ctf->getRedFlag(), &draw_at); core::rect rs(core::position2di(0, 0), icon->getSize()); core::rect rp(m_map_left+(int)(draw_at.getX()-(m_minimap_player_size/1.4f)), lower_y -(int)(draw_at.getY()+(m_minimap_player_size/2.2f)), @@ -531,10 +541,20 @@ void RaceGUI::drawGlobalMiniMap() lower_y -(int)(draw_at.getY()-(m_minimap_player_size/2.2f))); draw2DImage(icon, rp, rs, NULL, NULL, true); - track->mapPoint2MiniMap(ctf->getBlueFlag(), &draw_at); - icon = irr_driver->getTexture(FileManager::GUI, "blue_flag.png"); + if (!ctf->isBlueFlagInBase()) + { + track->mapPoint2MiniMap(Track::getCurrentTrack()->getBlueFlag().getOrigin(), + &draw_at); + core::rect rs(core::position2di(0, 0), icon->getSize()); + core::rect rp(m_map_left+(int)(draw_at.getX()-(m_minimap_player_size/1.4f)), + lower_y -(int)(draw_at.getY()+(m_minimap_player_size/2.2f)), + m_map_left+(int)(draw_at.getX()+(m_minimap_player_size/1.4f)), + lower_y -(int)(draw_at.getY()-(m_minimap_player_size/2.2f))); + draw2DImage(icon, rp, rs, NULL, NULL, true, true); + } + track->mapPoint2MiniMap(ctf->getBlueFlag(), &draw_at); core::rect bs(core::position2di(0, 0), icon->getSize()); core::rect bp(m_map_left+(int)(draw_at.getX()-(m_minimap_player_size/1.4f)), lower_y -(int)(draw_at.getY()+(m_minimap_player_size/2.2f)), diff --git a/src/tracks/drive_graph.cpp b/src/tracks/drive_graph.cpp index 189d56207..91007a3c7 100644 --- a/src/tracks/drive_graph.cpp +++ b/src/tracks/drive_graph.cpp @@ -22,6 +22,7 @@ #include "io/file_manager.hpp" #include "io/xml_node.hpp" #include "modes/world.hpp" +#include "race/race_manager.hpp" #include "tracks/check_lap.hpp" #include "tracks/check_line.hpp" #include "tracks/check_manager.hpp" @@ -724,3 +725,13 @@ DriveNode* DriveGraph::getNode(unsigned int j) const assert(n != NULL); return n; } // getNode + +// ----------------------------------------------------------------------------- +bool DriveGraph::hasLapLine() const +{ + if (Track::getCurrentTrack()->isCTF() && + race_manager->getMajorMode() == + RaceManager::MAJOR_MODE_CAPTURE_THE_FLAG) + return false; + return true; +} // hasLapLine diff --git a/src/tracks/drive_graph.hpp b/src/tracks/drive_graph.hpp index c41b109dd..4ce713284 100644 --- a/src/tracks/drive_graph.hpp +++ b/src/tracks/drive_graph.hpp @@ -69,7 +69,7 @@ private: // ------------------------------------------------------------------------ unsigned int getStartNode() const; // ------------------------------------------------------------------------ - virtual bool hasLapLine() const OVERRIDE { return true; } + virtual bool hasLapLine() const OVERRIDE; // ------------------------------------------------------------------------ virtual void differentNodeColor(int n, video::SColor* c) const OVERRIDE; diff --git a/src/tracks/graph.cpp b/src/tracks/graph.cpp index b53db294f..73eeb24d2 100644 --- a/src/tracks/graph.cpp +++ b/src/tracks/graph.cpp @@ -26,6 +26,7 @@ #include "graphics/sp/sp_mesh.hpp" #include "graphics/sp/sp_mesh_buffer.hpp" #include "modes/profile_world.hpp" +#include "race/race_manager.hpp" #include "tracks/arena_node_3d.hpp" #include "tracks/drive_node_2d.hpp" #include "tracks/drive_node_3d.hpp" @@ -420,6 +421,21 @@ RenderTarget* Graph::makeMiniMap(const core::dimension2du &dimension, } #endif + // Adjust bounding boxes for flags in CTF + if (Track::getCurrentTrack()->isCTF() && + race_manager->getMajorMode() == RaceManager::MAJOR_MODE_CAPTURE_THE_FLAG) + { + Vec3 red_flag = Track::getCurrentTrack()->getRedFlag().getOrigin(); + Vec3 blue_flag = Track::getCurrentTrack()->getBlueFlag().getOrigin(); + // In case the flag is placed outside of the graph, we scale it a bit + red_flag *= 1.1f; + blue_flag *= 1.1f; + m_bb_max.max(red_flag); + m_bb_max.max(blue_flag); + m_bb_min.min(red_flag); + m_bb_min.min(blue_flag); + } + m_node = irr_driver->addMesh(m_mesh, "mini_map"); #ifdef DEBUG m_node->setName("minimap-mesh"); diff --git a/src/tracks/track.cpp b/src/tracks/track.cpp index ade7b982d..874119bdc 100644 --- a/src/tracks/track.cpp +++ b/src/tracks/track.cpp @@ -1826,6 +1826,25 @@ void Track::loadTrackModel(bool reverse_track, unsigned int mode_id) // the race gui was created. The race gui is needed since it stores // the information about the size of the texture to render the mini // map to. + // Load the un-raycasted flag position first (for minimap) + if (m_is_ctf && + race_manager->getMajorMode() == RaceManager::MAJOR_MODE_CAPTURE_THE_FLAG) + { + for (unsigned int i=0; igetNumNodes(); i++) + { + const XMLNode *node = root->getNode(i); + const std::string &name = node->getName(); + if (name == "red-flag") + { + m_red_flag.setOrigin(flagCommand(node)); + } + else if (name == "blue-flag") + { + m_blue_flag.setOrigin(flagCommand(node)); + } + } // for igetNumNodes() + } + if (!m_is_arena && !m_is_soccer && !m_is_cutscene) loadDriveGraph(mode_id, reverse_track); else if ((m_is_arena || m_is_soccer) && !m_is_cutscene && m_has_navmesh) @@ -2422,7 +2441,7 @@ void Track::handleSky(const XMLNode &xml_node, const std::string &filename) } // handleSky //----------------------------------------------------------------------------- -void Track::flagCommand(const XMLNode *node) +Vec3 Track::flagCommand(const XMLNode *node) { Vec3 xyz; // Set some kind of default in case Y is not defined in the file @@ -2431,6 +2450,9 @@ void Track::flagCommand(const XMLNode *node) xyz.setY(1000); node->getXYZ(&xyz); + if (!m_track_mesh) + return xyz; + Vec3 loc(xyz); // Test if the item lies on a 3d node, if so adjust the normal @@ -2480,6 +2502,7 @@ void Track::flagCommand(const XMLNode *node) m_blue_flag = btTransform(shortestArcQuat(Vec3(0, 1, 0), normal), hit_point); } + return hit_point; } // flagCommand //----------------------------------------------------------------------------- diff --git a/src/tracks/track.hpp b/src/tracks/track.hpp index eab436dbe..a117819a7 100644 --- a/src/tracks/track.hpp +++ b/src/tracks/track.hpp @@ -430,7 +430,7 @@ public: void update(int ticks); void reset(); void itemCommand(const XMLNode *node); - void flagCommand(const XMLNode *node); + Vec3 flagCommand(const XMLNode *node); core::stringw getName() const; core::stringw getSortName() const; bool isInGroup(const std::string &group_name);