aboutsummaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/mainmenu.cpp69
-rw-r--r--src/ui/menuframework/menuclass.cpp115
-rw-r--r--src/ui/menuframework/menuframework.hpp56
-rw-r--r--src/ui/menus.hpp16
4 files changed, 256 insertions, 0 deletions
diff --git a/src/ui/mainmenu.cpp b/src/ui/mainmenu.cpp
new file mode 100644
index 0000000..7bb62b8
--- /dev/null
+++ b/src/ui/mainmenu.cpp
@@ -0,0 +1,69 @@
+#include "menus.hpp"
+#include "../master/resources.hpp"
+#include "../core/corepublic.hpp"
+#include <cstdlib>
+smAnmFile menubg;
+smEntity2D *menubEnt;
+smEntity2D *whitexf;
+BYTE whitea;
+bool exitPressed(int key){if((key==SMK_ENTER)||(key==SMK_Z))return true;return false;}
+bool startPressed(int key)
+//stub
+{
+ if((key==SMK_ENTER)||(key==SMK_Z))
+ {
+ extern sceneManager *sceneMgr;
+ gameScn=new gameScene;
+ sceneMgr->registerScene(gameScn,"GameScene",900);
+ sceneMgr->activateScene("GameScene");
+ sceneMgr->deactivateScene("MainMenu");
+ sceneMgr->startUpdate();
+ }
+ return false;
+}
+SMELT* mainMenuScene::sm=NULL;
+mainMenuScene::mainMenuScene()
+{
+ extern sceneManager *sceneMgr;
+ sm=smGetInterface(SMELT_APILEVEL);
+ menubg.loadAnmFromMemory(blrdtp.getFilePtr("menu.anm"),blrdtp.getFileSize("menu.anm"));
+ menubEnt=new smEntity2D(menubg.getTextureInfo("menubg")->tex,menubg.getTextureInfo("menubg")->rect);
+ whitexf=new smEntity2D(0,0,0,960,720);whitea=0xFF;whitexf->setZ(1);
+ sceneMgr->registerScene(this,"MainMenu",990);
+ menu=new menuLCD(43,20,7,360,370,&lcdfont);
+ menu->addCtrl(new menuCtrlLCD(0,20,&lcdfont));
+ menu->getCtrl(0)->setText(NULL,"START");
+ menu->getCtrl(0)->onKeyPressed(startPressed);
+ menu->addCtrl(new menuCtrlLCD(1,20,&lcdfont));
+ menu->getCtrl(1)->setText(NULL,"HIGHSCORE");
+ menu->addCtrl(new menuCtrlLCD(2,20,&lcdfont));
+ menu->getCtrl(2)->setText(NULL,"REPLAY");
+ menu->addCtrl(new menuCtrlLCD(3,20,&lcdfont));
+ menu->getCtrl(3)->setText(NULL,"CONSOLE");
+ menu->addCtrl(new menuCtrlLCD(4,20,&lcdfont));
+ menu->getCtrl(4)->setText(NULL,"NOW PLAYING");
+ menu->addCtrl(new menuCtrlLCD(5,20,&lcdfont));
+ menu->getCtrl(5)->setText(NULL,"OPTIONS");
+ menu->addCtrl(new menuCtrlLCD(6,20,&lcdfont));
+ menu->getCtrl(6)->setText(NULL,"HELP");
+ menu->addCtrl(new menuCtrlLCD(7,20,&lcdfont));
+ menu->getCtrl(7)->setText(NULL,"EXIT");
+ menu->getCtrl(7)->onKeyPressed(exitPressed);
+}
+mainMenuScene::~mainMenuScene()
+{
+ delete menu;delete menubEnt;delete whitexf;
+ menubg.close();sm->smRelease();
+}
+bool mainMenuScene::sceneUpdate(){return menu->update();}
+bool mainMenuScene::sceneRender()
+{
+ sm->smClrscr(0xFF000000);
+ if(whitea>6)whitea-=6;else whitea=0;
+ whitexf->setColor(SETA(0x00FFFFFF,whitea));
+ menubEnt->render(0,0);
+ menu->render();
+ whitexf->render(0,0);
+ return false;
+}
+mainMenuScene *mainMenuScn;
diff --git a/src/ui/menuframework/menuclass.cpp b/src/ui/menuframework/menuclass.cpp
new file mode 100644
index 0000000..d135a01
--- /dev/null
+++ b/src/ui/menuframework/menuclass.cpp
@@ -0,0 +1,115 @@
+#include "menuframework.hpp"
+#include <cstring>
+#include <cmath>
+SMELT* menuCtrlLCD::sm=NULL;
+SMELT* menuLCD::sm=NULL;
+void menuCtrlLCD::render(float x,float y)
+{
+ fnt->setColor(color);
+ fnt->render(x+skv,y,1,ALIGN_LEFT,NULL,rt);
+}
+void menuCtrlLCD::update()
+{
+ if(overlen)
+ {
+ if(selected)
+ {
+ ++scd;
+ if(scd>30)++scv,scd=0;
+ if(scv>(int)strlen(tr))scv=0;
+ char rr[48];sprintf(rr,"%s %s",tr,tr);
+ sprintf(rt,"%s %.*s",tl,(int)(maxw-strlen(tl)-1),rr+scv);
+ }
+ else
+ {
+ scv=0;
+ sprintf(rt,"%s %.*s...",tl,(int)(maxw-strlen(tl)-4),tr);
+ }
+ }
+ if(skd>0){skv=-skv;--skd;}else skd=skv=0;
+ if(selected)
+ {color=SETA(color,(int)(0x60*fabsf(sin(6*sm->smGetTime())))+0x90);}
+ else
+ color=SETA(color,0x80);
+}
+void menuCtrlLCD::setText(const char* l,const char* r)
+{
+ if(!l)l="";if(!r)r="";
+ tl=l;tr=r;
+ if((int)(strlen(l)+strlen(r)+1)>maxw)
+ {
+ overlen=true;scv=0;scd=0;
+ }
+ else
+ {
+ overlen=false;
+ sprintf(rt,"%s %*s",l,(int)(maxw-strlen(l)-1),r);
+ }
+}
+void menuLCD::addCtrl(menuCtrlLCD *ctrl)
+{
+ if(ctrl->id==0)ctrl->selected=true;else ctrl->selected=false;
+ menuCtrlLCD *last=ctrls;
+ if(!ctrls)
+ {
+ ctrls=ctrl;
+ ctrl->last=0;
+ ctrl->next=0;
+ }
+ else
+ {
+ while(last->next)last=last->next;
+ last->next=ctrl;
+ ctrl->last=last;
+ ctrl->next=0;
+ }
+ ctrl->color=0x80333333;
+}
+menuCtrlLCD* menuLCD::getCtrl(int id)
+{
+ for(menuCtrlLCD* i=ctrls;i;i=i->next)
+ if(i->id==id)return i;
+ return NULL;
+}
+bool menuLCD::update()
+{
+ if(sm->smGetKeyState(SMK_DOWN)==SMKST_HIT)
+ {
+ getCtrl(selected)->selected=false;
+ menuCtrlLCD* c;
+ for(int i=selected+1;(c=getCtrl(i));++i)
+ {if(c->enabled){selected=i;break;}}
+ getCtrl(selected)->selected=true;
+ }
+ if(sm->smGetKeyState(SMK_UP)==SMKST_HIT)
+ {
+ getCtrl(selected)->selected=false;
+ menuCtrlLCD* c;
+ for(int i=selected-1;(c=getCtrl(i));++i)
+ {if(c->enabled){selected=i;break;}}
+ getCtrl(selected)->selected=true;
+ }
+ for(menuCtrlLCD* i=ctrls;i;i=i->next)i->update();
+ if(sm->smGetKey())
+ return getCtrl(selected)->ikp();
+ else return false;
+}
+void menuLCD::render()
+{
+ int cr=rows/2+1;
+ getCtrl(selected)->render(x,y+(cr-1)*itemh);
+ menuCtrlLCD* t=getCtrl(selected);
+ for(int ccr=cr-1;ccr>0;--ccr)
+ {
+ if(t)t=getCtrl(t->id-1);
+ if(!t){fnt->setColor(0x80333333);fnt->printf(x,y+(ccr-1)*itemh,1,ALIGN_LEFT,NULL,"%*s",maxw," ");}
+ else t->render(x,y+(ccr-1)*itemh);
+ }
+ t=getCtrl(selected);
+ for(int ccr=cr+1;ccr<=rows;++ccr)
+ {
+ if(t)t=getCtrl(t->id+1);
+ if(!t){fnt->setColor(0x80333333);fnt->printf(x,y+(ccr-1)*itemh,1,ALIGN_LEFT,NULL,"%*s",maxw," ");}
+ else t->render(x,y+(ccr-1)*itemh);
+ }
+}
diff --git a/src/ui/menuframework/menuframework.hpp b/src/ui/menuframework/menuframework.hpp
new file mode 100644
index 0000000..1879686
--- /dev/null
+++ b/src/ui/menuframework/menuframework.hpp
@@ -0,0 +1,56 @@
+#ifndef BLRMENUFW_H
+#define BLRMENUFW_H
+#include "smelt.hpp"
+#include "smbmfont.hpp"
+typedef bool (*smHooki)(int);
+class menuCtrlLCD
+{
+protected:
+ static SMELT *sm;
+private:
+ smHooki keyPressedf;
+ bool overlen;
+ const char *tl,*tr;
+ int scv,scd,maxw,skv,skd;
+ char rt[64];
+public:
+ int id;
+ bool enabled,selected;
+ DWORD color;
+ menuCtrlLCD *next,*last;
+ smBMFont *fnt;
+ menuCtrlLCD(int _id,int mw,smBMFont *font)
+ {
+ sm=smGetInterface(SMELT_APILEVEL);enabled=true;keyPressedf=NULL;
+ color=0xFFFFFFFF;id=_id;maxw=mw;fnt=font;skv=0;next=last=NULL;
+ }
+ virtual ~menuCtrlLCD(){sm->smRelease();}
+ void render(float x,float y);
+ void update();
+ virtual void updateHook(){}
+ void setText(const char *l,const char *r);
+ void onKeyPressed(smHooki kpf){keyPressedf=kpf;}//parameter is the key pressed. The return value has no effect.
+ void shake(int intv,int dur){skv=intv;skd=dur;}
+ bool ikp(){if(keyPressedf)return keyPressedf(sm->smGetKey());else return false;}
+};
+class menuLCD
+{
+private:
+ static SMELT *sm;
+ float itemh,x,y;
+ int maxw,rows,selected;
+ menuCtrlLCD *ctrls;
+ smBMFont *fnt;
+public:
+ menuLCD(float ih,int mw,int rowc,float _x,float _y,smBMFont *font)
+ {
+ ctrls=NULL;selected=0;sm=smGetInterface(SMELT_APILEVEL);
+ maxw=mw;itemh=ih;rows=rowc;x=_x;y=_y;fnt=font;
+ }
+ ~menuLCD(){menuCtrlLCD *c,*n;c=ctrls;while(c){n=c->next;delete c;c=n;}sm->smRelease();}
+ void addCtrl(menuCtrlLCD *ctrl);
+ menuCtrlLCD* getCtrl(int id);
+ bool update();
+ void render();
+};
+#endif
diff --git a/src/ui/menus.hpp b/src/ui/menus.hpp
new file mode 100644
index 0000000..780a3a6
--- /dev/null
+++ b/src/ui/menus.hpp
@@ -0,0 +1,16 @@
+#include "../master/master.hpp"
+#include "menuframework/menuframework.hpp"
+extern smAnmFile menubg;
+extern smEntity2D *menubEnt;
+class mainMenuScene:public scenePrototype
+{
+private:
+ menuLCD *menu;
+ static SMELT* sm;
+public:
+ mainMenuScene();
+ ~mainMenuScene();
+ bool sceneUpdate()override;
+ bool sceneRender()override;
+};
+extern mainMenuScene *mainMenuScn;