void OptionsScreenUI::loadedFromFile() { m_inited = false; GUIEngine::SpinnerWidget* skinSelector = getWidget<GUIEngine::SpinnerWidget>("skinchoice"); assert( skinSelector != NULL ); skinSelector->m_properties[PROP_WRAP_AROUND] = "true"; m_skins.clear(); skinSelector->clearLabels(); std::set<std::string> skinFiles; file_manager->listFiles(skinFiles /* out */, file_manager->getAsset(FileManager::SKIN,""), true /* make full path */ ); for (std::set<std::string>::iterator it = skinFiles.begin(); it != skinFiles.end(); it++) { if(StringUtils::getExtension(*it)=="stkskin") { m_skins.push_back( *it ); } } if (m_skins.size() == 0) { Log::warn("OptionsScreenUI", "Could not find a single skin, make sure that " "the data files are correctly installed"); skinSelector->setActive(false); return; } const int skin_count = (int)m_skins.size(); for (int n=0; n<skin_count; n++) { const std::string skinFileName = StringUtils::getBasename(m_skins[n]); const std::string skinName = StringUtils::removeExtension( skinFileName ); skinSelector->addLabel( core::stringw(skinName.c_str()) ); } skinSelector->m_properties[GUIEngine::PROP_MIN_VALUE] = "0"; skinSelector->m_properties[GUIEngine::PROP_MAX_VALUE] = StringUtils::toString(skin_count-1); } // loadedFromFile
void OptionsScreenVideo::updateGfxSlider() { GUIEngine::SpinnerWidget* gfx = getWidget<GUIEngine::SpinnerWidget>("gfx_level"); assert( gfx != NULL ); bool found = false; for (int l=0; l<GFX_LEVEL_AMOUNT; l++) { if (GFX_PRESETS[l].animatedCharacters == UserConfigParams::m_show_steering_animations && GFX_PRESETS[l].animatedScenery == UserConfigParams::m_graphical_effects && GFX_PRESETS[l].anisotropy == UserConfigParams::m_anisotropic && GFX_PRESETS[l].bloom == UserConfigParams::m_bloom && GFX_PRESETS[l].glow == UserConfigParams::m_glow && GFX_PRESETS[l].lights == UserConfigParams::m_dynamic_lights && GFX_PRESETS[l].lightshaft == UserConfigParams::m_light_shaft && GFX_PRESETS[l].mlaa == UserConfigParams::m_mlaa && GFX_PRESETS[l].motionblur == UserConfigParams::m_motionblur && //GFX_PRESETS[l].shaders == UserConfigParams::m_pixel_shaders GFX_PRESETS[l].shadows == UserConfigParams::m_shadows_resolution && GFX_PRESETS[l].ssao == UserConfigParams::m_ssao && GFX_PRESETS[l].weather == UserConfigParams::m_weather_effects && GFX_PRESETS[l].dof == UserConfigParams::m_dof && GFX_PRESETS[l].global_illumination == UserConfigParams::m_gi && GFX_PRESETS[l].degraded_ibl == UserConfigParams::m_degraded_IBL && GFX_PRESETS[l].hd_textures == (UserConfigParams::m_high_definition_textures & 0x01)) { gfx->setValue(l + 1); found = true; break; } } if (!found) { //I18N: custom video settings gfx->setCustomText( _("Custom") ); } updateTooltip(); }
void OptionsScreenUI::eventCallback(Widget* widget, const std::string& name, const int playerID) { if (name == "options_choice") { std::string selection = ((RibbonWidget*)widget)->getSelectionIDString(PLAYER_ID_GAME_MASTER); Screen *screen = NULL; if (selection == "tab_audio") screen = OptionsScreenAudio::getInstance(); else if (selection == "tab_video") screen = OptionsScreenVideo::getInstance(); else if (selection == "tab_players") screen = TabbedUserScreen::getInstance(); else if (selection == "tab_controls") screen = OptionsScreenInput::getInstance(); //else if (selection == "tab_ui") // screen = OptionsScreenUI::getInstance(); if(screen) StateManager::get()->replaceTopMostScreen(screen); } else if(name == "back") { StateManager::get()->escapePressed(); } else if (name == "skinchoice") { GUIEngine::SpinnerWidget* skinSelector = getWidget<GUIEngine::SpinnerWidget>("skinchoice"); assert( skinSelector != NULL ); const core::stringw selectedSkin = skinSelector->getStringValue(); UserConfigParams::m_skin_file = core::stringc(selectedSkin.c_str()).c_str() + std::string(".stkskin"); GUIEngine::reloadSkin(); } else if (name == "showfps") { CheckBoxWidget* fps = getWidget<CheckBoxWidget>("showfps"); assert( fps != NULL ); UserConfigParams::m_display_fps = fps->getState(); } else if (name=="enable-internet") { CheckBoxWidget* internet = getWidget<CheckBoxWidget>("enable-internet"); assert( internet != NULL ); UserConfigParams::m_internet_status = internet->getState() ? RequestManager::IPERM_ALLOWED : RequestManager::IPERM_NOT_ALLOWED; // If internet gets enabled, re-initialise the addon manager (which // happens in a separate thread) so that news.xml etc can be // downloaded if necessary. CheckBoxWidget *stats = getWidget<CheckBoxWidget>("enable-hw-report"); LabelWidget *stats_label = getWidget<LabelWidget>("label-hw-report"); if(internet->getState()) { NewsManager::get()->init(false); stats->setVisible(true); stats_label->setVisible(true); stats->setState(UserConfigParams::m_hw_report_enable); } else { stats->setVisible(false); stats_label->setVisible(false); PlayerProfile* profile = PlayerManager::getCurrentPlayer(); if (profile != NULL && profile->isLoggedIn()) profile->requestSignOut(); } } else if (name=="enable-hw-report") { CheckBoxWidget* stats = getWidget<CheckBoxWidget>("enable-hw-report"); UserConfigParams::m_hw_report_enable = stats->getState(); if(stats->getState()) HardwareStats::reportHardwareStats(); } else if (name=="show-login") { CheckBoxWidget* show_login = getWidget<CheckBoxWidget>("show-login"); assert( show_login != NULL ); UserConfigParams::m_always_show_login_screen = show_login->getState(); } else if (name=="perPlayerDifficulty") { CheckBoxWidget* difficulty = getWidget<CheckBoxWidget>("perPlayerDifficulty"); assert( difficulty != NULL ); UserConfigParams::m_per_player_difficulty = difficulty->getState(); } else if (name == "language") { ListWidget* list_widget = getWidget<ListWidget>("language"); std::string selection = list_widget->getSelectionInternalName(); delete translations; if (selection == "system") { #ifdef WIN32 _putenv("LANGUAGE="); #else unsetenv("LANGUAGE"); #endif } else { #ifdef WIN32 std::string s=std::string("LANGUAGE=")+selection.c_str(); _putenv(s.c_str()); #else setenv("LANGUAGE", selection.c_str(), 1); #endif } translations = new Translations(); // Reload fonts for new translation GUIEngine::getStateManager()->hardResetAndGoToScreen<MainMenuScreen>(); font_manager->getFont<BoldFace>()->reset(); font_manager->getFont<RegularFace>()->reset(); GUIEngine::getFont()->updateRTL(); GUIEngine::getTitleFont()->updateRTL(); GUIEngine::getSmallFont()->updateRTL(); GUIEngine::getLargeFont()->updateRTL(); GUIEngine::getOutlineFont()->updateRTL(); UserConfigParams::m_language = selection.c_str(); user_config->saveConfig(); OptionsScreenUI::getInstance()->push(); } } // eventCallback
void OptionsScreenUI::init() { Screen::init(); RibbonWidget* ribbon = getWidget<RibbonWidget>("options_choice"); assert(ribbon != NULL); ribbon->select( "tab_ui", PLAYER_ID_GAME_MASTER ); ribbon->getRibbonChildren()[0].setTooltip( _("Graphics") ); ribbon->getRibbonChildren()[1].setTooltip( _("Audio") ); ribbon->getRibbonChildren()[3].setTooltip( _("Players") ); ribbon->getRibbonChildren()[4].setTooltip( _("Controls") ); GUIEngine::SpinnerWidget* skinSelector = getWidget<GUIEngine::SpinnerWidget>("skinchoice"); assert( skinSelector != NULL ); // ---- video modes CheckBoxWidget* fps = getWidget<CheckBoxWidget>("showfps"); assert( fps != NULL ); fps->setState( UserConfigParams::m_display_fps ); CheckBoxWidget* news = getWidget<CheckBoxWidget>("enable-internet"); assert( news != NULL ); news->setState( UserConfigParams::m_internet_status ==RequestManager::IPERM_ALLOWED ); CheckBoxWidget* stats = getWidget<CheckBoxWidget>("enable-hw-report"); assert( stats != NULL ); LabelWidget *stats_label = getWidget<LabelWidget>("label-hw-report"); assert( stats_label ); stats->setState(UserConfigParams::m_hw_report_enable); if(news->getState()) { stats_label->setVisible(true); stats->setVisible(true); stats->setState(UserConfigParams::m_hw_report_enable); } else { stats_label->setVisible(false); stats->setVisible(false); } CheckBoxWidget* difficulty = getWidget<CheckBoxWidget>("perPlayerDifficulty"); assert( difficulty != NULL ); difficulty->setState( UserConfigParams::m_per_player_difficulty ); difficulty->setTooltip(_("In multiplayer mode, players can select handicapped (more difficult) profiles on the kart selection screen")); CheckBoxWidget* show_login = getWidget<CheckBoxWidget>("show-login"); assert( show_login!= NULL ); show_login->setState( UserConfigParams::m_always_show_login_screen); // --- select the right skin in the spinner bool currSkinFound = false; const int skinCount = (int) m_skins.size(); for (int n=0; n<skinCount; n++) { const std::string skinFileName = StringUtils::getBasename(m_skins[n]); if (UserConfigParams::m_skin_file.c_str() == skinFileName) { skinSelector->setValue(n); currSkinFound = true; break; } } if (!currSkinFound) { Log::warn("OptionsScreenUI", "Couldn't find current skin in the list of skins!"); skinSelector->setValue(0); GUIEngine::reloadSkin(); } // --- language ListWidget* list_widget = getWidget<ListWidget>("language"); // I18N: in the language choice, to select the same language as the OS list_widget->addItem("system", _("System Language")); const std::vector<std::string>* lang_list = translations->getLanguageList(); const int amount = (int)lang_list->size(); // The names need to be sorted alphabetically. Store the 2-letter // language names in a mapping, to be able to get them from the // user visible full name. std::vector<core::stringw> nice_lang_list; std::map<core::stringw, std::string> nice_name_2_id; for (int n=0; n<amount; n++) { std::string code_name = (*lang_list)[n]; std::string s_name = translations->getLocalizedName(code_name) + " (" + tinygettext::Language::from_name(code_name).get_language() + ")"; core::stringw nice_name = translations->fribidize(StringUtils::utf8ToWide(s_name)); nice_lang_list.push_back(nice_name); nice_name_2_id[nice_name] = code_name; } std::sort(nice_lang_list.begin(), nice_lang_list.end()); for(unsigned int i=0; i<nice_lang_list.size(); i++) { list_widget->addItem(nice_name_2_id[nice_lang_list[i]], nice_lang_list[i]); } list_widget->setSelectionID( list_widget->getItemID(UserConfigParams::m_language) ); // Forbid changing language while in-game, since this crashes (changing the language involves // tearing down and rebuilding the menu stack. not good when in-game) list_widget->setActive(StateManager::get()->getGameState() != GUIEngine::INGAME_MENU); } // init
void OptionsScreenUI::eventCallback(Widget* widget, const std::string& name, const int playerID) { if (name == "options_choice") { std::string selection = ((RibbonWidget*)widget)->getSelectionIDString(PLAYER_ID_GAME_MASTER).c_str(); if (selection == "tab_audio") StateManager::get()->replaceTopMostScreen(OptionsScreenAudio::getInstance()); else if (selection == "tab_video") StateManager::get()->replaceTopMostScreen(OptionsScreenVideo::getInstance()); else if (selection == "tab_players") StateManager::get()->replaceTopMostScreen(OptionsScreenPlayers::getInstance()); else if (selection == "tab_controls") StateManager::get()->replaceTopMostScreen(OptionsScreenInput::getInstance()); } else if(name == "back") { StateManager::get()->escapePressed(); } else if (name == "skinchoice") { GUIEngine::SpinnerWidget* skinSelector = getWidget<GUIEngine::SpinnerWidget>("skinchoice"); assert( skinSelector != NULL ); const core::stringw selectedSkin = skinSelector->getStringValue(); UserConfigParams::m_skin_file = core::stringc(selectedSkin.c_str()).c_str() + std::string(".stkskin"); GUIEngine::reloadSkin(); } else if (name == "showfps") { CheckBoxWidget* fps = getWidget<CheckBoxWidget>("showfps"); assert( fps != NULL ); UserConfigParams::m_display_fps = fps->getState(); } else if (name=="enable-internet") { CheckBoxWidget* news = getWidget<CheckBoxWidget>("enable-internet"); assert( news != NULL ); if(INetworkHttp::get()) { INetworkHttp::get()->stopNetworkThread(); INetworkHttp::destroy(); } UserConfigParams::m_internet_status = news->getState() ? INetworkHttp::IPERM_ALLOWED : INetworkHttp::IPERM_NOT_ALLOWED; INetworkHttp::create(); // Note that the network thread must be started after the assignment // to network_http (since the thread might use network_http, otherwise // a race condition can be introduced resulting in a crash). INetworkHttp::get()->startNetworkThread(); } else if (name=="minimal-racegui") { CheckBoxWidget* min_gui = getWidget<CheckBoxWidget>("minimal-racegui"); assert( min_gui != NULL ); UserConfigParams::m_minimal_race_gui = !UserConfigParams::m_minimal_race_gui; } else if (name == "language") { ListWidget* list_widget = getWidget<ListWidget>("language"); std::string selection = list_widget->getSelectionInternalName(); delete translations; if (selection == "system") { #ifdef WIN32 _putenv("LANGUAGE="); #else unsetenv("LANGUAGE"); #endif } else { #ifdef WIN32 std::string s=std::string("LANGUAGE=")+selection.c_str(); _putenv(s.c_str()); #else setenv("LANGUAGE", selection.c_str(), 1); #endif } translations = new Translations(); GUIEngine::getStateManager()->hardResetAndGoToScreen<MainMenuScreen>(); GUIEngine::getFont()->updateRTL(); GUIEngine::getTitleFont()->updateRTL(); GUIEngine::getSmallFont()->updateRTL(); UserConfigParams::m_language = selection.c_str(); user_config->saveConfig(); GUIEngine::getStateManager()->pushScreen(OptionsScreenUI::getInstance()); } } // eventCallback
void OptionsScreenUI::init() { Screen::init(); RibbonWidget* ribbon = getWidget<RibbonWidget>("options_choice"); if (ribbon != NULL) ribbon->select( "tab_ui", PLAYER_ID_GAME_MASTER ); ribbon->getRibbonChildren()[0].setTooltip( _("Graphics") ); ribbon->getRibbonChildren()[1].setTooltip( _("Audio") ); ribbon->getRibbonChildren()[3].setTooltip( _("Players") ); ribbon->getRibbonChildren()[4].setTooltip( _("Controls") ); GUIEngine::SpinnerWidget* skinSelector = getWidget<GUIEngine::SpinnerWidget>("skinchoice"); assert( skinSelector != NULL ); // ---- video modes CheckBoxWidget* fps = getWidget<CheckBoxWidget>("showfps"); assert( fps != NULL ); fps->setState( UserConfigParams::m_display_fps ); CheckBoxWidget* news = getWidget<CheckBoxWidget>("enable-internet"); assert( news != NULL ); news->setState( UserConfigParams::m_internet_status ==INetworkHttp::IPERM_ALLOWED ); CheckBoxWidget* min_gui = getWidget<CheckBoxWidget>("minimal-racegui"); assert( min_gui != NULL ); min_gui->setState( UserConfigParams::m_minimal_race_gui); if (StateManager::get()->getGameState() == GUIEngine::INGAME_MENU) min_gui->setDeactivated(); else min_gui->setActivated(); // --- select the right skin in the spinner bool currSkinFound = false; const int skinCount = m_skins.size(); for (int n=0; n<skinCount; n++) { const std::string skinFileName = StringUtils::getBasename(m_skins[n]); if (UserConfigParams::m_skin_file.c_str() == skinFileName) { skinSelector->setValue(n); currSkinFound = true; break; } } if (!currSkinFound) { std::cerr << "WARNING: couldn't find current skin in the list of skins!!\n"; skinSelector->setValue(0); GUIEngine::reloadSkin(); } // --- language ListWidget* list_widget = getWidget<ListWidget>("language"); // I18N: in the language choice, to select the same language as the OS list_widget->addItem("system", _("System Language")); const std::vector<std::string>* lang_list = translations->getLanguageList(); const int amount = lang_list->size(); for (int n=0; n<amount; n++) { std::string code_name = (*lang_list)[n]; std::string nice_name = tinygettext::Language::from_name(code_name.c_str()).get_name(); list_widget->addItem(code_name, core::stringw(code_name.c_str()) + " (" + nice_name.c_str() + ")"); } list_widget->setSelectionID( list_widget->getItemID(UserConfigParams::m_language) ); // Forbid changing language while in-game, since this crashes (changing the language involves // tearing down and rebuilding the menu stack. not good when in-game) if (StateManager::get()->getGameState() == GUIEngine::INGAME_MENU) { list_widget->setDeactivated(); } else { list_widget->setActivated(); } } // init
void OptionsScreenVideo::updateTooltip() { GUIEngine::SpinnerWidget* gfx = getWidget<GUIEngine::SpinnerWidget>("gfx_level"); assert( gfx != NULL ); core::stringw tooltip; //I18N: in the graphical options tooltip; // indicates a graphical feature is enabled const core::stringw enabled = _LTR("Enabled"); //I18N: in the graphical options tooltip; // indicates a graphical feature is disabled const core::stringw disabled = _LTR("Disabled"); //I18N: if all kart animations are enabled const core::stringw all = _LTR("All"); //I18N: if some kart animations are enabled const core::stringw me = _LTR("Me Only"); //I18N: if no kart animations are enabled const core::stringw none = _LTR("None"); //I18N: in graphical options // tooltip = tooltip + L"\n" + _("Pixel shaders: %s", // UserConfigParams::m_pixel_shaders ? enabled : disabled); //I18N: in graphical options tooltip = _("Animated Scenery: %s", UserConfigParams::m_graphical_effects ? enabled : disabled); //I18N: in graphical options tooltip = tooltip + L"\n" + _("Weather Effects: %s", UserConfigParams::m_weather_effects ? enabled : disabled); //I18N: in graphical options tooltip = tooltip + L"\n" + _("Animated Characters: %s", UserConfigParams::m_show_steering_animations == 2 ? all : (UserConfigParams::m_show_steering_animations == 1 ? me : none)); //I18N: in graphical options tooltip = tooltip + L"\n" + _("Dynamic lights: %s", UserConfigParams::m_dynamic_lights ? enabled : disabled); //I18N: in graphical options tooltip = tooltip + L"\n" + _("Motion blur: %s", UserConfigParams::m_motionblur ? enabled : disabled); //I18N: in graphical options tooltip = tooltip + L"\n" + _("Anti-aliasing: %s", UserConfigParams::m_mlaa ? enabled : disabled); //I18N: in graphical options tooltip = tooltip + L"\n" + _("Ambient occlusion: %s", UserConfigParams::m_ssao ? enabled : disabled); //I18N: in graphical options if (UserConfigParams::m_shadows_resolution == 0) tooltip = tooltip + L"\n" + _("Shadows: %s", disabled); else tooltip = tooltip + L"\n" + _("Shadows: %i", UserConfigParams::m_shadows_resolution); //I18N: in graphical options tooltip = tooltip + L"\n" + _("Bloom: %s", UserConfigParams::m_bloom ? enabled : disabled); //I18N: in graphical options tooltip = tooltip + L"\n" + _("Glow (outlines): %s", UserConfigParams::m_glow ? enabled : disabled); //I18N: in graphical options tooltip = tooltip + L"\n" + _("Light shaft (God rays): %s", UserConfigParams::m_light_shaft ? enabled : disabled); //I18N: in graphical options tooltip = tooltip + L"\n" + _("Depth of field: %s", UserConfigParams::m_dof ? enabled : disabled); //I18N: in graphical options tooltip = tooltip + L"\n" + _("Global illumination: %s", UserConfigParams::m_gi ? enabled : disabled); //I18N: in graphical options tooltip = tooltip + L"\n" + _("Use high definition textures: %s", (UserConfigParams::m_high_definition_textures & 0x1) == 0 ? disabled : enabled); gfx->setTooltip(tooltip); } // updateTooltip
void OptionsScreenVideo::init() { Screen::init(); RibbonWidget* ribbon = getWidget<RibbonWidget>("options_choice"); assert(ribbon != NULL); ribbon->select( "tab_video", PLAYER_ID_GAME_MASTER ); ribbon->getRibbonChildren()[1].setTooltip( _("Audio") ); ribbon->getRibbonChildren()[2].setTooltip( _("User Interface") ); ribbon->getRibbonChildren()[3].setTooltip( _("Players") ); ribbon->getRibbonChildren()[4].setTooltip( _("Controls") ); GUIEngine::ButtonWidget* applyBtn = getWidget<GUIEngine::ButtonWidget>("apply_resolution"); assert( applyBtn != NULL ); GUIEngine::SpinnerWidget* gfx = getWidget<GUIEngine::SpinnerWidget>("gfx_level"); assert( gfx != NULL ); GUIEngine::CheckBoxWidget* vsync = getWidget<GUIEngine::CheckBoxWidget>("vsync"); assert( vsync != NULL ); vsync->setState( UserConfigParams::m_vsync ); // ---- video modes DynamicRibbonWidget* res = getWidget<DynamicRibbonWidget>("resolutions"); assert( res != NULL ); CheckBoxWidget* full = getWidget<CheckBoxWidget>("fullscreen"); assert( full != NULL ); full->setState( UserConfigParams::m_fullscreen ); CheckBoxWidget* rememberWinpos = getWidget<CheckBoxWidget>("rememberWinpos"); rememberWinpos->setState(UserConfigParams::m_remember_window_location); rememberWinpos->setActive(UserConfigParams::m_fullscreen); // --- get resolution list from irrlicht the first time if (!m_inited) { res->clearItems(); const std::vector<IrrDriver::VideoMode>& modes = irr_driver->getVideoModes(); const int amount = (int)modes.size(); std::vector<Resolution> resolutions; Resolution r; bool found_config_res = false; // for some odd reason, irrlicht sometimes fails to report the good // old standard resolutions // those are always useful for windowed mode bool found_1024_768 = false; for (int n=0; n<amount; n++) { r.width = modes[n].getWidth(); r.height = modes[n].getHeight(); resolutions.push_back(r); if (r.width == UserConfigParams::m_width && r.height == UserConfigParams::m_height) { found_config_res = true; } if (r.width == 1024 && r.height == 768) { found_1024_768 = true; } } if (!found_config_res) { r.width = UserConfigParams::m_width; r.height = UserConfigParams::m_height; resolutions.push_back(r); if (r.width == 1024 && r.height == 768) { found_1024_768 = true; } } // next found resolution // Add default resolutions that were not found by irrlicht if (!found_1024_768) { r.width = 1024; r.height = 768; resolutions.push_back(r); } // Sort resolutions by size std::sort(resolutions.begin(), resolutions.end()); // Add resolutions list for(std::vector<Resolution>::iterator it = resolutions.begin(); it != resolutions.end(); it++) { const float ratio = it->getRatio(); char name[32]; sprintf(name, "%ix%i", it->width, it->height); core::stringw label; label += it->width; label += L"\u00D7"; label += it->height; #define ABOUT_EQUAL(a , b) (fabsf( a - b ) < 0.01) if (ABOUT_EQUAL( ratio, (5.0f/4.0f) )) res->addItem(label, name, "/gui/screen54.png"); else if (ABOUT_EQUAL( ratio, (4.0f/3.0f) )) res->addItem(label, name, "/gui/screen43.png"); else if (ABOUT_EQUAL( ratio, (16.0f/10.0f))) res->addItem(label, name, "/gui/screen1610.png"); else if (ABOUT_EQUAL( ratio, (5.0f/3.0f) )) res->addItem(label, name, "/gui/screen53.png"); else if (ABOUT_EQUAL( ratio, (3.0f/2.0f) )) res->addItem(label, name, "/gui/screen32.png"); else if (ABOUT_EQUAL( ratio, (16.0f/9.0f) )) res->addItem(label, name, "/gui/screen169.png"); else res->addItem(label, name, "/gui/screen_other.png"); #undef ABOUT_EQUAL } // add next resolution } // end if not inited res->updateItemDisplay(); // ---- select current resolution every time char searching_for[32]; snprintf(searching_for, 32, "%ix%i", (int)UserConfigParams::m_width, (int)UserConfigParams::m_height); if (!res->setSelection(searching_for, PLAYER_ID_GAME_MASTER, false /* focus it */, true /* even if deactivated*/)) { Log::error("OptionsScreenVideo", "Cannot find resolution %s", searching_for); } // --- set gfx settings values updateGfxSlider(); // ---- forbid changing resolution or animation settings from in-game // (we need to disable them last because some items can't be edited when // disabled) bool in_game = StateManager::get()->getGameState() == GUIEngine::INGAME_MENU; res->setActive(!in_game); full->setActive(!in_game); applyBtn->setActive(!in_game); gfx->setActive(!in_game); getWidget<ButtonWidget>("custom")->setActive(!in_game); } // init
void OptionsScreenVideo::init() { Screen::init(); RibbonWidget* ribbon = getWidget<RibbonWidget>("options_choice"); if (ribbon != NULL) ribbon->select( "tab_video", PLAYER_ID_GAME_MASTER ); ribbon->getRibbonChildren()[1].setTooltip( _("Audio") ); ribbon->getRibbonChildren()[2].setTooltip( _("User Interface") ); ribbon->getRibbonChildren()[3].setTooltip( _("Players") ); ribbon->getRibbonChildren()[4].setTooltip( _("Controls") ); GUIEngine::ButtonWidget* applyBtn = getWidget<GUIEngine::ButtonWidget>("apply_resolution"); assert( applyBtn != NULL ); GUIEngine::SpinnerWidget* gfx = getWidget<GUIEngine::SpinnerWidget>("gfx_level"); assert( gfx != NULL ); GUIEngine::CheckBoxWidget* vsync = getWidget<GUIEngine::CheckBoxWidget>("vsync"); assert( vsync != NULL ); vsync->setState( UserConfigParams::m_vsync ); // ---- video modes DynamicRibbonWidget* res = getWidget<DynamicRibbonWidget>("resolutions"); assert( res != NULL ); CheckBoxWidget* full = getWidget<CheckBoxWidget>("fullscreen"); assert( full != NULL ); full->setState( UserConfigParams::m_fullscreen ); CheckBoxWidget* rememberWinpos = getWidget<CheckBoxWidget>("rememberWinpos"); rememberWinpos->setState(UserConfigParams::m_remember_window_location); if (UserConfigParams::m_fullscreen) rememberWinpos->setDeactivated(); else rememberWinpos->setActivated(); // --- get resolution list from irrlicht the first time if (!m_inited) { res->clearItems(); const std::vector<IrrDriver::VideoMode>& modes = irr_driver->getVideoModes(); const int amount = (int)modes.size(); bool found_config_res = false; // for some odd reason, irrlicht sometimes fails to report the good // old standard resolutions // those are always useful for windowed mode // allow 800x600 only for debug mode #ifdef DEBUG bool found_800_600 = false; #endif bool found_1024_640 = false; bool found_1024_768 = false; for (int n=0; n<amount; n++) { const int w = modes[n].getWidth(); const int h = modes[n].getHeight(); const float ratio = (float)w / h; if (w == UserConfigParams::m_width && h == UserConfigParams::m_height) { found_config_res = true; } if (w == 800 && h == 600) { #ifdef DEBUG found_800_600 = true; #else continue; #endif } else if (w == 1024 && h == 640) { found_1024_640 = true; } else if (w == 1024 && h == 768) { found_1024_768 = true; } char name[32]; sprintf( name, "%ix%i", w, h ); core::stringw label; label += w; label += L"\u00D7"; label += h; #define ABOUT_EQUAL(a , b) (fabsf( a - b ) < 0.01) if (ABOUT_EQUAL( ratio, (5.0f/4.0f) )) res->addItem(label, name, "/gui/screen54.png"); else if (ABOUT_EQUAL( ratio, (4.0f/3.0f) )) res->addItem(label, name, "/gui/screen43.png"); else if (ABOUT_EQUAL( ratio, (16.0f/10.0f))) res->addItem(label, name, "/gui/screen1610.png"); else if (ABOUT_EQUAL( ratio, (5.0f/3.0f) )) res->addItem(label, name, "/gui/screen53.png"); else if (ABOUT_EQUAL( ratio, (3.0f/2.0f) )) res->addItem(label, name, "/gui/screen32.png"); else if (ABOUT_EQUAL( ratio, (16.0f/9.0f) )) res->addItem(label, name, "/gui/screen169.png"); else res->addItem(label, name, "/gui/screen_other.png"); #undef ABOUT_EQUAL } // next resolution if (!found_config_res) { const int w = UserConfigParams::m_width; const int h = UserConfigParams::m_height; const float ratio = (float)w / h; if (w == 800 && h == 600) { #ifdef DEBUG found_800_600 = true; #endif } else if (w == 1024 && h == 640) { found_1024_640 = true; } else if (w == 1024 && h == 768) { found_1024_768 = true; } char name[32]; sprintf( name, "%ix%i", w, h ); core::stringw label; label += w; label += L"\u00D7"; label += h; #define ABOUT_EQUAL(a , b) (fabsf( a - b ) < 0.01) if (ABOUT_EQUAL( ratio, (5.0f/4.0f) )) res->addItem(label, name, "/gui/screen54.png"); else if (ABOUT_EQUAL( ratio, (4.0f/3.0f) )) res->addItem(label, name, "/gui/screen43.png"); else if (ABOUT_EQUAL( ratio, (16.0f/10.0f) )) res->addItem(label, name, "/gui/screen1610.png"); else if (ABOUT_EQUAL( ratio, (5.0f/3.0f) )) res->addItem(label, name, "/gui/screen53.png"); else if (ABOUT_EQUAL( ratio, (3.0f/2.0f) )) res->addItem(label, name, "/gui/screen32.png"); else if (ABOUT_EQUAL( ratio, (16.0f/9.0f) )) res->addItem(label, name, "/gui/screen169.png"); else res->addItem(label, name, "/gui/screen_other.png"); #undef ABOUT_EQUAL } #ifdef DEBUG if (!found_800_600) { res->addItem(L"800\u00D7600", "800x600", "/gui/screen43.png"); } #endif if (!found_1024_640) { res->addItem(L"1024\u00D7640", "1024x640", "/gui/screen1610.png"); } if (!found_1024_768) { res->addItem(L"1024\u00D7768", "1024x768", "/gui/screen43.png"); } } // end if not inited res->updateItemDisplay(); // ---- select current resolution every time char searching_for[32]; snprintf(searching_for, 32, "%ix%i", (int)UserConfigParams::m_width, (int)UserConfigParams::m_height); if (!res->setSelection(searching_for, PLAYER_ID_GAME_MASTER, false /* focus it */, true /* even if deactivated*/)) { Log::error("OptionsScreenVideo", "Cannot find resolution %s", searching_for); } // --- set gfx settings values updateGfxSlider(); // ---- forbid changing resolution or animation settings from in-game // (we need to disable them last because some items can't be edited when // disabled) if (StateManager::get()->getGameState() == GUIEngine::INGAME_MENU) { res->setDeactivated(); full->setDeactivated(); applyBtn->setDeactivated(); gfx->setDeactivated(); getWidget<ButtonWidget>("custom")->setDeactivated(); } else { // Enable back widgets if they were visited in-game previously res->setActivated(); full->setActivated(); applyBtn->setActivated(); gfx->setActivated(); getWidget<ButtonWidget>("custom")->setActivated(); } } // init
void OptionsScreenUI::eventCallback(Widget* widget, const std::string& name, const int playerID) { if (name == "options_choice") { std::string selection = ((RibbonWidget*)widget)->getSelectionIDString(PLAYER_ID_GAME_MASTER).c_str(); if (selection == "tab_audio") StateManager::get()->replaceTopMostScreen(OptionsScreenAudio::getInstance()); else if (selection == "tab_video") StateManager::get()->replaceTopMostScreen(OptionsScreenVideo::getInstance()); else if (selection == "tab_players") StateManager::get()->replaceTopMostScreen(OptionsScreenPlayers::getInstance()); else if (selection == "tab_controls") StateManager::get()->replaceTopMostScreen(OptionsScreenInput::getInstance()); } else if(name == "back") { StateManager::get()->escapePressed(); } else if (name == "skinchoice") { GUIEngine::SpinnerWidget* skinSelector = getWidget<GUIEngine::SpinnerWidget>("skinchoice"); assert( skinSelector != NULL ); const core::stringw selectedSkin = skinSelector->getStringValue(); UserConfigParams::m_skin_file = core::stringc(selectedSkin.c_str()).c_str() + std::string(".stkskin"); GUIEngine::reloadSkin(); } else if (name == "showfps") { CheckBoxWidget* fps = getWidget<CheckBoxWidget>("showfps"); assert( fps != NULL ); UserConfigParams::m_display_fps = fps->getState(); } else if (name=="enable-internet") { CheckBoxWidget* internet = getWidget<CheckBoxWidget>("enable-internet"); assert( internet != NULL ); UserConfigParams::m_internet_status = internet->getState() ? RequestManager::IPERM_ALLOWED : RequestManager::IPERM_NOT_ALLOWED; // If internet gets enabled, re-initialise the addon manager (which // happens in a separate thread) so that news.xml etc can be // downloaded if necessary. if(internet->getState()) NewsManager::get()->init(false); } else if (name == "language") { ListWidget* list_widget = getWidget<ListWidget>("language"); std::string selection = list_widget->getSelectionInternalName(); delete translations; if (selection == "system") { #ifdef WIN32 _putenv("LANGUAGE="); #else unsetenv("LANGUAGE"); #endif } else { #ifdef WIN32 std::string s=std::string("LANGUAGE=")+selection.c_str(); _putenv(s.c_str()); #else setenv("LANGUAGE", selection.c_str(), 1); #endif } translations = new Translations(); GUIEngine::getStateManager()->hardResetAndGoToScreen<MainMenuScreen>(); GUIEngine::getFont()->updateRTL(); GUIEngine::getTitleFont()->updateRTL(); GUIEngine::getSmallFont()->updateRTL(); UserConfigParams::m_language = selection.c_str(); user_config->saveConfig(); GUIEngine::getStateManager()->pushScreen(OptionsScreenUI::getInstance()); } } // eventCallback