diff --git a/engine/src/scenes/node2d.h b/engine/src/scenes/node2d.h index 1590959..62bc66e 100644 --- a/engine/src/scenes/node2d.h +++ b/engine/src/scenes/node2d.h @@ -163,6 +163,9 @@ namespace enginend { } void boot()override{this->tinted::boot();} void tick()override{ + } + void draw()override { + this->tinted::tick(); Vector2 mouse=GetMousePosition(); if(CheckCollisionPointRec(mouse,{pos.x,pos.y,size.x,size.y})){hover=true; @@ -175,9 +178,6 @@ namespace enginend { }else{ hover=false; } - } - void draw()override { - if (hover) { if (pressed) { c=isboolean?boolean? @@ -195,6 +195,7 @@ namespace enginend { } if(this->texture!=nullptr)DrawTexture(*texture,pos.x,pos.y,this->theme->tint); else DrawRectangle(pos.x,pos.y,size.x,size.y,this->theme->tint); + } void exit()override{this->tinted::exit();} }; diff --git a/engine/src/scenes/node2drelative.h b/engine/src/scenes/node2drelative.h index bdb9c9b..572f5e3 100644 --- a/engine/src/scenes/node2drelative.h +++ b/engine/src/scenes/node2drelative.h @@ -118,7 +118,10 @@ namespace enginend{ void boot()override{} void tick()override{} void draw()override{ - if(texture==nullptr)return; + if(texture==nullptr) { + colored::draw(); + return; + } float sw=GetScreenWidth(); float sh=GetScreenHeight(); float ax=x*sw; @@ -181,6 +184,7 @@ namespace enginend{ int minw=(minsize.x>aw)?minsize.x:aw; DrawRectangle(ax-charsize.x,ay-charsize.y,minw+p,minh+p,this->theme->background); DrawTextEx(this->theme->font,content.c_str(),{ax,ay},fs,1,this->theme->text); + DrawRectangleLines(ax, ay, aw, ah, this->theme->border); } void exit()override{ tinted::exit(); @@ -193,13 +197,16 @@ namespace enginend{ const bool isboolean; bool boolean=false; button():func(nullptr),pressed(false),hover(false),isboolean(false){} - button(Texture2D* texture,enginend::theme* theme,double x,double y,double w,double h,void(*f)()):func(f),pressed(false),hover(false),isboolean(false) { - this->theme=theme; - }button(Texture2D* texture,enginend::theme* theme,double x,double y,double w,double h,void(*f)(),bool isboolean):func(f),pressed(false),hover(false),isboolean(isboolean) { - this->theme=theme; + button(Texture2D* texture,enginend::theme* theme,double x,double y,double w,double h,std::function f):func(f),pressed(false),hover(false),isboolean(false) { + this->theme=theme;this->texture=texture;this->x=x;this->y=y;this->w=w;this->h=h; + }button(Texture2D* texture,enginend::theme* theme,double x,double y,double w,double h,std::function f,bool isboolean):func(f),pressed(false),hover(false),isboolean(isboolean) { + this->theme=theme;this->texture=texture;this->x=x;this->y=y;this->w=w;this->h=h; } void boot()override{} void tick()override{ + } + void draw()override { + Vector2 mouse=GetMousePosition(); float sw=GetScreenWidth(); float sh=GetScreenHeight(); @@ -224,10 +231,12 @@ namespace enginend{ this->theme->booleanbutton[3]:this->theme->booleanbutton[0]: this->theme->button[0]; } - } - void draw()override { - - tinted::draw(); + float ax=x*sw; + float ay=y*sh; + float aw=w*sw; + float ah=h*sh; + DrawRectangle(ax,ay,aw,ah,c); + DrawRectangleLines(ax, ay, aw, ah, this->theme->border); } void exit()override{ tinted::exit(); @@ -237,13 +246,13 @@ namespace enginend{ std::string label; int fs; Color txc; - labeledbutton(std::string name,Texture2D* texture,enginend::theme*theme,Color text, - double x,double y,double w,double h,void(*f)(),int size):fs(size),txc(text),label(name), + labeledbutton(std::string name,Texture2D* texture,enginend::theme*theme, + double x,double y,double w,double h,std::function f,int size):fs(size),label(name), button(texture,theme,x,y,w,h,f) {} - labeledbutton(std::string name,Texture2D* texture,enginend::theme*theme,Color text, - double x,double y,double w,double h,void(*f)(), - int size,bool isboolean):fs(size),txc(text),label(name), + labeledbutton(std::string name,Texture2D* texture,enginend::theme*theme, + double x,double y,double w,double h,std::function f, + int size,bool isboolean):fs(size),label(name), button(texture,theme,x,y,w,h,f,isboolean) {} void boot()override{} @@ -258,11 +267,17 @@ namespace enginend{ float ay=y*sh; float aw=w*sw; float ah=h*sh; + tiny::echo("ax %f x %f sw %f",ax,x,sw); + tiny::echo("ay %f y %f sh %f",ay,y,sh); + tiny::echo("aw %f w %f sw %f",aw,w,sw); + tiny::echo("ah %f h %f sh %f",ah,h,sh); Vector2 tsize=MeasureTextEx(this->theme->font,label.c_str(),fs,1); Vector2 tpos={ ax+(aw-tsize.x)/2, ay+(ah-tsize.y)/2 }; + tiny::echo("tsize\nw %f h %f",tsize.x,tsize.y); + tiny::echo("tpos\nx %f y %f",tpos.x,tpos.y); if (hover) { if (pressed) { txc=isboolean?boolean? @@ -279,6 +294,7 @@ namespace enginend{ this->theme->buttontext[0]; } DrawTextEx(this->theme->font,label.c_str(),tpos,fs,1,txc); + DrawRectangleLinesEx({ax, ay, aw, ah},5., this->theme->border); } void exit()override{ button::exit(); diff --git a/engine/src/scenes/nodes.h b/engine/src/scenes/nodes.h index e995e2f..af0b863 100644 --- a/engine/src/scenes/nodes.h +++ b/engine/src/scenes/nodes.h @@ -8,7 +8,7 @@ namespace enginend { struct theme; - + namespace nodes { struct node{ public: @@ -29,7 +29,7 @@ void draw(){for (node* n: children){n->draw();}} void exit(){for (node* n: children){n->exit();}} }; - + typedef struct theme { Color booleanbutton[6],button[3],booleantext[6],buttontext[3],text,buttonborder[3],booleanborder[6],border,background ,textfieldbg @@ -42,6 +42,6 @@ Color tint; }; extern enginend::theme* DEFAULT; - + } diff --git a/engine/src/scenes/scene.h b/engine/src/scenes/scene.h index 5a36929..95ad4a9 100644 --- a/engine/src/scenes/scene.h +++ b/engine/src/scenes/scene.h @@ -8,7 +8,7 @@ namespace enginend { struct scene{ - std::list nodes; + std::vector nodes; virtual void boot() { int i=0; tiny::echo((char*)"initializing scene"); diff --git a/games/endlauncher/src/main.cpp b/games/endlauncher/src/main.cpp index 647c037..ec352c6 100644 --- a/games/endlauncher/src/main.cpp +++ b/games/endlauncher/src/main.cpp @@ -149,6 +149,7 @@ public: buttonslabel[0]=LoadTexture("res/options.png"); buttons[1]=new button(&menubtn[0], enginend::DEFAULT,468,58+(18*1),96,16,std::function([]() { OpenURL("http://kosumi.ddns.net:60000/"); + })); buttonslabel[1]=LoadTexture("res/website.png"); buttons[2]=new button(&menubtn[0], enginend::DEFAULT,468,58+(18*2),96,16,std::function([]() { diff --git a/games/forespend/src/client/client.cpp b/games/forespend/src/client/client.cpp index db2a912..9619739 100644 --- a/games/forespend/src/client/client.cpp +++ b/games/forespend/src/client/client.cpp @@ -10,6 +10,7 @@ void client::boot() { this->tickrate=20; // SetConfigFlags(); InitWindow(380,240,"forespend - 0.03h"); + initthemes(); this->currentscene=new mainmenu(); this->currentscene->boot(); target=LoadRenderTexture(380,240); diff --git a/games/forespend/src/client/scenes/configmenu.cpp b/games/forespend/src/client/scenes/configmenu.cpp index 0bba678..189afe3 100644 --- a/games/forespend/src/client/scenes/configmenu.cpp +++ b/games/forespend/src/client/scenes/configmenu.cpp @@ -2,26 +2,32 @@ #include "../../common/themes.h" #include int configmenupage=0; // 0 is before the mainpage is showing. aka pause menu/main menu when start game -enginend::group mainpage= enginend::group( +enginend::group maincfgpage= enginend::group( { - new enginend::nodes::labeledbutton("video",nullptr,&clienttheme,100,100,0,0,std::function([]() { + new enginend::nodes::relative::labeledbutton("video",nullptr,clienttheme,0,0.04,1,0.2,std::function([]() { + configmenupage=2; + }),32), + new enginend::nodes::relative::labeledbutton("sound",nullptr,clienttheme,0,0.27,1,0.2,std::function([]() { - }),forefont,32), - new enginend::nodes::labeledbutton("sound",nullptr,&clienttheme,100,100,0,0,std::function([]() { + }),32), + new enginend::nodes::relative::labeledbutton("input",nullptr,clienttheme,0,0.51,1,0.2,std::function([]() { - }),forefont,32), - new enginend::nodes::labeledbutton("input",nullptr,&clienttheme,100,100,0,0,std::function([]() { - - }),forefont,32), + }),32), + new enginend::nodes::relative::labeledbutton("back",nullptr,clienttheme,0,0.75,1,0.2,std::function([]() { + configmenupage=0; + }),32), } ); enginend::group graphics= enginend::group( - { - new enginend::nodes::labeledbutton("fullscreen",nullptr,&clienttheme,100,100,0,0,std::function([]() { - - }),forefont,32), +{ + new enginend::nodes::relative::labeledbutton("fullscreen",nullptr,clienttheme,0,0.04,1,0.2,std::function([]() { + (dynamic_cast(graphics.children[0]))->boolean^=true; + }),32,true), + new enginend::nodes::relative::labeledbutton("back",nullptr,clienttheme,0,0.75,1,0.2,std::function([]() { + configmenupage=1; + }),32), } ); enginend::group sound= enginend::group( diff --git a/games/forespend/src/client/scenes/mainmenu.h b/games/forespend/src/client/scenes/mainmenu.h index b0f5878..84cc406 100644 --- a/games/forespend/src/client/scenes/mainmenu.h +++ b/games/forespend/src/client/scenes/mainmenu.h @@ -1,28 +1,72 @@ #pragma once #include #include "configmenu.h" - +#include "../../common/themes.h" class mainmenu :public virtual enginend::scene{ private: Texture2D bg= LoadTexture(AT("res/images/tilesheet.png")); public: void boot() override { - - this->nodes=std::list{ + this->nodes=std::vector{ new enginend::nodes::relative::animated(AT("res/images/sky.gif"),0,0,1,1,2), - new enginend::nodes::relative::text(nullptr,{255,127,0,255},{0,0,0,0},0.25,0.05,0.8,0.1,forefont,32,"FORESPEND"), + new enginend::nodes::relative::text(nullptr,clienttheme,0.17,0.05,0.8,0.3,32,"FORESPEND"), + new enginend::nodes::relative::labeledbutton("PLAY",nullptr,clienttheme,0.30,0.25,0.4,0.2, + std::function([]{ + + }),32), + new enginend::nodes::relative::labeledbutton("OPTIONS",nullptr,clienttheme,0.02,0.75,0.56,0.2, + std::function([]{ + configmenupage=1; + }),32), + new enginend::nodes::relative::labeledbutton("EXIT",nullptr,clienttheme,0.63,0.75,0.35,0.2, + std::function([](){ + std::exit(1); + }),32), }; enginend::scene::boot(); } void tick() override { - for (enginend::nodes::node* n : this->nodes) { - n->tick(); - + switch (configmenupage) { + case 0:{ + for (enginend::nodes::node* n : this->nodes) { + n->tick(); + } + break; + } + case 1: {this->nodes[0]->tick(); + for (enginend::nodes::node* n : maincfgpage.children) { + n->tick(); + } + break; + } + case 2: {this->nodes[0]->tick(); + for (enginend::nodes::node* n : graphics.children) { + n->tick(); + } + break; + } } } void draw() override { - for (enginend::nodes::node* n : this->nodes) { - n->draw(); + switch (configmenupage) { + case 0:{ + for (enginend::nodes::node* n : this->nodes) { + n->draw(); + } + break; + } + case 1: {this->nodes[0]->draw(); + for (enginend::nodes::node* n : maincfgpage.children) { + n->draw(); + } + break; + } + case 2: {this->nodes[0]->draw(); + for (enginend::nodes::node* n : graphics.children) { + n->draw(); + } + break; + } } } void exit() override { diff --git a/games/forespend/src/common/themes.cpp b/games/forespend/src/common/themes.cpp index 865a165..b64cfb9 100644 --- a/games/forespend/src/common/themes.cpp +++ b/games/forespend/src/common/themes.cpp @@ -1,10 +1,10 @@ #include "themes.h" -Font forefont; -enginend::theme clienttheme{ + +enginend::theme CLIENTTHEME{ .textfieldbg ={127,0,0,127}, .background = {0,0,0,0}, - .border = {0,0,0,0}, + .border = {0,255,255,0}, .booleanbutton = { {0,200,0,180}, {100,200,100,180}, @@ -14,7 +14,14 @@ enginend::theme clienttheme{ {255,100,100,255}, }, .text = {255,127,0,255}, - .font = forefont, + .booleantext = { + {255,255,255,255}, + {255,255,255,255}, + {255,255,255,255}, + {255,255,255,255}, + {255,255,255,255}, + {255,255,255,255} + }, .tint = {255,255,255,255}, .button = { {0,0,0,0}, @@ -28,8 +35,7 @@ enginend::theme clienttheme{ } }; -enginend::theme servertheme; -void initthemes() { - forefont=LoadFont(AT("res/fonts/dos.fnt")); -} \ No newline at end of file +enginend::theme* clienttheme=&CLIENTTHEME; +enginend::theme* servertheme; + diff --git a/games/forespend/src/common/themes.h b/games/forespend/src/common/themes.h index c082819..8e77931 100644 --- a/games/forespend/src/common/themes.h +++ b/games/forespend/src/common/themes.h @@ -1,7 +1,13 @@ #pragma once #include -extern Font forefont; -extern enginend::theme clienttheme; -extern enginend::theme servertheme; -void initthemes(); \ No newline at end of file +extern enginend::theme* clienttheme; +extern enginend::theme* servertheme; +inline void initthemes() { + tiny::warning("loading font"); + clienttheme->font = LoadFont(AT("res/fonts/dos.fnt")); + if (clienttheme->font.recs==nullptr) { + tiny::fatal("LoadFont() failed"); + exit(404); + } +} \ No newline at end of file diff --git a/games/forespend/src/main.cpp b/games/forespend/src/main.cpp index 4612351..740cdb5 100644 --- a/games/forespend/src/main.cpp +++ b/games/forespend/src/main.cpp @@ -13,7 +13,6 @@ int main(int argc, char** argv) { enginend::program* game; tiny::startup("forespend","0.03g-rewrite"); bool isserver = false; - initthemes(); if (argc>1) { for (int i=1;i