Start of options screen.
This commit is contained in:
parent
7695f34280
commit
289415cc87
|
@ -43,7 +43,7 @@ _OBJS += cJSON.o
|
||||||
_OBJS += key.o keycard.o
|
_OBJS += key.o keycard.o
|
||||||
_OBJS += laser.o laserBlob.o laserDroid.o laserTrap.o lift.o lookup.o
|
_OBJS += laser.o laserBlob.o laserDroid.o laserTrap.o lift.o lookup.o
|
||||||
_OBJS += machineGunBlob.o machineGunDroid.o main.o map.o maths.o mia.o missile.o
|
_OBJS += machineGunBlob.o machineGunDroid.o main.o map.o maths.o mia.o missile.o
|
||||||
_OBJS += objectives.o
|
_OBJS += objectives.o options.o
|
||||||
_OBJS += particles.o player.o plasmaBlob.o plasmaDroid.o pistolBlob.o pistolDroid.o postMission.o powerPoint.o powerPool.o pressurePlate.o pushBlock.o
|
_OBJS += particles.o player.o plasmaBlob.o plasmaDroid.o pistolBlob.o pistolDroid.o postMission.o powerPoint.o powerPool.o pressurePlate.o pushBlock.o
|
||||||
_OBJS += quadtree.o
|
_OBJS += quadtree.o
|
||||||
_OBJS += radar.o
|
_OBJS += radar.o
|
||||||
|
|
|
@ -33,53 +33,57 @@ static void keyboard(void);
|
||||||
static void joypad(void);
|
static void joypad(void);
|
||||||
static void back(void);
|
static void back(void);
|
||||||
|
|
||||||
static Widget soundVolumeWidget;
|
static Widget *soundVolumeWidget;
|
||||||
static Widget musicVolumeWidget;
|
static Widget *musicVolumeWidget;
|
||||||
static Widget bloodGoreWidget;
|
static Widget *bloodGoreWidget;
|
||||||
static Widget trophyScreenshotWidget;
|
static Widget *trophyScreenshotWidget;
|
||||||
static Widget trophyAlertWidget;
|
static Widget *trophyAlertWidget;
|
||||||
static Widget inventoryWidget;
|
static Widget *inventoryWidget;
|
||||||
static Widget keyboardWidget;
|
static Widget *keyboardWidget;
|
||||||
static Widget joypadWidget;
|
static Widget *joypadWidget;
|
||||||
static Widget backWidget;
|
static Widget *backWidget;
|
||||||
|
static Texture *atlasTexture;
|
||||||
|
static Atlas *background;
|
||||||
|
|
||||||
void initOptions((void)(*callback))
|
void initOptions(void (*callback)(void))
|
||||||
{
|
{
|
||||||
returnFromOptions = callback;
|
returnFromOptions = callback;
|
||||||
|
|
||||||
atlasTexture = getTexture("");
|
atlasTexture = getTexture("gfx/atlas/atlas.png");
|
||||||
|
|
||||||
soundVolumeWidget = getWidget("soundVolume", "options")
|
background = getImageFromAtlas("gfx/main/options.png");
|
||||||
|
|
||||||
|
soundVolumeWidget = getWidget("soundVolume", "options");
|
||||||
soundVolumeWidget->action = soundVolume;
|
soundVolumeWidget->action = soundVolume;
|
||||||
soundVolumeWidget->value = game.config.soundVolume;
|
soundVolumeWidget->value = app.config.soundVolume;
|
||||||
|
|
||||||
musicVolumeWidget = getWidget("musicVolume", "options")
|
musicVolumeWidget = getWidget("musicVolume", "options");
|
||||||
musicVolumeWidget->action = musicVolume;
|
musicVolumeWidget->action = musicVolume;
|
||||||
musicVolumeWidget->value = game.config.musicVolume;
|
musicVolumeWidget->value = app.config.musicVolume;
|
||||||
|
|
||||||
bloodGoreWidget = getWidget("bloodGore", "options")
|
bloodGoreWidget = getWidget("bloodGore", "options");
|
||||||
bloodGoreWidget->action = bloodGore;
|
bloodGoreWidget->action = bloodGore;
|
||||||
bloodGoreWidget->value = game.config.blood;
|
bloodGoreWidget->value = app.config.blood;
|
||||||
|
|
||||||
trophyScreenshotWidget = getWidget("trophyScreenshot", "options")
|
trophyScreenshotWidget = getWidget("trophyScreenshot", "options");
|
||||||
trophyScreenshotWidget->action = trophyScreenshot;
|
trophyScreenshotWidget->action = trophyScreenshot;
|
||||||
trophyScreenshotWidget->value = game.config.trophyScreenshot;
|
trophyScreenshotWidget->value = app.config.trophyScreenshot;
|
||||||
|
|
||||||
trophyAlertWidget = getWidget("trophyAlert", "options")
|
trophyAlertWidget = getWidget("trophyAlert", "options");
|
||||||
trophyAlertWidget->action = trophyAlert;
|
trophyAlertWidget->action = trophyAlert;
|
||||||
trophyAlertWidget->value = game.config.trophyAlert;
|
trophyAlertWidget->value = app.config.trophyAlert;
|
||||||
|
|
||||||
inventoryWidget = getWidget("inventory", "options")
|
inventoryWidget = getWidget("inventory", "options");
|
||||||
inventoryWidget->action = inventory;
|
inventoryWidget->action = inventory;
|
||||||
inventoryWidget->value = game.config.inventory;
|
inventoryWidget->value = app.config.inventory;
|
||||||
|
|
||||||
keyboardWidget = getWidget("keyboard", "options")
|
keyboardWidget = getWidget("keyboard", "options");
|
||||||
keyboardWidget->action = keyboard;
|
keyboardWidget->action = keyboard;
|
||||||
|
|
||||||
joypadWidget = getWidget("joypad", "options")
|
joypadWidget = getWidget("joypad", "options");
|
||||||
joypadWidget->action = joypad;
|
joypadWidget->action = joypad;
|
||||||
|
|
||||||
backWidget = getWidget("back", "options")
|
backWidget = getWidget("back", "options");
|
||||||
backWidget->action = back;
|
backWidget->action = back;
|
||||||
|
|
||||||
showWidgetGroup("options");
|
showWidgetGroup("options");
|
||||||
|
@ -90,42 +94,54 @@ void initOptions((void)(*callback))
|
||||||
|
|
||||||
static void logic(void)
|
static void logic(void)
|
||||||
{
|
{
|
||||||
|
doWidgets();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void draw(void)
|
static void draw(void)
|
||||||
{
|
{
|
||||||
|
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void soundVolume(void)
|
static void soundVolume(void)
|
||||||
{
|
{
|
||||||
|
app.config.soundVolume = soundVolumeWidget->value;
|
||||||
|
|
||||||
|
Mix_Volume(-1, app.config.soundVolume);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void musicVolume(void)
|
static void musicVolume(void)
|
||||||
{
|
{
|
||||||
|
app.config.musicVolume = musicVolumeWidget->value;
|
||||||
|
|
||||||
|
Mix_VolumeMusic(app.config.musicVolume);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void bloodGore(void)
|
static void bloodGore(void)
|
||||||
{
|
{
|
||||||
|
app.config.blood = bloodGoreWidget->value;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void trophyScreenshot(void)
|
static void trophyScreenshot(void)
|
||||||
{
|
{
|
||||||
|
app.config.trophyScreenshot = trophyScreenshotWidget->value;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void trophyAlert(void)
|
static void trophyAlert(void)
|
||||||
{
|
{
|
||||||
|
app.config.trophyAlert = trophyAlertWidget->value;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void inventory(void)
|
static void inventory(void)
|
||||||
{
|
{
|
||||||
|
app.config.inventory = inventoryWidget->value;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void keyboard(void)
|
static void keyboard(void)
|
||||||
|
@ -140,5 +156,7 @@ static void joypad(void)
|
||||||
|
|
||||||
static void back(void)
|
static void back(void)
|
||||||
{
|
{
|
||||||
|
saveConfig();
|
||||||
|
|
||||||
|
returnFromOptions();
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,20 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../common.h"
|
#include "../common.h"
|
||||||
|
#include "SDL2/SDL_mixer.h"
|
||||||
|
|
||||||
|
extern void showWidgetGroup(char *group);
|
||||||
|
extern Widget *getWidget(char *name, char *group);
|
||||||
|
extern void drawWidgets(void);
|
||||||
|
extern Texture *getTexture(const char *filename);
|
||||||
|
extern Atlas *getImageFromAtlas(char *filename);
|
||||||
|
extern void doWidgets(void);
|
||||||
|
extern void drawWidgets(void);
|
||||||
|
extern void blitRect(SDL_Texture *texture, int x, int y, SDL_Rect *srcRect, int center);
|
||||||
|
extern void blitRectScaled(SDL_Texture *texture, int x, int y, int w, int h, SDL_Rect *srcRect, int center);
|
||||||
|
extern void saveConfig(void);
|
||||||
|
extern void drawText(int x, int y, int size, int align, SDL_Color c, const char *format, ...);
|
||||||
|
|
||||||
extern App app;
|
extern App app;
|
||||||
|
extern Colors colors;
|
||||||
extern Game game;
|
extern Game game;
|
||||||
|
|
|
@ -85,8 +85,8 @@ void initSDL(void)
|
||||||
|
|
||||||
Mix_AllocateChannels(64);
|
Mix_AllocateChannels(64);
|
||||||
|
|
||||||
Mix_Volume(-1, app.config.soundVolume * (MIX_MAX_VOLUME / 10));
|
Mix_Volume(-1, app.config.soundVolume);
|
||||||
Mix_VolumeMusic(app.config.musicVolume * (MIX_MAX_VOLUME / 10));
|
Mix_VolumeMusic(app.config.musicVolume);
|
||||||
|
|
||||||
app.window = SDL_CreateWindow("Blob Wars : Attrition", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, app.winWidth, app.winHeight, windowFlags);
|
app.window = SDL_CreateWindow("Blob Wars : Attrition", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, app.winWidth, app.winHeight, windowFlags);
|
||||||
|
|
||||||
|
@ -197,8 +197,8 @@ static void initDefaultConfig(void)
|
||||||
app.config.trophyAlert = 1;
|
app.config.trophyAlert = 1;
|
||||||
app.config.trophyScreenshot = 1;
|
app.config.trophyScreenshot = 1;
|
||||||
|
|
||||||
app.config.musicVolume = 8;
|
app.config.musicVolume = 100;
|
||||||
app.config.soundVolume = 10;
|
app.config.soundVolume = 128;
|
||||||
|
|
||||||
app.config.keyControls[CONTROL_LEFT] = SDL_SCANCODE_A;
|
app.config.keyControls[CONTROL_LEFT] = SDL_SCANCODE_A;
|
||||||
app.config.keyControls[CONTROL_RIGHT] = SDL_SCANCODE_D;
|
app.config.keyControls[CONTROL_RIGHT] = SDL_SCANCODE_D;
|
||||||
|
|
|
@ -30,6 +30,9 @@ static Widget widgets[MAX_WIDGETS];
|
||||||
static Widget *selectedWidget;
|
static Widget *selectedWidget;
|
||||||
static int widgetIndex;
|
static int widgetIndex;
|
||||||
static int numWidgets;
|
static int numWidgets;
|
||||||
|
static Atlas *left;
|
||||||
|
static Atlas *right;
|
||||||
|
static Texture *atlasTexture;
|
||||||
|
|
||||||
void initWidgets(void)
|
void initWidgets(void)
|
||||||
{
|
{
|
||||||
|
@ -40,6 +43,10 @@ void initWidgets(void)
|
||||||
selectedWidget = NULL;
|
selectedWidget = NULL;
|
||||||
|
|
||||||
loadWidgets();
|
loadWidgets();
|
||||||
|
|
||||||
|
atlasTexture = getTexture("gfx/atlas/atlas.png");
|
||||||
|
left = getImageFromAtlas("gfx/ui/left.png");
|
||||||
|
right = getImageFromAtlas("gfx/ui/right.png");
|
||||||
}
|
}
|
||||||
|
|
||||||
void doWidgets(void)
|
void doWidgets(void)
|
||||||
|
@ -90,12 +97,16 @@ static void updateWidgetValue(int dir)
|
||||||
{
|
{
|
||||||
selectedWidget->value = limit(selectedWidget->value + dir, 0, selectedWidget->numOptions - 1);
|
selectedWidget->value = limit(selectedWidget->value + dir, 0, selectedWidget->numOptions - 1);
|
||||||
selectedWidget->action();
|
selectedWidget->action();
|
||||||
|
app.keyboard[SDL_SCANCODE_LEFT] = app.keyboard[SDL_SCANCODE_RIGHT] = 0;
|
||||||
|
clearControl(CONTROL_LEFT);
|
||||||
|
clearControl(CONTROL_RIGHT);
|
||||||
|
playSound(SND_MENU_SELECT, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawWidgets(void)
|
void drawWidgets(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i, j, x;
|
||||||
Widget *w;
|
Widget *w;
|
||||||
|
|
||||||
for (i = 0 ; i < numWidgets ; i++)
|
for (i = 0 ; i < numWidgets ; i++)
|
||||||
|
@ -104,9 +115,6 @@ void drawWidgets(void)
|
||||||
|
|
||||||
if (w->visible)
|
if (w->visible)
|
||||||
{
|
{
|
||||||
switch (w->type)
|
|
||||||
{
|
|
||||||
case WT_BUTTON:
|
|
||||||
if (w != selectedWidget)
|
if (w != selectedWidget)
|
||||||
{
|
{
|
||||||
drawRect(w->x, w->y, w->w, w->h, 0, 0, 0, 255);
|
drawRect(w->x, w->y, w->w, w->h, 0, 0, 0, 255);
|
||||||
|
@ -117,13 +125,30 @@ void drawWidgets(void)
|
||||||
drawRect(w->x, w->y, w->w, w->h, 0, 128, 0, 255);
|
drawRect(w->x, w->y, w->w, w->h, 0, 128, 0, 255);
|
||||||
drawOutlineRect(w->x, w->y, w->w, w->h, 0, 255, 0, 255);
|
drawOutlineRect(w->x, w->y, w->w, w->h, 0, 255, 0, 255);
|
||||||
}
|
}
|
||||||
|
|
||||||
drawText(w->x + w->w / 2, w->y + 2, 24, TA_CENTER, colors.white, w->label);
|
drawText(w->x + w->w / 2, w->y + 2, 24, TA_CENTER, colors.white, w->label);
|
||||||
|
|
||||||
|
switch (w->type)
|
||||||
|
{
|
||||||
|
case WT_BUTTON:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WT_SLIDER:
|
case WT_SLIDER:
|
||||||
|
drawRect(w->x + w->w + 25, w->y, 500 * (w->value * 1.0 / w->maxValue), 40, 0, 128, 0, 255);
|
||||||
|
drawOutlineRect(w->x + w->w + 25, w->y, 500, 40, 0, 255, 0, 255);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WT_SPINNER:
|
case WT_SPINNER:
|
||||||
|
for (j = 0 ; j < w->numOptions ; j++)
|
||||||
|
{
|
||||||
|
x = w->x + w->w + 25 + (125 * j);
|
||||||
|
if (j == w->value)
|
||||||
|
{
|
||||||
|
drawRect(x, w->y, 100, w->h, 0, 128, 0, 255);
|
||||||
|
drawOutlineRect(x, w->y, 100, w->h, 0, 255, 0, 255);
|
||||||
|
}
|
||||||
|
drawText(x + 50, w->y + 2, 24, TA_CENTER, colors.white, w->options[j]);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WT_INPUT:
|
case WT_INPUT:
|
||||||
|
@ -306,6 +331,11 @@ static void loadWidgetGroup(char *filename)
|
||||||
createWidgetOptions(w, cJSON_GetObjectItem(node, "options")->valuestring);
|
createWidgetOptions(w, cJSON_GetObjectItem(node, "options")->valuestring);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case WT_SLIDER:
|
||||||
|
w->minValue = cJSON_GetObjectItem(node, "minValue")->valueint;
|
||||||
|
w->maxValue = cJSON_GetObjectItem(node, "maxValue")->valueint;
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,9 @@ extern void playSound(int snd, int ch);
|
||||||
extern int isControl(int type);
|
extern int isControl(int type);
|
||||||
extern void clearControl(int type);
|
extern void clearControl(int type);
|
||||||
extern int collision(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2);
|
extern int collision(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2);
|
||||||
|
extern Texture *getTexture(const char *filename);
|
||||||
|
extern Atlas *getImageFromAtlas(char *filename);
|
||||||
|
extern void blitRect(SDL_Texture *texture, int x, int y, SDL_Rect *srcRect, int center);
|
||||||
|
|
||||||
extern App app;
|
extern App app;
|
||||||
extern Colors colors;
|
extern Colors colors;
|
||||||
|
|
|
@ -23,11 +23,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
void initAtlasTest(void)
|
void initAtlasTest(void)
|
||||||
{
|
{
|
||||||
dev.cheatStatic = 0;
|
dev.cheatStatic = 0;
|
||||||
dev.cheatBlind = 1;
|
dev.cheatBlind = 0;
|
||||||
dev.cheatNoEnemies = 0;
|
dev.cheatNoEnemies = 0;
|
||||||
dev.cheatKeys = 0;
|
dev.cheatKeys = 0;
|
||||||
dev.cheatPower = 1;
|
dev.cheatPower = 0;
|
||||||
dev.cheatHealth = 1;
|
dev.cheatHealth = 0;
|
||||||
dev.cheatLevels = 0;
|
dev.cheatLevels = 0;
|
||||||
|
|
||||||
loadGame();
|
loadGame();
|
||||||
|
@ -37,5 +37,7 @@ void initAtlasTest(void)
|
||||||
initWorld();
|
initWorld();
|
||||||
*/
|
*/
|
||||||
|
|
||||||
initHub();
|
/*initHub();*/
|
||||||
|
|
||||||
|
initOptions();
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
extern void initWorld(void);
|
extern void initWorld(void);
|
||||||
extern void initHub(void);
|
extern void initHub(void);
|
||||||
extern void loadGame(void);
|
extern void loadGame(void);
|
||||||
|
extern void initOptions(void);
|
||||||
|
|
||||||
extern Dev dev;
|
extern Dev dev;
|
||||||
extern Game game;
|
extern Game game;
|
||||||
|
|
Loading…
Reference in New Issue