From 5cbb13cf4b7fe612f9659848b97a25cf3c75b74a Mon Sep 17 00:00:00 2001 From: kin-fuyuki Date: Fri, 20 Feb 2026 05:38:16 -0300 Subject: [PATCH] ok ok i made a ton of progress on theming --- CMakeLists.txt | 2 +- engine/CMakeLists.txt | 6 +- engine/src/scenes/node2drelative.h | 90 +++++++++++++------ engine/src/scenes/nodes.h | 7 +- games/endlauncher/CMakeLists.txt | 5 +- games/endlauncher/src/main.cpp | 7 +- games/forespend/CMakeLists.txt | 6 +- games/forespend/src/client/client.cpp | 1 - .../src/client/scenes/configmenu.cpp | 16 ++-- .../forespend/src/client/scenes/configmenu.h | 4 +- games/forespend/src/common/themes.cpp | 35 +++++++- games/forespend/src/common/themes.h | 6 +- games/forespend/src/main.cpp | 2 + lib/raylib | 2 +- 14 files changed, 128 insertions(+), 61 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1ebeda6..021dc09 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.20) project(games) -set(CMAKE_CXX_FLAGS "-std=c++17 -Wno-error ") +set(CMAKE_CXX_FLAGS "-std=c++26 -Wno-error -Oz") if(WIN32) set(PLATFORM_DIR "windows") else() diff --git a/engine/CMakeLists.txt b/engine/CMakeLists.txt index da60153..0d56041 100644 --- a/engine/CMakeLists.txt +++ b/engine/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.20) -set(CMAKE_CXX_FLAGS "-std=c++26 -Wno-error -w") +set(CMAKE_CXX_FLAGS "-std=c++26 -Wno-error -w -Oz -g") if (DEFINED PLATFORMNAME) SET(CURRPLATFORM ${PLATFORMNAME}) @@ -9,7 +9,7 @@ endif (DEFINED PLATFORMNAME) file(GLOB_RECURSE ENGINE_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp") -add_library(enginend SHARED ${ENGINE_SOURCES} ) +add_library(enginend STATIC ${ENGINE_SOURCES} ) target_link_directories( enginend PUBLIC "${CMAKE_SOURCE_DIR}/link/${CURRPLATFORM}") @@ -33,8 +33,8 @@ target_link_directories( test PUBLIC "${CMAKE_SOURCE_DIR}/link/${CURRPLATFORM}") target_link_libraries(test PRIVATE - #"${CMAKE_SOURCE_DIR}/link/${CURRPLATFORM}/libenginend.so" enginend + raylib ) target_include_directories(test PUBLIC ${CMAKE_SOURCE_DIR}/include diff --git a/engine/src/scenes/node2drelative.h b/engine/src/scenes/node2drelative.h index 9411a6b..18fbfae 100644 --- a/engine/src/scenes/node2drelative.h +++ b/engine/src/scenes/node2drelative.h @@ -135,17 +135,15 @@ namespace enginend{ protected: std::string result; public: - Font font; float fs; - Color txc; std::string content; text(){fs=20;} - text(Texture2D* texture,Color txcol,Color color,double x,double y,double w,double h,Font f,float fsize,std::string txt): + text(Texture2D* texture,enginend::theme* theme,double x,double y,double w,double h,float fsize,std::string txt): //tinted(texture,color,x,y,w,h), - font(f),fs(fsize),content(txt),txc(txcol) + fs(fsize),content(txt) { this->x=x;this->y=y;this->w=w;this->h=h; - this->texture=texture;this->c=color; + this->texture=texture;this->theme=theme; result=content; size_t initp=0; while((initp=result.find("\n",initp))!=std::string::npos){ @@ -175,14 +173,14 @@ namespace enginend{ tiny::echo("og: %f %f %f %f", x,y,w,h); tiny::echo("drawing text: %s", content.c_str()); tiny::echo("transformed: %f %f %f %f", ax, ay, aw, ah); - Vector2 minsize=MeasureTextEx(font,content.c_str(),fs,1); - Vector2 charsize=MeasureTextEx(font," ",fs,1); + Vector2 minsize=MeasureTextEx(this->theme->font,content.c_str(),fs,1); + Vector2 charsize=MeasureTextEx(this->theme->font," ",fs,1); float p=charsize.x>charsize.y?charsize.x/minsize.x:charsize.y/minsize.y; p=p*2; int minh=(minsize.y>ah)?minsize.y:ah; int minw=(minsize.x>aw)?minsize.x:aw; - DrawRectangle(ax-charsize.x,ay-charsize.y,minw+p,minh+p,c); - DrawTextEx(font,content.c_str(),{ax,ay},fs,1,txc); + 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); } void exit()override{ tinted::exit(); @@ -192,8 +190,14 @@ namespace enginend{ void(*func)(); bool pressed; bool hover; - button():func(nullptr),pressed(false),hover(false){} - button(Texture2D* texture,Color color,double x,double y,double w,double h,void(*f)()):func(f),pressed(false),hover(false),tinted(texture,color,x,y,w,h){} + 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; + } void boot()override{} void tick()override{ Vector2 mouse=GetMousePosition(); @@ -203,16 +207,26 @@ namespace enginend{ if(CheckCollisionPointRec(mouse,r)){hover=true; if(IsMouseButtonPressed(MOUSE_LEFT_BUTTON)){ pressed=true; + c=isboolean?boolean? + this->theme->booleanbutton[5]:this->theme->booleanbutton[2]: + this->theme->button[2]; if(func)func(); }else{ pressed=false; + c=isboolean?boolean? + this->theme->booleanbutton[4]:this->theme->button[1]: + this->theme->button[1]; } }else{ hover=false; pressed=false; + c=isboolean?boolean? + this->theme->booleanbutton[3]:this->theme->button[0]: + this->theme->button[0]; } } void draw()override { + tinted::draw(); } void exit()override{ @@ -221,13 +235,16 @@ namespace enginend{ }; struct labeledbutton :virtual public button { std::string label; - Font font; int fs; Color txc; - labeledbutton(std::string name,Texture2D* texture,Color color,Color text, + 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), + 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)(), - Font fnt,int size):font(fnt),fs(size),txc(text),label(name), - button(texture,color,x,y,w,h,f) + int size,bool isboolean):fs(size),txc(text),label(name), + button(texture,theme,x,y,w,h,f,isboolean) {} void boot()override{} void tick()override{ @@ -241,12 +258,27 @@ namespace enginend{ float ay=y*sh; float aw=w*sw; float ah=h*sh; - Vector2 tsize=MeasureTextEx(font,label.c_str(),fs,1); + Vector2 tsize=MeasureTextEx(this->theme->font,label.c_str(),fs,1); Vector2 tpos={ ax+(aw-tsize.x)/2, ay+(ah-tsize.y)/2 }; - DrawTextEx(font,label.c_str(),tpos,fs,1,txc); + if (hover) { + if (pressed) { + txc=isboolean?boolean? + this->theme->booleantext[5]:this->theme->booleantext[2]: + this->theme->buttontext[2]; + }else { + txc=isboolean?boolean? + this->theme->booleantext[4]:this->theme->buttontext[1]: + this->theme->button[1]; + } + }else { + txc=isboolean?boolean? + this->theme->booleantext[3]:this->theme->button[0]: + this->theme->button[0]; + } + DrawTextEx(this->theme->font,label.c_str(),tpos,fs,1,txc); } void exit()override{ button::exit(); @@ -288,8 +320,8 @@ namespace enginend{ }; struct textfield :public text{ textfield(){} - textfield(Texture2D* texture,Color txcol,Color color,double x,double y,double w,double h,Font f,float fsize,std::string txt): - text(texture,txcol,color,x,y,w,h,f,fsize,txt){} + textfield(Texture2D* texture,enginend::theme *theme,double x,double y,double w,double h,float fsize,std::string txt): + text(texture,theme,x,y,w,h,fsize,txt){} void boot()override{} void tick()override{ text::tick(); @@ -301,13 +333,13 @@ namespace enginend{ float ay=y*sh; float aw=w*sw; float ah=h*sh; - Vector2 charsize=MeasureTextEx(font," ",fs,0); - Vector2 minsize=MeasureTextEx(font,content.c_str(),fs,charsize.x/2); + Vector2 charsize=MeasureTextEx(this->theme->font," ",fs,0); + Vector2 minsize=MeasureTextEx(this->theme->font,content.c_str(),fs,charsize.x/2); float po=charsize.x>charsize.y?charsize.x/charsize.y:charsize.y/charsize.x;po=po*5; int minh=(minsize.y>ah)?minsize.y:ah; int minw=(minsize.x>aw)?minsize.x:aw; - DrawRectangle(ax-(po/2),ay-(po/2),minw+(po*1.1),minh+(po*1.1),c); - DrawTextEx(font,content.c_str(),{ax,ay},fs,charsize.x/2,txc); + DrawRectangle(ax-(po/2),ay-(po/2),minw+(po*1.1),minh+(po*1.1),this->theme->textfieldbg); + DrawTextEx(this->theme->font,content.c_str(),{ax,ay},fs,charsize.x/2,this->theme->text); } void exit()override{ text::exit(); @@ -317,8 +349,8 @@ namespace enginend{ bool active; int cpos; textinput():active(false),cpos(0){} - textinput(Texture2D* texture,Color txcol,Color color,double x,double y,double w,double h,Font f,float fsize):active(false),cpos(0), - text(texture,txcol,color,x,y,w,h,f,fsize,""){} + textinput(Texture2D* texture,enginend::theme *theme,double x,double y,double w,double h,float fsize):active(false),cpos(0), + text(texture,theme,x,y,w,h,fsize,""){} void boot()override{} void tick()override{ text::tick(); @@ -351,7 +383,7 @@ namespace enginend{ float sh=GetScreenHeight(); float ax=x*sw; float ay=y*sh; - DrawRectangle(ax+MeasureTextEx(font,content.c_str(),fs,1).x,ay,2,fs,{0,0,0,127}); + DrawRectangle(ax+MeasureTextEx(this->theme->font,content.c_str(),fs,1).x,ay,2,fs,{0,0,0,127}); } } void exit()override{ @@ -362,8 +394,8 @@ namespace enginend{ bool active; int cpos; textinputfield():active(false),cpos(0){} - textinputfield(Texture2D* texture,Color txcol,Color color,double x,double y,double w,double h,Font f,float fsize):active(false),cpos(0), - textfield(texture,txcol,color,x,y,w,h,f,fsize,""){} + textinputfield(Texture2D* texture,enginend::theme *theme,double x,double y,double w,double h,float fsize):active(false),cpos(0), + textfield(texture,theme,x,y,w,h,fsize,""){} void boot()override{} void tick()override{ textfield::tick(); @@ -411,7 +443,7 @@ namespace enginend{ line+=ch; } } - DrawRectangle(p.x+MeasureTextEx(font,line.c_str(),fs,1).x,p.y,2,fs,rl::BLACK); + DrawRectangle(p.x+MeasureTextEx(this->theme->font,line.c_str(),fs,1).x,p.y,2,fs,rl::BLACK); } } void exit()override{ diff --git a/engine/src/scenes/nodes.h b/engine/src/scenes/nodes.h index 9259760..814fdf5 100644 --- a/engine/src/scenes/nodes.h +++ b/engine/src/scenes/nodes.h @@ -7,9 +7,12 @@ #include namespace enginend { + struct theme; + namespace nodes { struct node{ public: + enginend::theme* theme; virtual void boot()=0; virtual void tick()=0; virtual void draw()=0; @@ -29,7 +32,9 @@ struct theme { // in case if its a boolean button, it will use booleanbutton - Color booleanbutton[3],button[3],booleantext[3],buttontext[3],text,buttonborder[3],booleanborder[3],border; + Color booleanbutton[6],button[3],booleantext[6],buttontext[3],text,buttonborder[3],booleanborder[6],border,background + ,textfieldbg + ; Font font; diff --git a/games/endlauncher/CMakeLists.txt b/games/endlauncher/CMakeLists.txt index bdbf3d1..00f7b1e 100644 --- a/games/endlauncher/CMakeLists.txt +++ b/games/endlauncher/CMakeLists.txt @@ -7,7 +7,7 @@ else () endif (DEFINED PLATFORMNAME) -set(CMAKE_CXX_FLAGS "-std=c++26 -w -g -Wno-error -O0") +set(CMAKE_CXX_FLAGS "-std=c++11 -w -g -Wno-error -O0") file(GLOB_RECURSE ENDLAUNCHER "src/*.cpp") add_executable(endlauncher ${ENDLAUNCHER}) @@ -18,7 +18,8 @@ target_link_directories( endlauncher PUBLIC "${CMAKE_SOURCE_DIR}/link/${PLATFORMNAME}") target_link_libraries(endlauncher PRIVATE - "${CMAKE_SOURCE_DIR}/link/${PLATFORMNAME}/libenginend.so" + enginend + raylib curl zip ) target_include_directories(endlauncher PUBLIC diff --git a/games/endlauncher/src/main.cpp b/games/endlauncher/src/main.cpp index 44e57a2..0d6f7d6 100644 --- a/games/endlauncher/src/main.cpp +++ b/games/endlauncher/src/main.cpp @@ -1,6 +1,5 @@ -#include -#include -#include + +#include #include "netio.h" #include #include @@ -119,6 +118,8 @@ public: const char* CONF() final{return "test.tdf";} launcher(){}; void boot() override { + currentscene = new scene{}; + tickrate=15; framerate=15; SetConfigFlags(FLAG_WINDOW_UNDECORATED|FLAG_WINDOW_TRANSPARENT|FLAG_WINDOW_TOPMOST); diff --git a/games/forespend/CMakeLists.txt b/games/forespend/CMakeLists.txt index a9a7f36..fa21fad 100644 --- a/games/forespend/CMakeLists.txt +++ b/games/forespend/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.20) -set(CMAKE_CXX_FLAGS "-std=c++26 -Wno-error -w") +set(CMAKE_CXX_FLAGS "-std=c++26 -Wno-error -Oz -w -g") file(GLOB_RECURSE FORESPEND_SOURCES CONFIGURE_DEPENDS "src/*.cpp") add_executable(forespend ${FORESPEND_SOURCES}) if(NOT DEFINED ${ARCH}) @@ -14,8 +14,8 @@ target_link_directories( forespend PUBLIC "${CMAKE_SOURCE_DIR}/link") target_link_libraries(forespend PRIVATE - "${CMAKE_SOURCE_DIR}/link/${PLATFORMNAME}/libenginend.so" - "${CMAKE_SOURCE_DIR}/link/${PLATFORMNAME}/libraylib.a" + enginend + raylib ) target_include_directories(forespend PUBLIC ${CMAKE_SOURCE_DIR}/include diff --git a/games/forespend/src/client/client.cpp b/games/forespend/src/client/client.cpp index d0aa196..db2a912 100644 --- a/games/forespend/src/client/client.cpp +++ b/games/forespend/src/client/client.cpp @@ -10,7 +10,6 @@ void client::boot() { this->tickrate=20; // SetConfigFlags(); InitWindow(380,240,"forespend - 0.03h"); - initconfigmenu(); 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 c43f0c7..321cfa8 100644 --- a/games/forespend/src/client/scenes/configmenu.cpp +++ b/games/forespend/src/client/scenes/configmenu.cpp @@ -1,17 +1,16 @@ #include "configmenu.h" - +#include "../../common/themes.h" #include -Font forefont; int configmenupage=0; // 0 is before the mainpage is showing. aka pause menu/main menu when start game enginend::group mainpage= enginend::group( { - new enginend::nodes::labeledbutton("video",nullptr,{255,127,0,255},{0,0,0,0},100,100,0,0,std::function([]() { + new enginend::nodes::labeledbutton("video",nullptr,&clienttheme,100,100,0,0,std::function([]() { }),forefont,32), - new enginend::nodes::labeledbutton("sound",nullptr,{255,127,0,255},{0,0,0,0},100,100,0,0,std::function([]() { + new enginend::nodes::labeledbutton("sound",nullptr,&clienttheme,100,100,0,0,std::function([]() { }),forefont,32), - new enginend::nodes::labeledbutton("input",nullptr,{255,127,0,255},{0,0,0,0},100,100,0,0,std::function([]() { + new enginend::nodes::labeledbutton("input",nullptr,&clienttheme,100,100,0,0,std::function([]() { }),forefont,32), @@ -20,7 +19,7 @@ enginend::group mainpage= enginend::group( enginend::group graphics= enginend::group( { - new enginend::nodes::labeledbutton("fullscreen",nullptr,{255,127,0,255},{0,0,0,0},100,100,0,0,std::function([]() { + new enginend::nodes::labeledbutton("fullscreen",nullptr,&clienttheme,100,100,0,0,std::function([]() { }),forefont,32), } @@ -34,7 +33,4 @@ enginend::group controls= enginend::group( { } -); -void initconfigmenu() { - forefont=LoadFont(AT("res/fonts/dos.fnt")); -} \ No newline at end of file +); \ No newline at end of file diff --git a/games/forespend/src/client/scenes/configmenu.h b/games/forespend/src/client/scenes/configmenu.h index 5e59f6e..ca5ebbd 100644 --- a/games/forespend/src/client/scenes/configmenu.h +++ b/games/forespend/src/client/scenes/configmenu.h @@ -3,10 +3,8 @@ #include -extern Font forefont; extern enginend::group maincfgpage; extern enginend::group graphics; extern enginend::group sound; extern enginend::group controls; -extern int configmenupage; -void initconfigmenu(); \ No newline at end of file +extern int configmenupage; \ No newline at end of file diff --git a/games/forespend/src/common/themes.cpp b/games/forespend/src/common/themes.cpp index 495195f..865a165 100644 --- a/games/forespend/src/common/themes.cpp +++ b/games/forespend/src/common/themes.cpp @@ -1,4 +1,35 @@ #include "themes.h" -enginend::theme clienttheme; -enginend::theme servertheme; \ No newline at end of file +Font forefont; +enginend::theme clienttheme{ + .textfieldbg ={127,0,0,127}, + .background = {0,0,0,0}, + .border = {0,0,0,0}, + .booleanbutton = { + {0,200,0,180}, + {100,200,100,180}, + {100,255,100,255}, + {200,0,0,180}, + {200,100,100,180}, + {255,100,100,255}, + }, + .text = {255,127,0,255}, + .font = forefont, + .tint = {255,255,255,255}, + .button = { + {0,0,0,0}, + {255,255,255,80}, + {255,255,255,160} + }, + .buttontext = { + {255,255,255,255}, + {255,255,255,255}, + {255,255,255,255} + } + +}; +enginend::theme servertheme; + +void initthemes() { + forefont=LoadFont(AT("res/fonts/dos.fnt")); +} \ No newline at end of file diff --git a/games/forespend/src/common/themes.h b/games/forespend/src/common/themes.h index 0e70df9..c082819 100644 --- a/games/forespend/src/common/themes.h +++ b/games/forespend/src/common/themes.h @@ -1,5 +1,7 @@ #pragma once -#include +#include +extern Font forefont; extern enginend::theme clienttheme; -extern enginend::theme servertheme; \ No newline at end of file +extern enginend::theme servertheme; +void initthemes(); \ No newline at end of file diff --git a/games/forespend/src/main.cpp b/games/forespend/src/main.cpp index bbcfb62..4612351 100644 --- a/games/forespend/src/main.cpp +++ b/games/forespend/src/main.cpp @@ -4,6 +4,7 @@ #include "server/server.h" #include "client/client.h" +#include "common/themes.h" PLATFORM platform=LINUX; std::string androidpackage="kn.kinfuyuki.forespend"; inline const char* COMMONCONFIG(){return "common.tdf";} @@ -12,6 +13,7 @@ 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