Draw and configure input widgets.
This commit is contained in:
parent
1b4e50c727
commit
f5bf3ddcaa
|
@ -29,9 +29,11 @@ static void bloodGore(void);
|
||||||
static void trophyScreenshot(void);
|
static void trophyScreenshot(void);
|
||||||
static void trophyAlert(void);
|
static void trophyAlert(void);
|
||||||
static void inventory(void);
|
static void inventory(void);
|
||||||
static void keyboard(void);
|
static void controls(void);
|
||||||
static void joypad(void);
|
|
||||||
static void back(void);
|
static void back(void);
|
||||||
|
static void setGeneralOptions(void);
|
||||||
|
static void setControlOptions(void);
|
||||||
|
static int section;
|
||||||
|
|
||||||
static Widget *soundVolumeWidget;
|
static Widget *soundVolumeWidget;
|
||||||
static Widget *musicVolumeWidget;
|
static Widget *musicVolumeWidget;
|
||||||
|
@ -39,20 +41,36 @@ 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 *controlsWidget;
|
||||||
static Widget *joypadWidget;
|
|
||||||
static Widget *backWidget;
|
|
||||||
static Texture *atlasTexture;
|
static Texture *atlasTexture;
|
||||||
static Atlas *background;
|
static Atlas *background;
|
||||||
|
|
||||||
void initOptions(void (*callback)(void))
|
void initOptions(void (*callback)(void))
|
||||||
{
|
{
|
||||||
|
startSectionTransition();
|
||||||
|
|
||||||
|
section = SECTION_MAIN;
|
||||||
|
|
||||||
returnFromOptions = callback;
|
returnFromOptions = callback;
|
||||||
|
|
||||||
atlasTexture = getTexture("gfx/atlas/atlas.png");
|
atlasTexture = getTexture("gfx/atlas/atlas.png");
|
||||||
|
|
||||||
background = getImageFromAtlas("gfx/main/options.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 = getWidget("soundVolume", "options");
|
||||||
soundVolumeWidget->action = soundVolume;
|
soundVolumeWidget->action = soundVolume;
|
||||||
soundVolumeWidget->value = app.config.soundVolume;
|
soundVolumeWidget->value = app.config.soundVolume;
|
||||||
|
@ -77,24 +95,24 @@ void initOptions(void (*callback)(void))
|
||||||
inventoryWidget->action = inventory;
|
inventoryWidget->action = inventory;
|
||||||
inventoryWidget->value = app.config.inventory;
|
inventoryWidget->value = app.config.inventory;
|
||||||
|
|
||||||
keyboardWidget = getWidget("keyboard", "options");
|
controlsWidget = getWidget("controls", "options");
|
||||||
keyboardWidget->action = keyboard;
|
controlsWidget->action = controls;
|
||||||
|
|
||||||
joypadWidget = getWidget("joypad", "options");
|
getWidget("back", "options")->action = back;
|
||||||
joypadWidget->action = joypad;
|
getWidget("back", "controls")->action = back;
|
||||||
|
}
|
||||||
|
|
||||||
backWidget = getWidget("back", "options");
|
static void setControlOptions(void)
|
||||||
backWidget->action = back;
|
{
|
||||||
|
getWidget("left", "controls")->value = app.config.keyControls[CONTROL_LEFT];
|
||||||
showWidgetGroup("options");
|
getWidget("right", "controls")->value = app.config.keyControls[CONTROL_RIGHT];
|
||||||
|
getWidget("up", "controls")->value = app.config.keyControls[CONTROL_UP];
|
||||||
if (!app.joypad)
|
getWidget("down", "controls")->value = app.config.keyControls[CONTROL_DOWN];
|
||||||
{
|
getWidget("jump", "controls")->value = app.config.keyControls[CONTROL_JUMP];
|
||||||
joypadWidget->visible = 0;
|
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];
|
||||||
app.delegate.logic = logic;
|
getWidget("map", "controls")->value = app.config.keyControls[CONTROL_MAP];
|
||||||
app.delegate.draw = draw;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void logic(void)
|
static void logic(void)
|
||||||
|
@ -149,19 +167,31 @@ static void inventory(void)
|
||||||
app.config.inventory = inventoryWidget->value;
|
app.config.inventory = inventoryWidget->value;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void keyboard(void)
|
static void controls(void)
|
||||||
{
|
{
|
||||||
|
section = SECTION_CONTROLS;
|
||||||
|
|
||||||
}
|
playSound(SND_MENU_SELECT, 0);
|
||||||
|
|
||||||
static void joypad(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
|
showWidgetGroup("controls");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void back(void)
|
static void back(void)
|
||||||
{
|
{
|
||||||
saveConfig();
|
switch (section)
|
||||||
|
{
|
||||||
|
case SECTION_MAIN:
|
||||||
|
playSound(SND_MENU_BACK, 0);
|
||||||
|
startSectionTransition();
|
||||||
|
saveConfig();
|
||||||
|
returnFromOptions();
|
||||||
|
endSectionTransition();
|
||||||
|
break;
|
||||||
|
|
||||||
returnFromOptions();
|
case SECTION_CONTROLS:
|
||||||
|
playSound(SND_MENU_BACK, 0);
|
||||||
|
section = SECTION_MAIN;
|
||||||
|
showWidgetGroup("options");
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
#include "../common.h"
|
#include "../common.h"
|
||||||
#include "SDL2/SDL_mixer.h"
|
#include "SDL2/SDL_mixer.h"
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
SECTION_MAIN,
|
||||||
|
SECTION_CONTROLS
|
||||||
|
};
|
||||||
|
|
||||||
extern void showWidgetGroup(char *group);
|
extern void showWidgetGroup(char *group);
|
||||||
extern Widget *getWidget(char *name, char *group);
|
extern Widget *getWidget(char *name, char *group);
|
||||||
extern void drawWidgets(void);
|
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 blitRectScaled(SDL_Texture *texture, int x, int y, int w, int h, SDL_Rect *srcRect, int center);
|
||||||
extern void saveConfig(void);
|
extern void saveConfig(void);
|
||||||
extern void drawText(int x, int y, int size, int align, SDL_Color c, const char *format, ...);
|
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 App app;
|
||||||
extern Colors colors;
|
extern Colors colors;
|
||||||
|
|
|
@ -79,7 +79,10 @@ void doWidgets(void)
|
||||||
|
|
||||||
if (isControl(CONTROL_FIRE) || app.keyboard[SDL_SCANCODE_RETURN] || app.keyboard[SDL_SCANCODE_SPACE])
|
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;
|
app.keyboard[SDL_SCANCODE_SPACE] = app.keyboard[SDL_SCANCODE_RETURN] = 0;
|
||||||
clearControl(CONTROL_FIRE);
|
clearControl(CONTROL_FIRE);
|
||||||
|
@ -158,6 +161,10 @@ void drawWidgets(void)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WT_INPUT:
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue