Show start and cancel widgets on mission info.
This commit is contained in:
parent
17ee7642e9
commit
bd6b6d752a
100
src/hub/hub.c
100
src/hub/hub.c
|
@ -38,6 +38,9 @@ static void options(void);
|
|||
static void stats(void);
|
||||
static void trophies(void);
|
||||
static void quit(void);
|
||||
static void doCursor(void);
|
||||
static void doMissionSelect(void);
|
||||
static void doMissionInfo(void);
|
||||
|
||||
static HubMission hubMissionHead;
|
||||
static HubMission *hubMissionTail;
|
||||
|
@ -61,11 +64,15 @@ void initHub(void)
|
|||
HubMission *mission, *teeka;
|
||||
Tuple *t;
|
||||
|
||||
startSectionTransition();
|
||||
|
||||
memset(&hubMissionHead, 0, sizeof(HubMission));
|
||||
hubMissionTail = &hubMissionHead;
|
||||
|
||||
memset(&keySprites, 0, sizeof(Sprite*) * MAX_KEY_TYPES);
|
||||
|
||||
loadMusic("music/61321__mansardian__news-background.ogg");
|
||||
|
||||
atlasTexture = getTexture("gfx/atlas/atlas.png");
|
||||
worldMap = getImageFromAtlas("gfx/hub/worldMap.jpg");
|
||||
alert = getImageFromAtlas("gfx/hub/alert.png");
|
||||
|
@ -161,47 +168,34 @@ void initHub(void)
|
|||
|
||||
app.delegate.logic = &logic;
|
||||
app.delegate.draw = &draw;
|
||||
|
||||
playMusic(1);
|
||||
|
||||
endSectionTransition();
|
||||
}
|
||||
|
||||
static void logic(void)
|
||||
{
|
||||
HubMission *m;
|
||||
|
||||
blipValue += 0.1;
|
||||
|
||||
blipSize = 64 + (sin(blipValue) * 16);
|
||||
|
||||
animateSprites();
|
||||
|
||||
doCursor();
|
||||
|
||||
if (selectedMission == NULL)
|
||||
{
|
||||
if (app.keyboard[SDL_SCANCODE_ESCAPE])
|
||||
{
|
||||
showWidgetGroup("hub");
|
||||
showingWidgets = 1;
|
||||
}
|
||||
else if (isControl(CONTROL_FIRE) || app.mouse.button[SDL_BUTTON_LEFT])
|
||||
{
|
||||
m = getMissionAt(cursor.x, cursor.y);
|
||||
|
||||
if (m != NULL)
|
||||
{
|
||||
selectedMission = m;
|
||||
app.mouse.button[SDL_BUTTON_LEFT] = 0;
|
||||
clearControl(CONTROL_FIRE);
|
||||
|
||||
showWidgetGroup("mission");
|
||||
}
|
||||
}
|
||||
doMissionSelect();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (app.keyboard[SDL_SCANCODE_ESCAPE])
|
||||
{
|
||||
cancel();
|
||||
}
|
||||
doMissionInfo();
|
||||
}
|
||||
}
|
||||
|
||||
static void doCursor(void)
|
||||
{
|
||||
if (app.mouse.dx != 0 || app.mouse.dy != 0)
|
||||
{
|
||||
cursor.x = app.mouse.x;
|
||||
|
@ -229,6 +223,49 @@ static void logic(void)
|
|||
}
|
||||
}
|
||||
|
||||
static void doMissionSelect(void)
|
||||
{
|
||||
HubMission *m;
|
||||
|
||||
if (app.keyboard[SDL_SCANCODE_ESCAPE])
|
||||
{
|
||||
showWidgetGroup("hub");
|
||||
showingWidgets = 1;
|
||||
}
|
||||
else if (isControl(CONTROL_FIRE) || app.mouse.button[SDL_BUTTON_LEFT])
|
||||
{
|
||||
m = getMissionAt(cursor.x, cursor.y);
|
||||
|
||||
if (m != NULL)
|
||||
{
|
||||
selectedMission = m;
|
||||
app.mouse.button[SDL_BUTTON_LEFT] = 0;
|
||||
clearControl(CONTROL_FIRE);
|
||||
|
||||
showWidgetGroup("mission");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void doMissionInfo(void)
|
||||
{
|
||||
Widget *w;
|
||||
|
||||
w = selectWidgetAt(cursor.x, cursor.y);
|
||||
|
||||
if ((w != NULL) && (isControl(CONTROL_FIRE) || app.mouse.button[SDL_BUTTON_LEFT]))
|
||||
{
|
||||
w->action();
|
||||
app.mouse.button[SDL_BUTTON_LEFT] = 0;
|
||||
clearControl(CONTROL_FIRE);
|
||||
}
|
||||
|
||||
if (app.keyboard[SDL_SCANCODE_ESCAPE])
|
||||
{
|
||||
cancel();
|
||||
}
|
||||
}
|
||||
|
||||
static void draw(void)
|
||||
{
|
||||
blitRectScaled(atlasTexture->texture, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, &worldMap->rect, 0);
|
||||
|
@ -240,6 +277,8 @@ static void draw(void)
|
|||
if (selectedMission != NULL)
|
||||
{
|
||||
drawMissionInfo();
|
||||
|
||||
drawWidgets();
|
||||
}
|
||||
|
||||
blitRect(atlasTexture->texture, cursor.x, cursor.y, getCurrentFrame(cursorSpr), 1);
|
||||
|
@ -265,6 +304,9 @@ static void drawMissions(void)
|
|||
blitRectScaled(atlasTexture->texture, mission->x, mission->y, blipSize, blipSize, &alert->rect, 1);
|
||||
drawText(mission->x, mission->y - 32, 18, TA_CENTER, colors.white, mission->name);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -308,12 +350,14 @@ static void drawMissionInfo(void)
|
|||
drawText(x + 15, y + 100, 22, TA_LEFT, colors.white, selectedMission->description);
|
||||
limitTextWidth(0);
|
||||
|
||||
drawText(SCREEN_WIDTH / 2, y + h - 165, 24, TA_CENTER, colors.white, "Keys");
|
||||
|
||||
size = 65;
|
||||
mid = size / 2;
|
||||
|
||||
y = (((SCREEN_HEIGHT - h) / 2) + h) - 100;
|
||||
y = (((SCREEN_HEIGHT - h) / 2) + h) - 225;
|
||||
|
||||
drawText(SCREEN_WIDTH / 2, y, 24, TA_CENTER, colors.white, "Keys");
|
||||
|
||||
y += 64;
|
||||
|
||||
x = ((SCREEN_WIDTH - w) / 2) + 30;
|
||||
|
||||
|
@ -471,6 +515,8 @@ static void startMission(void)
|
|||
STRNCPY(game.worldId, selectedMission->id, MAX_NAME_LENGTH);
|
||||
|
||||
saveGame();
|
||||
|
||||
stopMusic();
|
||||
}
|
||||
|
||||
static void cancel(void)
|
||||
|
|
|
@ -42,6 +42,13 @@ extern void saveGame(void);
|
|||
extern void hideAllWidgets(void);
|
||||
extern void showWidgetGroup(char *group);
|
||||
extern Widget *getWidget(char *name, char *group);
|
||||
extern void drawWidgets(void);
|
||||
extern Widget *selectWidgetAt(int x, int y);
|
||||
extern void loadMusic(char *filename);
|
||||
extern void playMusic(int loop);
|
||||
extern void stopMusic(void);
|
||||
extern void startSectionTransition(void);
|
||||
extern void endSectionTransition(void);
|
||||
|
||||
extern App app;
|
||||
extern Colors colors;
|
||||
|
|
|
@ -341,7 +341,6 @@ typedef struct {
|
|||
int winHeight;
|
||||
float scaleX;
|
||||
float scaleY;
|
||||
int hideMouse;
|
||||
Mouse mouse;
|
||||
SDL_Joystick *joypad;
|
||||
int keyboard[MAX_KEYBOARD_KEYS];
|
||||
|
|
|
@ -182,6 +182,33 @@ Widget *getWidget(char *name, char *group)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
Widget *selectWidgetAt(int x, int y)
|
||||
{
|
||||
Widget *w;
|
||||
int i;
|
||||
|
||||
for (i = 0 ; i < numWidgets ; i++)
|
||||
{
|
||||
w = &widgets[i];
|
||||
|
||||
if (w->visible && collision(w->x, w->y, w->w, w->h, x, y, 1, 1))
|
||||
{
|
||||
if (w != selectedWidget)
|
||||
{
|
||||
playSound(SND_MENU_NAV, 0);
|
||||
}
|
||||
|
||||
widgetIndex = i;
|
||||
selectedWidget = w;
|
||||
return w;
|
||||
}
|
||||
}
|
||||
|
||||
selectedWidget = NULL;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void hideAllWidgets(void)
|
||||
{
|
||||
int i;
|
||||
|
|
|
@ -31,6 +31,7 @@ extern float limit(float i, float a, float b);
|
|||
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 App app;
|
||||
extern Colors colors;
|
||||
|
|
Loading…
Reference in New Issue