From 59e14944328f237089213410acc90de3b278eb23 Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Sat, 4 Mar 2017 14:50:30 +0100 Subject: gui: Remove teams --- gui.cpp | 59 ++++++++++++++++++++++++++++++++++++++++++++++------------- world.cpp | 23 +++++++++++++++++++++++ world.h | 4 ++++ 3 files changed, 73 insertions(+), 13 deletions(-) diff --git a/gui.cpp b/gui.cpp index 4629dbb..353b6fb 100644 --- a/gui.cpp +++ b/gui.cpp @@ -1,7 +1,10 @@ #include #include #include +#include +#include #include +#include #include #include @@ -19,14 +22,14 @@ using namespace std; struct ColourTeam{ - Team *team; + const Team *team; Fl_Color col; }; class BotList{ struct Item{ ColourTeam *cteam; - Fl_Box *box; + Fl_Group *grp; }; Fl_Scroll *listScr; @@ -36,17 +39,34 @@ 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_Box *box=new Fl_Box(listScr->x(),listScr->y()+20*teams.size(),listScr->w(),20); - box->color(cteam->col); - box->label(cteam->team->name.data()); - box->box(FL_FLAT_BOX); - box->align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE); - listScr->add(box); + 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,box}); + teams.push_back({cteam,grp}); } void remove(ColourTeam *cteam){ @@ -54,11 +74,13 @@ public: for(i=0;iposition(teams[j].box->x(),teams[j].box->y()-20); + teams[j].grp->position(teams[j].grp->x(),teams[j].grp->y()-20); } teams.erase(teams.begin()+i); + listScr->redraw(); } }; @@ -95,7 +117,7 @@ public: Simulation(World *world,BotList *botList) :world(world),botList(botList){} - void add(Team *team){ + void add(const Team *team){ (void)world; teams.push_back({{team,genColour()}}); botList->add(&teams.back().cteam); @@ -110,6 +132,17 @@ public: } add(new Team(assemble(preprocess(f)))); } + + void remove(const Team *team){ + size_t i; + for(i=0;iremove(&teams[i].cteam); + world->removeTeam(team); + teams.erase(teams.begin()+i); + } }; @@ -150,7 +183,7 @@ int main(int argc,char **argv){ window->hide(); });*/ - Fl_Group *botlistGroup=new Fl_Group(10,10,150,120); + Fl_Group *botlistGroup=new Fl_Group(10,10,150,300); botlistGroup->box(FL_BORDER_BOX); BotList *botList=makeBotlist(botlistGroup); botlistGroup->end(); diff --git a/world.cpp b/world.cpp index bc08f9d..63ba3c1 100644 --- a/world.cpp +++ b/world.cpp @@ -270,6 +270,20 @@ Robot& World::createInFront(const Robot *caller,const Team *team,int iset,int nb return *r; } +void World::removeRobot(const Robot *r){ + *botptr(r)=nullptr; +} + +void World::removeTeam(const Team *team){ + for(int y=0;yteam==team){ + board[y][x]=nullptr; + } + } + } +} + void World::tick(){ for(int y=0;y