Added button to restore default controls.

This commit is contained in:
Steve 2016-04-17 11:26:04 +01:00
parent 6dda5c3df1
commit 7c100f0c37
3 changed files with 58 additions and 2 deletions

View File

@ -103,9 +103,19 @@
"group" : "controls",
"type" : "WT_BUTTON",
"text" : "OK",
"x" : -1,
"x" : 500,
"y" : 650,
"w" : 100,
"w" : 200,
"h": 34
},
{
"name" : "restore",
"group" : "controls",
"type" : "WT_BUTTON",
"text" : "Restore Defaults",
"x" : 780,
"y" : 650,
"w" : 200,
"h": 34
}
]

View File

@ -20,6 +20,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "controls.h"
static void restoreDefaults(void);
static const char *controlName[CONTROL_MAX];
static Widget *controlWidget[CONTROL_MAX];
@ -70,6 +72,8 @@ void initControlsDisplay(void)
sprintf(controlWidget[i]->options[1], "Btn %d", app.mouseControls[i]);
}
}
getWidget("restore", "controls")->action = restoreDefaults;
}
int isControl(int type)
@ -185,3 +189,43 @@ void drawControls(void)
drawWidgets("controls");
}
static void restoreDefaults(void)
{
int i;
cJSON *root, *controlsJSON, *node;
char *text;
text = readFile("data/app/"CONFIG_FILENAME);
root = cJSON_Parse(text);
controlsJSON = cJSON_GetObjectItem(root, "controls");
if (controlsJSON)
{
node = cJSON_GetObjectItem(controlsJSON, "keys")->child;
while (node)
{
i = lookup(node->string);
app.keyControls[i] = node->valueint;
node = node->next;
}
node = cJSON_GetObjectItem(controlsJSON, "mouse")->child;
while (node)
{
i = lookup(node->string);
app.mouseControls[i] = node->valueint;
node = node->next;
}
}
cJSON_Delete(root);
free(text);
initControlsDisplay();
}

View File

@ -19,6 +19,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "../common.h"
#include "../json/cJSON.h"
extern void drawText(int x, int y, int size, int align, SDL_Color c, const char *format, ...);
extern char *getTranslatedString(char *string);
@ -27,6 +28,7 @@ extern void drawWidgets(char *groupName);
extern char *getLookupName(char *prefix, long num);
extern long lookup(char *name);
extern void limitTextWidth(int width);
extern char *readFile(char *filename);
extern App app;
extern Colors colors;