blobwarsAttrition/src/game/options.c

274 lines
8.2 KiB
C
Raw Normal View History

2018-02-19 20:15:07 +01:00
/*
Copyright (C) 2018 Parallel Realities
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "options.h"
static void (*returnFromOptions)(void);
static void logic(void);
static void draw(void);
static void soundVolume(void);
static void musicVolume(void);
2018-02-27 22:54:52 +01:00
static void fullscreen(void);
static void windowSize(void);
2018-02-19 20:15:07 +01:00
static void bloodGore(void);
static void trophyScreenshot(void);
static void trophyAlert(void);
static void inventory(void);
2018-02-20 18:50:26 +01:00
static void controls(void);
2018-02-19 20:15:07 +01:00
static void back(void);
2018-02-20 18:50:26 +01:00
static void setGeneralOptions(void);
2018-02-27 22:54:52 +01:00
static void setWindowSizeOption(void);
2018-02-20 18:50:26 +01:00
static void setControlOptions(void);
static int section;
2018-02-19 20:15:07 +01:00
2018-02-20 12:29:50 +01:00
static Widget *soundVolumeWidget;
static Widget *musicVolumeWidget;
2018-02-27 22:54:52 +01:00
static Widget *windowSizeWidget;
static Widget *fullscreenWidget;
2018-02-20 12:29:50 +01:00
static Widget *bloodGoreWidget;
static Widget *trophyScreenshotWidget;
static Widget *trophyAlertWidget;
static Widget *inventoryWidget;
2018-02-20 18:50:26 +01:00
static Widget *controlsWidget;
2018-02-20 12:29:50 +01:00
static Texture *atlasTexture;
static Atlas *background;
void initOptions(void (*callback)(void))
2018-02-19 20:15:07 +01:00
{
2018-02-20 18:50:26 +01:00
startSectionTransition();
section = SECTION_MAIN;
2018-02-19 20:15:07 +01:00
returnFromOptions = callback;
2018-02-20 12:29:50 +01:00
atlasTexture = getTexture("gfx/atlas/atlas.png");
background = getImageFromAtlas("gfx/main/options.png");
2018-02-20 18:50:26 +01:00
setGeneralOptions();
setControlOptions();
showWidgetGroup("options");
2018-03-15 09:01:04 +01:00
app.delegate.logic = &logic;
app.delegate.draw = &draw;
2018-02-20 18:50:26 +01:00
endSectionTransition();
}
2018-02-19 20:15:07 +01:00
2018-02-20 18:50:26 +01:00
static void setGeneralOptions(void)
{
2018-02-20 12:29:50 +01:00
soundVolumeWidget = getWidget("soundVolume", "options");
2018-02-19 20:15:07 +01:00
soundVolumeWidget->action = soundVolume;
2018-02-20 20:24:17 +01:00
soundVolumeWidget->value[0] = app.config.soundVolume;
2018-02-19 20:15:07 +01:00
2018-02-20 12:29:50 +01:00
musicVolumeWidget = getWidget("musicVolume", "options");
2018-02-19 20:15:07 +01:00
musicVolumeWidget->action = musicVolume;
2018-02-20 20:24:17 +01:00
musicVolumeWidget->value[0] = app.config.musicVolume;
2018-02-27 22:54:52 +01:00
fullscreenWidget = getWidget("fullscreen", "options");
fullscreenWidget->action = fullscreen;
fullscreenWidget->value[0] = app.config.fullscreen;
windowSizeWidget = getWidget("windowSize", "options");
windowSizeWidget->action = windowSize;
setWindowSizeOption();
2018-02-19 20:15:07 +01:00
2018-02-20 12:29:50 +01:00
bloodGoreWidget = getWidget("bloodGore", "options");
2018-02-19 20:15:07 +01:00
bloodGoreWidget->action = bloodGore;
2018-02-20 20:24:17 +01:00
bloodGoreWidget->value[0] = app.config.blood;
2018-02-19 20:15:07 +01:00
2018-02-20 12:29:50 +01:00
trophyScreenshotWidget = getWidget("trophyScreenshot", "options");
2018-02-19 20:15:07 +01:00
trophyScreenshotWidget->action = trophyScreenshot;
2018-02-20 20:24:17 +01:00
trophyScreenshotWidget->value[0] = app.config.trophyScreenshot;
2018-02-19 20:15:07 +01:00
2018-02-20 12:29:50 +01:00
trophyAlertWidget = getWidget("trophyAlert", "options");
2018-02-19 20:15:07 +01:00
trophyAlertWidget->action = trophyAlert;
2018-02-20 20:24:17 +01:00
trophyAlertWidget->value[0] = app.config.trophyAlert;
2018-02-19 20:15:07 +01:00
2018-02-20 12:29:50 +01:00
inventoryWidget = getWidget("inventory", "options");
2018-02-19 20:15:07 +01:00
inventoryWidget->action = inventory;
2018-02-20 20:24:17 +01:00
inventoryWidget->value[0] = app.config.inventory;
2018-02-19 20:15:07 +01:00
2018-02-20 18:50:26 +01:00
controlsWidget = getWidget("controls", "options");
controlsWidget->action = controls;
2018-02-20 18:50:26 +01:00
getWidget("back", "options")->action = back;
getWidget("back", "controls")->action = back;
}
2018-02-19 20:15:07 +01:00
2018-02-27 22:54:52 +01:00
static void setWindowSizeOption(void)
{
int i;
char winSize[16];
sprintf(winSize, "%d x %d", app.config.winWidth, app.config.winHeight);
for (i = 0 ; i < windowSizeWidget->numOptions ; i++)
{
if (strcmp(windowSizeWidget->options[i], winSize) == 0)
{
windowSizeWidget->value[0] = i;
return;
}
}
}
2018-02-20 18:50:26 +01:00
static void setControlOptions(void)
{
2018-02-20 20:24:17 +01:00
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];
2018-02-19 20:15:07 +01:00
}
static void logic(void)
{
2018-02-20 12:29:50 +01:00
doWidgets();
2018-02-19 20:15:07 +01:00
}
static void draw(void)
{
2018-02-20 12:29:50 +01:00
float h;
h = (SCREEN_WIDTH / 800.0) * background->rect.h;
drawText(SCREEN_WIDTH / 2, 50, 40, TA_CENTER, colors.white, "Options");
blitRectScaled(atlasTexture->texture, 0, SCREEN_HEIGHT - h, SCREEN_WIDTH, h, &background->rect, 0);
drawWidgets();
2018-02-19 20:15:07 +01:00
}
static void soundVolume(void)
{
2018-02-20 20:24:17 +01:00
app.config.soundVolume = soundVolumeWidget->value[0];
2018-02-20 12:29:50 +01:00
Mix_Volume(-1, app.config.soundVolume);
2018-02-19 20:15:07 +01:00
}
static void musicVolume(void)
{
2018-02-20 20:24:17 +01:00
app.config.musicVolume = musicVolumeWidget->value[0];
2018-02-20 12:29:50 +01:00
Mix_VolumeMusic(app.config.musicVolume);
2018-02-19 20:15:07 +01:00
}
2018-02-27 22:54:52 +01:00
static void fullscreen(void)
{
app.config.fullscreen = fullscreenWidget->value[0];
}
static void windowSize(void)
{
int i;
i = windowSizeWidget->value[0];
sscanf(windowSizeWidget->options[i], "%d x %d", &app.config.winWidth, &app.config.winHeight);
}
2018-02-19 20:15:07 +01:00
static void bloodGore(void)
{
2018-02-20 20:24:17 +01:00
app.config.blood = bloodGoreWidget->value[0];
2018-02-19 20:15:07 +01:00
}
static void trophyScreenshot(void)
{
2018-02-20 20:24:17 +01:00
app.config.trophyScreenshot = trophyScreenshotWidget->value[0];
2018-02-19 20:15:07 +01:00
}
static void trophyAlert(void)
{
2018-02-20 20:24:17 +01:00
app.config.trophyAlert = trophyAlertWidget->value[0];
2018-02-19 20:15:07 +01:00
}
static void inventory(void)
{
2018-02-20 20:24:17 +01:00
app.config.inventory = inventoryWidget->value[0];
2018-02-19 20:15:07 +01:00
}
2018-02-20 18:50:26 +01:00
static void controls(void)
2018-02-19 20:15:07 +01:00
{
2018-02-20 18:50:26 +01:00
section = SECTION_CONTROLS;
playSound(SND_MENU_SELECT, 0);
showWidgetGroup("controls");
2018-02-19 20:15:07 +01:00
}
2018-02-20 20:24:17 +01:00
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];
}
2018-02-19 20:15:07 +01:00
static void back(void)
{
2018-02-20 18:50:26 +01:00
switch (section)
{
case SECTION_MAIN:
playSound(SND_MENU_BACK, 0);
startSectionTransition();
saveConfig();
returnFromOptions();
endSectionTransition();
break;
case SECTION_CONTROLS:
2018-02-20 20:24:17 +01:00
updateControlConfig();
2018-02-20 18:50:26 +01:00
playSound(SND_MENU_BACK, 0);
section = SECTION_MAIN;
showWidgetGroup("options");
break;
}
2018-02-19 20:15:07 +01:00
}