/** Write settings to config file. */ void UserConfig::saveConfig() { const std::string filename = file_manager->getUserConfigFile(m_filename); try { std::ofstream configfile (filename.c_str(), std::ofstream::out); configfile << "<?xml version=\"1.0\"?>\n"; configfile << "<stkconfig version=\"" << m_current_config_version << "\" >\n\n"; const int paramAmount = all_params.size(); for(int i=0; i<paramAmount; i++) { //Log::info("UserConfig", "Saving parameter %d to file", i); all_params[i].write(configfile); } configfile << "</stkconfig>\n"; configfile.close(); } catch (std::runtime_error& e) { Log::error("UserConfig::saveConfig", "Failed to write config to %s, because %s", filename.c_str(), e.what()); } } // saveConfig
/** Write settings to config file. */ void UserConfig::saveConfig() { const std::string filename = file_manager->getUserConfigFile(m_filename); try { std::ofstream configfile (filename.c_str(), std::ofstream::out); configfile << "<?xml version=\"1.0\"?>\n"; configfile << "<stkconfig version=\"" << m_current_config_version << "\" >\n\n"; const int paramAmount = all_params.size(); for(int i=0; i<paramAmount; i++) { //std::cout << "saving parameter " << i << " to file\n"; all_params[i].write(configfile); } configfile << "</stkconfig>\n"; configfile.close(); } catch (std::runtime_error& e) { std::cerr << "[UserConfig::saveConfig] ERROR: Failed to write config to " << filename.c_str() << "; cause : " << e.what() << "\n"; } } // saveConfig
/** Rebuild the list of tracks and GPs. This need to be recomputed e.g. to * take unlocked tracks into account. */ void TracksScreen::buildTrackList() { DynamicRibbonWidget* tracks_widget = this->getWidget<DynamicRibbonWidget>("tracks"); RibbonWidget* tabs = this->getWidget<RibbonWidget>("trackgroups"); // Reset track list everytime (accounts for locking changes, etc.) tracks_widget->clearItems(); m_random_track_list.clear(); const std::string& curr_group_name = tabs->getSelectionIDString(0); const int track_amount = (int)track_manager->getNumberOfTracks(); // First build a list of all tracks to be displayed // (e.g. exclude arenas, ...) PtrVector<Track, REF> tracks; for (int n = 0; n < track_amount; n++) { Track* curr = track_manager->getTrack(n); if (race_manager->getMinorMode() == RaceManager::MINOR_MODE_EASTER_EGG && !curr->hasEasterEggs()) continue; if (curr->isArena() || curr->isSoccer()||curr->isInternal()) continue; if (curr_group_name != ALL_TRACK_GROUPS_ID && !curr->isInGroup(curr_group_name)) continue; tracks.push_back(curr); } // for n<track_amount tracks.insertionSort(); for (unsigned int i = 0; i < tracks.size(); i++) { Track *curr = tracks.get(i); if (PlayerManager::getCurrentPlayer()->isLocked(curr->getIdent())) { tracks_widget->addItem( _("Locked : solve active challenges to gain access to more!"), "locked", curr->getScreenshotFile(), LOCKED_BADGE, IconButtonWidget::ICON_PATH_TYPE_ABSOLUTE); } else { tracks_widget->addItem(translations->fribidize(curr->getName()), curr->getIdent(), curr->getScreenshotFile(), 0, IconButtonWidget::ICON_PATH_TYPE_ABSOLUTE); m_random_track_list.push_back(curr->getIdent()); } } tracks_widget->addItem(_("Random Track"), "random_track", "/gui/track_random.png", 0 /* no badge */, IconButtonWidget::ICON_PATH_TYPE_RELATIVE); tracks_widget->updateItemDisplay(); std::random_shuffle( m_random_track_list.begin(), m_random_track_list.end() ); } // buildTrackList
virtual bool OnEvent(const SEvent& event) { bool out = CGUIEditBox::OnEvent(event); if (event.EventType == EET_KEY_INPUT_EVENT && event.KeyInput.PressedDown) { for (unsigned int n=0; n<m_listeners.size(); n++) { m_listeners[n].onTextUpdated(); } } return out; }
/** This function adds a list of widgets recursively, effectively creating the hierarchy * of widgets. * \param widgets The vector of widgets to add * \param parent The parent widget of the vector of widgets */ void AbstractTopLevelContainer::addWidgetsRecursively( PtrVector<Widget>& widgets, Widget* parent) { const unsigned short widgets_amount = widgets.size(); // ------- add widgets for (int n=0; n<widgets_amount; n++) { if (widgets[n].getType() == WTYPE_DIV) { widgets[n].add(); // Will do nothing, but will maybe reserve an ID addWidgetsRecursively(widgets[n].m_children, &widgets[n]); } else { // warn if widget has no dimensions (except for ribbons and icons, // where it is normal since it adjusts to its contents) if ((widgets[n].m_w < 1 || widgets[n].m_h < 1) && widgets[n].getType() != WTYPE_RIBBON && widgets[n].getType() != WTYPE_ICON_BUTTON && widgets[n].getType() != WTYPE_SPACER) { Log::warn("AbstractTopLevelContainer::addWidgetsRecursively", "Widget %s of type %d has no dimensions", widgets[n].m_properties[PROP_ID].c_str(), widgets[n].getType()); } if (widgets[n].m_x == -1 || widgets[n].m_y == -1) { Log::warn("AbstractTopLevelContainer::addWidgetsRecursively", "Widget %s of type %d has no position", widgets[n].m_properties[PROP_ID].c_str(), widgets[n].getType()); } widgets[n].add(); } } // for n in all widgets } // addWidgetsRecursively
/** Load configuration values from file. */ bool UserConfig::loadConfig() { const std::string filename = file_manager->getUserConfigFile(m_filename); XMLNode* root = file_manager->createXMLTree(filename); if(!root || root->getName() != "stkconfig") { Log::error("UserConfig", "Could not read user config file '%s'.", filename.c_str()); if(root) delete root; // Create a default config file - just in case that stk crashes later // there is a config file that can be modified (to e.g. disable // shaders) saveConfig(); return false; } // ---- Read config file version int config_file_version = m_current_config_version; if(root->get("version", &config_file_version) < 1) { GUIEngine::showMessage( _("Your config file was malformed, so it was deleted and a new one will be created."), 10.0f); Log::error("UserConfig", "Warning, malformed user config file! Contains no version"); } if (config_file_version < m_current_config_version) { // current version (8) is 100% incompatible with other versions (which were lisp) // so we just delete the old config. in the future, for smaller updates, we can // add back the code previously there that upgraded the config file to the new // format instead of overwriting it. GUIEngine::showMessage(_("Your config file was too old, so it was deleted and a new one will be created."), 10.0f); Log::info("UserConfig", "Your config file was too old, so it was deleted and a new one will be created."); delete root; return false; } // if configFileVersion<SUPPORTED_CONFIG_VERSION // ---- Read parameters values (all parameter objects must have been created before this point if // you want them automatically read from the config file) const int paramAmount = all_params.size(); for(int i=0; i<paramAmount; i++) { all_params[i].findYourDataInAChildOf(root); } // ---- Read Saved GP's UserConfigParams::m_saved_grand_prix_list.clearAndDeleteAll(); std::vector<XMLNode*> saved_gps; root->getNodes("SavedGP", saved_gps); const int gp_amount = saved_gps.size(); for (int i=0; i<gp_amount; i++) { UserConfigParams::m_saved_grand_prix_list.push_back( new SavedGrandPrix( saved_gps[i]) ); } delete root; return true; } // loadConfig
int getKeyboardConfigAmount() const { return m_keyboard_configs.size(); }
int getKeyboardAmount() { return m_keyboards.size(); }
int getGamePadConfigAmount() const { return m_gamepad_configs.size(); }
int getGamePadAmount() const { return m_gamepads.size(); }
/** Returns the total number of karts of this GP. */ int getTotalKarts() const { return m_karts.size(); }
void KartSelectionScreen::setKartsFromCurrentGroup() { RibbonWidget* tabs = getWidget<RibbonWidget>("kartgroups"); assert(tabs != NULL); std::string selected_kart_group = tabs->getSelectionIDString(PLAYER_ID_GAME_MASTER); UserConfigParams::m_last_used_kart_group = selected_kart_group; // This can happen if addons are removed so that also the previously // selected kart group is removed. In this case, select the // 'standard' group if (selected_kart_group != ALL_KART_GROUPS_ID && !kart_properties_manager->getKartsInGroup(selected_kart_group).size()) { selected_kart_group = DEFAULT_GROUP_NAME; } DynamicRibbonWidget* w = getWidget<DynamicRibbonWidget>("karts"); w->clearItems(); int usable_kart_count = 0; PtrVector<const KartProperties, REF> karts; for(unsigned int i=0; i<kart_properties_manager->getNumberOfKarts(); i++) { const KartProperties* prop = kart_properties_manager->getKartById(i); // Ignore karts that are not in the selected group if(selected_kart_group != ALL_KART_GROUPS_ID && !prop->isInGroup(selected_kart_group)) continue; karts.push_back(prop); } karts.insertionSort(); for(unsigned int i=0; i<karts.size(); i++) { const KartProperties* prop = karts.get(i); if (PlayerManager::getCurrentPlayer()->isLocked(prop->getIdent()) && !m_multiplayer) { w->addItem(_("Locked : solve active challenges to gain access to more!"), ID_LOCKED + prop->getIdent(), prop->getAbsoluteIconFile(), LOCKED_BADGE, IconButtonWidget::ICON_PATH_TYPE_ABSOLUTE); } else { w->addItem(translations->fribidize(prop->getName()), prop->getIdent(), prop->getAbsoluteIconFile(), 0, IconButtonWidget::ICON_PATH_TYPE_ABSOLUTE); usable_kart_count++; } } // add random if (usable_kart_count > 1) { w->addItem(_("Random Kart"), RANDOM_KART_ID, "/gui/random_kart.png"); } w->updateItemDisplay(); }
/** Returns the number of players in the config file.*/ unsigned int getNumPlayers() const { return m_all_players.size(); }
void ModelViewWidget::setupRTTScene(PtrVector<scene::IMesh, REF>& mesh, AlignedArray<Vec3>& mesh_location, AlignedArray<Vec3>& mesh_scale, const std::vector<int>& model_frames) { irr_driver->suppressSkyBox(); if (m_rtt_main_node != NULL) m_rtt_main_node->remove(); if (m_light != NULL) m_light->remove(); if (m_camera != NULL) m_camera->remove(); m_rtt_main_node = NULL; m_camera = NULL; m_light = NULL; irr_driver->clearLights(); if (model_frames[0] == -1) { scene::ISceneNode* node = irr_driver->addMesh(mesh.get(0), "rtt_mesh", NULL); node->setPosition(mesh_location[0].toIrrVector()); node->setScale(mesh_scale[0].toIrrVector()); node->setMaterialFlag(video::EMF_FOG_ENABLE, false); m_rtt_main_node = node; } else { scene::IAnimatedMeshSceneNode* node = irr_driver->addAnimatedMesh((scene::IAnimatedMesh*)mesh.get(0), "rtt_mesh", NULL); node->setPosition(mesh_location[0].toIrrVector()); node->setFrameLoop(model_frames[0], model_frames[0]); node->setAnimationSpeed(0); node->setScale(mesh_scale[0].toIrrVector()); node->setMaterialFlag(video::EMF_FOG_ENABLE, false); m_rtt_main_node = node; } assert(m_rtt_main_node != NULL); assert(mesh.size() == mesh_location.size()); assert(mesh.size() == model_frames.size()); const int mesh_amount = mesh.size(); for (int n = 1; n<mesh_amount; n++) { if (model_frames[n] == -1) { scene::ISceneNode* node = irr_driver->addMesh(mesh.get(n), "rtt_node", m_rtt_main_node); node->setPosition(mesh_location[n].toIrrVector()); node->updateAbsolutePosition(); node->setScale(mesh_scale[n].toIrrVector()); } else { scene::IAnimatedMeshSceneNode* node = irr_driver->addAnimatedMesh((scene::IAnimatedMesh*)mesh.get(n), "modelviewrtt", m_rtt_main_node); node->setPosition(mesh_location[n].toIrrVector()); node->setFrameLoop(model_frames[n], model_frames[n]); node->setAnimationSpeed(0); node->updateAbsolutePosition(); node->setScale(mesh_scale[n].toIrrVector()); //Log::info("ModelViewWidget", "Set frame %d", model_frames[n]); } } irr_driver->getSceneManager()->setAmbientLight(video::SColor(255, 35, 35, 35)); const core::vector3df &spot_pos = core::vector3df(0, 30, 40); m_light = irr_driver->addLight(spot_pos, 0.3f /* energy */, 10 /* distance */, 1.0f /* r */, 1.0f /* g */, 1.0f /* g*/, true, NULL); m_rtt_main_node->setMaterialFlag(video::EMF_GOURAUD_SHADING, true); m_rtt_main_node->setMaterialFlag(video::EMF_LIGHTING, true); const int materials = m_rtt_main_node->getMaterialCount(); for (int n = 0; n<materials; n++) { m_rtt_main_node->getMaterial(n).setFlag(video::EMF_LIGHTING, true); // set size of specular highlights m_rtt_main_node->getMaterial(n).Shininess = 100.0f; m_rtt_main_node->getMaterial(n).SpecularColor.set(255, 50, 50, 50); m_rtt_main_node->getMaterial(n).DiffuseColor.set(255, 150, 150, 150); m_rtt_main_node->getMaterial(n).setFlag(video::EMF_GOURAUD_SHADING, true); } m_camera = irr_driver->getSceneManager()->addCameraSceneNode(); m_camera->setAspectRatio(1.0f); m_camera->setPosition(core::vector3df(0.0, 20.0f, 70.0f)); m_camera->setUpVector(core::vector3df(0.0, 1.0, 0.0)); m_camera->setTarget(core::vector3df(0, 10, 0.0f)); m_camera->setFOV(DEGREE_TO_RAD*50.0f); m_camera->updateAbsolutePosition(); }
void Screen::parseScreenFileDiv(irr::io::IXMLReader* xml, PtrVector<Widget>& append_to, irr::gui::IGUIElement* parent) { // parse XML file while (xml && xml->read()) { switch (xml->getNodeType()) { case irr::io::EXN_TEXT: { break; } case irr::io::EXN_ELEMENT: { /* find which type of widget is specified by the current tag, and instanciate it */ if (wcscmp(L"div", xml->getNodeName()) == 0) { Widget* w = new Widget(WTYPE_DIV); append_to.push_back(w); } else if (wcscmp(L"stkgui", xml->getNodeName()) == 0) { // outer node that's there only to comply with XML standard (and expat) continue; } else if (wcscmp(L"placeholder", xml->getNodeName()) == 0) { Widget* w = new Widget(WTYPE_DIV, true); append_to.push_back(w); } else if (wcscmp(L"box", xml->getNodeName()) == 0) { Widget* w = new Widget(WTYPE_DIV); w->m_show_bounding_box = true; append_to.push_back(w); } else if (wcscmp(L"bottombar", xml->getNodeName()) == 0) { Widget* w = new Widget(WTYPE_DIV); w->m_bottom_bar = true; append_to.push_back(w); } else if (wcscmp(L"topbar", xml->getNodeName()) == 0) { Widget* w = new Widget(WTYPE_DIV); w->m_top_bar = true; append_to.push_back(w); } else if (wcscmp(L"roundedbox", xml->getNodeName()) == 0) { Widget* w = new Widget(WTYPE_DIV); w->m_show_bounding_box = true; w->m_is_bounding_box_round = true; append_to.push_back(w); } else if (wcscmp(L"ribbon", xml->getNodeName()) == 0) { append_to.push_back(new RibbonWidget()); } else if (wcscmp(L"buttonbar", xml->getNodeName()) == 0) { append_to.push_back(new RibbonWidget(RIBBON_TOOLBAR)); } else if (wcscmp(L"tabs", xml->getNodeName()) == 0) { append_to.push_back(new RibbonWidget(RIBBON_TABS)); } else if (wcscmp(L"spinner", xml->getNodeName()) == 0) { append_to.push_back(new SpinnerWidget()); } else if (wcscmp(L"button", xml->getNodeName()) == 0) { append_to.push_back(new ButtonWidget()); } else if (wcscmp(L"gauge", xml->getNodeName()) == 0) { append_to.push_back(new SpinnerWidget(true)); } else if (wcscmp(L"progressbar", xml->getNodeName()) == 0) { append_to.push_back(new ProgressBarWidget()); } else if (wcscmp(L"icon-button", xml->getNodeName()) == 0) { append_to.push_back(new IconButtonWidget()); } else if (wcscmp(L"icon", xml->getNodeName()) == 0) { append_to.push_back(new IconButtonWidget(IconButtonWidget::SCALE_MODE_KEEP_TEXTURE_ASPECT_RATIO, false, false)); } else if (wcscmp(L"checkbox", xml->getNodeName()) == 0) { append_to.push_back(new CheckBoxWidget()); } else if (wcscmp(L"label", xml->getNodeName()) == 0) { append_to.push_back(new LabelWidget()); } else if (wcscmp(L"bright", xml->getNodeName()) == 0) { append_to.push_back(new LabelWidget(false, true)); } else if (wcscmp(L"bubble", xml->getNodeName()) == 0) { append_to.push_back(new BubbleWidget()); } else if (wcscmp(L"header", xml->getNodeName()) == 0) { append_to.push_back(new LabelWidget(true)); } else if (wcscmp(L"spacer", xml->getNodeName()) == 0) { append_to.push_back(new Widget(WTYPE_SPACER)); } else if (wcscmp(L"ribbon_grid", xml->getNodeName()) == 0) { append_to.push_back(new DynamicRibbonWidget(false /* combo */, true /* multi-row */)); } else if (wcscmp(L"scrollable_ribbon", xml->getNodeName()) == 0) { append_to.push_back(new DynamicRibbonWidget(true /* combo */, false /* multi-row */)); } else if (wcscmp(L"scrollable_toolbar", xml->getNodeName()) == 0) { append_to.push_back(new DynamicRibbonWidget(false /* combo */, false /* multi-row */)); } else if (wcscmp(L"model", xml->getNodeName()) == 0) { append_to.push_back(new ModelViewWidget()); } else if (wcscmp(L"list", xml->getNodeName()) == 0) { append_to.push_back(new ListWidget()); } else if (wcscmp(L"textbox", xml->getNodeName()) == 0) { append_to.push_back(new TextBoxWidget()); } else { std::cerr << "/!\\ Warning /!\\ : unknown tag found in STK GUI file : '" << xml->getNodeName() << "'" << std::endl; continue; } /* retrieve the created widget */ Widget& widget = append_to[append_to.size()-1]; /* read widget properties using macro magic */ #define READ_PROPERTY( prop_name, prop_flag ) const wchar_t* prop_name = xml->getAttributeValue( L###prop_name ); \ if(prop_name != NULL) widget.m_properties[prop_flag] = core::stringc(prop_name).c_str(); else widget.m_properties[prop_flag] = "" READ_PROPERTY(id, PROP_ID); READ_PROPERTY(proportion, PROP_PROPORTION); READ_PROPERTY(width, PROP_WIDTH); READ_PROPERTY(height, PROP_HEIGHT); READ_PROPERTY(child_width, PROP_CHILD_WIDTH); READ_PROPERTY(child_height, PROP_CHILD_HEIGHT); READ_PROPERTY(word_wrap, PROP_WORD_WRAP); //READ_PROPERTY(grow_with_text, PROP_GROW_WITH_TEXT); READ_PROPERTY(x, PROP_X); READ_PROPERTY(y, PROP_Y); READ_PROPERTY(layout, PROP_LAYOUT); READ_PROPERTY(align, PROP_ALIGN); READ_PROPERTY(icon, PROP_ICON); READ_PROPERTY(focus_icon, PROP_FOCUS_ICON); READ_PROPERTY(text_align, PROP_TEXT_ALIGN); READ_PROPERTY(min_value, PROP_MIN_VALUE); READ_PROPERTY(max_value, PROP_MAX_VALUE); READ_PROPERTY(square_items, PROP_SQUARE); READ_PROPERTY(max_width, PROP_MAX_WIDTH); READ_PROPERTY(max_height, PROP_MAX_HEIGHT); READ_PROPERTY(extend_label, PROP_EXTEND_LABEL); READ_PROPERTY(label_location, PROP_LABELS_LOCATION); READ_PROPERTY(max_rows, PROP_MAX_ROWS); READ_PROPERTY(wrap_around, PROP_WRAP_AROUND); #undef READ_PROPERTY const wchar_t* text = xml->getAttributeValue( L"text" ); if (text != NULL) { widget.m_text = _(text); widget.m_is_text_rtl = (translations->isRTLLanguage() && widget.m_text != text); } if (parent != NULL) { widget.setParent(parent); } /* a new div starts here, continue parsing with this new div as new parent */ if (widget.getType() == WTYPE_DIV || widget.getType() == WTYPE_RIBBON) { parseScreenFileDiv( xml, append_to[append_to.size()-1].m_children, parent ); } }// end case EXN_ELEMENT break; case irr::io::EXN_ELEMENT_END: { // we're done parsing this 'div', return one step back in the recursive call if (wcscmp(L"div", xml->getNodeName()) == 0) return; if (wcscmp(L"box", xml->getNodeName()) == 0) return; if (wcscmp(L"placeholder", xml->getNodeName()) == 0) return; if (wcscmp(L"roundedbox", xml->getNodeName()) == 0) return; if (wcscmp(L"bottombar", xml->getNodeName()) == 0) return; if (wcscmp(L"topbar", xml->getNodeName()) == 0) return; // We're done parsing this 'ribbon', return one step back in // the recursive call. if (wcscmp(L"ribbon", xml->getNodeName()) == 0 || wcscmp(L"buttonbar", xml->getNodeName()) == 0 || wcscmp(L"tabs", xml->getNodeName()) == 0) return; } break; default: break; }//end switch } // end while } // end function