From bb0cf72635a9afdfd967686bb42766d2b42ab1db Mon Sep 17 00:00:00 2001 From: Benau Date: Sat, 13 Jan 2018 00:38:46 +0800 Subject: [PATCH] Add required code and color selector for rainbow karts --- data/gui/kart_color_slider.stkgui | 19 +++ data/gui/user_screen.stkgui | 2 + data/gui/user_screen_tab.stkgui | 2 + src/config/player_profile.cpp | 31 ++-- src/config/player_profile.hpp | 7 + src/graphics/render_info.hpp | 43 +----- src/guiengine/widgets/model_view_widget.cpp | 10 +- src/guiengine/widgets/model_view_widget.hpp | 4 +- src/guiengine/widgets/player_kart_widget.cpp | 6 +- src/karts/abstract_kart.cpp | 6 +- src/karts/abstract_kart.hpp | 4 +- src/karts/ghost_kart.cpp | 3 +- src/karts/kart.cpp | 5 +- src/karts/kart.hpp | 4 +- src/karts/kart_model.cpp | 11 +- src/karts/kart_model.hpp | 10 +- src/karts/kart_properties.cpp | 4 +- src/karts/kart_properties.hpp | 4 +- src/karts/kart_rewinder.cpp | 5 +- src/karts/kart_rewinder.hpp | 4 +- src/karts/kart_with_stats.cpp | 3 +- src/modes/soccer_world.cpp | 3 +- src/modes/three_strikes_battle.cpp | 2 +- src/modes/world.cpp | 19 ++- .../dialogs/kart_color_slider_dialog.cpp | 137 ++++++++++++++++++ .../dialogs/kart_color_slider_dialog.hpp | 49 +++++++ src/states_screens/feature_unlocked.cpp | 3 +- src/states_screens/grand_prix_lose.cpp | 3 +- src/states_screens/grand_prix_win.cpp | 3 +- src/states_screens/kart_selection.cpp | 10 +- src/states_screens/kart_selection.hpp | 3 +- src/states_screens/network_kart_selection.cpp | 3 +- src/states_screens/soccer_setup_screen.cpp | 8 +- src/states_screens/user_screen.cpp | 6 + src/tracks/track_object_presentation.cpp | 1 - 35 files changed, 316 insertions(+), 121 deletions(-) create mode 100644 data/gui/kart_color_slider.stkgui create mode 100644 src/states_screens/dialogs/kart_color_slider_dialog.cpp create mode 100644 src/states_screens/dialogs/kart_color_slider_dialog.hpp diff --git a/data/gui/kart_color_slider.stkgui b/data/gui/kart_color_slider.stkgui new file mode 100644 index 000000000..2ab8a82e7 --- /dev/null +++ b/data/gui/kart_color_slider.stkgui @@ -0,0 +1,19 @@ + + +
+
+ + + +
+
+
diff --git a/data/gui/user_screen.stkgui b/data/gui/user_screen.stkgui index 711a87c04..86ab8ec37 100644 --- a/data/gui/user_screen.stkgui +++ b/data/gui/user_screen.stkgui @@ -62,6 +62,8 @@ I18N="In the user screen" text="Delete" label_location="bottom"/> + diff --git a/data/gui/user_screen_tab.stkgui b/data/gui/user_screen_tab.stkgui index 84f1f9179..9e4ae03e8 100644 --- a/data/gui/user_screen_tab.stkgui +++ b/data/gui/user_screen_tab.stkgui @@ -67,6 +67,8 @@ I18N="In the user screen" text="Delete" label_location="bottom"/> + diff --git a/src/config/player_profile.cpp b/src/config/player_profile.cpp index fb1bcd269..a7b10f42a 100644 --- a/src/config/player_profile.cpp +++ b/src/config/player_profile.cpp @@ -48,6 +48,7 @@ PlayerProfile::PlayerProfile(const core::stringw& name, bool is_guest) m_last_online_name = ""; m_last_was_online = false; m_remember_password = false; + m_default_kart_color = 0.0f; initRemainingData(); } // PlayerProfile @@ -76,24 +77,25 @@ PlayerProfile::PlayerProfile(const XMLNode* node) m_remember_password = false; m_story_mode_status = NULL; m_achievements_status = NULL; + m_default_kart_color = 0.0f; m_icon_filename = ""; - node->getAndDecode("name", &m_local_name); - node->get("guest", &m_is_guest_account ); - node->get("use-frequency", &m_use_frequency ); - node->get("unique-id", &m_unique_id ); - node->get("saved-session", &m_saved_session ); - node->get("saved-user", &m_saved_user_id ); - node->get("saved-token", &m_saved_token ); - node->get("last-online-name", &m_last_online_name ); - node->get("last-was-online", &m_last_was_online ); - node->get("remember-password", &m_remember_password); - node->get("icon-filename", &m_icon_filename ); - + node->getAndDecode("name", &m_local_name); + node->get("guest", &m_is_guest_account ); + node->get("use-frequency", &m_use_frequency ); + node->get("unique-id", &m_unique_id ); + node->get("saved-session", &m_saved_session ); + node->get("saved-user", &m_saved_user_id ); + node->get("saved-token", &m_saved_token ); + node->get("last-online-name", &m_last_online_name ); + node->get("last-was-online", &m_last_was_online ); + node->get("remember-password", &m_remember_password); + node->get("icon-filename", &m_icon_filename ); + node->get("default-kart-color", &m_default_kart_color); #ifdef DEBUG m_magic_number = 0xABCD1234; #endif - + } // PlayerProfile //------------------------------------------------------------------------------ @@ -211,7 +213,8 @@ void PlayerProfile::save(UTFWriter &out) << L"\" saved-token=\"" << m_saved_token << L"\"\n"; out << L" last-online-name=\"" << m_last_online_name << L"\" last-was-online=\"" << m_last_was_online << L"\"\n"; - out << L" remember-password=\"" << m_remember_password << L"\">\n"; + out << L" remember-password=\"" << m_remember_password << L"\"\n"; + out << L" default-kart-color=\"" << m_default_kart_color << L"\">\n"; { if(m_story_mode_status) m_story_mode_status->save(out); diff --git a/src/config/player_profile.hpp b/src/config/player_profile.hpp index 780b04b33..9c5cfebb0 100644 --- a/src/config/player_profile.hpp +++ b/src/config/player_profile.hpp @@ -106,6 +106,9 @@ private: /** True if the login data are saved. */ bool m_remember_password; + /** Default kart color (in hue) used in game, 0.0f to use the original. */ + float m_default_kart_color; + /** The complete challenge state. */ StoryModeStatus *m_story_mode_status; @@ -300,6 +303,10 @@ public: /** Sets if this player was logged in last time it was used. */ void setRememberPassword(bool b) { m_remember_password = b; } // ------------------------------------------------------------------------ + void setDefaultKartColor(float c) { m_default_kart_color = c; } + // ------------------------------------------------------------------------ + float getDefaultKartColor() const { return m_default_kart_color; } + }; // class PlayerProfile #endif diff --git a/src/graphics/render_info.hpp b/src/graphics/render_info.hpp index b04af392c..6aa90c752 100644 --- a/src/graphics/render_info.hpp +++ b/src/graphics/render_info.hpp @@ -21,34 +21,13 @@ #include "utils/no_copy.hpp" -#include -#include - -namespace irr -{ - namespace scene { class IMesh; } -} - -enum KartRenderType: unsigned int -{ - KRT_DEFAULT, - KRT_RED, - KRT_ORANGE, - KRT_YELLOW, - KRT_GREEN, - KRT_PALE_BLUE, - KRT_BLUE, - KRT_PURPLE, - KRT_TRANSPARENT, -}; - /** * \ingroup graphics */ class RenderInfo : public NoCopy { private: - float m_static_hue; + float m_hue; bool m_transparent; @@ -56,31 +35,17 @@ public: // ------------------------------------------------------------------------ RenderInfo(float hue = 0.0f, bool transparent = false) { - m_static_hue = hue; + m_hue = hue; m_transparent = transparent; } // ------------------------------------------------------------------------ - ~RenderInfo() {} - // ------------------------------------------------------------------------ - void setHue(float hue) { m_static_hue = hue; } + void setHue(float hue) { m_hue = hue; } // ------------------------------------------------------------------------ void setTransparent(bool transparent) { m_transparent = transparent; } // ------------------------------------------------------------------------ - float getHue() const { return m_static_hue; } + float getHue() const { return m_hue; } // ------------------------------------------------------------------------ bool isTransparent() const { return m_transparent; } - // ------------------------------------------------------------------------ - void setKartModelRenderInfo(KartRenderType krt) - { - setHue(krt == KRT_RED ? 1.0f : - krt == KRT_ORANGE ? 0.06f : - krt == KRT_YELLOW ? 0.17f : - krt == KRT_GREEN ? 0.35f : - krt == KRT_PALE_BLUE ? 0.5f : - krt == KRT_BLUE ? 0.66f : - krt == KRT_PURPLE ? 0.8f : 0.0f); - setTransparent(krt == KRT_TRANSPARENT ? true : false); - } }; // RenderInfo diff --git a/src/guiengine/widgets/model_view_widget.cpp b/src/guiengine/widgets/model_view_widget.cpp index 5c44d9470..df93cccf7 100644 --- a/src/guiengine/widgets/model_view_widget.cpp +++ b/src/guiengine/widgets/model_view_widget.cpp @@ -39,8 +39,9 @@ using namespace GUIEngine; using namespace irr::core; using namespace irr::gui; -ModelViewWidget::ModelViewWidget() : -IconButtonWidget(IconButtonWidget::SCALE_MODE_KEEP_TEXTURE_ASPECT_RATIO, false, false) +ModelViewWidget::ModelViewWidget(unsigned rtt_size) : +IconButtonWidget(IconButtonWidget::SCALE_MODE_KEEP_TEXTURE_ASPECT_RATIO, false, false), +m_rtt_size(rtt_size) { m_rtt_main_node = NULL; m_camera = NULL; @@ -48,7 +49,7 @@ IconButtonWidget(IconButtonWidget::SCALE_MODE_KEEP_TEXTURE_ASPECT_RATIO, false, m_type = WTYPE_MODEL_VIEW; m_render_target = NULL; m_rotation_mode = ROTATE_OFF; - m_render_info.reset(new RenderInfo()); + m_render_info = std::make_shared(); m_angle = 0; // so that the base class doesn't complain there is no icon defined @@ -84,6 +85,7 @@ void ModelViewWidget::add() // ----------------------------------------------------------------------------- void ModelViewWidget::clearModels() { + m_render_info->setHue(0.0f); m_models.clearWithoutDeleting(); m_model_location.clear(); m_model_frames.clear(); @@ -178,7 +180,7 @@ void ModelViewWidget::update(float delta) { std::string name = "model view "; name += m_properties[PROP_ID].c_str(); - m_render_target = irr_driver->createRenderTarget(irr::core::dimension2du(512,512), name); + m_render_target = irr_driver->createRenderTarget(irr::core::dimension2du(m_rtt_size, m_rtt_size), name); } if (m_rtt_main_node == NULL) diff --git a/src/guiengine/widgets/model_view_widget.hpp b/src/guiengine/widgets/model_view_widget.hpp index f3100af2f..1e5834283 100644 --- a/src/guiengine/widgets/model_view_widget.hpp +++ b/src/guiengine/widgets/model_view_widget.hpp @@ -65,11 +65,13 @@ namespace GUIEngine std::shared_ptr m_render_info; + const unsigned m_rtt_size; + public: LEAK_CHECK() - ModelViewWidget(); + ModelViewWidget(unsigned rtt_size = 512); virtual ~ModelViewWidget(); void add(); diff --git a/src/guiengine/widgets/player_kart_widget.cpp b/src/guiengine/widgets/player_kart_widget.cpp index 1d10a6b7f..0aa7323e2 100644 --- a/src/guiengine/widgets/player_kart_widget.cpp +++ b/src/guiengine/widgets/player_kart_widget.cpp @@ -20,6 +20,7 @@ #include "config/player_manager.hpp" #include "config/user_config.hpp" +#include "graphics/render_info.hpp" #include "guiengine/widgets/kart_stats_widget.hpp" #include "guiengine/widgets/model_view_widget.hpp" #include "guiengine/widgets/player_name_spinner.hpp" @@ -217,7 +218,8 @@ PlayerKartWidget::PlayerKartWidget(KartSelectionScreen* parent, kart_model.getFrame(KartModel::AF_WIN_END) : kart_model.getBaseFrame(), kart_model.getAnimationSpeed()); - + m_model_view->getModelViewRenderInfo()->setHue( + m_associated_player->getConstProfile()->getDefaultKartColor()); model_location.setScale(core::vector3df(1.0f, 1.0f, 1.0f)); for (unsigned i = 0; i < 4; i++) { @@ -642,6 +644,8 @@ GUIEngine::EventPropagation PlayerKartWidget::transmitEvent(Widget* w, m_handicapped = false; m_model_view->unsetBadge(ANCHOR_BADGE); } + m_model_view->getModelViewRenderInfo()->setHue( + m_associated_player->getConstProfile()->getDefaultKartColor()); } } diff --git a/src/karts/abstract_kart.cpp b/src/karts/abstract_kart.cpp index 3d8a5c042..8290a5d1a 100644 --- a/src/karts/abstract_kart.cpp +++ b/src/karts/abstract_kart.cpp @@ -19,7 +19,6 @@ #include "karts/abstract_kart.hpp" -#include "graphics/render_info.hpp" #include "items/powerup.hpp" #include "karts/abstract_kart_animation.hpp" #include "karts/kart_model.hpp" @@ -36,7 +35,8 @@ AbstractKart::AbstractKart(const std::string& ident, int world_kart_id, int position, const btTransform& init_transform, - PerPlayerDifficulty difficulty, KartRenderType krt) + PerPlayerDifficulty difficulty, + std::shared_ptr ri) : Moveable() { m_world_kart_id = world_kart_id; @@ -60,7 +60,7 @@ AbstractKart::AbstractKart(const std::string& ident, // released when the kart is deleted, but since the original // kart_model is stored in the kart_properties all the time, // there is no risk of a mesh being deleted to early. - m_kart_model = m_kart_properties->getKartModelCopy(krt); + m_kart_model = m_kart_properties->getKartModelCopy(ri); m_kart_width = m_kart_model->getWidth(); m_kart_height = m_kart_model->getHeight(); m_kart_length = m_kart_model->getLength(); diff --git a/src/karts/abstract_kart.hpp b/src/karts/abstract_kart.hpp index ea1cf5f74..2baa13afc 100644 --- a/src/karts/abstract_kart.hpp +++ b/src/karts/abstract_kart.hpp @@ -45,12 +45,12 @@ class KartModel; class KartProperties; class Material; class Powerup; +class RenderInfo; class SFXBuffer; class Skidding; class SlipStream; class TerrainInfo; -enum KartRenderType: unsigned int; /** An abstract interface for the actual karts. Some functions are actually * implemented here in order to allow inlining. @@ -102,7 +102,7 @@ public: int world_kart_id, int position, const btTransform& init_transform, PerPlayerDifficulty difficulty, - KartRenderType krt); + std::shared_ptr ri); virtual ~AbstractKart(); virtual core::stringw getName() const; virtual void reset(); diff --git a/src/karts/ghost_kart.cpp b/src/karts/ghost_kart.cpp index 464b6de4f..52e8d634a 100644 --- a/src/karts/ghost_kart.cpp +++ b/src/karts/ghost_kart.cpp @@ -29,7 +29,8 @@ GhostKart::GhostKart(const std::string& ident, unsigned int world_kart_id, int position) : Kart(ident, world_kart_id, position, btTransform(btQuaternion(0, 0, 0, 1)), - PLAYER_DIFFICULTY_NORMAL, KRT_TRANSPARENT) + PLAYER_DIFFICULTY_NORMAL, + std::make_shared(0.0f, true/*transparent*/)) { } // GhostKart diff --git a/src/karts/kart.cpp b/src/karts/kart.cpp index b2dd7095b..536921acf 100644 --- a/src/karts/kart.cpp +++ b/src/karts/kart.cpp @@ -35,7 +35,6 @@ #include "graphics/material_manager.hpp" #include "graphics/particle_emitter.hpp" #include "graphics/particle_kind_manager.hpp" -#include "graphics/render_info.hpp" #include "graphics/shadow.hpp" #include "graphics/skid_marks.hpp" #include "graphics/slip_stream.hpp" @@ -106,9 +105,9 @@ */ Kart::Kart (const std::string& ident, unsigned int world_kart_id, int position, const btTransform& init_transform, - PerPlayerDifficulty difficulty, KartRenderType krt) + PerPlayerDifficulty difficulty, std::shared_ptr ri) : AbstractKart(ident, world_kart_id, position, init_transform, - difficulty, krt) + difficulty, ri) #if defined(WIN32) && !defined(__CYGWIN__) && !defined(__MINGW32__) # pragma warning(1:4355) diff --git a/src/karts/kart.hpp b/src/karts/kart.hpp index ac60599f0..2f8e1080f 100644 --- a/src/karts/kart.hpp +++ b/src/karts/kart.hpp @@ -53,8 +53,6 @@ class SlipStream; class Stars; class TerrainInfo; -enum KartRenderType: unsigned int; - /** The main kart class. All type of karts are of this object, but with * different controllers. The controllers are what turn a kart into a * player kart (i.e. the controller handle input), or an AI kart (the @@ -247,7 +245,7 @@ public: Kart(const std::string& ident, unsigned int world_kart_id, int position, const btTransform& init_transform, PerPlayerDifficulty difficulty, - KartRenderType krt); + std::shared_ptr ri); virtual ~Kart(); virtual void init(RaceManager::KartType type); virtual void kartIsInRestNow(); diff --git a/src/karts/kart_model.cpp b/src/karts/kart_model.cpp index e3b1018e3..b6ff453d6 100644 --- a/src/karts/kart_model.cpp +++ b/src/karts/kart_model.cpp @@ -31,7 +31,6 @@ #include "graphics/material.hpp" #include "graphics/material_manager.hpp" #include "graphics/mesh_tools.hpp" -#include "graphics/render_info.hpp" #include "graphics/sp/sp_animation.hpp" #include "graphics/sp/sp_mesh.hpp" #include "graphics/sp/sp_mesh_buffer.hpp" @@ -132,7 +131,6 @@ KartModel::KartModel(bool is_master) m_animation_speed = 25; m_current_animation = AF_DEFAULT; m_play_non_loop = false; - m_krt = KRT_DEFAULT; m_support_colorization = false; } // KartModel @@ -316,7 +314,7 @@ KartModel::~KartModel() * It is also marked not to be a master copy, so attachModel can be called * for this instance. */ -KartModel* KartModel::makeCopy(KartRenderType krt) +KartModel* KartModel::makeCopy(std::shared_ptr ri) { // Make sure that we are copying from a master objects, and // that there is indeed no animated node defined here ... @@ -337,13 +335,11 @@ KartModel* KartModel::makeCopy(KartRenderType krt) km->m_animated_node = NULL; km->m_hat_name = m_hat_name; km->m_hat_bone = m_hat_bone; - km->m_krt = krt; km->m_support_colorization = m_support_colorization; - km->m_render_info = std::make_shared(); + km->m_render_info = ri; km->m_inverse_bone_matrices = m_inverse_bone_matrices; km->m_version = m_version; km->m_exhaust_xml = m_exhaust_xml; - km->m_render_info->setKartModelRenderInfo(krt); km->m_nitro_emitter_position[0] = m_nitro_emitter_position[0]; km->m_nitro_emitter_position[1] = m_nitro_emitter_position[1]; @@ -1225,8 +1221,7 @@ void KartModel::resetVisualWheelPosition() //----------------------------------------------------------------------------- std::shared_ptr KartModel::getRenderInfo() { - return m_support_colorization || m_krt == KRT_TRANSPARENT ? - m_render_info : NULL; + return m_support_colorization ? m_render_info : NULL; } // getRenderInfo //----------------------------------------------------------------------------- diff --git a/src/karts/kart_model.hpp b/src/karts/kart_model.hpp index b42dc2881..93126566d 100644 --- a/src/karts/kart_model.hpp +++ b/src/karts/kart_model.hpp @@ -40,8 +40,6 @@ class KartProperties; class RenderInfo; class XMLNode; -enum KartRenderType: unsigned int; - /** A speed-weighted object is an object whose characteristics are influenced by the kart's speed */ struct SpeedWeightedObject { @@ -311,11 +309,7 @@ private: /** Pointer to the kart object belonging to this kart model. */ AbstractKart* m_kart; - /** Tell the render type of this kart model, either colorized (red / blue now) - * or transparent (ghost kart). */ - KartRenderType m_krt; - - /** For our engine to get the desired hue / saturation for colorization. */ + /** For our engine to get the desired hue for colorization. */ std::shared_ptr m_render_info; /** True if this kart model can be colorization in red / blue (now only @@ -350,7 +344,7 @@ private: public: KartModel(bool is_master); ~KartModel(); - KartModel* makeCopy(KartRenderType krt); + KartModel* makeCopy(std::shared_ptr ri); void reset(); void loadInfo(const XMLNode &node); bool loadModels(const KartProperties &kart_properties); diff --git a/src/karts/kart_properties.cpp b/src/karts/kart_properties.cpp index 26ff8853b..bb0bdb590 100644 --- a/src/karts/kart_properties.cpp +++ b/src/karts/kart_properties.cpp @@ -305,9 +305,9 @@ void KartProperties::load(const std::string &filename, const std::string &node) * \param krt The KartRenderType, like default, red, blue or transparent. * see the RenderInfo include for details */ -KartModel* KartProperties::getKartModelCopy(KartRenderType krt) const +KartModel* KartProperties::getKartModelCopy(std::shared_ptr ri) const { - return m_kart_model->makeCopy(krt); + return m_kart_model->makeCopy(ri); } // getKartModelCopy // ---------------------------------------------------------------------------- diff --git a/src/karts/kart_properties.hpp b/src/karts/kart_properties.hpp index 27fa71b16..a25b3cdec 100644 --- a/src/karts/kart_properties.hpp +++ b/src/karts/kart_properties.hpp @@ -43,9 +43,9 @@ class CachedCharacteristic; class CombinedCharacteristic; class KartModel; class Material; +class RenderInfo; class XMLNode; -enum KartRenderType: unsigned int; /** * \brief This class stores the properties of a kart. @@ -241,7 +241,7 @@ public: video::ITexture *getMinimapIcon () const {return m_minimap_icon; } // ------------------------------------------------------------------------ - KartModel* getKartModelCopy(KartRenderType krt) const; + KartModel* getKartModelCopy(std::shared_ptr ri=nullptr) const; // ------------------------------------------------------------------------ /** Returns a pointer to the main KartModel object. This copy * should not be modified, not attachModel be called on it. */ diff --git a/src/karts/kart_rewinder.cpp b/src/karts/kart_rewinder.cpp index 05c81c423..8de2ec2f3 100644 --- a/src/karts/kart_rewinder.cpp +++ b/src/karts/kart_rewinder.cpp @@ -24,7 +24,6 @@ #include "karts/max_speed.hpp" #include "karts/skidding.hpp" #include "modes/world.hpp" -#include "graphics/render_info.hpp" #include "network/rewind_manager.hpp" #include "network/network_string.hpp" #include "physics/btKart.hpp" @@ -35,10 +34,10 @@ KartRewinder::KartRewinder(const std::string& ident,unsigned int world_kart_id, int position, const btTransform& init_transform, PerPlayerDifficulty difficulty, - KartRenderType krt) + std::shared_ptr ri) : Rewinder(/*can_be_destroyed*/ false) , Kart(ident, world_kart_id, position, init_transform, difficulty, - krt) + ri) { } // KartRewinder diff --git a/src/karts/kart_rewinder.hpp b/src/karts/kart_rewinder.hpp index 37c5f16d2..ac2883045 100644 --- a/src/karts/kart_rewinder.hpp +++ b/src/karts/kart_rewinder.hpp @@ -26,8 +26,6 @@ class AbstractKart; class BareNetworkString; -enum KartRenderType: unsigned int; - class KartRewinder : public Rewinder, public Kart { private: @@ -40,7 +38,7 @@ public: unsigned int world_kart_id, int position, const btTransform& init_transform, PerPlayerDifficulty difficulty, - KartRenderType krt); + std::shared_ptr ri); virtual ~KartRewinder() {}; virtual BareNetworkString* saveState() const; void reset(); diff --git a/src/karts/kart_with_stats.cpp b/src/karts/kart_with_stats.cpp index a0b461f5d..c77e04bdd 100644 --- a/src/karts/kart_with_stats.cpp +++ b/src/karts/kart_with_stats.cpp @@ -18,7 +18,6 @@ #include "karts/kart_with_stats.hpp" -#include "graphics/render_info.hpp" #include "karts/explosion_animation.hpp" #include "karts/rescue_animation.hpp" #include "items/item.hpp" @@ -29,7 +28,7 @@ KartWithStats::KartWithStats(const std::string& ident, int position, const btTransform& init_transform, PerPlayerDifficulty difficulty) : Kart(ident, world_kart_id, position, - init_transform, difficulty, KRT_DEFAULT) + init_transform, difficulty, nullptr) { } // KartWithStats diff --git a/src/modes/soccer_world.cpp b/src/modes/soccer_world.cpp index 61e3363e2..ce2e750af 100644 --- a/src/modes/soccer_world.cpp +++ b/src/modes/soccer_world.cpp @@ -413,7 +413,8 @@ AbstractKart *SoccerWorld::createKart(const std::string &kart_ident, int index, m_kart_position_map[index] = (unsigned)(pos_index - 1); AbstractKart *new_kart = new Kart(kart_ident, index, position, init_pos, - difficulty, team == SOCCER_TEAM_BLUE ? KRT_BLUE : KRT_RED); + difficulty, team == SOCCER_TEAM_BLUE ? + std::make_shared(0.66f) : std::make_shared(1.0f)); new_kart->init(race_manager->getKartType(index)); Controller *controller = NULL; diff --git a/src/modes/three_strikes_battle.cpp b/src/modes/three_strikes_battle.cpp index 6781cb39a..5a5d3dd53 100644 --- a/src/modes/three_strikes_battle.cpp +++ b/src/modes/three_strikes_battle.cpp @@ -724,7 +724,7 @@ void ThreeStrikesBattle::loadCustomModels() { AbstractKart* sta = new Kart(sta_list[i], (int)m_karts.size(), (int)m_karts.size() + 1, pos[i], PLAYER_DIFFICULTY_NORMAL, - KRT_RED); + std::make_shared(1.0f)); sta->init(RaceManager::KartType::KT_SPARE_TIRE); sta->setController(new SpareTireAI(sta)); diff --git a/src/modes/world.cpp b/src/modes/world.cpp index 826055c93..db4468b6a 100644 --- a/src/modes/world.cpp +++ b/src/modes/world.cpp @@ -337,36 +337,47 @@ AbstractKart *World::createKart(const std::string &kart_ident, int index, if (race_manager->hasGhostKarts()) gk = ReplayPlay::get()->getNumGhostKart(); + std::shared_ptr ri = std::make_shared(); int position = index+1; btTransform init_pos = getStartTransform(index - gk); AbstractKart *new_kart; if (RewindManager::get()->isEnabled()) new_kart = new KartRewinder(kart_ident, index, position, init_pos, - difficulty, KRT_DEFAULT); + difficulty, ri); else new_kart = new Kart(kart_ident, index, position, init_pos, difficulty, - KRT_DEFAULT); + ri); new_kart->init(race_manager->getKartType(index)); Controller *controller = NULL; switch(kart_type) { case RaceManager::KT_PLAYER: + { controller = new LocalPlayerController(new_kart, StateManager::get()->getActivePlayer(local_player_id)); + const float hue = StateManager::get()->getActivePlayer(local_player_id) + ->getConstProfile()->getDefaultKartColor(); + if (hue > 0.0f) + { + ri->setHue(hue); + } m_num_players ++; break; + } case RaceManager::KT_NETWORK_PLAYER: + { controller = new NetworkPlayerController(new_kart); m_num_players++; break; + } case RaceManager::KT_AI: + { controller = loadAIController(new_kart); break; + } case RaceManager::KT_GHOST: - break; case RaceManager::KT_LEADER: - break; case RaceManager::KT_SPARE_TIRE: break; } diff --git a/src/states_screens/dialogs/kart_color_slider_dialog.cpp b/src/states_screens/dialogs/kart_color_slider_dialog.cpp new file mode 100644 index 000000000..5527dcb48 --- /dev/null +++ b/src/states_screens/dialogs/kart_color_slider_dialog.cpp @@ -0,0 +1,137 @@ +// SuperTuxKart - a fun racing game with go-kart +// Copyright (C) 2010-2015 Marianne Gagnon +// +// 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/dialogs/kart_color_slider_dialog.hpp" + +#include "config/player_profile.hpp" +#include "config/user_config.hpp" +#include "karts/kart_model.hpp" +#include "karts/kart_properties.hpp" +#include "karts/kart_properties_manager.hpp" +#include "graphics/irr_driver.hpp" +#include "graphics/render_info.hpp" +#include "guiengine/engine.hpp" +#include "guiengine/widgets/button_widget.hpp" +#include "guiengine/widgets/label_widget.hpp" +#include "guiengine/widgets/model_view_widget.hpp" +#include "guiengine/widgets/spinner_widget.hpp" + + +using namespace GUIEngine; + +// ------------------------------------------------------------------------------------------------------ +KartColorSliderDialog::KartColorSliderDialog(PlayerProfile* pp) + : ModalDialog(0.75f, 0.75f, MODAL_DIALOG_LOCATION_BOTTOM) +{ + loadFromFile("kart_color_slider.stkgui"); + m_player_profile = pp; + getWidget("color-slider")->setValue(int(pp->getDefaultKartColor() * 100.0f)); + m_model_view->getModelViewRenderInfo()->setHue( + float(getWidget("color-slider")->getValue()) / 100.0f); +} // KartColorSliderDialog + +// ------------------------------------------------------------------------------------------------------ +void KartColorSliderDialog::beforeAddingWidgets() +{ + Widget* kart_screen = getWidget("kart-screen"); + m_model_view = new ModelViewWidget(irr_driver->getActualScreenSize().Height > 1280 || + irr_driver->getActualScreenSize().Width > 1280 ? 1024 : 512); + + const KartProperties* props = kart_properties_manager->getKart(UserConfigParams::m_default_kart); + const KartModel& kart_model = props->getMasterKartModel(); + + core::matrix4 model_location; + + float scale = 35.0f; + if (kart_model.getLength() > 1.45f) + { + // if kart is too long, size it down a bit so that it fits + scale = 30.0f; + } + + model_location.setScale(core::vector3df(scale, scale, scale)); + + // Add the kart model (including wheels and speed weight objects) + const bool has_win_anime = + (((kart_model.getFrame(KartModel::AF_WIN_LOOP_START) > -1 || + kart_model.getFrame(KartModel::AF_WIN_START) > -1) && + kart_model.getFrame(KartModel::AF_WIN_END) > -1) || + (kart_model.getFrame(KartModel::AF_SELECTION_START) > -1 && + kart_model.getFrame(KartModel::AF_SELECTION_END) > -1)); + m_model_view->addModel(kart_model.getModel(), model_location, + has_win_anime ? + kart_model.getFrame(KartModel::AF_SELECTION_START) > -1 ? + kart_model.getFrame(KartModel::AF_SELECTION_START) : + kart_model.getFrame(KartModel::AF_WIN_LOOP_START) > -1 ? + kart_model.getFrame(KartModel::AF_WIN_LOOP_START) : + kart_model.getFrame(KartModel::AF_WIN_START) : + kart_model.getBaseFrame(), + has_win_anime ? + kart_model.getFrame(KartModel::AF_SELECTION_END) > -1 ? + kart_model.getFrame(KartModel::AF_SELECTION_END) : + kart_model.getFrame(KartModel::AF_WIN_END) : + kart_model.getBaseFrame(), + kart_model.getAnimationSpeed()); + + model_location.setScale(core::vector3df(1.0f, 1.0f, 1.0f)); + for (unsigned i = 0; i < 4; i++) + { + model_location.setTranslation(kart_model + .getWheelGraphicsPosition(i).toIrrVector()); + m_model_view->addModel(kart_model.getWheelModel(i), model_location); + } + + for (unsigned i = 0; i < kart_model.getSpeedWeightedObjectsCount(); + i++) + { + const SpeedWeightedObject& obj = + kart_model.getSpeedWeightedObject(i); + core::matrix4 swol = obj.m_location; + if (!obj.m_bone_name.empty()) + { + core::matrix4 inv = + kart_model.getInverseBoneMatrix(obj.m_bone_name); + swol = inv * obj.m_location; + } + m_model_view->addModel(obj.m_model, swol, -1, -1, 0.0f, + obj.m_bone_name); + } + + m_model_view->setRotateContinuously(35.0f); + m_model_view->update(0); + kart_screen->getChildren().push_back(m_model_view); + m_model_view->move(kart_screen->m_w / 2, kart_screen->m_h / 2, + kart_screen->m_w / 2, kart_screen->m_w / 2); +} // beforeAddingWidgets + +// ------------------------------------------------------------------------------------------------------ +GUIEngine::EventPropagation KartColorSliderDialog::processEvent(const std::string& eventSource) +{ + if (eventSource == "color-slider") + { + m_model_view->getModelViewRenderInfo()->setHue( + float(getWidget("color-slider")->getValue()) / 100.0f); + } + else if (eventSource == "close") + { + float color = float(getWidget("color-slider")->getValue()); + m_player_profile->setDefaultKartColor(color / 100.0f); + ModalDialog::dismiss(); + return GUIEngine::EVENT_BLOCK; + } + return GUIEngine::EVENT_LET; +} // processEvent diff --git a/src/states_screens/dialogs/kart_color_slider_dialog.hpp b/src/states_screens/dialogs/kart_color_slider_dialog.hpp new file mode 100644 index 000000000..a2285d5a5 --- /dev/null +++ b/src/states_screens/dialogs/kart_color_slider_dialog.hpp @@ -0,0 +1,49 @@ +// SuperTuxKart - a fun racing game with go-kart +// Copyright (C) 2018 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_KART_COLOR_SLIDER_HPP +#define HEADER_KART_COLOR_SLIDER_HPP + +#include "guiengine/modaldialog.hpp" +#include "utils/cpp2011.hpp" + +class PlayerProfile; +namespace GUIEngine { class ModelViewWidget; } + +/** + * \ingroup states_screens + */ +class KartColorSliderDialog : public GUIEngine::ModalDialog +{ +private: + PlayerProfile* m_player_profile; + + GUIEngine::ModelViewWidget* m_model_view; + +public: + KartColorSliderDialog(PlayerProfile* pp); + + ~KartColorSliderDialog() {} + + virtual void beforeAddingWidgets() OVERRIDE; + + GUIEngine::EventPropagation processEvent(const std::string& eventSource) OVERRIDE; +}; + + +#endif diff --git a/src/states_screens/feature_unlocked.cpp b/src/states_screens/feature_unlocked.cpp index bddc650eb..b2fccb05d 100644 --- a/src/states_screens/feature_unlocked.cpp +++ b/src/states_screens/feature_unlocked.cpp @@ -25,7 +25,6 @@ #include "challenges/unlock_manager.hpp" #include "config/player_manager.hpp" #include "graphics/central_settings.hpp" -#include "graphics/render_info.hpp" #include "graphics/sp/sp_base.hpp" #include "graphics/sp/sp_mesh.hpp" #include "graphics/sp/sp_mesh_buffer.hpp" @@ -334,7 +333,7 @@ void FeatureUnlockedCutScene::init() else if (m_unlocked_stuff[n].m_unlocked_kart != NULL) { KartModel *kart_model = - m_unlocked_stuff[n].m_unlocked_kart->getKartModelCopy(KRT_DEFAULT); + m_unlocked_stuff[n].m_unlocked_kart->getKartModelCopy(); m_all_kart_models.push_back(kart_model); m_unlocked_stuff[n].m_root_gift_node = kart_model->attachModel(true, false); m_unlocked_stuff[n].m_scale = 5.0f; diff --git a/src/states_screens/grand_prix_lose.cpp b/src/states_screens/grand_prix_lose.cpp index d91d8a553..f8fabff02 100644 --- a/src/states_screens/grand_prix_lose.cpp +++ b/src/states_screens/grand_prix_lose.cpp @@ -24,7 +24,6 @@ #include "config/player_manager.hpp" #include "graphics/irr_driver.hpp" #include "graphics/lod_node.hpp" -#include "graphics/render_info.hpp" #include "guiengine/engine.hpp" #include "guiengine/scalable_font.hpp" #include "guiengine/widgets/button_widget.hpp" @@ -184,7 +183,7 @@ void GrandPrixLose::setKarts(std::vector ident_arg) const KartProperties* kart = kart_properties_manager->getKart(ident_arg[n]); if (kart != NULL) { - KartModel* kart_model = kart->getKartModelCopy(KRT_DEFAULT); + KartModel* kart_model = kart->getKartModelCopy(); m_all_kart_models.push_back(kart_model); scene::ISceneNode* kart_main_node = kart_model->attachModel(true, false); LODNode* lnode = dynamic_cast(kart_main_node); diff --git a/src/states_screens/grand_prix_win.cpp b/src/states_screens/grand_prix_win.cpp index 5e18f33fa..37b4fdad5 100644 --- a/src/states_screens/grand_prix_win.cpp +++ b/src/states_screens/grand_prix_win.cpp @@ -24,7 +24,6 @@ #include "config/player_manager.hpp" #include "graphics/irr_driver.hpp" #include "graphics/lod_node.hpp" -#include "graphics/render_info.hpp" #include "guiengine/engine.hpp" #include "guiengine/scalable_font.hpp" #include "guiengine/widgets/button_widget.hpp" @@ -345,7 +344,7 @@ void GrandPrixWin::setKarts(const std::string idents_arg[3]) const KartProperties* kp = kart_properties_manager->getKart(idents[i]); if (kp == NULL) continue; - KartModel* kart_model = kp->getKartModelCopy(KRT_DEFAULT); + KartModel* kart_model = kp->getKartModelCopy(); m_all_kart_models.push_back(kart_model); scene::ISceneNode* kart_main_node = kart_model->attachModel(true, false); LODNode* lnode = dynamic_cast(kart_main_node); diff --git a/src/states_screens/kart_selection.cpp b/src/states_screens/kart_selection.cpp index c9049ee93..1be21a906 100644 --- a/src/states_screens/kart_selection.cpp +++ b/src/states_screens/kart_selection.cpp @@ -23,6 +23,7 @@ #include "config/player_manager.hpp" #include "config/user_config.hpp" #include "graphics/irr_driver.hpp" +#include "graphics/render_info.hpp" #include "guiengine/widgets/bubble_widget.hpp" #include "guiengine/widgets/kart_stats_widget.hpp" #include "guiengine/widgets/model_view_widget.hpp" @@ -202,7 +203,9 @@ void KartHoverListener::onSelectionChanged(DynamicRibbonWidget* theWidget, if (m_parent->m_kart_widgets[player_id].getKartInternalName() == selectionID) return; // already selected - m_parent->updateKartWidgetModel(player_id, selectionID, selectionText); + m_parent->updateKartWidgetModel(player_id, selectionID, selectionText, + m_parent->m_kart_widgets[player_id].getAssociatedPlayer()->getProfile() + ->getDefaultKartColor()); m_parent->m_kart_widgets[player_id].setKartInternalName(selectionID); m_parent->updateKartStats(player_id, selectionID); m_parent->validateKartChoices(); @@ -821,7 +824,7 @@ void KartSelectionScreen::updateKartStats(uint8_t widget_id, // ---------------------------------------------------------------------------- void KartSelectionScreen::updateKartWidgetModel(int widget_id, const std::string& selection, - const irr::core::stringw& selectionText) + const irr::core::stringw& selectionText, float kart_color) { // Update the displayed model ModelViewWidget* w3 = m_kart_widgets[widget_id].m_model_view; @@ -907,6 +910,7 @@ void KartSelectionScreen::updateKartWidgetModel(int widget_id, kart_model.getBaseFrame(), kart_model.getAnimationSpeed()); + w3->getModelViewRenderInfo()->setHue(kart_color); model_location.setScale(core::vector3df(1.0f, 1.0f, 1.0f)); for (unsigned i = 0; i < 4; i++) { @@ -932,7 +936,7 @@ void KartSelectionScreen::updateKartWidgetModel(int widget_id, //w3->update(0); m_kart_widgets[widget_id].m_kart_name - ->setText( selectionText.c_str(), false ); + ->setText( selectionText.c_str(), false ); } else Log::warn("KartSelectionScreen", "could not " diff --git a/src/states_screens/kart_selection.hpp b/src/states_screens/kart_selection.hpp index a9e31f8c4..c66483f67 100644 --- a/src/states_screens/kart_selection.hpp +++ b/src/states_screens/kart_selection.hpp @@ -114,7 +114,8 @@ protected: * user validates */ void updateKartWidgetModel(int widget_id, const std::string& selection, - const irr::core::stringw& selectionText); + const irr::core::stringw& selectionText, + float kart_color); /** Adds a message to the screen which indicates that players must press fire to join. */ void addMultiplayerMessage(); diff --git a/src/states_screens/network_kart_selection.cpp b/src/states_screens/network_kart_selection.cpp index 36735d127..8e2361bb1 100644 --- a/src/states_screens/network_kart_selection.cpp +++ b/src/states_screens/network_kart_selection.cpp @@ -169,7 +169,8 @@ void NetworkKartSelectionScreen::playerSelected(uint8_t player_id, return; KartSelectionScreen::updateKartWidgetModel(widget_id, kart_name, - irr::core::stringw(kart_name.c_str())); + irr::core::stringw(kart_name.c_str()), + /*Todo get color*/0.0f); KartSelectionScreen::updateKartStats(widget_id, kart_name); m_kart_widgets[widget_id].setKartInternalName(kart_name); m_kart_widgets[widget_id].markAsReady(); // mark player ready diff --git a/src/states_screens/soccer_setup_screen.cpp b/src/states_screens/soccer_setup_screen.cpp index a67ceb272..8a1899c5b 100644 --- a/src/states_screens/soccer_setup_screen.cpp +++ b/src/states_screens/soccer_setup_screen.cpp @@ -157,8 +157,8 @@ void SoccerSetupScreen::beforeAddingWidget() info.support_colorization = kart_model.supportColorization(); if (info.support_colorization) { - kart_view->getModelViewRenderInfo()->setKartModelRenderInfo - (info.team == SOCCER_TEAM_BLUE ? KRT_BLUE : KRT_RED); + kart_view->getModelViewRenderInfo()->setHue + (info.team == SOCCER_TEAM_BLUE ? 0.66f : 1.0f); } core::matrix4 model_location; @@ -277,9 +277,9 @@ void SoccerSetupScreen::changeTeam(int player_id, SoccerTeam team) // Change the kart color if (m_kart_view_info[player_id].support_colorization) { - KartRenderType krt = team == SOCCER_TEAM_RED ? KRT_RED : KRT_BLUE; + const float hue = team == SOCCER_TEAM_RED ? 1.0f : 0.66f; m_kart_view_info[player_id].view->getModelViewRenderInfo() - ->setKartModelRenderInfo(krt); + ->setHue(hue); } for (unsigned int i = 0; i < m_kart_view_info.size(); i++) diff --git a/src/states_screens/user_screen.cpp b/src/states_screens/user_screen.cpp index c9ef957ee..dedbd8381 100644 --- a/src/states_screens/user_screen.cpp +++ b/src/states_screens/user_screen.cpp @@ -27,6 +27,7 @@ #include "guiengine/widgets/list_widget.hpp" #include "guiengine/widgets/text_box_widget.hpp" #include "states_screens/dialogs/message_dialog.hpp" +#include "states_screens/dialogs/kart_color_slider_dialog.hpp" #include "states_screens/dialogs/recovery_dialog.hpp" #include "states_screens/main_menu_screen.hpp" #include "states_screens/options_screen_audio.hpp" @@ -153,6 +154,7 @@ void BaseUserScreen::init() getWidget("new_user")->setActive(!in_game); getWidget("rename")->setActive(!in_game); getWidget("delete")->setActive(!in_game); + getWidget("default_kart_color")->setActive(!in_game); m_new_registered_data = false; if (m_auto_login) @@ -380,6 +382,10 @@ void BaseUserScreen::eventCallback(Widget* widget, // Init will automatically be called, which // refreshes the player list } + else if (button == "default_kart_color") + { + new KartColorSliderDialog(getSelectedPlayer()); + } else if (button == "delete") { deletePlayer(); diff --git a/src/tracks/track_object_presentation.cpp b/src/tracks/track_object_presentation.cpp index 11b211788..6b696801c 100644 --- a/src/tracks/track_object_presentation.cpp +++ b/src/tracks/track_object_presentation.cpp @@ -30,7 +30,6 @@ #include "graphics/particle_emitter.hpp" #include "graphics/particle_kind_manager.hpp" #include "graphics/stk_particle.hpp" -#include "graphics/render_info.hpp" #include "io/file_manager.hpp" #include "io/xml_node.hpp" #include "input/device_manager.hpp"