Draw and configure input widgets.

This commit is contained in:
Steve 2018-02-20 17:50:26 +00:00
parent 1b4e50c727
commit f5bf3ddcaa
3 changed files with 78 additions and 32 deletions

View File

@ -29,9 +29,11 @@ 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 controls(void);
static void back(void);
static void setGeneralOptions(void);
static void setControlOptions(void);
static int section;
static Widget *soundVolumeWidget;
static Widget *musicVolumeWidget;
@ -39,20 +41,36 @@ static Widget *bloodGoreWidget;
static Widget *trophyScreenshotWidget;
static Widget *trophyAlertWidget;
static Widget *inventoryWidget;
static Widget *keyboardWidget;
static Widget *joypadWidget;
static Widget *backWidget;
static Widget *controlsWidget;
static Texture *atlasTexture;
static Atlas *background;
void initOptions(void (*callback)(void))
{
startSectionTransition();
section = SECTION_MAIN;
returnFromOptions = callback;
atlasTexture = getTexture("gfx/atlas/atlas.png");
background = getImageFromAtlas("gfx/main/options.png");
setGeneralOptions();
setControlOptions();
showWidgetGroup("options");
app.delegate.logic = logic;
app.delegate.draw = draw;
endSectionTransition();
}
static void setGeneralOptions(void)
{
soundVolumeWidget = getWidget("soundVolume", "options");
soundVolumeWidget->action = soundVolume;
soundVolumeWidget->value = app.config.soundVolume;
@ -77,24 +95,24 @@ void initOptions(void (*callback)(void))
inventoryWidget->action = inventory;
inventoryWidget->value = app.config.inventory;
keyboardWidget = getWidget("keyboard", "options");
keyboardWidget->action = keyboard;
controlsWidget = getWidget("controls", "options");
controlsWidget->action = controls;
joypadWidget = getWidget("joypad", "options");
joypadWidget->action = joypad;
backWidget = getWidget("back", "options");
backWidget->action = back;
getWidget("back", "options")->action = back;
getWidget("back", "controls")->action = back;
}
showWidgetGroup("options");
if (!app.joypad)
{
joypadWidget->visible = 0;
}
app.delegate.logic = logic;
app.delegate.draw = draw;
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];
}
static void logic(void)
@ -149,19 +167,31 @@ static void inventory(void)
app.config.inventory = inventoryWidget->value;
}
static void keyboard(void)
static void controls(void)
{
}
static void joypad(void)
{
section = SECTION_CONTROLS;
playSound(SND_MENU_SELECT, 0);
showWidgetGroup("controls");
}
static void back(void)
{
saveConfig();
returnFromOptions();
switch (section)
{
case SECTION_MAIN:
playSound(SND_MENU_BACK, 0);
startSectionTransition();
saveConfig();
returnFromOptions();
endSectionTransition();
break;
case SECTION_CONTROLS:
playSound(SND_MENU_BACK, 0);
section = SECTION_MAIN;
showWidgetGroup("options");
break;
}
}

View File

@ -21,6 +21,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "../common.h"
#include "SDL2/SDL_mixer.h"
enum
{
SECTION_MAIN,
SECTION_CONTROLS
};
extern void showWidgetGroup(char *group);
extern Widget *getWidget(char *name, char *group);
extern void drawWidgets(void);
@ -32,6 +38,9 @@ extern void blitRect(SDL_Texture *texture, int x, int y, SDL_Rect *srcRect, int
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 void startSectionTransition(void);
extern void endSectionTransition(void);
extern void playSound(int snd, int ch);
extern App app;
extern Colors colors;

View File

@ -79,7 +79,10 @@ void doWidgets(void)
if (isControl(CONTROL_FIRE) || app.keyboard[SDL_SCANCODE_RETURN] || app.keyboard[SDL_SCANCODE_SPACE])
{
selectedWidget->action();
if (selectedWidget->type != WT_INPUT)
{
selectedWidget->action();
}
app.keyboard[SDL_SCANCODE_SPACE] = app.keyboard[SDL_SCANCODE_RETURN] = 0;
clearControl(CONTROL_FIRE);
@ -158,6 +161,10 @@ void drawWidgets(void)
break;
case WT_INPUT:
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));
break;
}
}