From b757d628d06570c93feb2f485b7a9f9b8134ca25 Mon Sep 17 00:00:00 2001 From: sf17k Date: Sat, 28 May 2011 23:29:52 -0400 Subject: [PATCH] minor changes in menu system --- Source/GameDraw.cpp | 9 +++---- Source/Menu.cpp | 58 ++++++++++++++++++++++++++------------------- Source/Menu.h | 8 +++---- 3 files changed, 42 insertions(+), 33 deletions(-) diff --git a/Source/GameDraw.cpp b/Source/GameDraw.cpp index 66f1e27..ad67446 100644 --- a/Source/GameDraw.cpp +++ b/Source/GameDraw.cpp @@ -2276,7 +2276,7 @@ void Game::DrawMenu() { Menu::addButton(3,"Delete User",NULL,400,10,-1,-1); Menu::addButton(4,"Main Menu",NULL,5,10,-1,-1); Menu::addButton(5,"Change User",NULL,5,180,-1,-1); - Menu::addButton(6,"",NULL,200,420,-1,-1); + Menu::addButton(6,"Campaign : "+accountactive->getCurrentCampaign(),NULL,200,420,-1,-1); //show campaign map //with (2,-5) offset from old code @@ -2291,8 +2291,10 @@ void Game::DrawMenu() { if(!active) itemsize/=2; - if(i>=1) - Menu::addMapLine(campaignlevels[i-1].getCenter(),midpoint,0.5,active?1:0.5,active?1:0.5,0,0); + if(i>=1){ + XYZ start=campaignlevels[i-1].getCenter(); + Menu::addMapLine(start.x,start.y,midpoint.x-start.x,midpoint.y-start.y,0.5,active?1:0.5,active?1:0.5,0,0); + } Menu::addMapMarker(NB_CAMPAIGN_MENU_ITEM+i, Mapcircletexture, NULL, midpoint.x-itemsize/2, midpoint.y-itemsize/2, itemsize, itemsize, active?1:0.5, 0, 0); @@ -2304,7 +2306,6 @@ void Game::DrawMenu() { } } } - Menu::setButtonText(6,"Campaign : "+accountactive->getCurrentCampaign()); } break; case 6: { diff --git a/Source/Menu.cpp b/Source/Menu.cpp index 515fe3c..affdf9a 100644 --- a/Source/Menu.cpp +++ b/Source/Menu.cpp @@ -17,15 +17,22 @@ struct MenuItem { float r,g,b; float effectfade; - XYZ linestart; - XYZ lineend; float linestartsize; float lineendsize; - MenuItem(MenuItemType _type, int _id, const string& _label, int _texture, MBCallback _cb, - int _x, int _y, int _w, int _h, float _r, float _g, float _b): - type(_type),id(_id),label(_label),texture(_texture),cb(_cb), - x(_x),y(_y),w(_w),h(_h),r(_r),g(_g),b(_b),effectfade(0) { + void init(MenuItemType _type, int _id, const string& _label, int _texture, MBCallback _cb, + int _x, int _y, int _w, int _h, float _r, float _g, float _b, + float _linestartsize=1, float _lineendsize=1){ + type=_type; + id=_id; + label=_label; + texture=_texture; + cb=_cb; + x=_x; y=_y; w=_w; h=_h; + r=_r; g=_g; b=_b; + effectfade=0; + linestartsize=_linestartsize; + lineendsize=_lineendsize; if(type==MenuItem::BUTTON){ if(w==-1) w=label.length()*10; @@ -33,9 +40,6 @@ struct MenuItem { h=20; } } - MenuItem(const XYZ& start, const XYZ& end, float startsize, float endsize, float _r, float _g, float _b): - type(MAPLINE),id(-1),label(""),r(_r),g(_g),b(_b), - linestart(start),lineend(end),linestartsize(startsize),lineendsize(endsize) { } }; vector items; @@ -62,28 +66,28 @@ void Menu::clearMenu(){ } void Menu::addLabel(int id,const string& label,int x,int y){ - items.push_back(MenuItem(MenuItem::LABEL,id,label,0,NULL,x,y,-1,-1,1,0,0)); -} -void Menu::addButton(int id,const string& label,MBCallback cb,int x,int y,int w,int h){ - items.push_back(MenuItem(MenuItem::BUTTON,id,label,0,cb,x,y,w,h,1,0,0)); + items.push_back(MenuItem()); + items.back().init(MenuItem::LABEL,id,label,0,NULL,x,y,-1,-1,1,0,0); } void Menu::addButton(int id,const string& label,MBCallback cb,int x,int y,int w,int h,float r,float g,float b){ - items.push_back(MenuItem(MenuItem::BUTTON,id,label,0,cb,x,y,w,h,r,g,b)); + items.push_back(MenuItem()); + items.back().init(MenuItem::BUTTON,id,label,0,cb,x,y,w,h,r,g,b); } void Menu::addImage(int id,int texture,int x,int y,int w,int h){ - items.push_back(MenuItem(MenuItem::IMAGE,id,"",texture,NULL,x,y,w,h,1,1,1)); -} -void Menu::addImageButton(int id,int texture,MBCallback cb,int x,int y,int w,int h){ - items.push_back(MenuItem(MenuItem::IMAGEBUTTON,id,"",texture,cb,x,y,w,h,1,1,1)); + items.push_back(MenuItem()); + items.back().init(MenuItem::IMAGE,id,"",texture,NULL,x,y,w,h,1,1,1); } void Menu::addImageButton(int id,int texture,MBCallback cb,int x,int y,int w,int h,float r,float g,float b){ - items.push_back(MenuItem(MenuItem::IMAGEBUTTON,id,"",texture,cb,x,y,w,h,r,g,b)); + items.push_back(MenuItem()); + items.back().init(MenuItem::IMAGEBUTTON,id,"",texture,cb,x,y,w,h,r,g,b); } -void Menu::addMapLine(const XYZ& start, const XYZ& end, float startsize, float endsize, float r,float g,float b){ - items.push_back(MenuItem(start,end,startsize,endsize,r,g,b)); +void Menu::addMapLine(int x, int y, int w, int h, float startsize, float endsize, float r,float g,float b){ + items.push_back(MenuItem()); + items.back().init(MenuItem::MAPLINE,-1,"",0,NULL,x,y,w,h,r,g,b,startsize,endsize); } void Menu::addMapMarker(int id,int texture,MBCallback cb,int x,int y,int w,int h,float r,float g,float b){ - items.push_back(MenuItem(MenuItem::MAPMARKER,id,"",texture,cb,x,y,w,h,r,g,b)); + items.push_back(MenuItem()); + items.back().init(MenuItem::MAPMARKER,id,"",texture,cb,x,y,w,h,r,g,b); } void Menu::setMapItem(int id){ @@ -203,8 +207,14 @@ void Menu::drawItems(Game* game){ game->text.glPrintOutlined(0.9,0,0,it->x,it->y,it->label.c_str(),0,0.6,640,480); break; case MenuItem::MAPLINE: { - XYZ linestart=it->linestart; - XYZ lineend=it->lineend; + XYZ linestart; + linestart.x=it->x; + linestart.y=it->y; + linestart.z=0; + XYZ lineend; + lineend.x=it->x+it->w; + lineend.y=it->y+it->h; + lineend.z=0; XYZ offset=lineend-linestart; XYZ fac=offset; Normalise(&fac); diff --git a/Source/Menu.h b/Source/Menu.h index f671ebc..6f5de85 100644 --- a/Source/Menu.h +++ b/Source/Menu.h @@ -9,12 +9,10 @@ namespace Menu { void GUITick(Game* game); void clearMenu(); void addLabel(int id,const string& label,int x,int y); - void addButton(int id,const string& label,MBCallback cb,int x,int y,int w,int h); - void addButton(int id,const string& label,MBCallback cb,int x,int y,int w,int h,float r,float g,float b); + void addButton(int id,const string& label,MBCallback cb,int x,int y,int w,int h,float r=1,float g=0,float b=0); void addImage(int id,int texture,int x,int y,int w,int h); - void addImageButton(int id,int texture,MBCallback cb,int x,int y,int w,int h); - void addImageButton(int id,int texture,MBCallback cb,int x,int y,int w,int h,float r,float g,float b); - void addMapLine(const XYZ& start, const XYZ& end, float startsize, float endsize, float r,float g,float b); + void addImageButton(int id,int texture,MBCallback cb,int x,int y,int w,int h,float r=1,float g=1,float b=1); + void addMapLine(int x, int y, int w, int h, float startsize, float endsize, float r,float g,float b); void addMapMarker(int id,int texture,MBCallback cb,int x,int y,int w,int h,float r,float g,float b); void setMapItem(int id); void setButtonText(int id,const string& label); -- 2.39.2