feat: add limit fps setting feature and fix close window in settings
This commit is contained in:
@@ -5,6 +5,7 @@ window_width = 1280 ; in Pixel
|
||||
window_height = 720 ; in Pixel
|
||||
|
||||
showFPS = 0 ; OFF = 0, ON = 1
|
||||
limitFPS = 1 ; OFF = 0, ON = 1
|
||||
soundtrackOn = 1 ; OFF = 0, ON = 1
|
||||
|
||||
font_path = assets/SproutLandsUI/fonts/pixelFont-7-8x14-sproutLands.fnt
|
||||
|
||||
+3
-2
@@ -118,8 +118,8 @@ typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
Button showFPS;
|
||||
Button limitFPS;
|
||||
Button soundtrackOn;
|
||||
|
||||
} MenuSettings;
|
||||
|
||||
|
||||
@@ -210,6 +210,7 @@ typedef struct {
|
||||
|
||||
typedef struct {
|
||||
bool showFPS;
|
||||
bool limitFPS;
|
||||
bool soundtrackOn;
|
||||
} Flags;
|
||||
|
||||
@@ -239,7 +240,7 @@ void RenderMenuMain(MenuMain *m, Font *font, const char *title, Flags *flags);
|
||||
void CleanupMenuMain(MenuMain *m);
|
||||
|
||||
void InitMenuSettings(MenuSettings *s);
|
||||
void UpdateMenuSettings(MenuSettings *s, MenuView *menuView, Flags *flags);
|
||||
void UpdateMenuSettings(MenuSettings *s, MenuView *menuView, State *state, Flags *flags);
|
||||
void RenderMenuSettings(MenuSettings *s, Flags *flags);
|
||||
void CleanupMenuSettings(MenuSettings *s);
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ void ConfigApp(App* app){
|
||||
InitConfig(&app->config, "config/config.ini");
|
||||
app->state.currentView = GetConfigInt(&app->config, "startView");
|
||||
app->flags.showFPS = GetConfigInt(&app->config, "showFPS");
|
||||
app->flags.limitFPS = GetConfigInt(&app->config, "limitFPS");
|
||||
app->flags.soundtrackOn = GetConfigInt(&app->config, "soundtrackOn");
|
||||
app->window.title = GetConfigString(&app->config, "window_title");
|
||||
app->window.width = GetConfigInt(&app->config, "window_width");
|
||||
|
||||
+5
-2
@@ -56,8 +56,11 @@ void StartGame(App *app)
|
||||
void UpdateGame(App *app)
|
||||
{
|
||||
GameState *g = &app->game;
|
||||
|
||||
SetTargetFPS(0);
|
||||
if (app->flags.limitFPS){
|
||||
SetTargetFPS(60);
|
||||
} else {
|
||||
SetTargetFPS(0);
|
||||
}
|
||||
|
||||
StartGame(app);
|
||||
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@ void UpdateMenu(MenuState *m, State *state, Flags *flags)
|
||||
|
||||
case SETTINGS:
|
||||
{
|
||||
UpdateMenuSettings(&m->menuSettings, &m->menuView, flags);
|
||||
UpdateMenuSettings(&m->menuSettings, &m->menuView, state, flags);
|
||||
}break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
+15
-5
@@ -10,19 +10,25 @@ void InitMenuSettings(MenuSettings *s)
|
||||
int standardSpacing = standardButtonDimensions.y / 2;
|
||||
|
||||
Vector2 button1Pos = {windowCenter.x, windowCenter.y};
|
||||
Vector2 button2Pos = {windowCenter.x, windowCenter.y + standardButtonDimensions.y + standardSpacing};
|
||||
Vector2 button2Pos = {windowCenter.x, windowCenter.y + standardButtonDimensions.y * 1 + standardSpacing * 1};
|
||||
Vector2 button3Pos = {windowCenter.x, windowCenter.y + standardButtonDimensions.y * 2 + standardSpacing * 2};
|
||||
|
||||
s->showFPS = initButton("showFPS", standardButtonDimensions, button1Pos);
|
||||
s->soundtrackOn = initButton("soundtrackOn", standardButtonDimensions, button2Pos);
|
||||
s->limitFPS = initButton("limitFPS", standardButtonDimensions, button2Pos);
|
||||
s->soundtrackOn = initButton("soundtrackOn", standardButtonDimensions, button3Pos);
|
||||
}
|
||||
|
||||
void UpdateMenuSettings(MenuSettings *s, MenuView *menuView,Flags *flags)
|
||||
void UpdateMenuSettings(MenuSettings *s, MenuView *menuView, State* state, Flags *flags)
|
||||
{
|
||||
|
||||
if(isButtonClicked(&s->showFPS)){
|
||||
flags->showFPS = !flags->showFPS;
|
||||
}
|
||||
|
||||
if(isButtonClicked(&s->limitFPS)){
|
||||
flags->limitFPS = !flags->limitFPS;
|
||||
}
|
||||
|
||||
if(isButtonClicked(&s->soundtrackOn)){
|
||||
flags->soundtrackOn = !flags->soundtrackOn;
|
||||
}
|
||||
@@ -31,6 +37,10 @@ void UpdateMenuSettings(MenuSettings *s, MenuView *menuView,Flags *flags)
|
||||
*menuView = MAIN;
|
||||
}
|
||||
|
||||
if (WindowShouldClose() && !IsKeyPressed(KEY_ESCAPE)){
|
||||
state->running = false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -40,13 +50,13 @@ void RenderMenuSettings(MenuSettings *s, Flags *flags)
|
||||
ClearBackground(BLACK);
|
||||
|
||||
renderButton(&s->showFPS);
|
||||
renderButton(&s->limitFPS);
|
||||
renderButton(&s->soundtrackOn);
|
||||
|
||||
if (flags->showFPS){
|
||||
DrawFPS(10,10);
|
||||
}
|
||||
|
||||
renderButton(&s->soundtrackOn);
|
||||
|
||||
EndDrawing();
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user