#include #include #include #include #include #include #include #include #include #include #include #include //#include #include #include #include #include #include "parse.h" #include "world.h" using namespace std; struct ColourTeam{ const Team *team; Fl_Color col; }; class BotList{ struct Item{ ColourTeam *cteam; Fl_Group *grp; }; Fl_Scroll *listScr; vector teams; public: BotList(Fl_Group *parent){ listScr=new Fl_Scroll(parent->x()+1,parent->y()+25,parent->w()-2,parent->h()-26); listScr->end(); listScr->user_data(this); } ~BotList(){ delete listScr; } void add(ColourTeam *cteam){ Fl_Group *grp=new Fl_Group(listScr->x(),listScr->y()+20*teams.size(),listScr->w(),20); grp->color(cteam->col); grp->label(cteam->team->name.data()); grp->labelcolor(fl_contrast(FL_WHITE,cteam->col)); grp->box(FL_FLAT_BOX); grp->align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE); Fl_Button *delBtn=new Fl_Button(grp->x()+grp->w()-20,grp->y()+2,grp->h()-4,grp->h()-4,"X"); delBtn->box(FL_THIN_UP_BOX); delBtn->labelcolor(FL_RED); delBtn->labelfont(FL_BOLD); delBtn->callback([](Fl_Widget *wid,void *cteam){ BotList *self=(BotList*)wid->parent()->parent()->user_data(); self->remove((ColourTeam*)cteam); },(void*)cteam); grp->end(); listScr->add(grp); listScr->redraw(); teams.push_back({cteam,grp}); } void remove(ColourTeam *cteam){ size_t i; for(i=0;iposition(teams[j].grp->x(),teams[j].grp->y()-20); } teams.erase(teams.begin()+i); listScr->redraw(); } }; class Simulation{ struct Item{ ColourTeam cteam; }; vector teams; World *world; BotList *botList; Fl_Color genColour(){ static const int nBase=7; static const Fl_Color baselist[nBase]={ FL_RED, FL_GREEN, FL_BLUE, FL_YELLOW, FL_MAGENTA, FL_DARK_RED, FL_DARK_CYAN, }; bool taken[nBase]; memset(taken,0,nBase*sizeof(bool)); for(const Item &item : teams){ int i; for(i=0;iadd(&teams.back().cteam); } void add(const char *fname){ cout<<"Adding team from file <"<"<remove(&teams[i].cteam); world->removeTeam(team); teams.erase(teams.begin()+i); } }; Simulation *simulation; static void openBotFileChooser(){ Fl_Native_File_Chooser fc(Fl_Native_File_Chooser::BROWSE_MULTI_FILE); fc.title("Add bots to sim"); fc.filter("Robocom Bot Files\t*.rob"); switch(fc.show()) { case -1: cout << "Native File Chooser error: " << fc.errmsg() << endl; break; case 1: break; default: { int count = fc.count(); for(int i=0; iadd(fc.filename(i)); } break; } } } static BotList* makeBotlist(Fl_Group *parent){ Fl_Button *openBtn=new Fl_Button(parent->x()+1,parent->y()+1,70,20,"Add bots"); openBtn->callback([](Fl_Widget*,void*){ openBotFileChooser(); }); return new BotList(parent); } int main(int argc,char **argv){ struct timeval tv; gettimeofday(&tv,nullptr); srand(tv.tv_sec*1000000+tv.tv_usec); Fl_Window *window=new Fl_Window(960,800,"Mocobor"); /*window->callback([](Fl_Widget*,void*){ if(Fl::event()==FL_SHORTCUT&&Fl::event_key()==FL_Escape)return; window->hide(); });*/ Fl_Group *botlistGroup=new Fl_Group(10,10,150,300); botlistGroup->box(FL_BORDER_BOX); BotList *botList=makeBotlist(botlistGroup); botlistGroup->end(); window->end(); World world; simulation=new Simulation(&world,botList); window->show(argc,argv); return Fl::run(); }