- [NEW] configuration file working.

- [NEW] zoom(), fullscreen(), cursor(), getconf(), setconf().
- [CHG] now zoom and fullscreen are controlled by the game, not by mini.
- [FIX] quit() now actually quits.
- [NEW] btnp() without parameters returns key pressed.
- [NEW] zoom, fullscreen and cursor are saved to config automatically.
This commit is contained in:
2023-01-18 17:41:57 +01:00
parent 4c0cf979d3
commit e53befb700
8 changed files with 207 additions and 18 deletions

View File

@@ -19,11 +19,12 @@ struct surface_t {
char window_title[256];
char config_folder[256];
uint16_t screen_width = 160;
uint16_t screen_height = 120;
uint8_t screen_zoom = 4;
bool screen_fullscreen = false;
uint8_t show_cursor = SDL_ENABLE;
bool screen_cursor = true;
surface_t surfaces[10];
surface_t *screen_surface = &surfaces[0];
@@ -100,10 +101,11 @@ void read_ini() {
if (value != NULL) {
value[strlen(value)-1] = '\0';
if (strcmp(line, "title") == 0) strcpy(window_title, value);
else if (strcmp(line, "config") == 0) strcpy(config_folder, value);
else if (strcmp(line, "width") == 0) screen_width = atoi(value);
else if (strcmp(line, "height") == 0) screen_height = atoi(value);
else if (strcmp(line, "zoom") == 0) screen_zoom = atoi(value);
else if (strcmp(line, "hidemouse") == 0) show_cursor = SDL_DISABLE;
else if (strcmp(line, "fullscreen") == 0) screen_fullscreen = atoi(value);
else if (strcmp(line, "files") == 0) {
//lua_files = (char*)malloc(strlen(value));
strcpy(lua_files, value);
@@ -194,7 +196,7 @@ void createDisplay() {
mini_ren = SDL_CreateRenderer(mini_win, -1, 0);
//SDL_CreateWindowAndRenderer(512,512,0,&mini_win,&mini_ren);
SDL_RenderSetLogicalSize(mini_ren, screen_width, screen_height);
SDL_ShowCursor(show_cursor);
SDL_ShowCursor(screen_cursor?SDL_ENABLE:SDL_DISABLE);
mini_bak = SDL_CreateTexture(mini_ren, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, screen_width, screen_height);
}
@@ -224,6 +226,14 @@ int main(int argc,char*argv[]){
file_setresourcefilename(res_file);
#endif
read_ini();
file_setconfigfolder(config_folder);
const char *zoom = file_getconfigvalue("zoom");
if (zoom) screen_zoom=atoi(zoom);
const char *fullscreen = file_getconfigvalue("fullscreen");
if (fullscreen) screen_fullscreen=strcmp(fullscreen, "true")==0?true:false;
const char *cursor = file_getconfigvalue("cursor");
if (cursor) screen_cursor=strcmp(cursor, "true")?true:false;
setdest(newsurf(screen_width, screen_height));
SDL_Init(SDL_INIT_EVERYTHING);
@@ -248,15 +258,20 @@ int main(int argc,char*argv[]){
while(SDL_PollEvent(&mini_eve)) {
if (mini_eve.type == SDL_QUIT) { should_exit=true; should_quit=true; break; }
if (mini_eve.type == SDL_KEYDOWN) {
/*
if (mini_eve.key.keysym.scancode == SDL_SCANCODE_F2) {
screen_zoom+=2; if (screen_zoom>=10) screen_zoom=2;
destroyDisplay();
createDisplay();
char strzoom[3];
file_setconfigvalue("zoom", SDL_itoa(screen_zoom, strzoom, 10));
} else if (mini_eve.key.keysym.scancode == SDL_SCANCODE_F3) {
screen_fullscreen = !screen_fullscreen;
destroyDisplay();
createDisplay();
file_setconfigvalue("fullscreen", screen_fullscreen?"true":"false");
}
*/
#ifdef DEBUG
if (mini_eve.key.keysym.scancode == SDL_SCANCODE_F1) {
if (lua_is_playing()) {
@@ -846,6 +861,10 @@ bool btn(uint8_t i) {
return keys[i];
}
int wbtnp() {
return key_just_pressed;
}
bool btnp(uint8_t i) {
return key_just_pressed == i;
}
@@ -1072,6 +1091,47 @@ void stopsound(int soundchannel) {
Mix_HaltChannel(soundchannel);
}
int getzoom() {
return screen_zoom;
}
void setzoom(const int value) {
screen_zoom = value;
destroyDisplay();
createDisplay();
char strzoom[3];
file_setconfigvalue("zoom", SDL_itoa(screen_zoom, strzoom, 10));
}
bool getfullscreen() {
return screen_fullscreen;
}
void setfullscreen(const bool value) {
screen_fullscreen=value;
destroyDisplay();
createDisplay();
file_setconfigvalue("fullscreen", screen_fullscreen?"true":"false");
}
bool getcursor() {
return screen_cursor;
}
void setcursor(const bool value) {
screen_cursor=value;
SDL_ShowCursor(screen_cursor?SDL_ENABLE:SDL_DISABLE);
}
const char* getconfig(const char* key) {
return file_getconfigvalue(key);
}
void setconfig(const char* key, const char* value) {
file_setconfigvalue(key, value);
}
void exit() {
should_exit = true;
should_quit = true;
}