okie menus are working

This commit is contained in:
kin fuyuki 2026-02-20 09:58:58 -03:00
commit 05e28fe820
No known key found for this signature in database
GPG key ID: 0E4E8E519FB71401
11 changed files with 135 additions and 55 deletions

View file

@ -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();}
};

View file

@ -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<void()> 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<void()> 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<void()> 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<void()> 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();

View file

@ -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;
}

View file

@ -8,7 +8,7 @@
namespace enginend {
struct scene{
std::list<enginend::nodes::node*> nodes;
std::vector<enginend::nodes::node*> nodes;
virtual void boot() {
int i=0;
tiny::echo((char*)"initializing scene");

View file

@ -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<void()>([]() {
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<void()>([]() {

View file

@ -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);

View file

@ -2,26 +2,32 @@
#include "../../common/themes.h"
#include <enginend/scenes/node2d.h>
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),
new enginend::nodes::labeledbutton("sound",nullptr,&clienttheme,100,100,0,0,std::function<void()>([]() {
}),32),
new enginend::nodes::relative::labeledbutton("input",nullptr,clienttheme,0,0.51,1,0.2,std::function<void()>([]() {
}),forefont,32),
new enginend::nodes::labeledbutton("input",nullptr,&clienttheme,100,100,0,0,std::function<void()>([]() {
}),forefont,32),
}),32),
new enginend::nodes::relative::labeledbutton("back",nullptr,clienttheme,0,0.75,1,0.2,std::function<void()>([]() {
configmenupage=0;
}),32),
}
);
enginend::group graphics= enginend::group(
{
new enginend::nodes::labeledbutton("fullscreen",nullptr,&clienttheme,100,100,0,0,std::function<void()>([]() {
}),forefont,32),
{
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;
}),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(

View file

@ -1,28 +1,72 @@
#pragma once
#include <enginend/engine.h>
#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<enginend::nodes::node*>{
this->nodes=std::vector<enginend::nodes::node*>{
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();
}
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 {

View file

@ -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"));
}
enginend::theme* clienttheme=&CLIENTTHEME;
enginend::theme* servertheme;

View file

@ -1,7 +1,13 @@
#pragma once
#include <enginend/engine.h>
extern Font forefont;
extern enginend::theme clienttheme;
extern enginend::theme servertheme;
void initthemes();
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);
}
}

View file

@ -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<argc;i++) {
if (argv[i]=="server ") {