///@brief set MainWindow on desktop void dbPositionWindow( u32 id, s32 x, s32 y) { dbPRINT("dbPositionWindow()\n"); DarkGDK_SGlobalStruct& app = DarkGDK_SGlobalStruct::getInstance(); if (!app.Device) { dbERROR("dbPositionWindow() - Invalid pointer to IrrlichtDevice\n"); return; } video::IVideoDriver* driver = app.Device->getVideoDriver(); if (!driver) { dbERROR("dbPositionWindow() - Invalid pointer to IVideoDriver\n"); return; } const core::recti winRect = dbWindowPosition(id); const HWND hWnd = reinterpret_cast<HWND>( driver->getExposedVideoData().OpenGLWin32.HWnd ); const u32 hStyle = GetWindowLong( hWnd, GWL_EXSTYLE ); const BOOL result = SetWindowPos( hWnd, HWND_TOP, x, y, winRect.getWidth(), winRect.getHeight(), hStyle ); if (result == FALSE) { dbERROR("dbPositionWindow() - Error in WinApi\n"); } }
KartStatsWidget::KartStatsWidget(core::recti area, const int player_id, std::string kart_group, bool multiplayer, bool display_text) : Widget(WTYPE_DIV) { m_player_id = player_id; const std::string default_kart = UserConfigParams::m_default_kart; const KartProperties* props = kart_properties_manager->getKart(default_kart); if(!props) { // If the default kart can't be found (e.g. previously a addon // kart was used, but the addon package was removed), use the // first kart as a default. This way we don't have to hardcode // any kart names. int id = kart_properties_manager->getKartByGroup(kart_group, 0); if (id == -1) { props = kart_properties_manager->getKartById(0); } else { props = kart_properties_manager->getKartById(id); } if(!props) Log::fatal("KartSelectionScreen", "Can't find default " "kart '%s' nor any other kart.", default_kart.c_str()); } for (int i = 0; i < SKILL_COUNT; ++i) { irr::core::recti skillArea(0, 0, 1, 1); SkillLevelWidget* skill_bar = NULL; skill_bar = new SkillLevelWidget(skillArea, m_player_id, multiplayer, display_text); m_skills.push_back(skill_bar); m_children.push_back(skill_bar); } m_skills[SKILL_MASS]->setValue((int)(props->getMass()/5)); m_skills[SKILL_MASS]->setLabel("WEIGHT"); m_skills[SKILL_MASS]->m_properties[PROP_ID] = StringUtils::insertValues("@p%i_mass", m_player_id); m_skills[SKILL_SPEED]->setValue((int)((props->getAbsMaxSpeed()-20)*9)); m_skills[SKILL_SPEED]->setLabel("SPEED"); m_skills[SKILL_SPEED]->m_properties[PROP_ID] = StringUtils::insertValues("@p%i_speed", m_player_id); m_skills[SKILL_POWER]->setValue((int)(props->getAvgPower())); m_skills[SKILL_POWER]->setLabel("POWER"); m_skills[SKILL_POWER]->m_properties[PROP_ID] = StringUtils::insertValues("@p%i_power", m_player_id); move(area.UpperLeftCorner.X, area.UpperLeftCorner.Y, area.getWidth(), area.getHeight()); } // KartStatsWidget
CNrpMiniMap::CNrpMiniMap( const core::recti& rectange, IGUIEnvironment* env, s32 id, scene::ISceneNode* pr_node/*=NULL */ ) : CNrpRotatableImage( rectange, env, id, env->getRootGUIElement() ) { animNode_ = pr_node; scale_ = 1.f; startSize_.Width = rectange.getWidth(); startSize_.Height = rectange.getHeight(); mouse2rotate_ = false; offsetAngle_ = 0; }
KartStatsWidget::KartStatsWidget(core::recti area, const int player_id, std::string kart_group, bool multiplayer, bool display_text) : Widget(WTYPE_DIV) { m_title_font = !multiplayer; m_player_id = player_id; const std::string default_kart = UserConfigParams::m_default_kart; const KartProperties* props = kart_properties_manager->getKart(default_kart); if(!props) { // If the default kart can't be found (e.g. previously a addon // kart was used, but the addon package was removed), use the // first kart as a default. This way we don't have to hardcode // any kart names. int id = kart_properties_manager->getKartByGroup(kart_group, 0); if (id == -1) { props = kart_properties_manager->getKartById(0); } else { props = kart_properties_manager->getKartById(id); } if(!props) Log::fatal("KartSelectionScreen", "Can't find default " "kart '%s' nor any other kart.", default_kart.c_str()); } for (int i = 0; i < SKILL_COUNT; ++i) { irr::core::recti skillArea(0, 0, 1, 1); SkillLevelWidget* skill_bar = NULL; skill_bar = new SkillLevelWidget(skillArea, m_player_id, multiplayer, display_text); m_skills.push_back(skill_bar); m_children.push_back(skill_bar); } setValues(props); move(area.UpperLeftCorner.X, area.UpperLeftCorner.Y, area.getWidth(), area.getHeight()); } // KartStatsWidget
/** Draws the powerup icons on the screen (called once for each player). * \param kart The kart for which to draw the powerup icons. * \param viewport The viewport into which to draw the icons. * \param scaling The scaling to use when draing the icons. */ void RaceGUIBase::drawPowerupIcons(const AbstractKart* kart, const core::recti &viewport, const core::vector2df &scaling) { // If player doesn't have any powerups or has completed race, do nothing. const Powerup* powerup = kart->getPowerup(); if (powerup->getType() == PowerupManager::POWERUP_NOTHING || kart->hasFinishedRace()) return; int n = kart->getPowerup()->getNum() ; if (n<1) return; // shouldn't happen, but just in case if (n>5) n=5; // Display at most 5 items int nSize = (int)(64.0f*std::min(scaling.X, scaling.Y)); int itemSpacing = (int)(std::min(scaling.X, scaling.Y)*30); int x1 = viewport.UpperLeftCorner.X + viewport.getWidth()/2 - (n * itemSpacing)/2; int y1 = viewport.UpperLeftCorner.Y + (int)(20 * scaling.Y); assert(powerup != NULL); assert(powerup->getIcon() != NULL); video::ITexture *t=powerup->getIcon()->getTexture(); assert(t != NULL); core::rect<s32> rect(core::position2di(0, 0), t->getOriginalSize()); for ( int i = 0 ; i < n ; i++ ) { int x2 = (int)(x1+i*itemSpacing); core::rect<s32> pos(x2, y1, x2+nSize, y1+nSize); draw2DImage(t, pos, rect, NULL, NULL, true); } // for i } // drawPowerupIcons
/** 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) { 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 */); } } // drawEnergyMeter
SkillLevelWidget::SkillLevelWidget(core::recti area, const int player_id, bool multiplayer, bool display_text, const int value, const stringw& label) : Widget(WTYPE_DIV) { m_player_id = player_id; m_display_text = display_text; setSize(area.UpperLeftCorner.X, area.UpperLeftCorner.Y, area.getWidth(), area.getHeight() ); // ---- Mass skill level widget m_bar = NULL; m_bar = new ProgressBarWidget(false); m_bar->setValue(value); m_bar->m_x = m_bar_x; m_bar->m_y = m_bar_y; m_bar->m_w = m_bar_w; m_bar->m_h = m_bar_h; m_bar->m_properties[PROP_ID] = StringUtils::insertValues("@p%i_skill_bar", m_player_id); m_label = NULL; m_label = new LabelWidget(!multiplayer, true); m_label->setText(label,false); m_label->m_x = m_label_x; m_label->m_y = m_label_y; m_label->m_w = m_label_w; m_label->m_h = m_label_h; m_label->m_properties[PROP_ID] = StringUtils::insertValues("@p%i_skill_label", m_player_id); m_children.push_back(m_bar); m_children.push_back(m_label); } // KartStatsWidget
void MainMenuScene::onRedraw() { video::IVideoDriver* driver = appContext.getDevice()->getVideoDriver(); core::dimension2du screenSize(driver->getScreenSize()); const core::recti headerRect = staticImagesRects[HashedString("title")]; const core::position2di headerPos( screenSize.Width/2 - headerRect.getWidth()/2, 0); driver->beginScene(true, true, COLOR_CORNFLOWER_BLUE); const core::recti tileRect = staticImagesRects[HashedString("tile")]; irr::u32 time = appContext.getDevice()->getTimer()->getTime(); irr::u32 offset = (time/30) % tileRect.getWidth(); // draw tiled background for (int x = -1; x < (int)screenSize.Width/tileRect.getWidth() + 1; x++) { for (int y = -1; y < (int)screenSize.Height/tileRect.getHeight() + 1; y++) { driver->draw2DImage(staticImages, core::position2di(offset + x * tileRect.getWidth(), offset + y * tileRect.getHeight()), tileRect, 0, video::SColor(255,255,255,255), false); } } // draw header driver->draw2DImage(staticImages, headerPos, headerRect, 0, video::SColor(255,255,255,255), true); core::dimension2du bounds(arcadeMenu->getBounds()); core::vector2df topLeft( screenSize.Width/2 - bounds.Width/2, screenSize.Height*2/3 - bounds.Height/2); arcadeMenu->render(topLeft); appContext.getDevice()->getSceneManager()->drawAll(); appContext.getDevice()->getGUIEnvironment()->drawAll(); driver->endScene(); }
/** 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 MinimalRaceGUI::drawEnergyMeter(const AbstractKart *kart, const core::recti &viewport, const core::vector2df &scaling) { 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 // In split screen mode of 3 or 4 players, the players on // the left side will have the energy meter on the left side int mirrored = race_manager->getNumLocalPlayers()>=3 && viewport.UpperLeftCorner.X==0; int x = mirrored ? 0 : viewport.LowerRightCorner.X - w; int y = viewport.UpperLeftCorner.Y + viewport.getHeight()/2- h/2; // Background // ---------- core::rect<s32> dest(x+mirrored*w, y+mirrored*h, x+(1-mirrored)*w, y+(1-mirrored)*h); irr_driver->getVideoDriver()->draw2DImage(m_gauge_empty, dest, 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); irr_driver->getVideoDriver()->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> dest(x+mirrored*w, mirrored ? y+h : y, x+(1-mirrored)*w, mirrored ? y : y + h); core::rect<s32> clip(x, y1, x + w, y + h); core::rect<s32> tex_c(0, mirrored ? 256 : 0, 64, mirrored ? 0 : 256); irr_driver->getVideoDriver()->draw2DImage(m_gauge_full, dest, tex_c, &clip, NULL /* colors */, true /* alpha */); } } // drawEnergyMeter
PlayerKartWidget::PlayerKartWidget(KartSelectionScreen* parent, StateManager::ActivePlayer* associated_player, core::recti area, const int player_id, std::string kart_group, const int irrlicht_widget_id) : Widget(WTYPE_DIV) { #ifdef DEBUG if (associated_player) assert(associated_player->ok()); m_magic_number = 0x33445566; #endif m_ready_text = NULL; m_parent_screen = parent; m_associated_player = associated_player; x_speed = 1.0f; y_speed = 1.0f; w_speed = 1.0f; h_speed = 1.0f; m_ready = false; m_difficulty = PLAYER_DIFFICULTY_NORMAL; m_not_updated_yet = true; m_irrlicht_widget_id = irrlicht_widget_id; m_player_id = player_id; m_properties[PROP_ID] = StringUtils::insertValues("@p%i", m_player_id); setSize(area.UpperLeftCorner.X, area.UpperLeftCorner.Y, area.getWidth(), area.getHeight() ); target_x = m_x; target_y = m_y; target_w = m_w; target_h = m_h; // ---- Player identity spinner m_player_ident_spinner = NULL; m_player_ident_spinner = new PlayerNameSpinner(parent, m_player_id); m_player_ident_spinner->m_x = player_name_x; m_player_ident_spinner->m_y = player_name_y; m_player_ident_spinner->m_w = player_name_w; m_player_ident_spinner->m_h = player_name_h; // ---- KartStatsWidget m_kart_stats = NULL; // area for the stats widget core::recti statsArea; if (!parent->m_multiplayer) { statsArea = core::recti(m_kart_stats_x, m_kart_stats_y, m_kart_stats_x + m_kart_stats_w, m_kart_stats_y + m_kart_stats_h); } else { statsArea = core::recti(m_x , m_y + m_h/2, m_x + m_w, m_y + m_h); } m_kart_stats = new GUIEngine::KartStatsWidget(statsArea, player_id, kart_group, m_parent_screen->m_multiplayer, !m_parent_screen->m_multiplayer || parent->m_kart_widgets.size() == 0); m_kart_stats->m_properties[PROP_ID] = StringUtils::insertValues("@p%i_stats", m_player_id); m_children.push_back(m_kart_stats); if (parent->m_multiplayer && associated_player) { if (associated_player->getDevice()->getType() == DT_KEYBOARD) { m_player_ident_spinner->setBadge(KEYBOARD_BADGE); } else if (associated_player->getDevice()->getType() == DT_GAMEPAD) { m_player_ident_spinner->setBadge(GAMEPAD_BADGE); } } if (irrlicht_widget_id == -1) { m_player_ident_spinner->m_tab_down_root = g_root_id; } spinnerID = StringUtils::insertValues("@p%i_spinner", m_player_id); m_player_ident_spinner->m_properties[PROP_ID] = spinnerID; if (parent->m_multiplayer) { const int player_amount = PlayerManager::get()->getNumPlayers(); m_player_ident_spinner->m_properties[PROP_MIN_VALUE] = "0"; m_player_ident_spinner->m_properties[PROP_MAX_VALUE] = StringUtils::toString(player_amount-1); m_player_ident_spinner->m_properties[PROP_WRAP_AROUND] = "true"; } else { m_player_ident_spinner->m_properties[PROP_MIN_VALUE] = "0"; m_player_ident_spinner->m_properties[PROP_MAX_VALUE] = "0"; } //m_player_ident_spinner->m_event_handler = this; m_children.push_back(m_player_ident_spinner); // ----- Kart model view m_model_view = new ModelViewWidget(); m_model_view->m_x = model_x; m_model_view->m_y = model_y; m_model_view->m_w = model_w; m_model_view->m_h = model_h; m_model_view->m_properties[PROP_ID] = StringUtils::insertValues("@p%i_model", m_player_id); //m_model_view->setParent(this); m_children.push_back(m_model_view); // Init kart model const std::string default_kart = UserConfigParams::m_default_kart; const KartProperties* props = kart_properties_manager->getKart(default_kart); if(!props) { // If the default kart can't be found (e.g. previously a addon // kart was used, but the addon package was removed), use the // first kart as a default. This way we don't have to hardcode // any kart names. int id = kart_properties_manager->getKartByGroup(kart_group, 0); if (id == -1) { props = kart_properties_manager->getKartById(0); } else { props = kart_properties_manager->getKartById(id); } if(!props) Log::fatal("KartSelectionScreen", "Can't find default " "kart '%s' nor any other kart.", default_kart.c_str()); } m_kart_internal_name = props->getIdent(); const KartModel &kart_model = props->getMasterKartModel(); 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; } core::matrix4 model_location; model_location.setScale(core::vector3df(scale, scale, scale)); const bool has_win_anime = UserConfigParams::m_animated_characters && (((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()); 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++) { 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 ); // ---- Kart name label m_kart_name = new LabelWidget(false, true); m_kart_name->setText(props->getName(), false); m_kart_name->m_properties[PROP_TEXT_ALIGN] = "center"; m_kart_name->m_properties[PROP_ID] = StringUtils::insertValues("@p%i_kartname", m_player_id); m_kart_name->m_x = kart_name_x; m_kart_name->m_y = kart_name_y; m_kart_name->m_w = kart_name_w; m_kart_name->m_h = kart_name_h; m_children.push_back(m_kart_name); } // PlayerKartWidget
bool blitImageToImage( IImage* dst, core::position2di dstPos, IImage* src, const core::recti& srcRect, bool debugLog) { if (debugLog) { printf("blitImageToImage(x=%i,y=%i,rect(%i,%i,%i,%i))\n", dstPos.X, dstPos.Y, srcRect.UpperLeftCorner.X, srcRect.UpperLeftCorner.Y,srcRect.LowerRightCorner.X, srcRect.LowerRightCorner.Y); } if (!dst) { printf("Destination Image does not exist.\n"); return false; } if (!src) { printf("Source Image does not exist.\n"); return false; } const core::dimension2du& dstSize = dst->getDimension(); const core::dimension2du& srcSize = src->getDimension(); if (dstPos.X >= (s32)dstSize.Width) // ! if you forget cast to s32 it always fails when X < 0 return false; if (dstPos.Y >= (s32)dstSize.Height) // ! if you forget cast to s32 it always fails when Y < 0 return false; u32 dstPitch = dst->getPitch(); u32 dstBPP = dst->getBytesPerPixel(); u8* dstPtr = (u8*)dst->lock(); u32 srcPitch = src->getPitch(); u32 srcBPP = src->getBytesPerPixel(); u8* srcPtr = (u8*)src->lock(); if (debugLog) { printf("dst: %i, %i, pos=%i, %i, bpp=%i, pitch=%i\n", dstSize.Width, dstSize.Height, dstPos.X, dstPos.Y, dstBPP, dstPitch); printf("src: %i, %i, bpp=%i, pitch=%i\n", srcSize.Width, srcSize.Height, srcBPP, srcPitch); } // inc dst pointer to start-pos; // dstPtr += (u32)dstPos.X*dstBPP + (u32)dstPos.Y*dstPitch; // slow and save, can be much optimized, but not now for (u32 y=0; y<(u32)srcRect.getHeight(); ++y) { for (u32 x=0; x<(u32)srcRect.getWidth(); ++x) { s32 sx = srcRect.UpperLeftCorner.X + x; s32 sy = srcRect.UpperLeftCorner.Y + y; if (sx>=0 && sy>=0) { SColor color = src->getPixel( (u32)sx, (u32)sy); s32 dx = dstPos.X + (s32)x; s32 dy = dstPos.Y + (s32)y; if (dx>=0 && dy>=0) dst->setPixel( (u32)dx, (u32)dy, color); } } } src->unlock(); dst->unlock(); return true; }
PlayerKartWidget::PlayerKartWidget(KartSelectionScreen* parent, StateManager::ActivePlayer* associated_player, Online::OnlineProfile* associated_user, core::recti area, const int player_id, std::string kart_group, const int irrlicht_widget_id) : Widget(WTYPE_DIV) { #ifdef DEBUG if (associated_player) assert(associated_player->ok()); m_magic_number = 0x33445566; #endif m_ready_text = NULL; m_parent_screen = parent; m_associated_user = associated_user; m_associated_player = associated_player; x_speed = 1.0f; y_speed = 1.0f; w_speed = 1.0f; h_speed = 1.0f; m_ready = false; m_handicapped = false; m_not_updated_yet = true; m_irrlicht_widget_id = irrlicht_widget_id; m_player_id = player_id; m_properties[PROP_ID] = StringUtils::insertValues("@p%i", m_player_id); setSize(area.UpperLeftCorner.X, area.UpperLeftCorner.Y, area.getWidth(), area.getHeight() ); target_x = m_x; target_y = m_y; target_w = m_w; target_h = m_h; // ---- Player identity spinner m_player_ident_spinner = NULL; m_player_ident_spinner = new PlayerNameSpinner(parent, m_player_id); m_player_ident_spinner->m_x = player_name_x; m_player_ident_spinner->m_y = player_name_y; m_player_ident_spinner->m_w = player_name_w; m_player_ident_spinner->m_h = player_name_h; // ---- KartStatsWidget m_kart_stats = NULL; // area for the stats widget core::recti statsArea; if (!parent->m_multiplayer) { statsArea = core::recti(m_kart_stats_x, m_kart_stats_y, m_kart_stats_x + m_kart_stats_w, m_kart_stats_y + m_kart_stats_h); } else { statsArea = core::recti(m_x , m_y + m_h/2, m_x + m_w, m_y + m_h); } m_kart_stats = new GUIEngine::KartStatsWidget(statsArea, player_id, kart_group, m_parent_screen->m_multiplayer, !m_parent_screen->m_multiplayer || parent->m_kart_widgets.size() == 0); m_kart_stats->m_properties[PROP_ID] = StringUtils::insertValues("@p%i_stats", m_player_id); m_children.push_back(m_kart_stats); if (parent->m_multiplayer && associated_player) { if (associated_player->getDevice()->getType() == DT_KEYBOARD) { m_player_ident_spinner->setBadge(KEYBOARD_BADGE); } else if (associated_player->getDevice()->getType() == DT_GAMEPAD) { m_player_ident_spinner->setBadge(GAMEPAD_BADGE); } } else if (m_associated_user) // online user, FIXME is that useful ? { m_player_ident_spinner->setBadge(OK_BADGE); } if (irrlicht_widget_id == -1) { m_player_ident_spinner->m_tab_down_root = g_root_id; } spinnerID = StringUtils::insertValues("@p%i_spinner", m_player_id); m_player_ident_spinner->m_properties[PROP_ID] = spinnerID; if (parent->m_multiplayer) { const int player_amount = PlayerManager::get()->getNumPlayers(); m_player_ident_spinner->m_properties[PROP_MIN_VALUE] = "0"; m_player_ident_spinner->m_properties[PROP_MAX_VALUE] = StringUtils::toString(player_amount-1); m_player_ident_spinner->m_properties[PROP_WRAP_AROUND] = "true"; } else { m_player_ident_spinner->m_properties[PROP_MIN_VALUE] = "0"; m_player_ident_spinner->m_properties[PROP_MAX_VALUE] = "0"; } //m_player_ident_spinner->m_event_handler = this; m_children.push_back(m_player_ident_spinner); // ----- Kart model view m_model_view = new ModelViewWidget(); m_model_view->m_x = model_x; m_model_view->m_y = model_y; m_model_view->m_w = model_w; m_model_view->m_h = model_h; m_model_view->m_properties[PROP_ID] = StringUtils::insertValues("@p%i_model", m_player_id); //m_model_view->setParent(this); m_children.push_back(m_model_view); // Init kart model const std::string default_kart = UserConfigParams::m_default_kart; const KartProperties* props = kart_properties_manager->getKart(default_kart); if(!props) { // If the default kart can't be found (e.g. previously a addon // kart was used, but the addon package was removed), use the // first kart as a default. This way we don't have to hardcode // any kart names. int id = kart_properties_manager->getKartByGroup(kart_group, 0); if (id == -1) { props = kart_properties_manager->getKartById(0); } else { props = kart_properties_manager->getKartById(id); } if(!props) Log::fatal("KartSelectionScreen", "Can't find default " "kart '%s' nor any other kart.", default_kart.c_str()); } m_kartInternalName = props->getIdent(); const KartModel &kart_model = props->getMasterKartModel(); 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; } m_model_view->addModel( kart_model.getModel(), Vec3(0,0,0), Vec3(scale, scale, scale), kart_model.getBaseFrame() ); m_model_view->addModel( kart_model.getWheelModel(0), kart_model.getWheelGraphicsPosition(0) ); m_model_view->addModel( kart_model.getWheelModel(1), kart_model.getWheelGraphicsPosition(1) ); m_model_view->addModel( kart_model.getWheelModel(2), kart_model.getWheelGraphicsPosition(2) ); m_model_view->addModel( kart_model.getWheelModel(3), kart_model.getWheelGraphicsPosition(3) ); for(size_t i=0 ; i < kart_model.getSpeedWeightedObjectsCount() ; i++) { const SpeedWeightedObject& obj = kart_model.getSpeedWeightedObject((int)i); m_model_view->addModel(obj.m_model, obj.m_position); } m_model_view->setRotateContinuously( 35.0f ); // ---- Kart name label m_kart_name = new LabelWidget(true, true); m_kart_name->setText(props->getName(), false); m_kart_name->m_properties[PROP_TEXT_ALIGN] = "center"; m_kart_name->m_properties[PROP_ID] = StringUtils::insertValues("@p%i_kartname", m_player_id); m_kart_name->m_x = kart_name_x; m_kart_name->m_y = kart_name_y; m_kart_name->m_w = kart_name_w; m_kart_name->m_h = kart_name_h; m_children.push_back(m_kart_name); } // PlayerKartWidget