okie menus are working
This commit is contained in:
parent
3932589790
commit
05e28fe820
11 changed files with 135 additions and 55 deletions
|
|
@ -163,6 +163,9 @@ namespace enginend {
|
||||||
}
|
}
|
||||||
void boot()override{this->tinted::boot();}
|
void boot()override{this->tinted::boot();}
|
||||||
void tick()override{
|
void tick()override{
|
||||||
|
}
|
||||||
|
void draw()override {
|
||||||
|
|
||||||
this->tinted::tick();
|
this->tinted::tick();
|
||||||
Vector2 mouse=GetMousePosition();
|
Vector2 mouse=GetMousePosition();
|
||||||
if(CheckCollisionPointRec(mouse,{pos.x,pos.y,size.x,size.y})){hover=true;
|
if(CheckCollisionPointRec(mouse,{pos.x,pos.y,size.x,size.y})){hover=true;
|
||||||
|
|
@ -175,9 +178,6 @@ namespace enginend {
|
||||||
}else{
|
}else{
|
||||||
hover=false;
|
hover=false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
void draw()override {
|
|
||||||
|
|
||||||
if (hover) {
|
if (hover) {
|
||||||
if (pressed) {
|
if (pressed) {
|
||||||
c=isboolean?boolean?
|
c=isboolean?boolean?
|
||||||
|
|
@ -195,6 +195,7 @@ namespace enginend {
|
||||||
}
|
}
|
||||||
if(this->texture!=nullptr)DrawTexture(*texture,pos.x,pos.y,this->theme->tint);
|
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);
|
else DrawRectangle(pos.x,pos.y,size.x,size.y,this->theme->tint);
|
||||||
|
|
||||||
}
|
}
|
||||||
void exit()override{this->tinted::exit();}
|
void exit()override{this->tinted::exit();}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -118,7 +118,10 @@ namespace enginend{
|
||||||
void boot()override{}
|
void boot()override{}
|
||||||
void tick()override{}
|
void tick()override{}
|
||||||
void draw()override{
|
void draw()override{
|
||||||
if(texture==nullptr)return;
|
if(texture==nullptr) {
|
||||||
|
colored::draw();
|
||||||
|
return;
|
||||||
|
}
|
||||||
float sw=GetScreenWidth();
|
float sw=GetScreenWidth();
|
||||||
float sh=GetScreenHeight();
|
float sh=GetScreenHeight();
|
||||||
float ax=x*sw;
|
float ax=x*sw;
|
||||||
|
|
@ -181,6 +184,7 @@ namespace enginend{
|
||||||
int minw=(minsize.x>aw)?minsize.x:aw;
|
int minw=(minsize.x>aw)?minsize.x:aw;
|
||||||
DrawRectangle(ax-charsize.x,ay-charsize.y,minw+p,minh+p,this->theme->background);
|
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);
|
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{
|
void exit()override{
|
||||||
tinted::exit();
|
tinted::exit();
|
||||||
|
|
@ -193,13 +197,16 @@ namespace enginend{
|
||||||
const bool isboolean;
|
const bool isboolean;
|
||||||
bool boolean=false;
|
bool boolean=false;
|
||||||
button():func(nullptr),pressed(false),hover(false),isboolean(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) {
|
button(Texture2D* texture,enginend::theme* theme,double x,double y,double w,double h,std::function<void()> f):func(f),pressed(false),hover(false),isboolean(false) {
|
||||||
this->theme=theme;
|
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,void(*f)(),bool isboolean):func(f),pressed(false),hover(false),isboolean(isboolean) {
|
}button(Texture2D* texture,enginend::theme* theme,double x,double y,double w,double h,std::function<void()> f,bool isboolean):func(f),pressed(false),hover(false),isboolean(isboolean) {
|
||||||
this->theme=theme;
|
this->theme=theme;this->texture=texture;this->x=x;this->y=y;this->w=w;this->h=h;
|
||||||
}
|
}
|
||||||
void boot()override{}
|
void boot()override{}
|
||||||
void tick()override{
|
void tick()override{
|
||||||
|
}
|
||||||
|
void draw()override {
|
||||||
|
|
||||||
Vector2 mouse=GetMousePosition();
|
Vector2 mouse=GetMousePosition();
|
||||||
float sw=GetScreenWidth();
|
float sw=GetScreenWidth();
|
||||||
float sh=GetScreenHeight();
|
float sh=GetScreenHeight();
|
||||||
|
|
@ -224,10 +231,12 @@ namespace enginend{
|
||||||
this->theme->booleanbutton[3]:this->theme->booleanbutton[0]:
|
this->theme->booleanbutton[3]:this->theme->booleanbutton[0]:
|
||||||
this->theme->button[0];
|
this->theme->button[0];
|
||||||
}
|
}
|
||||||
}
|
float ax=x*sw;
|
||||||
void draw()override {
|
float ay=y*sh;
|
||||||
|
float aw=w*sw;
|
||||||
tinted::draw();
|
float ah=h*sh;
|
||||||
|
DrawRectangle(ax,ay,aw,ah,c);
|
||||||
|
DrawRectangleLines(ax, ay, aw, ah, this->theme->border);
|
||||||
}
|
}
|
||||||
void exit()override{
|
void exit()override{
|
||||||
tinted::exit();
|
tinted::exit();
|
||||||
|
|
@ -237,13 +246,13 @@ namespace enginend{
|
||||||
std::string label;
|
std::string label;
|
||||||
int fs;
|
int fs;
|
||||||
Color txc;
|
Color txc;
|
||||||
labeledbutton(std::string name,Texture2D* texture,enginend::theme*theme,Color text,
|
labeledbutton(std::string name,Texture2D* texture,enginend::theme*theme,
|
||||||
double x,double y,double w,double h,void(*f)(),int size):fs(size),txc(text),label(name),
|
double x,double y,double w,double h,std::function<void()> f,int size):fs(size),label(name),
|
||||||
button(texture,theme,x,y,w,h,f)
|
button(texture,theme,x,y,w,h,f)
|
||||||
{}
|
{}
|
||||||
labeledbutton(std::string name,Texture2D* texture,enginend::theme*theme,Color text,
|
labeledbutton(std::string name,Texture2D* texture,enginend::theme*theme,
|
||||||
double x,double y,double w,double h,void(*f)(),
|
double x,double y,double w,double h,std::function<void()> f,
|
||||||
int size,bool isboolean):fs(size),txc(text),label(name),
|
int size,bool isboolean):fs(size),label(name),
|
||||||
button(texture,theme,x,y,w,h,f,isboolean)
|
button(texture,theme,x,y,w,h,f,isboolean)
|
||||||
{}
|
{}
|
||||||
void boot()override{}
|
void boot()override{}
|
||||||
|
|
@ -258,11 +267,17 @@ namespace enginend{
|
||||||
float ay=y*sh;
|
float ay=y*sh;
|
||||||
float aw=w*sw;
|
float aw=w*sw;
|
||||||
float ah=h*sh;
|
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 tsize=MeasureTextEx(this->theme->font,label.c_str(),fs,1);
|
||||||
Vector2 tpos={
|
Vector2 tpos={
|
||||||
ax+(aw-tsize.x)/2,
|
ax+(aw-tsize.x)/2,
|
||||||
ay+(ah-tsize.y)/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 (hover) {
|
||||||
if (pressed) {
|
if (pressed) {
|
||||||
txc=isboolean?boolean?
|
txc=isboolean?boolean?
|
||||||
|
|
@ -279,6 +294,7 @@ namespace enginend{
|
||||||
this->theme->buttontext[0];
|
this->theme->buttontext[0];
|
||||||
}
|
}
|
||||||
DrawTextEx(this->theme->font,label.c_str(),tpos,fs,1,txc);
|
DrawTextEx(this->theme->font,label.c_str(),tpos,fs,1,txc);
|
||||||
|
DrawRectangleLinesEx({ax, ay, aw, ah},5., this->theme->border);
|
||||||
}
|
}
|
||||||
void exit()override{
|
void exit()override{
|
||||||
button::exit();
|
button::exit();
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
namespace enginend {
|
namespace enginend {
|
||||||
struct scene{
|
struct scene{
|
||||||
std::list<enginend::nodes::node*> nodes;
|
std::vector<enginend::nodes::node*> nodes;
|
||||||
virtual void boot() {
|
virtual void boot() {
|
||||||
int i=0;
|
int i=0;
|
||||||
tiny::echo((char*)"initializing scene");
|
tiny::echo((char*)"initializing scene");
|
||||||
|
|
|
||||||
|
|
@ -149,6 +149,7 @@ public:
|
||||||
buttonslabel[0]=LoadTexture("res/options.png");
|
buttonslabel[0]=LoadTexture("res/options.png");
|
||||||
buttons[1]=new button(&menubtn[0], enginend::DEFAULT,468,58+(18*1),96,16,std::function<void()>([]() {
|
buttons[1]=new button(&menubtn[0], enginend::DEFAULT,468,58+(18*1),96,16,std::function<void()>([]() {
|
||||||
OpenURL("http://kosumi.ddns.net:60000/");
|
OpenURL("http://kosumi.ddns.net:60000/");
|
||||||
|
|
||||||
}));
|
}));
|
||||||
buttonslabel[1]=LoadTexture("res/website.png");
|
buttonslabel[1]=LoadTexture("res/website.png");
|
||||||
buttons[2]=new button(&menubtn[0], enginend::DEFAULT,468,58+(18*2),96,16,std::function<void()>([]() {
|
buttons[2]=new button(&menubtn[0], enginend::DEFAULT,468,58+(18*2),96,16,std::function<void()>([]() {
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ void client::boot() {
|
||||||
this->tickrate=20;
|
this->tickrate=20;
|
||||||
// SetConfigFlags();
|
// SetConfigFlags();
|
||||||
InitWindow(380,240,"forespend - 0.03h");
|
InitWindow(380,240,"forespend - 0.03h");
|
||||||
|
initthemes();
|
||||||
this->currentscene=new mainmenu();
|
this->currentscene=new mainmenu();
|
||||||
this->currentscene->boot();
|
this->currentscene->boot();
|
||||||
target=LoadRenderTexture(380,240);
|
target=LoadRenderTexture(380,240);
|
||||||
|
|
|
||||||
|
|
@ -2,26 +2,32 @@
|
||||||
#include "../../common/themes.h"
|
#include "../../common/themes.h"
|
||||||
#include <enginend/scenes/node2d.h>
|
#include <enginend/scenes/node2d.h>
|
||||||
int configmenupage=0; // 0 is before the mainpage is showing. aka pause menu/main menu when start game
|
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<void()>([]() {
|
new enginend::nodes::relative::labeledbutton("video",nullptr,clienttheme,0,0.04,1,0.2,std::function<void()>([]() {
|
||||||
|
configmenupage=2;
|
||||||
|
}),32),
|
||||||
|
new enginend::nodes::relative::labeledbutton("sound",nullptr,clienttheme,0,0.27,1,0.2,std::function<void()>([]() {
|
||||||
|
|
||||||
}),forefont,32),
|
}),32),
|
||||||
new enginend::nodes::labeledbutton("sound",nullptr,&clienttheme,100,100,0,0,std::function<void()>([]() {
|
new enginend::nodes::relative::labeledbutton("input",nullptr,clienttheme,0,0.51,1,0.2,std::function<void()>([]() {
|
||||||
|
|
||||||
}),forefont,32),
|
}),32),
|
||||||
new enginend::nodes::labeledbutton("input",nullptr,&clienttheme,100,100,0,0,std::function<void()>([]() {
|
new enginend::nodes::relative::labeledbutton("back",nullptr,clienttheme,0,0.75,1,0.2,std::function<void()>([]() {
|
||||||
|
configmenupage=0;
|
||||||
}),forefont,32),
|
}),32),
|
||||||
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
enginend::group graphics= enginend::group(
|
enginend::group graphics= enginend::group(
|
||||||
{
|
{
|
||||||
new enginend::nodes::labeledbutton("fullscreen",nullptr,&clienttheme,100,100,0,0,std::function<void()>([]() {
|
new enginend::nodes::relative::labeledbutton("fullscreen",nullptr,clienttheme,0,0.04,1,0.2,std::function<void()>([]() {
|
||||||
|
(dynamic_cast<enginend::nodes::relative::labeledbutton*>(graphics.children[0]))->boolean^=true;
|
||||||
}),forefont,32),
|
}),32,true),
|
||||||
|
new enginend::nodes::relative::labeledbutton("back",nullptr,clienttheme,0,0.75,1,0.2,std::function<void()>([]() {
|
||||||
|
configmenupage=1;
|
||||||
|
}),32),
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
enginend::group sound= enginend::group(
|
enginend::group sound= enginend::group(
|
||||||
|
|
|
||||||
|
|
@ -1,29 +1,73 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <enginend/engine.h>
|
#include <enginend/engine.h>
|
||||||
#include "configmenu.h"
|
#include "configmenu.h"
|
||||||
|
#include "../../common/themes.h"
|
||||||
class mainmenu :public virtual enginend::scene{
|
class mainmenu :public virtual enginend::scene{
|
||||||
private:
|
private:
|
||||||
Texture2D bg= LoadTexture(AT("res/images/tilesheet.png"));
|
Texture2D bg= LoadTexture(AT("res/images/tilesheet.png"));
|
||||||
public:
|
public:
|
||||||
void boot() override {
|
void boot() override {
|
||||||
|
this->nodes=std::vector<enginend::nodes::node*>{
|
||||||
this->nodes=std::list<enginend::nodes::node*>{
|
|
||||||
new enginend::nodes::relative::animated(AT("res/images/sky.gif"),0,0,1,1,2),
|
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<void()>([]{
|
||||||
|
|
||||||
|
}),32),
|
||||||
|
new enginend::nodes::relative::labeledbutton("OPTIONS",nullptr,clienttheme,0.02,0.75,0.56,0.2,
|
||||||
|
std::function<void()>([]{
|
||||||
|
configmenupage=1;
|
||||||
|
}),32),
|
||||||
|
new enginend::nodes::relative::labeledbutton("EXIT",nullptr,clienttheme,0.63,0.75,0.35,0.2,
|
||||||
|
std::function<void()>([](){
|
||||||
|
std::exit(1);
|
||||||
|
}),32),
|
||||||
};
|
};
|
||||||
enginend::scene::boot();
|
enginend::scene::boot();
|
||||||
}
|
}
|
||||||
void tick() override {
|
void tick() override {
|
||||||
|
switch (configmenupage) {
|
||||||
|
case 0:{
|
||||||
for (enginend::nodes::node* n : this->nodes) {
|
for (enginend::nodes::node* n : this->nodes) {
|
||||||
n->tick();
|
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 {
|
void draw() override {
|
||||||
|
switch (configmenupage) {
|
||||||
|
case 0:{
|
||||||
for (enginend::nodes::node* n : this->nodes) {
|
for (enginend::nodes::node* n : this->nodes) {
|
||||||
n->draw();
|
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 {
|
void exit() override {
|
||||||
enginend::scene::exit();
|
enginend::scene::exit();
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
#include "themes.h"
|
#include "themes.h"
|
||||||
|
|
||||||
Font forefont;
|
|
||||||
enginend::theme clienttheme{
|
enginend::theme CLIENTTHEME{
|
||||||
.textfieldbg ={127,0,0,127},
|
.textfieldbg ={127,0,0,127},
|
||||||
.background = {0,0,0,0},
|
.background = {0,0,0,0},
|
||||||
.border = {0,0,0,0},
|
.border = {0,255,255,0},
|
||||||
.booleanbutton = {
|
.booleanbutton = {
|
||||||
{0,200,0,180},
|
{0,200,0,180},
|
||||||
{100,200,100,180},
|
{100,200,100,180},
|
||||||
|
|
@ -14,7 +14,14 @@ enginend::theme clienttheme{
|
||||||
{255,100,100,255},
|
{255,100,100,255},
|
||||||
},
|
},
|
||||||
.text = {255,127,0,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},
|
.tint = {255,255,255,255},
|
||||||
.button = {
|
.button = {
|
||||||
{0,0,0,0},
|
{0,0,0,0},
|
||||||
|
|
@ -28,8 +35,7 @@ enginend::theme clienttheme{
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
enginend::theme servertheme;
|
|
||||||
|
|
||||||
void initthemes() {
|
enginend::theme* clienttheme=&CLIENTTHEME;
|
||||||
forefont=LoadFont(AT("res/fonts/dos.fnt"));
|
enginend::theme* servertheme;
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,13 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <enginend/engine.h>
|
#include <enginend/engine.h>
|
||||||
|
|
||||||
extern Font forefont;
|
extern enginend::theme* clienttheme;
|
||||||
extern enginend::theme clienttheme;
|
extern enginend::theme* servertheme;
|
||||||
extern enginend::theme servertheme;
|
inline void initthemes() {
|
||||||
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -13,7 +13,6 @@ int main(int argc, char** argv) {
|
||||||
enginend::program* game;
|
enginend::program* game;
|
||||||
tiny::startup("forespend","0.03g-rewrite");
|
tiny::startup("forespend","0.03g-rewrite");
|
||||||
bool isserver = false;
|
bool isserver = false;
|
||||||
initthemes();
|
|
||||||
if (argc>1) {
|
if (argc>1) {
|
||||||
for (int i=1;i<argc;i++) {
|
for (int i=1;i<argc;i++) {
|
||||||
if (argv[i]=="server ") {
|
if (argv[i]=="server ") {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue