More widget work.

This commit is contained in:
Steve 2018-02-15 22:56:22 +00:00
parent 1df85d0937
commit 0d87786af4
8 changed files with 78 additions and 21 deletions

Binary file not shown.

View File

@ -268,8 +268,9 @@ enum
enum
{
SND_SELECT,
SND_BACK,
SND_MENU_SELECT,
SND_MENU_BACK,
SND_MENU_NAV,
SND_PISTOL,
SND_MACHINE_GUN,
SND_PLASMA,

View File

@ -451,7 +451,6 @@ typedef struct {
int minEnemySpawnTime, maxEnemySpawnTime;
unsigned long entityCounter;
int entityChaseTimer;
int showingInfoMessage;
int allObjectivesComplete;
int frameCounter;
int currentStatus;

View File

@ -88,8 +88,10 @@ static Mix_Chunk *loadSound(char *filename)
static void loadSounds(void)
{
sounds[SND_BACK] = loadSound("sound/50557__broumbroum__sf3-sfx-menu-back.ogg");
sounds[SND_SELECT] = loadSound("sound/50561__broumbroum__sf3-sfx-menu-select.ogg");
sounds[SND_MENU_BACK] = loadSound("sound/50557__broumbroum__sf3-sfx-menu-back.ogg");
sounds[SND_MENU_SELECT] = loadSound("sound/50561__broumbroum__sf3-sfx-menu-select.ogg");
sounds[SND_MENU_NAV] = loadSound("sound/146721__fins__menu-click.ogg");
sounds[SND_PISTOL] = loadSound("sound/Gun_44magnum-freesoundeffects.ogg");
sounds[SND_MACHINE_GUN] = loadSound("sound/67020__ls__submachinegun2.ogg");
sounds[SND_PLASMA] = loadSound("sound/93017__cosmicd__60.ogg");
@ -127,6 +129,7 @@ static void loadSounds(void)
sounds[SND_DENIED] = loadSound("sound/142608__autistic-lucario__error.ogg");
sounds[SND_CONFIRMED] = loadSound("sound/39028__wildweasel__cardlock-open.ogg");
sounds[SND_HEART_CELL] = loadSound("sound/162467__kastenfrosch__gotitem.ogg");
sounds[SND_MISSION_COMPLETE] = loadSound("sound/113989__kastenfrosch__gewonnen.ogg");
sounds[SND_TROPHY] = loadSound("sound/278142__ricemaster__effect-notify.ogg");
}

View File

@ -37,6 +37,8 @@ void initWidgets(void)
numWidgets = 0;
selectedWidget = NULL;
loadWidgets();
}
@ -102,16 +104,15 @@ void drawWidgets(void)
case WT_BUTTON:
if (w != selectedWidget)
{
drawRect(w->x, w->y, w->w, w->h, 0, 64, 0, 255);
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);
drawText(w->x + w->w / 2, w->y + 2, 24, TA_CENTER, colors.white, w->label);
}
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.yellow, w->label);
}
drawText(w->x + w->w / 2, w->y + 2, 24, TA_CENTER, colors.white, w->label);
break;
case WT_SLIDER:
@ -129,6 +130,8 @@ void drawWidgets(void)
static void selectWidget(int dir)
{
int oldWidgetIndex = widgetIndex;
do
{
widgetIndex += dir;
@ -146,6 +149,11 @@ static void selectWidget(int dir)
selectedWidget = &widgets[widgetIndex];
} while (!selectedWidget->enabled && !selectedWidget->visible);
if (oldWidgetIndex != widgetIndex)
{
playSound(SND_MENU_NAV, 0);
}
}
Widget *getWidget(char *name, char *group)
@ -197,6 +205,7 @@ void showWidgetGroup(char *group)
if (selectedWidget == NULL)
{
selectedWidget = w;
widgetIndex = i;
}
w->visible = 1;

View File

@ -28,6 +28,7 @@ extern void drawText(int x, int y, int size, int align, SDL_Color c, const char
extern void drawRect(int x, int y, int w, int h, int r, int g, int b, int a);
extern void drawOutlineRect(int x, int y, int w, int h, int r, int g, int b, int a);
extern float limit(float i, float a, float b);
extern void playSound(int snd, int ch);
extern App app;
extern Colors colors;

View File

@ -36,6 +36,10 @@ static void spawnEnemies(void);
static int canAdd(Unit *u, int mx, int my);
static void startMission(void);
static void drawInGameWidgets(void);
static void handleWidgets(void);
static void resume(void);
static void options(void);
static void quit(void);
static Texture *background;
static int observationIndex;
@ -68,6 +72,10 @@ void initWorld(void)
world.state = WS_START;
observationIndex = 0;
getWidget("resume", "gamePaused")->action = resume;
getWidget("options", "gamePaused")->action = options;
getWidget("quit", "gamePaused")->action = quit;
if (world.missionType == MT_BOSS)
{
@ -90,10 +98,6 @@ void initWorld(void)
app.delegate.logic = logic;
app.delegate.draw = draw;
showWidgetGroup("gamePaused");
showingWidgets = 1;
startMission();
}
@ -259,7 +263,7 @@ static void doWorldInProgress(void)
doPlayer();
if (!world.showingInfoMessage)
if (!showingWidgets)
{
doBob();
@ -296,16 +300,38 @@ static void doWorldInProgress(void)
initRadar();
clearControl(CONTROL_MAP);
}
}
if (world.observationTimer > 0)
{
if (--world.observationTimer == FPS * 1.5)
if (app.keyboard[SDL_SCANCODE_ESCAPE])
{
world.entityToTrack = world.entitiesToObserve[0];
world.state = WS_OBSERVING;
app.keyboard[SDL_SCANCODE_ESCAPE] = 0;
showWidgetGroup("gamePaused");
playSound(SND_MENU_BACK, 0);
showingWidgets = 1;
}
if (world.observationTimer > 0)
{
if (--world.observationTimer == FPS * 1.5)
{
world.entityToTrack = world.entitiesToObserve[0];
world.state = WS_OBSERVING;
}
}
}
else
{
handleWidgets();
}
}
static void handleWidgets(void)
{
doWidgets();
if (app.keyboard[SDL_SCANCODE_ESCAPE])
{
resume();
}
}
@ -616,3 +642,18 @@ void exitRadar(void)
endSectionTransition();
}
static void resume(void)
{
app.keyboard[SDL_SCANCODE_ESCAPE] = 0;
hideAllWidgets();
showingWidgets = 0;
}
static void options(void)
{
}
static void quit(void)
{
}

View File

@ -76,6 +76,9 @@ extern void drawWidgets(void);
extern void showWidgetGroup(char *group);
extern void drawRect(int x, int y, int w, int h, int r, int g, int b, int a);
extern void drawOutlineRect(int x, int y, int w, int h, int r, int g, int b, int a);
extern void hideAllWidgets(void);
extern void doWidgets(void);
extern Widget *getWidget(char *name, char *group);
extern App app;
extern Colors colors;