bool FavouriteModCollection::saveFavourites(const QString & fileName) { if(fileName.isEmpty()) { return false; } QByteArray fileNameBytes = fileName.toLocal8Bit(); return saveFavourites(fileNameBytes.data()); }
void FavouriteModCollection::uninit(bool saveFavouriteMods) { if(saveFavouriteMods) { saveFavourites(); } m_initialized = false; m_mods = NULL; clearFavourites(); }
bool GUIMultiplayerMenu::OnEvent(const SEvent& event) { if (event.EventType==EET_KEY_INPUT_EVENT) { if ( event.KeyInput.PressedDown && ( event.KeyInput.Key == KEY_ESCAPE || event.KeyInput.Key == KEY_RETURN ) ) { acceptInput(); quitMenu(); return true; } } if (event.EventType == EET_GUI_EVENT) { if (event.GUIEvent.EventType == gui::EGET_ELEMENT_FOCUS_LOST && isVisible()) { if (!canTakeFocus(event.GUIEvent.Element)) { dstream << "GUIMainMenu: Not allowing focus change." << std::endl; // Returning true disables focus change return true; } } if (event.GUIEvent.EventType==gui::EGET_CHECKBOX_CHANGED) { acceptInput(); m_accepted = false; regenerateGui(m_screensize); } if (event.GUIEvent.EventType == gui::EGET_BUTTON_CLICKED) { switch (event.GUIEvent.Caller->getID()) { case GUI_ID_START_BUTTON: // Start game acceptInput(); m_accepted = false; m_gamecallback->startGame(); quitMenu(); return true; case GUI_ID_CONNECT_BUTTON: acceptInput(); m_data.selected_tab = TAB_MP_CONNECT; regenerateGui(m_screensize); return true; case GUI_ID_REMFAV_BUTTON: acceptInput(); if (m_data.selected_row > -1) { if (m_data.selected_tab == TAB_MP_LIST) { ServerInfo &info = m_data.servers.at(m_data.selected_row); if (info.is_favourite) { info.is_favourite = false; for ( std::vector<ServerInfo>::iterator i = m_data.favourites.begin(); i != m_data.favourites.end(); i++ ) { if ( i->name == info.name && i->addr == info.addr && i->mode == info.mode ) { m_data.favourites.erase(i); break; } } saveFavourites(); } }else if (m_data.selected_tab == TAB_MP_FAVOURITES) { ServerInfo &info = m_data.favourites.at(m_data.selected_row); if (info.is_favourite) { m_data.favourites.erase(m_data.favourites.begin()+m_data.selected_row); for ( std::vector<ServerInfo>::iterator i = m_data.servers.begin(); i != m_data.servers.end(); i++ ) { if ( i->name == info.name && i->addr == info.addr && i->mode == info.mode ) { i->is_favourite = false; break; } } saveFavourites(); m_data.selected_row = -1; } } } regenerateGui(m_screensize); return true; case GUI_ID_ADDFAV_BUTTON: acceptInput(); if (m_data.selected_tab == TAB_MP_LIST && m_data.selected_row > -1) { ServerInfo &info = m_data.servers.at(m_data.selected_row); if (info.name != L"" && !info.is_favourite) { info.is_favourite = true; m_data.favourites.push_back(info); saveFavourites(); } }else if (m_data.selected_tab == TAB_MP_CUSTOM) { ServerInfo info; info.name = m_data.mmdata->address+L":"+m_data.mmdata->port; info.addr = m_data.mmdata->address+L":"+m_data.mmdata->port; info.mode = L"custom"; info.is_favourite = true; m_data.servers.push_back(info); m_data.favourites.push_back(info); m_data.selected_tab = TAB_MP_FAVOURITES; m_data.selected_row = m_data.favourites.size()-1; } regenerateGui(m_screensize); return true; case GUI_ID_REFRESH_BUTTON: acceptInput(); fetchServers(); if ( ( m_data.selected_tab == TAB_MP_LIST && m_data.selected_row >= (int)m_data.servers.size() ) || ( m_data.selected_tab == TAB_MP_FAVOURITES && m_data.selected_row >= (int)m_data.favourites.size() ) ) { m_data.selected_row = -1; } regenerateGui(m_screensize); return true; case GUI_ID_TAB_MP_LIST: acceptInput(); m_accepted = false; if (m_data.selected_tab != TAB_MP_LIST) { m_data.selected_tab = TAB_MP_LIST; m_data.selected_row = -1; } regenerateGui(m_screensize); return true; case GUI_ID_TAB_MP_FAVOURITES: acceptInput(); m_accepted = false; if (m_data.selected_tab != TAB_MP_FAVOURITES) { m_data.selected_tab = TAB_MP_FAVOURITES; m_data.selected_row = -1; } regenerateGui(m_screensize); return true; case GUI_ID_TAB_MP_CUSTOM: acceptInput(); m_accepted = false; m_data.selected_tab = TAB_MP_CUSTOM; regenerateGui(m_screensize); return true; case GUI_ID_TAB_MP_MAINMENU: //back acceptInput(); quitMenu(); return true; } } if (event.GUIEvent.EventType == gui::EGET_EDITBOX_ENTER) { switch (event.GUIEvent.Caller->getID()) { case GUI_ID_ADDRESS_INPUT: case GUI_ID_PORT_INPUT: case GUI_ID_NAME_INPUT: case GUI_ID_PW_INPUT: m_gamecallback->startGame(); acceptInput(); quitMenu(); return true; } } if ( event.GUIEvent.EventType == gui::EGET_LISTBOX_CHANGED || event.GUIEvent.EventType == gui::EGET_LISTBOX_SELECTED_AGAIN ) { if (event.GUIEvent.Caller->getID() == GUI_ID_SERVER_LIST) { acceptInput(); regenerateGui(m_screensize); return true; } } } return Parent ? Parent->OnEvent(event) : false; }
bool FavouriteModCollection::saveFavourites() { return saveFavourites(SettingsManager::getInstance()->favouritesListFileName); }