void updateDate() { std::ostringstream dateText; int day = total_time % NUMOF_DAYS_IN_MONTH +1; // 1..NUMOF_DAYS_IN_MONTH day = 1 + ( 29 * day / NUMOF_DAYS_IN_MONTH ); // 1..30 dateText << day << ". "; dateText << current_month( total_time ); dateText << " "<< current_year( total_time ); Component* root = getGameView(); if( !root ) return; while( root->getParent() ) root = root->getParent(); if( dateText.str() == lastDateText ){ return; } Component* dateParagraphComponent = 0; dateParagraphComponent = root->findComponent( "dateParagraph" ); if( dateParagraphComponent == 0 ) { return;} Paragraph* dateParagraph = getParagraph( *root, "dateParagraph"); if( !dateParagraph ) { return;} dateParagraph->setText( dateText.str() ); lastDateText = dateText.str(); }
void Dialog::askRocket(){ if( !desktop ) { std::cerr << "No desktop found.\n"; return; } try { myDialogComponent = loadGUIFile( "gui/launch_rocket_yn.xml" ); assert( myDialogComponent != 0); registerDialog(); blockingDialogIsOpen = true; iAmBlocking = true; } catch(std::exception& e) { std::cerr << "Couldn't display message 'launch_rocket_yn': " << e.what() << "\n"; return; } Paragraph* p = getParagraph( *myDialogComponent, "DialogTitle" ); std::stringstream title; title << _("Launchsite") << " ( " << pointX <<" , " << pointY << " )"; p->setText( title.str() ); // connect signals Button* yesButton = getButton( *myDialogComponent, "Yes" ); yesButton->clicked.connect( makeCallback(*this, &Dialog::okayLaunchRocketButtonClicked ) ); Button* noButton = getButton( *myDialogComponent, "No" ); noButton->clicked.connect( makeCallback( *this, &Dialog::closeDialogButtonClicked ) ); Button* gotoButton = getButton( *myDialogComponent, "goto" ); gotoButton->clicked.connect( makeCallback( *this, &Dialog::gotoButtonClicked ) ); }
/* * Update Message in Message Window */ void updateMessageText( const std::string text ) { //Dialog Test Component* root = getGameView(); if(!root) { //happens while in menu. std::cerr << "Root not found.\n"; return; } while( root->getParent() ) root = root->getParent(); Desktop* desktop = dynamic_cast<Desktop*> (root); if(!desktop) { std::cerr << "Root not a desktop!?!\n"; return; } try { //test if message Windows is open Component* messageTextComponent = 0; messageTextComponent = root->findComponent( "messageText" ); if(messageTextComponent == 0) { messageTextComponent = loadGUIFile("gui/messagearea.xml"); assert(messageTextComponent != 0); desktop->addChildComponent(messageTextComponent); } Paragraph* messageText = getParagraph(*messageTextComponent, "messageText"); messageText->setText( text ); } catch(std::exception& e) { std::cerr << "Couldn't display message '" << text << "': " << e.what() << "\n"; return; } }
void Dialog::editMarket(){ if( !desktop ) { std::cerr << "No desktop found.\n"; return; } try { myDialogComponent = loadGUIFile( "gui/tradedialog.xml" ); assert( myDialogComponent != 0); registerDialog(); blockingDialogIsOpen = true; iAmBlocking = true; } catch(std::exception& e) { std::cerr << "Couldn't display dialog 'tradedialog.xml': " << e.what() << "\n"; return; } // set Dialog to Market-Data Paragraph* p = getParagraph( *myDialogComponent, "DialogTitle" ); std::stringstream title; title << _("Market") << " ( " << pointX <<" , " << pointY << " )"; p->setText( title.str() ); Market * market = static_cast <Market *> (world(pointX, pointY)->reportingConstruction); CheckButton* cb; cb = getCheckButton( *myDialogComponent, "BuyJobs" ); if( market->commodityRuleCount[Construction::STUFF_JOBS].take ) cb->check(); else cb->uncheck(); cb = getCheckButton( *myDialogComponent, "SellJobs" ); if( market->commodityRuleCount[Construction::STUFF_JOBS].give ) cb->check(); else cb->uncheck(); cb = getCheckButton( *myDialogComponent, "BuyFood" ); if( market->commodityRuleCount[Construction::STUFF_FOOD].take ) cb->check(); else cb->uncheck(); cb = getCheckButton( *myDialogComponent, "SellFood" ); if( market->commodityRuleCount[Construction::STUFF_FOOD].give ) cb->check(); else cb->uncheck(); cb = getCheckButton( *myDialogComponent, "BuyCoal" ); if( market->commodityRuleCount[Construction::STUFF_COAL].take ) cb->check(); else cb->uncheck(); cb = getCheckButton( *myDialogComponent, "SellCoal" ); if( market->commodityRuleCount[Construction::STUFF_COAL].give ) cb->check(); else cb->uncheck(); cb = getCheckButton( *myDialogComponent, "BuyOre" ); if( market->commodityRuleCount[Construction::STUFF_ORE].take ) cb->check(); else cb->uncheck(); cb = getCheckButton( *myDialogComponent, "SellOre" ); if( market->commodityRuleCount[Construction::STUFF_ORE].give ) cb->check(); else cb->uncheck(); cb = getCheckButton( *myDialogComponent, "BuyGoods" ); if( market->commodityRuleCount[Construction::STUFF_GOODS].take ) cb->check(); else cb->uncheck(); cb = getCheckButton( *myDialogComponent, "SellGoods" ); if( market->commodityRuleCount[Construction::STUFF_GOODS].give ) cb->check(); else cb->uncheck(); cb = getCheckButton( *myDialogComponent, "BuySteel" ); if( market->commodityRuleCount[Construction::STUFF_STEEL].take ) cb->check(); else cb->uncheck(); cb = getCheckButton( *myDialogComponent, "SellSteel" ); if( market->commodityRuleCount[Construction::STUFF_STEEL].give) cb->check(); else cb->uncheck(); cb = getCheckButton( *myDialogComponent, "BuyWaste" ); if( market->commodityRuleCount[Construction::STUFF_WASTE].take ) cb->check(); else cb->uncheck(); cb = getCheckButton( *myDialogComponent, "SellWaste" ); if( market->commodityRuleCount[Construction::STUFF_WASTE].give) cb->check(); else cb->uncheck(); // connect signals Button* applyButton = getButton( *myDialogComponent, "Apply" ); applyButton->clicked.connect( makeCallback(*this, &Dialog::applyMarketButtonClicked ) ); Button* gotoButton = getButton( *myDialogComponent, "goto" ); gotoButton->clicked.connect( makeCallback( *this, &Dialog::gotoButtonClicked ) ); }
void Dialog::setParagraph( const std::string paragraphName, const std::string text ){ Paragraph* p; try{ p = getParagraph( *myDialogComponent, paragraphName ); p->setText( text ); } catch(std::exception& e) { std::cerr << "Couldn't set " << paragraphName << " to '" << text << "': " << e.what() << "\n"; } }
void MainMenu::changeWorldLen(bool next) { std::ostringstream os; int new_len; new_len = world.len()+(next?25:-25); world.len(new_len); os << world.len(); getParagraph( *optionsMenu, "WorldLenParagraph")->setText(os.str()); }
void Dialog::editMarket(){ if( !desktop ) { std::cerr << "No desktop found.\n"; return; } try { myDialogComponent = loadGUIFile( "gui/tradedialog.xml" ); assert( myDialogComponent != 0); registerDialog(); blockingDialogIsOpen = true; iAmBlocking = true; } catch(std::exception& e) { std::cerr << "Couldn't display dialog 'tradedialog.xml': " << e.what() << "\n"; return; } // set Dialog to Market-Data Paragraph* p = getParagraph( *myDialogComponent, "DialogTitle" ); std::stringstream title; title << _("Market") << " ( " << pointX <<" , " << pointY << " )"; p->setText( title.str() ); CheckButton* cb; cb = getCheckButton( *myDialogComponent, "BuyJobs" ); if( MP_INFO( pointX,pointY ).flags & FLAG_MB_JOBS ) cb->check(); else cb->uncheck(); cb = getCheckButton( *myDialogComponent, "SellJobs" ); if( MP_INFO( pointX,pointY ).flags & FLAG_MS_JOBS ) cb->check(); else cb->uncheck(); cb = getCheckButton( *myDialogComponent, "BuyFood" ); if( MP_INFO( pointX,pointY ).flags & FLAG_MB_FOOD) cb->check(); else cb->uncheck(); cb = getCheckButton( *myDialogComponent, "SellFood" ); if( MP_INFO( pointX,pointY ).flags & FLAG_MS_FOOD) cb->check(); else cb->uncheck(); cb = getCheckButton( *myDialogComponent, "BuyCoal" ); if( MP_INFO( pointX,pointY ).flags & FLAG_MB_COAL) cb->check(); else cb->uncheck(); cb = getCheckButton( *myDialogComponent, "SellCoal" ); if( MP_INFO( pointX,pointY ).flags & FLAG_MS_COAL) cb->check(); else cb->uncheck(); cb = getCheckButton( *myDialogComponent, "BuyOre" ); if( MP_INFO( pointX,pointY ).flags & FLAG_MB_ORE) cb->check(); else cb->uncheck(); cb = getCheckButton( *myDialogComponent, "SellOre" ); if( MP_INFO( pointX,pointY ).flags & FLAG_MS_ORE) cb->check(); else cb->uncheck(); cb = getCheckButton( *myDialogComponent, "BuyGoods" ); if( MP_INFO( pointX,pointY ).flags & FLAG_MB_GOODS) cb->check(); else cb->uncheck(); cb = getCheckButton( *myDialogComponent, "SellGoods" ); if( MP_INFO( pointX,pointY ).flags & FLAG_MS_GOODS) cb->check(); else cb->uncheck(); cb = getCheckButton( *myDialogComponent, "BuySteel" ); if( MP_INFO( pointX,pointY ).flags & FLAG_MB_STEEL) cb->check(); else cb->uncheck(); cb = getCheckButton( *myDialogComponent, "SellSteel" ); if( MP_INFO( pointX,pointY ).flags & FLAG_MS_STEEL) cb->check(); else cb->uncheck(); // connect signals Button* applyButton = getButton( *myDialogComponent, "Apply" ); applyButton->clicked.connect( makeCallback(*this, &Dialog::applyMarketButtonClicked ) ); Button* gotoButton = getButton( *myDialogComponent, "goto" ); gotoButton->clicked.connect( makeCallback( *this, &Dialog::gotoButtonClicked ) ); }
static void formatFile( FILE *fp, int width, int offset ) { int ret; para p = { NULL, 0, 0, 0, 0 }; int oldos = 0; int erros = -1; wordlist *list = NULL; expandParagraph( &p, DEF_PARA_LEN ); for( ; ; ) { ret = getParagraph( fp, &p, &list ); if( ret & OUT_OF_MEM ) { if( erros != p.len ) { trimParagraph( &p ); erros = p.len; continue; } else if( p.len == 0 ) { Die( "fmt: out of memory error\n" ); } } if( p.len != 0 ) { if( p.indent <= oldos ) { // keep track of offsets & indents p.indent = oldos; // in case of out of mem. errors p.offset = oldos; } oldos = p.offset; formatParagraph( &p, width, offset, ret & OUT_OF_MEM ); } if( ret & END_LINE ) { // no need to format blank line fputchar( '\n' ); oldos = 0; } resetParagraph( &p ); resetWordlist( list ); if( ret & END_FILE ) { break; } erros = -1; } free( p.words ); // free the paragraph space freeWordlist( list ); // free the text space }
void updateMoney() { if( lastMoney == total_money ){ return; } //Prevent overflow if (total_money > 2000000000) total_money = 2000000000; else if (total_money < -2000000000) total_money = -2000000000; std::ostringstream moneyText; int money = total_money; if( abs(money) > 100000000 ){ moneyText << money/1000000 << _("M"); } else { if( abs(money) > 1000000 ){ moneyText << money/1000000 << " "; money %= 1000000; money = abs(money); moneyText << std::setw(6); moneyText << std::setfill('0'); } moneyText << money; } moneyText << _("$"); Component* root = getGameView(); if( !root ) return; while( root->getParent() ) root = root->getParent(); Component* moneyParagraphComponent = 0; moneyParagraphComponent = root->findComponent( "moneyParagraph" ); if( moneyParagraphComponent == 0 ) { return; } Paragraph* moneyParagraph = getParagraph( *root, "moneyParagraph"); if( !moneyParagraph ) return; moneyParagraph->setText( moneyText.str() ); lastMoney = total_money; }
//no Signals caught here, so ScreenInterface has to catch them. void Dialog::msgDialog( std::string message, std::string extraString){ if( !desktop ) { std::cerr << "No desktop found.\n"; return; } //generate filename. foo.mes => gui/foo.xml std::string filename = "gui/"; filename += message; std::string::size_type pos = filename.rfind( ".mes" ); if( pos != std::string::npos ){ filename.replace( pos, 4 ,".xml"); } std::auto_ptr<Component> myDialogComponent (loadGUIFile( filename )); //set Extra-String getParagraph( *myDialogComponent, "ExtraText" )->setText( extraString ); // connect signals Button* noButton = getButton( *myDialogComponent, "Ok" ); noButton->clicked.connect( makeCallback( *this, &Dialog::closeDialogButtonClicked ) ); this->myDialogComponent = myDialogComponent.release(); registerDialog(); }
// parse a .hpp file and generate corresponding PageData void parseFile(char *filename) { printf ("INFO : parsing file %s\n",filename); char *buf=loadTextFile(filename); if ( ! buf ) return; // now scan javadocs int fileOrder=1; char *ptr = strstr(buf,"/**"); while (ptr) { char *end = strstr(ptr,"*/"); if ( end ) { // parse the javadoc *end=0; char *directive = strchr(ptr,'@'); while ( directive ) { if ( startsWith(directive,"@PageName") ) { char *pageName=NULL; directive = getIdentifier(directive+sizeof("@PageName"),&pageName); curPage=getPage(pageName); curFunc=NULL; if(!curPage) { // non existing page. create a new one curPage=new PageData(); pages.push(curPage); curPage->filename = strdup(filename); curPage->fileOrder=fileOrder++; curPage->name=pageName; curFunc=NULL; } } else if ( startsWith(directive,"@PageTitle") ) { directive = getLineEnd(directive+sizeof("@PageTitle"),&curPage->title); } else if ( startsWith(directive,"@PageDesc") ) { directive = getParagraph(directive+sizeof("@PageDesc"),&curPage->desc); } else if ( startsWith(directive,"@PageFather") ) { directive = getIdentifier(directive+sizeof("@PageFather"),&curPage->fatherName); if ( strcmp(curPage->fatherName,curPage->name) == 0 ) { printf ("ERROR : file %s : page %s is its own father\n", filename, curPage->name); exit(1); } } else if ( startsWith(directive,"@PageCategory") ) { directive = getLineEnd(directive+sizeof("@PageCategory"),&curPage->categoryName); } else if ( startsWith(directive,"@FuncTitle") ) { curFunc=new FuncData(); curPage->funcs.push(curFunc); directive = getLineEnd(directive+sizeof("@FuncTitle"),&curFunc->title); } else if ( startsWith(directive,"@ColorTable") ) { directive += sizeof("@ColorTable"); curPage->colorTable=true; } else if ( startsWith(directive,"@ColorCategory") ) { Color col; directive=getLineEnd(directive+sizeof("@ColorCategory"),&col.name); col.category=true; colors.push(col); } else if ( startsWith(directive,"@Color") ) { Color col; directive=getIdentifier(directive+sizeof("@Color"),&col.name); sscanf(directive,"%d,%d,%d",&col.col.r,&col.col.g,&col.col.b); colors.push(col); while (! isspace(*directive)) directive++; } else if ( startsWith(directive,"@FuncDesc") ) { if (! curFunc ) { curFunc=new FuncData(); curPage->funcs.push(curFunc); } directive = getParagraph(directive+sizeof("@FuncDesc"),&curFunc->desc); } else if ( startsWith(directive,"@CppEx") ) { if (! curFunc ) { curFunc=new FuncData(); curPage->funcs.push(curFunc); } directive = getCodeParagraph(directive+sizeof("@CppEx")-1,&curFunc->cppEx); } else if ( startsWith(directive,"@C#Ex") ) { if (! curFunc ) { curFunc=new FuncData(); curPage->funcs.push(curFunc); } directive = getCodeParagraph(directive+sizeof("@C#Ex")-1,&curFunc->csEx); } else if ( startsWith(directive,"@CEx") ) { if (! curFunc ) { curFunc=new FuncData(); curPage->funcs.push(curFunc); } directive = getCodeParagraph(directive+sizeof("@CEx")-1,&curFunc->cEx); } else if ( startsWith(directive,"@PyEx") ) { if (! curFunc ) { curFunc=new FuncData(); curPage->funcs.push(curFunc); } directive = getCodeParagraph(directive+sizeof("@PyEx")-1,&curFunc->pyEx); } else if ( startsWith(directive,"@LuaEx") ) { if (! curFunc ) { curFunc=new FuncData(); curPage->funcs.push(curFunc); } directive = getCodeParagraph(directive+sizeof("@LuaEx")-1,&curFunc->luaEx); } else if ( startsWith(directive,"@Cpp") ) { if (! curFunc ) { curFunc=new FuncData(); curPage->funcs.push(curFunc); } directive = getCodeParagraph(directive+sizeof("@Cpp")-1,&curFunc->cpp); } else if ( startsWith(directive,"@C#") ) { if (! curFunc ) { curFunc=new FuncData(); curPage->funcs.push(curFunc); } directive = getCodeParagraph(directive+sizeof("@C#")-1,&curFunc->cs); } else if ( startsWith(directive,"@C") ) { if (! curFunc ) { curFunc=new FuncData(); curPage->funcs.push(curFunc); } directive = getCodeParagraph(directive+sizeof("@C")-1,&curFunc->c); } else if ( startsWith(directive,"@Py") ) { if (! curFunc ) { curFunc=new FuncData(); curPage->funcs.push(curFunc); } directive = getCodeParagraph(directive+sizeof("@Py")-1,&curFunc->py); } else if ( startsWith(directive,"@Lua") ) { if (! curFunc ) { curFunc=new FuncData(); curPage->funcs.push(curFunc); } directive = getCodeParagraph(directive+sizeof("@Lua")-1,&curFunc->lua); } else if ( startsWith(directive,"@Param") ) { ParamData *param=new ParamData(); curFunc->params.push(param); directive = getIdentifier(directive+sizeof("@Param"),¶m->name); directive = getParagraph(directive,¶m->desc); } else { char *tmp; directive = getIdentifier(directive,&tmp); printf ("WARN unknown directive '%s'\n",tmp); free(tmp); } directive = strchr(directive,'@'); } ptr=strstr(end+2,"/**"); } else ptr=NULL; } }
void LCPBar::setValue(int num, int value, int diff) { std::ostringstream compname; compname << "pbar_text" << (num+1); Paragraph* p = getParagraph(*this, compname.str()); std::ostringstream os; os<<std::fixed; os<<std::setprecision(1); if(num==PTECH) { os<<value/10000.0; } else if(num==PMONEY) { if(abs(value)>=1000000000) os<<value/1000000<<"M"; else if(abs(value)>1000000) os<<value/1000000.0<<"M"; else if(abs(value)>1000) os<<value/1000.0<<"K"; else os<<value; } else os<<value; if( diff != 0 ){ p->setText(os.str()); } os.str(""); os<<"pbar_barview"<<(num+1); float sv=0; switch(num) { case PPOP: sv=pbar_adjust_pop(diff); break; case PTECH: sv=pbar_adjust_tech(diff); break; case PFOOD: sv=pbar_adjust_food(diff);break; case PJOBS: sv=pbar_adjust_jobs(diff);break; case PCOAL: sv=pbar_adjust_coal(diff);break; case PGOODS: sv=pbar_adjust_goods(diff);break; case PORE: sv=pbar_adjust_ore(diff);break; case PSTEEL: sv=pbar_adjust_steel(diff);break; case PMONEY: sv=pbar_adjust_money(diff);break; }; sv/=10.0; if(sv>1.0) sv=1.0; if(sv<-1.0) sv=-1.0; Component *c=findComponent(os.str()+"a"); if(c) { BarView *bv=dynamic_cast<BarView*>(c); if(bv) { bv->setValue(sv); } } c=findComponent(os.str()+"b"); if(c) { BarView *bv=dynamic_cast<BarView*>(c); if(bv) { bv->setValue(sv); } } }
MainState MainMenu::run() { SDL_Event event; running = true; quitState = QUIT; Uint32 fpsTicks = SDL_GetTicks(); Uint32 lastticks = fpsTicks; int frame = 0; while(running) { while(SDL_PollEvent(&event)) { switch(event.type) { case SDL_VIDEORESIZE: initVideo(event.resize.w, event.resize.h); currentMenu->resize(event.resize.w, event.resize.h); getConfig()->videoX = event.resize.w; getConfig()->videoY = event.resize.h; if(currentMenu == optionsMenu.get())//update resolution display { std::stringstream mode; mode.str(""); mode << event.resize.w << "x" << event.resize.h; getParagraph( *optionsMenu, "resolutionParagraph")->setText(mode.str()); } break; case SDL_MOUSEMOTION: case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONDOWN: case SDL_KEYDOWN:{ Event gui_event(event); currentMenu->event(gui_event); break; } case SDL_KEYUP: { Event gui_event(event); //In menu ESC as well as ^c exits the game. //might come in handy if video-mode is not working as expected. if( ( gui_event.keysym.sym == SDLK_ESCAPE ) || ( gui_event.keysym.sym == SDLK_c && ( gui_event.keysym.mod & KMOD_CTRL) ) ){ running = false; quitState = QUIT; break; } currentMenu->event(gui_event); break; } case SDL_VIDEOEXPOSE: currentMenu->resize( currentMenu->getWidth(), currentMenu->getHeight() ); break; case SDL_ACTIVEEVENT: if( event.active.gain == 1 ){ currentMenu->resize( currentMenu->getWidth(), currentMenu->getHeight() ); } break; case SDL_QUIT: running = false; quitState = QUIT; break; default: break; } } SDL_Delay(100); // give the CPU time to relax... (we are in main menu) // create update Event Uint32 ticks = SDL_GetTicks(); float elapsedTime = ((float) (ticks - lastticks)) / 1000.0; currentMenu->event(Event(elapsedTime)); lastticks = ticks; if(currentMenu->needsRedraw()) { currentMenu->draw(*painter); flipScreenBuffer(); } frame++; if(ticks - fpsTicks > 1000) { #ifdef DEBUG_FPS printf("MainMenu FPS: %d.\n", (frame*1000) / (ticks - fpsTicks)); #endif frame = 0; fpsTicks = ticks; } } return quitState; }
/** Changes the displayed resolution in the options menu. This does not actually change the resolution. initVideo has to be called to do this. @param next if true change to the next resolution in the list; otherwise change to the previous one @todo sort modes before in ascending order and remove unsupported modes like 640x480 */ void MainMenu::changeResolution(bool next) { static SDL_Rect** modes = NULL; if(modes == NULL) { Uint32 flags = 0; if(getConfig()->useOpenGL){ flags = SDL_OPENGL; } else { flags = SDL_HWSURFACE; } flags |= SDL_FULLSCREEN; // only check for fullscreen modes to get useful results from SDL_ListModes modes = SDL_ListModes(NULL, flags); } if(modes == NULL) { std::cerr << "Error: SDL reports that no video modes are available!\n"; return; } else if (modes == (SDL_Rect**)-1) { /* FIXME: SDL docs say that this means that "Any dimension is okay for the given format". I'm not sure what to do in this case. For now I will just report an error. It may be an option to just show some default modes. Jaky */ std::cerr << "FIXME: SDL reports that any video mode is possible. Please report to the lincity-ng bugtracker if you get this error. Please use the --size switch or edit userconfig.xml to set your resolution.\n"; return; } const int width = getConfig()->videoX ; const int height = getConfig()->videoY; int closest_mode = -1; for (int i=0; modes[i]; ++i) { if((modes[i]->w == width) && (modes[i]->h == height)) { //std::cout << "detected mode: " << modes[i]->w << "x" << modes[i]->h << std::endl; closest_mode = i; break; } } if (closest_mode == -1) //no exact match for current resolution { closest_mode = 0; int dw2 = width-modes[0]->w; dw2 = dw2*dw2; int dh2 = height-modes[0]->h; dh2 = dh2*dh2; int best_fit = dw2 + dh2; for (int i=1; modes[i]; ++i) { //look for closeset match //std::cout << "testing mode: " << modes[i]->w << "x" << modes[i]->h; dw2 = width-modes[i]->w; dw2 = dw2*dw2; dh2 = height-modes[i]->h; dh2 = dh2*dh2; if(best_fit > (dw2 + dh2)) { closest_mode = i; best_fit = dw2 + dh2; //std::cout << ": better suited"; } //std::cout << std::endl; } } std::string currentMode = getParagraph( *optionsMenu, "resolutionParagraph")->getText(); int new_mode = 0; std::stringstream mode; mode.str(""); mode << modes[closest_mode]->w << "x" << modes[closest_mode]->h; if(next && modes[closest_mode+1]) { new_mode = closest_mode+1; } else if (!next && closest_mode > 0) { new_mode = closest_mode-1; } else { // nothing to do, because we are at the beginning and the user clicked prev or we are at the last mode and the user clickt next return; } getSound()->playSound("Click"); mode.str(""); mode << modes[new_mode]->w << "x" << modes[new_mode]->h; getParagraph( *optionsMenu, "resolutionParagraph")->setText(mode.str()); getConfig()->videoX = modes[new_mode]->w; getConfig()->videoY = modes[new_mode]->h; }
void MainMenu::loadOptionsMenu() { if(optionsMenu.get() == 0) { optionsMenu.reset(loadGUIFile("gui/options.xml")); CheckButton* currentCheckButton = getCheckButton(*optionsMenu, "BackgroundMusic"); currentCheckButton->clicked.connect( makeCallback(*this, &MainMenu::optionsMenuButtonClicked)); currentCheckButton = getCheckButton(*optionsMenu, "SoundFX"); currentCheckButton->clicked.connect( makeCallback(*this, &MainMenu::optionsMenuButtonClicked)); currentCheckButton = getCheckButton(*optionsMenu, "Fullscreen"); currentCheckButton->clicked.connect( makeCallback(*this, &MainMenu::optionsMenuButtonClicked)); currentCheckButton = getCheckButton(*optionsMenu, "MusicVolumePlus"); currentCheckButton->clicked.connect( makeCallback(*this, &MainMenu::optionsMenuButtonClicked)); currentCheckButton = getCheckButton(*optionsMenu, "MusicVolumeMinus"); currentCheckButton->clicked.connect( makeCallback(*this, &MainMenu::optionsMenuButtonClicked)); currentCheckButton = getCheckButton(*optionsMenu, "FXVolumePlus"); currentCheckButton->clicked.connect( makeCallback(*this, &MainMenu::optionsMenuButtonClicked)); currentCheckButton = getCheckButton(*optionsMenu, "FXVolumeMinus"); currentCheckButton->clicked.connect( makeCallback(*this, &MainMenu::optionsMenuButtonClicked)); currentCheckButton = getCheckButton(*optionsMenu, "TrackPrev"); currentCheckButton->clicked.connect( makeCallback(*this, &MainMenu::optionsMenuButtonClicked)); currentCheckButton = getCheckButton(*optionsMenu, "TrackNext"); currentCheckButton->clicked.connect( makeCallback(*this, &MainMenu::optionsMenuButtonClicked)); currentCheckButton = getCheckButton(*optionsMenu, "ResolutionPrev"); currentCheckButton->clicked.connect( makeCallback(*this, &MainMenu::optionsMenuButtonClicked)); currentCheckButton = getCheckButton(*optionsMenu, "ResolutionNext"); currentCheckButton->clicked.connect( makeCallback(*this, &MainMenu::optionsMenuButtonClicked)); currentCheckButton = getCheckButton(*optionsMenu, "WorldLenPrev"); currentCheckButton->clicked.connect( makeCallback(*this, &MainMenu::optionsMenuButtonClicked)); currentCheckButton = getCheckButton(*optionsMenu, "WorldLenNext"); currentCheckButton->clicked.connect( makeCallback(*this, &MainMenu::optionsMenuButtonClicked)); currentCheckButton = getCheckButton(*optionsMenu, "LanguagePrev"); currentCheckButton->clicked.connect( makeCallback(*this, &MainMenu::optionsMenuButtonClicked)); currentCheckButton = getCheckButton(*optionsMenu, "LanguageNext"); currentCheckButton->clicked.connect( makeCallback(*this, &MainMenu::optionsMenuButtonClicked)); currentCheckButton = getCheckButton(*optionsMenu, "BinaryMode"); currentCheckButton->clicked.connect( makeCallback(*this, &MainMenu::optionsMenuButtonClicked)); currentCheckButton = getCheckButton(*optionsMenu, "SeedMode"); currentCheckButton->clicked.connect( makeCallback(*this, &MainMenu::optionsMenuButtonClicked)); Button* currentButton = getButton(*optionsMenu, "BackButton"); currentButton->clicked.connect( makeCallback(*this, &MainMenu::optionsBackButtonClicked)); } //adjust checkbutton-states if( getConfig()->musicEnabled ){ getCheckButton(*optionsMenu, "BackgroundMusic")->check(); } else { getCheckButton(*optionsMenu, "BackgroundMusic")->uncheck(); } if( getConfig()->soundEnabled ){ getCheckButton(*optionsMenu, "SoundFX")->check(); } else { getCheckButton(*optionsMenu, "SoundFX")->uncheck(); } if( getConfig()->useFullScreen ){ getCheckButton(*optionsMenu, "Fullscreen")->check(); } else { getCheckButton(*optionsMenu, "Fullscreen")->uncheck(); } if (binary_mode) { getCheckButton(*optionsMenu, "BinaryMode")->check();} else { getCheckButton(*optionsMenu, "BinaryMode")->uncheck();} if (seed_compression) { getCheckButton(*optionsMenu, "SeedMode")->check();} else { getCheckButton(*optionsMenu, "SeedMode")->uncheck();} //current background track musicParagraph = getParagraph( *optionsMenu, "musicParagraph"); musicParagraph->setText(getSound()->currentTrack.title); std::stringstream mode; mode << SDL_GetVideoSurface()->w << "x" << SDL_GetVideoSurface()->h; getParagraph( *optionsMenu, "resolutionParagraph")->setText(mode.str()); mode.str(""); mode << world.len(); getParagraph( *optionsMenu, "WorldLenParagraph")->setText(mode.str()); languageParagraph = getParagraph( *optionsMenu, "languageParagraph"); currentLanguage = getConfig()->language; languageParagraph->setText( getConfig()->language ); languages = dictionaryManager->get_languages(); languages.insert( "autodetect" ); languages.insert( "en" ); // English is the default when no translation is used optionsMenu->resize(getConfig()->videoX, getConfig()->videoY); //(SDL_GetVideoSurface()->w, SDL_GetVideoSurface()->h); }
/* static int Pbarorder[] = { Construction::STUFF_FOOD, Construction::STUFF_JOBS, Construction::STUFF_GOODS, Construction::STUFF_COAL, Construction::STUFF_ORE, Construction::STUFF_STEEL, Construction::STUFF_WASTE, Construction::STUFF_KWH, Construction::STUFF_MWH, Construction::STUFF_WATER, }; */ void LCPBar::setValue(int num, int value, int diff) { if ((num > 8) && (pbarGlobalStyle == 0)) { return;} if ((pbarGlobalStyle == 1) && (num > 2) && (num < 9)) { return;} std::ostringstream os; int line_number = num+1; if ( (pbarGlobalStyle == 1) && (num>8)) { line_number -= PBAR_PAGE_SHIFT;} os << "pbar_text" << line_number; Paragraph* p = getParagraph(*this, os.str()); os.str(""); //compname << "pbar_title" << line_number; //Paragraph* pt = getParagraph(*this, compname.str()); if(num==PTECH) { os<<std::fixed; os<<std::setprecision(1); os<<value/10000.0; } else if(num==PMONEY || num==PPOP || num==PPOL) { char s[12]; num_to_ansi (s, sizeof(s), value); os<<s; } else if ((num >= PFOOD) && (num <= PHOUSE)) //percentages { os<<value<<"%"; } else { os<<"default"; } if (p) { p->setText(os.str());} float sv=0; switch(num) { case PPOP: sv = pbar_adjust_pop(diff); break; case PTECH: sv = pbar_adjust_tech(diff); break; case PPOL: sv = value<5000?100*diff/(1+value):value<25000?500*diff/value:5000*diff/value; break; case PMONEY: sv = pbar_adjust_money(diff); break; default: sv = diff; break; }; sv/=10.0; if(sv>1.0) sv=1.0; if(sv<-1.0) sv=-1.0; os.str(""); os<<"pbar_barview"<< line_number; Component *c=findComponent(os.str()+"a"); if(c) { BarView *bv=dynamic_cast<BarView*>(c); if(bv) { bv->setValue(sv); } } c=findComponent(os.str()+"b"); if(c) { BarView *bv=dynamic_cast<BarView*>(c); if(bv) { bv->setValue(sv); } } }