//! Adds an image element. IGUIImage* CGUIEnvironment::addImage(video::ITexture* image, core::position2d<s32> pos, bool useAlphaChannel, IGUIElement* parent, s32 id, const wchar_t* text) { if (!image) return 0; core::dimension2d<s32> sz = image->getOriginalSize(); IGUIImage* img = new CGUIImage(this, parent ? parent : this, id, core::rect<s32>(pos, sz)); if (text) img->setText(text); if (useAlphaChannel) img->setUseAlphaChannel(true); img->setImage(image); img->drop(); return img; }
void GrandPrixWin::init() { std::vector<std::string> parts; parts.push_back("gpwin"); ((CutsceneWorld*)World::getWorld())->setParts(parts); CutsceneWorld::setUseDuration(false); Screen::init(); World::getWorld()->setPhase(WorldStatus::RACE_PHASE); saveGPButton(); if (PlayerManager::getCurrentPlayer()->getRecentlyCompletedChallenges().size() > 0) { const core::dimension2d<u32>& frame_size = GUIEngine::getDriver()->getCurrentRenderTargetSize(); core::stringw message = _("You completed a challenge!"); const int message_width = GUIEngine::getFont()->getDimension(message.c_str()).Width + 30; const int label_height = GUIEngine::getFontHeight() + 15; const int y_from = frame_size.Height - label_height*2; const int y_to = frame_size.Height - label_height; const int label_x_from = frame_size.Width/2 - message_width/2; const int label_x_to = frame_size.Width/2 + message_width/2; // button_h is used in the x coordinates not by mistake, but because the icon is square and // scaled according to the available height. core::rect< s32 > iconarea(label_x_from - label_height, y_from, label_x_from, y_to); IGUIImage* img = GUIEngine::getGUIEnv()->addImage( iconarea ); img->setImage( irr_driver->getTexture( FileManager::GUI, "cup_gold.png") ); img->setScaleImage(true); img->setTabStop(false); img->setUseAlphaChannel(true); core::rect< s32 > icon2area(label_x_to, y_from, label_x_to + label_height, y_to); img = GUIEngine::getGUIEnv()->addImage( icon2area ); img->setImage( irr_driver->getTexture( FileManager::GUI,"cup_gold.png") ); img->setScaleImage(true); img->setTabStop(false); img->setUseAlphaChannel(true); m_unlocked_label = new GUIEngine::LabelWidget(); m_unlocked_label->m_properties[GUIEngine::PROP_ID] = "label"; m_unlocked_label->m_properties[GUIEngine::PROP_TEXT_ALIGN] = "center"; m_unlocked_label->m_x = label_x_from; m_unlocked_label->m_y = y_from; m_unlocked_label->m_w = message_width; m_unlocked_label->m_h = label_height; m_unlocked_label->setText(message, false); m_unlocked_label->add(); manualAddWidget(m_unlocked_label); } else { m_unlocked_label = NULL; } m_global_time = 0.0f; m_phase = 1; SFXManager::get()->quickSound("gp_end"); getWidget<ButtonWidget>("continue")->setFocusForPlayer(PLAYER_ID_GAME_MASTER); } // init
void GrandPrixWin::init() { Screen::init(); if (unlock_manager->getRecentlyUnlockedFeatures().size() > 0) { const core::dimension2d<u32>& frame_size = GUIEngine::getDriver()->getCurrentRenderTargetSize(); core::stringw message = _("You unlocked a new feature!"); const int message_width = GUIEngine::getFont()->getDimension(message.c_str()).Width + 30; const int label_height = GUIEngine::getFontHeight() + 15; const int y_from = frame_size.Height - label_height*2; const int y_to = frame_size.Height - label_height; const int label_x_from = frame_size.Width/2 - message_width/2; const int label_x_to = frame_size.Width/2 + message_width/2; // button_h is used in the x coordinates not by mistake, but because the icon is square and // scaled according to the available height. core::rect< s32 > iconarea(label_x_from - label_height, y_from, label_x_from, y_to); IGUIImage* img = GUIEngine::getGUIEnv()->addImage( iconarea ); img->setImage( irr_driver->getTexture( file_manager->getTextureFile("cup_gold.png") ) ); img->setScaleImage(true); img->setTabStop(false); img->setUseAlphaChannel(true); core::rect< s32 > icon2area(label_x_to, y_from, label_x_to + label_height, y_to); img = GUIEngine::getGUIEnv()->addImage( icon2area ); img->setImage( irr_driver->getTexture( file_manager->getTextureFile("cup_gold.png") ) ); img->setScaleImage(true); img->setTabStop(false); img->setUseAlphaChannel(true); m_unlocked_label = new GUIEngine::LabelWidget(); m_unlocked_label->m_properties[GUIEngine::PROP_ID] = "label"; m_unlocked_label->m_properties[GUIEngine::PROP_TEXT_ALIGN] = "center"; m_unlocked_label->m_x = label_x_from; m_unlocked_label->m_y = y_from; m_unlocked_label->m_w = message_width; m_unlocked_label->m_h = label_height; m_unlocked_label->setText(message, false); //const irr::video::SColor orange(255, 255, 126, 21); //unlocked_label->setColor(orange); m_unlocked_label->add(); manualAddWidget(m_unlocked_label); } else { m_unlocked_label = NULL; } m_phase = 1; m_sky_angle = 0.0f; m_global_time = 0.0f; video::ITexture *t = irr_driver->getTexture( file_manager->getTextureFile("clouds.png")); m_sky = irr_driver->addSkyDome(t, 16 /* hori_res */, 16 /* vert_res */, 1.0f /* texture_percent */, 2.0f /* sphere_percent */); m_camera = irr_driver->addCameraSceneNode(); m_camera_x = 3.0f; m_camera_y = 0.0f; m_camera_z = -5.0f; m_camera->setPosition( core::vector3df(m_camera_x, m_camera_y, m_camera_z) ); m_camera->setUpVector( core::vector3df(0.0, 1.0, 0.0) ); irr_driver->getSceneManager()->setActiveCamera(m_camera); m_camera_target_x = 1.5f; m_camera_target_z = 0.0f; m_camera->setTarget( core::vector3df(m_camera_target_x, -2.0f, m_camera_target_z) ); m_camera->setFOV( DEGREE_TO_RAD*50.0f ); m_camera->updateAbsolutePosition(); scene::IMesh* model_village = irr_driver->getMesh( file_manager->getModelFile("village.b3d") ); assert(model_village != NULL); m_village = irr_driver->addMesh(model_village); #ifdef DEBUG m_village->setName("village"); #endif m_village->setPosition( core::vector3df(2, INITIAL_Y, 0) ); scene::IMesh* podium_model = irr_driver->getMesh( file_manager->getModelFile("wood_podium.b3d") ); assert(podium_model != NULL); m_podium_step[0] = irr_driver->addMesh(podium_model); #ifdef DEBUG m_podium_step[0]->setName("Podium 0"); #endif m_podium_step[0]->setPosition( core::vector3df(m_podium_x[0], INITIAL_PODIUM_Y, m_podium_z[0]) ); m_podium_step[1] = irr_driver->addMesh(podium_model); #ifdef DEBUG m_podium_step[1]->setName("Podium 1"); #endif m_podium_step[1]->setPosition( core::vector3df(m_podium_x[1], INITIAL_PODIUM_Y, m_podium_z[1]) ); m_podium_step[2] = irr_driver->addMesh(podium_model); #ifdef DEBUG m_podium_step[2]->setName("Podium 2"); #endif m_podium_step[2]->setPosition( core::vector3df(m_podium_x[2], INITIAL_PODIUM_Y, m_podium_z[2]) ); scene::ISceneManager* sceneManager = irr_driver->getSceneManager(); sceneManager->setAmbientLight(video::SColor(255, 95, 95, 95)); const core::vector3df &sun_pos = core::vector3df( 0, 200, 100.0f ); m_light = irr_driver->getSceneManager()->addLightSceneNode(NULL, sun_pos, video::SColorf(0.25f,0.25f,0.25f), 300.0f /* radius */); m_light->getLightData().DiffuseColor = irr::video::SColorf(0.25f, 0.25f, 0.25f, 1.0f); m_light->getLightData().AmbientColor = irr::video::SColorf(0.25f, 0.25f, 0.25f, 1.0f); m_light->getLightData().SpecularColor = irr::video::SColorf(0.0f, 0.0f, 0.0f, 1.0f); sfx_manager->quickSound("gp_end"); } // init
void SpinnerWidget::add() { // retrieve min and max values std::string min_s = m_properties[PROP_MIN_VALUE]; std::string max_s = m_properties[PROP_MAX_VALUE]; m_wrap_around = (m_properties[PROP_WRAP_AROUND] == "true"); if (min_s.size() > 0) { if (!StringUtils::parseString<int>(min_s, &m_min)) { Log::warn("invalid value for spinner widget minimum value : %s", min_s.c_str()); } } if (max_s.size() > 0) { if (!StringUtils::parseString<int>(max_s, &m_max)) { Log::warn("invalid value for spinner widget maximum value : %s", max_s.c_str()); } } if (m_value == -1) { m_value = (m_min + m_max)/2; } // create sub-widgets if they don't already exist if (m_children.size() == 0) { std::string& icon = m_properties[PROP_ICON]; m_graphical = icon.size()>0; //FIXME: unclean to create "fake" button/label/icon widgets!! m_children.push_back( new Widget(WTYPE_BUTTON) ); m_children.push_back( new Widget(m_graphical ? WTYPE_ICON_BUTTON : WTYPE_LABEL) ); m_children.push_back( new Widget(WTYPE_BUTTON) ); } int widgetID; if (m_reserved_id != -1) { widgetID = m_reserved_id; } else { widgetID = getNewID(); } rect<s32> widget_size = rect<s32>(m_x, m_y, m_x + m_w, m_y + m_h); IGUIButton * btn = GUIEngine::getGUIEnv()->addButton(widget_size, m_parent, widgetID, L""); m_element = btn; m_element->setTabOrder( m_element->getID() ); // left arrow rect<s32> subsize_left_arrow = rect<s32>(0 ,0, m_h, m_h); IGUIButton * left_arrow = GUIEngine::getGUIEnv()->addButton(subsize_left_arrow, btn, getNewNoFocusID(), L" "); m_children[0].m_element = left_arrow; left_arrow->setTabStop(false); m_children[0].m_event_handler = this; m_children[0].m_properties[PROP_ID] = "left"; m_children[0].m_id = m_children[0].m_element->getID(); m_badge_x_shift = subsize_left_arrow.getWidth(); // label if (m_graphical) { ITexture* texture = getTexture(); assert(texture != NULL); const int texture_width = texture->getSize().Width; const int free_h_space = m_w - m_h*2 - texture_width; // to center image rect<s32> subsize_label = rect<s32>(m_h + free_h_space/2, 0, m_w - m_h+ free_h_space/2, m_h); IGUIImage * subbtn = GUIEngine::getGUIEnv()->addImage(subsize_label, btn, getNewNoFocusID()); m_children[1].m_element = subbtn; m_children[1].m_id = subbtn->getID(); m_children[1].m_event_handler = this; m_children[1].m_properties[PROP_ID] = "spinnerbody"; subbtn->setUseAlphaChannel(true); subbtn->setImage(texture); //subbtn->setScaleImage(true); } else { rect<s32> subsize_label = rect<s32>(m_h, 0, m_w - m_h, m_h); IGUIStaticText* label = GUIEngine::getGUIEnv()->addStaticText(stringw(m_value).c_str(), subsize_label, false /* border */, true /* word wrap */, btn, getNewNoFocusID()); m_children[1].m_element = label; m_children[1].m_event_handler = this; m_children[1].m_id = label->getID(); m_children[1].m_properties[PROP_ID] = "spinnerbody"; label->setTextAlignment(EGUIA_CENTER, EGUIA_CENTER); label->setTabStop(false); label->setNotClipped(true); if (m_labels.size() > 0) { label->setText(m_labels[m_value].c_str() ); } if (widget_size.getHeight() < GUIEngine::getFontHeight()) { label->setOverrideFont(GUIEngine::getSmallFont()); } } // right arrow rect<s32> subsize_right_arrow = rect<s32>(m_w - m_h, 0, m_w, m_h); IGUIButton * right_arrow = GUIEngine::getGUIEnv()->addButton(subsize_right_arrow, btn, getNewNoFocusID(), L" "); right_arrow->setTabStop(false); m_children[2].m_element = right_arrow; m_children[2].m_event_handler = this; m_children[2].m_properties[PROP_ID] = "right"; m_children[2].m_id = m_children[2].m_element->getID(); // refresh display setValue(m_value); }