Set and save control options.
This commit is contained in:
parent
f5bf3ddcaa
commit
59e8b08fdc
|
@ -73,27 +73,27 @@ static void setGeneralOptions(void)
|
|||
{
|
||||
soundVolumeWidget = getWidget("soundVolume", "options");
|
||||
soundVolumeWidget->action = soundVolume;
|
||||
soundVolumeWidget->value = app.config.soundVolume;
|
||||
soundVolumeWidget->value[0] = app.config.soundVolume;
|
||||
|
||||
musicVolumeWidget = getWidget("musicVolume", "options");
|
||||
musicVolumeWidget->action = musicVolume;
|
||||
musicVolumeWidget->value = app.config.musicVolume;
|
||||
musicVolumeWidget->value[0] = app.config.musicVolume;
|
||||
|
||||
bloodGoreWidget = getWidget("bloodGore", "options");
|
||||
bloodGoreWidget->action = bloodGore;
|
||||
bloodGoreWidget->value = app.config.blood;
|
||||
bloodGoreWidget->value[0] = app.config.blood;
|
||||
|
||||
trophyScreenshotWidget = getWidget("trophyScreenshot", "options");
|
||||
trophyScreenshotWidget->action = trophyScreenshot;
|
||||
trophyScreenshotWidget->value = app.config.trophyScreenshot;
|
||||
trophyScreenshotWidget->value[0] = app.config.trophyScreenshot;
|
||||
|
||||
trophyAlertWidget = getWidget("trophyAlert", "options");
|
||||
trophyAlertWidget->action = trophyAlert;
|
||||
trophyAlertWidget->value = app.config.trophyAlert;
|
||||
trophyAlertWidget->value[0] = app.config.trophyAlert;
|
||||
|
||||
inventoryWidget = getWidget("inventory", "options");
|
||||
inventoryWidget->action = inventory;
|
||||
inventoryWidget->value = app.config.inventory;
|
||||
inventoryWidget->value[0] = app.config.inventory;
|
||||
|
||||
controlsWidget = getWidget("controls", "options");
|
||||
controlsWidget->action = controls;
|
||||
|
@ -104,15 +104,25 @@ static void setGeneralOptions(void)
|
|||
|
||||
static void setControlOptions(void)
|
||||
{
|
||||
getWidget("left", "controls")->value = app.config.keyControls[CONTROL_LEFT];
|
||||
getWidget("right", "controls")->value = app.config.keyControls[CONTROL_RIGHT];
|
||||
getWidget("up", "controls")->value = app.config.keyControls[CONTROL_UP];
|
||||
getWidget("down", "controls")->value = app.config.keyControls[CONTROL_DOWN];
|
||||
getWidget("jump", "controls")->value = app.config.keyControls[CONTROL_JUMP];
|
||||
getWidget("fire", "controls")->value = app.config.keyControls[CONTROL_FIRE];
|
||||
getWidget("jetpack", "controls")->value = app.config.keyControls[CONTROL_JETPACK];
|
||||
getWidget("pause", "controls")->value = app.config.keyControls[CONTROL_PAUSE];
|
||||
getWidget("map", "controls")->value = app.config.keyControls[CONTROL_MAP];
|
||||
getWidget("left", "controls")->value[0] = app.config.keyControls[CONTROL_LEFT];
|
||||
getWidget("right", "controls")->value[0] = app.config.keyControls[CONTROL_RIGHT];
|
||||
getWidget("up", "controls")->value[0] = app.config.keyControls[CONTROL_UP];
|
||||
getWidget("down", "controls")->value[0] = app.config.keyControls[CONTROL_DOWN];
|
||||
getWidget("jump", "controls")->value[0] = app.config.keyControls[CONTROL_JUMP];
|
||||
getWidget("fire", "controls")->value[0] = app.config.keyControls[CONTROL_FIRE];
|
||||
getWidget("jetpack", "controls")->value[0] = app.config.keyControls[CONTROL_JETPACK];
|
||||
getWidget("pause", "controls")->value[0] = app.config.keyControls[CONTROL_PAUSE];
|
||||
getWidget("map", "controls")->value[0] = app.config.keyControls[CONTROL_MAP];
|
||||
|
||||
getWidget("left", "controls")->value[1] = app.config.joypadControls[CONTROL_LEFT];
|
||||
getWidget("right", "controls")->value[1] = app.config.joypadControls[CONTROL_RIGHT];
|
||||
getWidget("up", "controls")->value[1] = app.config.joypadControls[CONTROL_UP];
|
||||
getWidget("down", "controls")->value[1] = app.config.joypadControls[CONTROL_DOWN];
|
||||
getWidget("jump", "controls")->value[1] = app.config.joypadControls[CONTROL_JUMP];
|
||||
getWidget("fire", "controls")->value[1] = app.config.joypadControls[CONTROL_FIRE];
|
||||
getWidget("jetpack", "controls")->value[1] = app.config.joypadControls[CONTROL_JETPACK];
|
||||
getWidget("pause", "controls")->value[1] = app.config.joypadControls[CONTROL_PAUSE];
|
||||
getWidget("map", "controls")->value[1] = app.config.joypadControls[CONTROL_MAP];
|
||||
}
|
||||
|
||||
static void logic(void)
|
||||
|
@ -135,36 +145,36 @@ static void draw(void)
|
|||
|
||||
static void soundVolume(void)
|
||||
{
|
||||
app.config.soundVolume = soundVolumeWidget->value;
|
||||
app.config.soundVolume = soundVolumeWidget->value[0];
|
||||
|
||||
Mix_Volume(-1, app.config.soundVolume);
|
||||
}
|
||||
|
||||
static void musicVolume(void)
|
||||
{
|
||||
app.config.musicVolume = musicVolumeWidget->value;
|
||||
app.config.musicVolume = musicVolumeWidget->value[0];
|
||||
|
||||
Mix_VolumeMusic(app.config.musicVolume);
|
||||
}
|
||||
|
||||
static void bloodGore(void)
|
||||
{
|
||||
app.config.blood = bloodGoreWidget->value;
|
||||
app.config.blood = bloodGoreWidget->value[0];
|
||||
}
|
||||
|
||||
static void trophyScreenshot(void)
|
||||
{
|
||||
app.config.trophyScreenshot = trophyScreenshotWidget->value;
|
||||
app.config.trophyScreenshot = trophyScreenshotWidget->value[0];
|
||||
}
|
||||
|
||||
static void trophyAlert(void)
|
||||
{
|
||||
app.config.trophyAlert = trophyAlertWidget->value;
|
||||
app.config.trophyAlert = trophyAlertWidget->value[0];
|
||||
}
|
||||
|
||||
static void inventory(void)
|
||||
{
|
||||
app.config.inventory = inventoryWidget->value;
|
||||
app.config.inventory = inventoryWidget->value[0];
|
||||
}
|
||||
|
||||
static void controls(void)
|
||||
|
@ -176,6 +186,27 @@ static void controls(void)
|
|||
showWidgetGroup("controls");
|
||||
}
|
||||
|
||||
static void updateControlConfig(void)
|
||||
{
|
||||
app.config.keyControls[CONTROL_LEFT] = getWidget("left", "controls")->value[0];
|
||||
app.config.keyControls[CONTROL_RIGHT] = getWidget("right", "controls")->value[0];
|
||||
app.config.keyControls[CONTROL_UP] = getWidget("up", "controls")->value[0];
|
||||
app.config.keyControls[CONTROL_DOWN] = getWidget("down", "controls")->value[0];
|
||||
app.config.keyControls[CONTROL_JUMP] = getWidget("jump", "controls")->value[0];
|
||||
app.config.keyControls[CONTROL_FIRE] = getWidget("fire", "controls")->value[0];
|
||||
app.config.keyControls[CONTROL_MAP] = getWidget("map", "controls")->value[0];
|
||||
app.config.keyControls[CONTROL_PAUSE] = getWidget("pause", "controls")->value[0];
|
||||
|
||||
app.config.joypadControls[CONTROL_LEFT] = getWidget("left", "controls")->value[1];
|
||||
app.config.joypadControls[CONTROL_RIGHT] = getWidget("right", "controls")->value[1];
|
||||
app.config.joypadControls[CONTROL_UP] = getWidget("up", "controls")->value[1];
|
||||
app.config.joypadControls[CONTROL_DOWN] = getWidget("down", "controls")->value[1];
|
||||
app.config.joypadControls[CONTROL_JUMP] = getWidget("jump", "controls")->value[1];
|
||||
app.config.joypadControls[CONTROL_FIRE] = getWidget("fire", "controls")->value[1];
|
||||
app.config.joypadControls[CONTROL_MAP] = getWidget("map", "controls")->value[1];
|
||||
app.config.joypadControls[CONTROL_PAUSE] = getWidget("pause", "controls")->value[1];
|
||||
}
|
||||
|
||||
static void back(void)
|
||||
{
|
||||
switch (section)
|
||||
|
@ -189,6 +220,7 @@ static void back(void)
|
|||
break;
|
||||
|
||||
case SECTION_CONTROLS:
|
||||
updateControlConfig();
|
||||
playSound(SND_MENU_BACK, 0);
|
||||
section = SECTION_MAIN;
|
||||
showWidgetGroup("options");
|
||||
|
|
|
@ -487,7 +487,7 @@ struct Widget {
|
|||
int y;
|
||||
int w;
|
||||
int h;
|
||||
int value;
|
||||
int value[2];
|
||||
int minValue;
|
||||
int maxValue;
|
||||
int visible;
|
||||
|
|
|
@ -25,6 +25,7 @@ static void loadWidgets(void);
|
|||
static void createWidgetOptions(Widget *w, char *options);
|
||||
static void selectWidget(int dir);
|
||||
static void updateWidgetValue(int dir);
|
||||
static void handleInputWidget(void);
|
||||
|
||||
static Widget widgets[MAX_WIDGETS];
|
||||
static Widget *selectedWidget;
|
||||
|
@ -51,41 +52,54 @@ void initWidgets(void)
|
|||
|
||||
void doWidgets(void)
|
||||
{
|
||||
if (isControl(CONTROL_UP) || app.keyboard[SDL_SCANCODE_UP])
|
||||
if (!app.awaitingWidgetInput)
|
||||
{
|
||||
selectWidget(-1);
|
||||
|
||||
app.keyboard[SDL_SCANCODE_UP] = 0;
|
||||
clearControl(CONTROL_UP);
|
||||
}
|
||||
|
||||
if (isControl(CONTROL_DOWN) || app.keyboard[SDL_SCANCODE_DOWN])
|
||||
{
|
||||
selectWidget(1);
|
||||
|
||||
app.keyboard[SDL_SCANCODE_DOWN] = 0;
|
||||
clearControl(CONTROL_DOWN);
|
||||
}
|
||||
|
||||
if (isControl(CONTROL_LEFT) || app.keyboard[SDL_SCANCODE_LEFT])
|
||||
{
|
||||
updateWidgetValue(-1);
|
||||
}
|
||||
|
||||
if (isControl(CONTROL_RIGHT) || app.keyboard[SDL_SCANCODE_RIGHT])
|
||||
{
|
||||
updateWidgetValue(1);
|
||||
}
|
||||
|
||||
if (isControl(CONTROL_FIRE) || app.keyboard[SDL_SCANCODE_RETURN] || app.keyboard[SDL_SCANCODE_SPACE])
|
||||
{
|
||||
if (selectedWidget->type != WT_INPUT)
|
||||
if (isControl(CONTROL_UP) || app.keyboard[SDL_SCANCODE_UP])
|
||||
{
|
||||
selectedWidget->action();
|
||||
selectWidget(-1);
|
||||
|
||||
app.keyboard[SDL_SCANCODE_UP] = 0;
|
||||
clearControl(CONTROL_UP);
|
||||
}
|
||||
|
||||
app.keyboard[SDL_SCANCODE_SPACE] = app.keyboard[SDL_SCANCODE_RETURN] = 0;
|
||||
clearControl(CONTROL_FIRE);
|
||||
|
||||
if (isControl(CONTROL_DOWN) || app.keyboard[SDL_SCANCODE_DOWN])
|
||||
{
|
||||
selectWidget(1);
|
||||
|
||||
app.keyboard[SDL_SCANCODE_DOWN] = 0;
|
||||
clearControl(CONTROL_DOWN);
|
||||
}
|
||||
|
||||
if (isControl(CONTROL_LEFT) || app.keyboard[SDL_SCANCODE_LEFT])
|
||||
{
|
||||
updateWidgetValue(-1);
|
||||
}
|
||||
|
||||
if (isControl(CONTROL_RIGHT) || app.keyboard[SDL_SCANCODE_RIGHT])
|
||||
{
|
||||
updateWidgetValue(1);
|
||||
}
|
||||
|
||||
if (isControl(CONTROL_FIRE) || app.keyboard[SDL_SCANCODE_RETURN] || app.keyboard[SDL_SCANCODE_SPACE])
|
||||
{
|
||||
if (selectedWidget->type != WT_INPUT)
|
||||
{
|
||||
selectedWidget->action();
|
||||
}
|
||||
else if (!isControl(CONTROL_FIRE))
|
||||
{
|
||||
app.awaitingWidgetInput = 1;
|
||||
app.lastKeyPressed = 0;
|
||||
app.lastButtonPressed = -1;
|
||||
}
|
||||
|
||||
app.keyboard[SDL_SCANCODE_SPACE] = app.keyboard[SDL_SCANCODE_RETURN] = 0;
|
||||
clearControl(CONTROL_FIRE);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
handleInputWidget();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -93,12 +107,12 @@ static void updateWidgetValue(int dir)
|
|||
{
|
||||
if (selectedWidget->type == WT_SLIDER)
|
||||
{
|
||||
selectedWidget->value = limit(selectedWidget->value + dir, selectedWidget->minValue, selectedWidget->maxValue);
|
||||
selectedWidget->value[0] = limit(selectedWidget->value[0] + dir, selectedWidget->minValue, selectedWidget->maxValue);
|
||||
selectedWidget->action();
|
||||
}
|
||||
else if (selectedWidget->type == WT_SPINNER)
|
||||
{
|
||||
selectedWidget->value = limit(selectedWidget->value + dir, 0, selectedWidget->numOptions - 1);
|
||||
selectedWidget->value[0] = limit(selectedWidget->value[0] + dir, 0, selectedWidget->numOptions - 1);
|
||||
selectedWidget->action();
|
||||
app.keyboard[SDL_SCANCODE_LEFT] = app.keyboard[SDL_SCANCODE_RIGHT] = 0;
|
||||
clearControl(CONTROL_LEFT);
|
||||
|
@ -107,6 +121,35 @@ static void updateWidgetValue(int dir)
|
|||
}
|
||||
}
|
||||
|
||||
static void handleInputWidget(void)
|
||||
{
|
||||
if (app.keyboard[SDL_SCANCODE_ESCAPE])
|
||||
{
|
||||
app.awaitingWidgetInput = 0;
|
||||
}
|
||||
else if (app.keyboard[SDL_SCANCODE_BACKSPACE])
|
||||
{
|
||||
selectedWidget->value[0] = 0;
|
||||
selectedWidget->value[1] = -1;
|
||||
|
||||
app.awaitingWidgetInput = 0;
|
||||
}
|
||||
else if (app.lastKeyPressed != 0 || app.lastButtonPressed != -1)
|
||||
{
|
||||
if (app.lastKeyPressed != 0)
|
||||
{
|
||||
selectedWidget->value[0] = app.lastKeyPressed;
|
||||
}
|
||||
|
||||
if (app.lastButtonPressed != -1)
|
||||
{
|
||||
selectedWidget->value[1] = app.lastButtonPressed;
|
||||
}
|
||||
|
||||
app.awaitingWidgetInput = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void drawWidgets(void)
|
||||
{
|
||||
int i, j, x, tw, th, outline;
|
||||
|
@ -136,7 +179,7 @@ void drawWidgets(void)
|
|||
switch (w->type)
|
||||
{
|
||||
case WT_SLIDER:
|
||||
drawRect(w->x + w->w + 25, w->y, 500 * (w->value * 1.0 / w->maxValue), 40, 0, 128, 0, 255);
|
||||
drawRect(w->x + w->w + 25, w->y, 500 * (w->value[0] * 1.0 / w->maxValue), 40, 0, 128, 0, 255);
|
||||
drawOutlineRect(w->x + w->w + 25, w->y, 500, 40, 0, outline, 0, 255);
|
||||
break;
|
||||
|
||||
|
@ -148,7 +191,7 @@ void drawWidgets(void)
|
|||
|
||||
tw += 25;
|
||||
|
||||
if (j == w->value)
|
||||
if (j == w->value[0])
|
||||
{
|
||||
drawRect(x, w->y, tw, w->h, 0, 128, 0, 255);
|
||||
drawOutlineRect(x, w->y, tw, w->h, 0, outline, 0, 255);
|
||||
|
@ -164,7 +207,22 @@ void drawWidgets(void)
|
|||
x = w->x + w->w + 25;
|
||||
drawRect(x, w->y, 200, w->h, 0, 0, 0, 255);
|
||||
drawOutlineRect(x, w->y, 200, w->h, 0, outline, 0, 255);
|
||||
drawText(x + 100, w->y + 2, 24, TA_CENTER, colors.white, "%s", SDL_GetScancodeName(w->value));
|
||||
if (app.awaitingWidgetInput && w == selectedWidget)
|
||||
{
|
||||
drawText(x + 100, w->y + 2, 24, TA_CENTER, colors.white, "...");
|
||||
}
|
||||
else if (w->value[0] != -1 && w->value[1] != -1)
|
||||
{
|
||||
drawText(x + 100, w->y + 2, 24, TA_CENTER, colors.white, "%s or Btn %d", SDL_GetScancodeName(w->value[0]), w->value[1]);
|
||||
}
|
||||
else if (w->value[0] != -1)
|
||||
{
|
||||
drawText(x + 100, w->y + 2, 24, TA_CENTER, colors.white, "%s", SDL_GetScancodeName(w->value[0]));
|
||||
}
|
||||
else if (w->value[1] != -1)
|
||||
{
|
||||
drawText(x + 100, w->y + 2, 24, TA_CENTER, colors.white, "Btn %d", w->value[1]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -348,6 +406,9 @@ static void loadWidgetGroup(char *filename)
|
|||
w->minValue = cJSON_GetObjectItem(node, "minValue")->valueint;
|
||||
w->maxValue = cJSON_GetObjectItem(node, "maxValue")->valueint;
|
||||
break;
|
||||
|
||||
case WT_INPUT:
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue