diff --git a/common.mk b/common.mk index 2dba3ee..10fbdcd 100644 --- a/common.mk +++ b/common.mk @@ -43,7 +43,7 @@ _OBJS += cJSON.o _OBJS += key.o keycard.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 += 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 += quadtree.o _OBJS += radar.o diff --git a/src/game/options.c b/src/game/options.c index 12a3e8a..8c5e811 100644 --- a/src/game/options.c +++ b/src/game/options.c @@ -33,53 +33,57 @@ static void keyboard(void); static void joypad(void); static void back(void); -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 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 initOptions(void (*callback)(void)) { returnFromOptions = callback; - atlasTexture = getTexture(""); + atlasTexture = getTexture("gfx/atlas/atlas.png"); + + background = getImageFromAtlas("gfx/main/options.png"); - soundVolumeWidget = getWidget("soundVolume", "options") + soundVolumeWidget = getWidget("soundVolume", "options"); 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->value = game.config.musicVolume; + musicVolumeWidget->value = app.config.musicVolume; - bloodGoreWidget = getWidget("bloodGore", "options") + bloodGoreWidget = getWidget("bloodGore", "options"); 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->value = game.config.trophyScreenshot; + trophyScreenshotWidget->value = app.config.trophyScreenshot; - trophyAlertWidget = getWidget("trophyAlert", "options") + trophyAlertWidget = getWidget("trophyAlert", "options"); 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->value = game.config.inventory; + inventoryWidget->value = app.config.inventory; - keyboardWidget = getWidget("keyboard", "options") + keyboardWidget = getWidget("keyboard", "options"); keyboardWidget->action = keyboard; - joypadWidget = getWidget("joypad", "options") + joypadWidget = getWidget("joypad", "options"); joypadWidget->action = joypad; - backWidget = getWidget("back", "options") + backWidget = getWidget("back", "options"); backWidget->action = back; showWidgetGroup("options"); @@ -90,42 +94,54 @@ void initOptions((void)(*callback)) static void logic(void) { - + doWidgets(); } 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) { - + app.config.soundVolume = soundVolumeWidget->value; + + Mix_Volume(-1, app.config.soundVolume); } static void musicVolume(void) { - + app.config.musicVolume = musicVolumeWidget->value; + + Mix_VolumeMusic(app.config.musicVolume); } static void bloodGore(void) { - + app.config.blood = bloodGoreWidget->value; } static void trophyScreenshot(void) { - + app.config.trophyScreenshot = trophyScreenshotWidget->value; } static void trophyAlert(void) { - + app.config.trophyAlert = trophyAlertWidget->value; } static void inventory(void) { - + app.config.inventory = inventoryWidget->value; } static void keyboard(void) @@ -140,5 +156,7 @@ static void joypad(void) static void back(void) { - + saveConfig(); + + returnFromOptions(); } diff --git a/src/game/options.h b/src/game/options.h index 75c0187..0a744e9 100644 --- a/src/game/options.h +++ b/src/game/options.h @@ -19,6 +19,20 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #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 Colors colors; extern Game game; diff --git a/src/system/init.c b/src/system/init.c index 08e5d3d..962ec53 100644 --- a/src/system/init.c +++ b/src/system/init.c @@ -85,8 +85,8 @@ void initSDL(void) Mix_AllocateChannels(64); - Mix_Volume(-1, app.config.soundVolume * (MIX_MAX_VOLUME / 10)); - Mix_VolumeMusic(app.config.musicVolume * (MIX_MAX_VOLUME / 10)); + Mix_Volume(-1, app.config.soundVolume); + Mix_VolumeMusic(app.config.musicVolume); 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.trophyScreenshot = 1; - app.config.musicVolume = 8; - app.config.soundVolume = 10; + app.config.musicVolume = 100; + app.config.soundVolume = 128; app.config.keyControls[CONTROL_LEFT] = SDL_SCANCODE_A; app.config.keyControls[CONTROL_RIGHT] = SDL_SCANCODE_D; diff --git a/src/system/widgets.c b/src/system/widgets.c index bc18478..fbf74e4 100644 --- a/src/system/widgets.c +++ b/src/system/widgets.c @@ -30,6 +30,9 @@ static Widget widgets[MAX_WIDGETS]; static Widget *selectedWidget; static int widgetIndex; static int numWidgets; +static Atlas *left; +static Atlas *right; +static Texture *atlasTexture; void initWidgets(void) { @@ -40,6 +43,10 @@ void initWidgets(void) selectedWidget = NULL; loadWidgets(); + + atlasTexture = getTexture("gfx/atlas/atlas.png"); + left = getImageFromAtlas("gfx/ui/left.png"); + right = getImageFromAtlas("gfx/ui/right.png"); } void doWidgets(void) @@ -90,12 +97,16 @@ static void updateWidgetValue(int dir) { selectedWidget->value = limit(selectedWidget->value + dir, 0, selectedWidget->numOptions - 1); 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) { - int i; + int i, j, x; Widget *w; for (i = 0 ; i < numWidgets ; i++) @@ -104,26 +115,40 @@ void drawWidgets(void) if (w->visible) { + if (w != selectedWidget) + { + drawRect(w->x, w->y, w->w, w->h, 0, 0, 0, 255); + drawOutlineRect(w->x, w->y, w->w, w->h, 0, 128, 0, 255); + } + else + { + 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); + } + + drawText(w->x + w->w / 2, w->y + 2, 24, TA_CENTER, colors.white, w->label); + switch (w->type) { case WT_BUTTON: - if (w != selectedWidget) - { - drawRect(w->x, w->y, w->w, w->h, 0, 0, 0, 255); - drawOutlineRect(w->x, w->y, w->w, w->h, 0, 128, 0, 255); - } - else - { - 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); - } - drawText(w->x + w->w / 2, w->y + 2, 24, TA_CENTER, colors.white, w->label); break; 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; 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; case WT_INPUT: @@ -305,6 +330,11 @@ static void loadWidgetGroup(char *filename) case WT_SPINNER: createWidgetOptions(w, cJSON_GetObjectItem(node, "options")->valuestring); break; + + case WT_SLIDER: + w->minValue = cJSON_GetObjectItem(node, "minValue")->valueint; + w->maxValue = cJSON_GetObjectItem(node, "maxValue")->valueint; + break; default: break; diff --git a/src/system/widgets.h b/src/system/widgets.h index 430cce0..6808dc5 100644 --- a/src/system/widgets.h +++ b/src/system/widgets.h @@ -32,6 +32,9 @@ extern void playSound(int snd, int ch); extern int isControl(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 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 Colors colors; diff --git a/src/test/atlasTest.c b/src/test/atlasTest.c index 68afc7b..1d93327 100644 --- a/src/test/atlasTest.c +++ b/src/test/atlasTest.c @@ -23,11 +23,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. void initAtlasTest(void) { dev.cheatStatic = 0; - dev.cheatBlind = 1; + dev.cheatBlind = 0; dev.cheatNoEnemies = 0; dev.cheatKeys = 0; - dev.cheatPower = 1; - dev.cheatHealth = 1; + dev.cheatPower = 0; + dev.cheatHealth = 0; dev.cheatLevels = 0; loadGame(); @@ -37,5 +37,7 @@ void initAtlasTest(void) initWorld(); */ - initHub(); + /*initHub();*/ + + initOptions(); } diff --git a/src/test/atlasTest.h b/src/test/atlasTest.h index 5faa15d..866dc3c 100644 --- a/src/test/atlasTest.h +++ b/src/test/atlasTest.h @@ -23,6 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. extern void initWorld(void); extern void initHub(void); extern void loadGame(void); +extern void initOptions(void); extern Dev dev; extern Game game;