blobwarsAttrition/src/game/options.c

168 lines
3.9 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);
static void bloodGore(void);
static void trophyScreenshot(void);
static void trophyAlert(void);
static void inventory(void);
static void keyboard(void);
static void joypad(void);
static void back(void);
2018-02-20 12:29:50 +01:00
static Widget *soundVolumeWidget;
static Widget *musicVolumeWidget;
static Widget *bloodGoreWidget;
static Widget *trophyScreenshotWidget;
static Widget *trophyAlertWidget;
static Widget *inventoryWidget;
static Widget *keyboardWidget;
static Widget *joypadWidget;
static Widget *backWidget;
static Texture *atlasTexture;
static Atlas *background;
void initOptions(void (*callback)(void))
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-19 20:15:07 +01:00
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 12:29:50 +01:00
soundVolumeWidget->value = 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 12:29:50 +01:00
musicVolumeWidget->value = app.config.musicVolume;
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 12:29:50 +01:00
bloodGoreWidget->value = 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 12:29:50 +01:00
trophyScreenshotWidget->value = 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 12:29:50 +01:00
trophyAlertWidget->value = 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 12:29:50 +01:00
inventoryWidget->value = app.config.inventory;
2018-02-19 20:15:07 +01:00
2018-02-20 12:29:50 +01:00
keyboardWidget = getWidget("keyboard", "options");
2018-02-19 20:15:07 +01:00
keyboardWidget->action = keyboard;
2018-02-20 12:29:50 +01:00
joypadWidget = getWidget("joypad", "options");
2018-02-19 20:15:07 +01:00
joypadWidget->action = joypad;
2018-02-20 12:29:50 +01:00
backWidget = getWidget("back", "options");
2018-02-19 20:15:07 +01:00
backWidget->action = back;
showWidgetGroup("options");
if (!app.joypad)
{
joypadWidget->visible = 0;
}
2018-02-19 20:15:07 +01:00
app.delegate.logic = logic;
app.delegate.draw = draw;
}
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 12:29:50 +01:00
app.config.soundVolume = soundVolumeWidget->value;
Mix_Volume(-1, app.config.soundVolume);
2018-02-19 20:15:07 +01:00
}
static void musicVolume(void)
{
2018-02-20 12:29:50 +01:00
app.config.musicVolume = musicVolumeWidget->value;
Mix_VolumeMusic(app.config.musicVolume);
2018-02-19 20:15:07 +01:00
}
static void bloodGore(void)
{
2018-02-20 12:29:50 +01:00
app.config.blood = bloodGoreWidget->value;
2018-02-19 20:15:07 +01:00
}
static void trophyScreenshot(void)
{
2018-02-20 12:29:50 +01:00
app.config.trophyScreenshot = trophyScreenshotWidget->value;
2018-02-19 20:15:07 +01:00
}
static void trophyAlert(void)
{
2018-02-20 12:29:50 +01:00
app.config.trophyAlert = trophyAlertWidget->value;
2018-02-19 20:15:07 +01:00
}
static void inventory(void)
{
2018-02-20 12:29:50 +01:00
app.config.inventory = inventoryWidget->value;
2018-02-19 20:15:07 +01:00
}
static void keyboard(void)
{
}
static void joypad(void)
{
}
static void back(void)
{
2018-02-20 12:29:50 +01:00
saveConfig();
returnFromOptions();
2018-02-19 20:15:07 +01:00
}