Skip to content

Commit

Permalink
wip settings gui
Browse files Browse the repository at this point in the history
  • Loading branch information
xtreme8000 committed Jul 12, 2018
1 parent bf1f3db commit 58b1925
Show file tree
Hide file tree
Showing 10 changed files with 311 additions and 24 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -52,7 +52,7 @@ You will need to compile the following by yourself, or get hold of precompiled b
* libdeflate
* enet

Follow the instructions on their project page, then place produced static libraries in `lib/`.
Follow the instructions on their project page, then place produced static libraries in `libs/`.

Some files need to be copied to the `src/` directory.

Expand Down
Binary file added resources/png/ui/arrow.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/png/ui/box_check.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/png/ui/box_empty.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/common.h
Expand Up @@ -66,6 +66,7 @@
#include <unistd.h>
#include <time.h>
#include <pthread.h>
#include <limits.h>

#include "lodepng/lodepng.h"
#include "libdeflate.h"
Expand Down
75 changes: 73 additions & 2 deletions src/config.c
Expand Up @@ -21,6 +21,7 @@

struct RENDER_OPTIONS settings;
struct list config_keys;
struct list config_settings;

static int config_read_key(void* user, const char* section, const char* name, const char* value) {
if(!strcmp(section,"client")) {
Expand All @@ -46,7 +47,7 @@ static int config_read_key(void* user, const char* section, const char* name, co
settings.vsync = atoi(value);
}
if(!strcmp(name,"mouse_sensitivity")) {
settings.mouse_sensitivity = atof(value)/5.0F*MOUSE_SENSITIVITY;
settings.mouse_sensitivity = atof(value);
}
if(!strcmp(name,"show_news")) {
settings.show_news = atoi(value);
Expand Down Expand Up @@ -160,7 +161,7 @@ void config_reload() {
config_register_key(WINDOW_KEY_COMMAND,SDLK_SLASH,"chat_command",0);
config_register_key(WINDOW_KEY_HIDEHUD,SDLK_F6,"hide_hud",1);
#endif

#ifdef USE_GLFW
config_register_key(WINDOW_KEY_UP,GLFW_KEY_W,"move_forward",0);
config_register_key(WINDOW_KEY_DOWN,GLFW_KEY_S,"move_backward",0);
Expand Down Expand Up @@ -204,5 +205,75 @@ void config_reload() {
config_register_key(WINDOW_KEY_HIDEHUD,GLFW_KEY_F6,"hide_hud",1);
#endif

list_create(&config_settings,sizeof(struct config_setting));

list_add(&config_settings,&(struct config_setting){
.value=settings.name,
.type=CONFIG_TYPE_STRING,
.max=sizeof(settings.name)-1,
.name="Name",
.help="ingame player name"
});
list_add(&config_settings,&(struct config_setting){
.value=&settings.mouse_sensitivity,
.type=CONFIG_TYPE_FLOAT,
.max=INT_MAX,
.name="Mouse sensitivity"
});
list_add(&config_settings,&(struct config_setting){
.value=&settings.window_width,
.type=CONFIG_TYPE_INT,
.max=INT_MAX,
.name="Game width",
.defaults=640,800,854,1024,1280,1920,
.defaults_length=6
});
list_add(&config_settings,&(struct config_setting){
.value=&settings.window_height,
.type=CONFIG_TYPE_INT,
.max=INT_MAX,
.name="Game height",
.defaults=480,600,720,768,1024,1080,
.defaults_length=6
});
list_add(&config_settings,&(struct config_setting){
.value=&settings.vsync,
.type=CONFIG_TYPE_INT,
.max=INT_MAX,
.name="V-Sync",
.help="limits your game's fps",
.defaults=0,1,60,120,240,
.defaults_length=5
});
list_add(&config_settings,&(struct config_setting){
.value=&settings.fullscreen,
.type=CONFIG_TYPE_INT,
.max=1,
.name="Fullscreen"
});
list_add(&config_settings,&(struct config_setting){
.value=&settings.multisamples,
.type=CONFIG_TYPE_INT,
.max=16,
.name="Multisamples",
.help="smooth out block edges",
.defaults=0,1,2,4,8,16,
.defaults_length=6
});
list_add(&config_settings,&(struct config_setting){
.value=&settings.show_fps,
.type=CONFIG_TYPE_INT,
.max=1,
.name="Show fps",
.help="show your current fps and ping"
});
list_add(&config_settings,&(struct config_setting){
.value=&settings.show_news,
.type=CONFIG_TYPE_INT,
.max=1,
.name="Show news",
.help="opens the bns news on exit"
});

ini_parse("config.ini",config_read_key,NULL);
}
30 changes: 24 additions & 6 deletions src/config.h
Expand Up @@ -18,7 +18,7 @@
*/

extern struct RENDER_OPTIONS {
char name[17];
char name[16];
int opengl14;
int color_correction;
int shadow_entities;
Expand All @@ -29,11 +29,11 @@ extern struct RENDER_OPTIONS {
unsigned char multisamples;
int player_arms;
int fullscreen;
int greedy_meshing;
int vsync;
float mouse_sensitivity;
int show_news;
int show_fps;
int greedy_meshing;
int vsync;
float mouse_sensitivity;
int show_news;
int show_fps;
} settings;

extern struct list config_keys;
Expand All @@ -45,6 +45,24 @@ struct config_key_pair {
char name[32];
};

enum {
CONFIG_TYPE_STRING,
CONFIG_TYPE_INT,
CONFIG_TYPE_FLOAT
};

struct config_setting {
void* value;
int type;
int max;
char name[32];
char help[32];
int defaults[8];
int defaults_length;
};

extern struct list config_settings;

void config_register_key(int internal, int def, const char* name, int toggle);
int config_key_translate(int key, int dir);
struct config_key_pair* config_key(int key);
Expand Down

1 comment on commit 58b1925

@Edgamer63
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Congrats, you've done a Very good job! :D ... I should recommend to add Master volume Setting :D .

PD: it's quite similar to the style of a gui i've made recently, so if you want some graphic help, i'm a friend that you can ask for help :) .

Please sign in to comment.