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 ) ); }
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(); }
/* * 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 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 ) ); }
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; }
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); } } }
/* 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); } } }