Start of modal dialog display.

This commit is contained in:
Steve 2016-02-23 07:19:31 +00:00
parent 8afc9a757b
commit 368e9dc592
13 changed files with 179 additions and 8 deletions

View File

@ -17,7 +17,7 @@ OBJS += galacticMap.o game.o
OBJS += hud.o
OBJS += init.o input.o io.o items.o
OBJS += load.o locations.o lookup.o
OBJS += main.o messageBox.o mission.o missionInfo.o
OBJS += main.o messageBox.o mission.o missionInfo.o modalDialog.o
OBJS += objectives.o options.o
OBJS += player.o
OBJS += quadtree.o

View File

@ -1,6 +1,6 @@
[
"data/widgets/galacticMap.json",
"data/widgets/okCancel.json",
"data/widgets/modal.json",
"data/widgets/startBattle.json",
"data/widgets/inBattle.json",
"data/widgets/battleWon.json",

View File

@ -1,4 +1,14 @@
[
{
"name" : "ok",
"group" : "ok",
"type" : "WT_BUTTON",
"text" : "OK",
"x" : -1,
"y" : 680,
"w" : 150,
"h": 34
},
{
"name" : "ok",
"group" : "okCancel",

View File

@ -108,6 +108,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define BOOST_FINISHED_TIME (FPS * 0.75)
#define ECM_RECHARGE_TIME (FPS * 7)
enum
{
MD_NONE,
MD_OK,
MD_OK_CANCEL
};
enum
{
ET_FIGHTER,

View File

@ -50,6 +50,9 @@ int main(int argc, char *argv[])
lastFrameTime = SDL_GetTicks() + 1000;
expireTextTimer = SDL_GetTicks() + (1000 * 10);
app.modalDialog.type = MD_OK;
STRNCPY(app.modalDialog.message, "This is a longer message. This is a longer message. This is a longer message. This is a longer message. This is a longer message. This is a longer message. This is a longer message. This is a longer message. This is a longer message. ", MAX_DESCRIPTION_LENGTH);
while (1)
{
td += (SDL_GetTicks() - then);
@ -96,6 +99,11 @@ int main(int argc, char *argv[])
}
}
if (app.modalDialog.type != MD_NONE)
{
doModalDialog();
}
while (td >= LOGIC_RATE)
{
app.delegate.logic();
@ -108,6 +116,11 @@ int main(int argc, char *argv[])
app.delegate.draw();
if (app.modalDialog.type != MD_NONE)
{
drawModalDialog();
}
presentScene();
doDevKeys();

View File

@ -39,6 +39,8 @@ extern void doDevKeys(void);
extern void expireTexts(int all);
extern void prepareScene(void);
extern void presentScene(void);
extern void doModalDialog(void);
extern void drawModalDialog(void);
App app;
Colors colors;

View File

@ -71,6 +71,12 @@ typedef struct {
void (*handleMouseUp)(int x, int y, int btn);
} Delegate;
typedef struct {
int type;
int result;
char message[MAX_DESCRIPTION_LENGTH];
} ModalDialog;
struct Lookup {
char name[MAX_NAME_LENGTH];
long value;
@ -385,6 +391,7 @@ typedef struct {
SDL_Renderer *renderer;
SDL_Window *window;
Delegate delegate;
ModalDialog modalDialog;
} App;
typedef struct {

View File

@ -95,7 +95,7 @@ void initSDL(void)
void initGameSystem(void)
{
int STEPS = 12;
int STEPS = 13;
initColor(&colors.red, 255, 0, 0);
initColor(&colors.orange, 255, 128, 0);
@ -158,6 +158,10 @@ void initGameSystem(void)
initBattle();
showLoadingStep(12, STEPS);
initModalDialog();
showLoadingStep(13, STEPS);
}
/*

View File

@ -58,6 +58,7 @@ extern void destroyGalacticMap(void);
extern void destroyWidgets(void);
extern void expireTexts(int all);
extern void initInput(void);
extern void initModalDialog(void);
extern void createSaveFolder(void);
extern char *getFileLocation(char *filename);

View File

@ -85,3 +85,23 @@ void drawMouse(void)
blit(mousePointer, app.mouse.x, app.mouse.y, 1);
}
void clearInput(void)
{
SDL_Event event;
int i;
for (i = 0 ; i < MAX_KEYBOARD_KEYS ; i++)
{
app.keyboard[i] = 0;
}
for (i = 0 ; i < MAX_MOUSE_BUTTONS ; i++)
{
app.mouse.button[i] = 0;
}
while (SDL_PollEvent(&event))
{
}
}

80
src/system/modalDialog.c Normal file
View File

@ -0,0 +1,80 @@
/*
Copyright (C) 2015-2016 Parallel Realities
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "modalDialog.h"
static Widget *ok;
static Widget *okCancelOK;
static Widget *okCancelCancel;
void initModalDialog(void)
{
ok = getWidget("ok", "ok");
okCancelOK = getWidget("ok", "okCancel");
okCancelCancel = getWidget("cancel", "okCancel");
}
void doModalDialog(void)
{
doWidgets();
clearInput();
}
void drawModalDialog(void)
{
SDL_Rect r;
limitTextWidth(700);
SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_BLEND);
SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 96);
SDL_RenderFillRect(app.renderer, NULL);
r.w = 800;
r.h = getWrappedTextHeight(app.modalDialog.message, 24) + 100;
r.x = (SCREEN_WIDTH / 2) - (r.w / 2);
r.y = (SCREEN_HEIGHT / 2) - (r.h / 2);
ok->rect.y = okCancelOK->rect.y = okCancelCancel->rect.y = r.y + r.h - 50;
SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 225);
SDL_RenderFillRect(app.renderer, &r);
SDL_SetRenderDrawColor(app.renderer, 255, 255, 255, 200);
SDL_RenderDrawRect(app.renderer, &r);
SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_NONE);
drawText(SCREEN_WIDTH / 2, r.y + 10, 24, TA_CENTER, colors.white, app.modalDialog.message);
switch (app.modalDialog.type)
{
case MD_OK:
drawWidgets("ok");
break;
case MD_OK_CANCEL:
drawWidgets("okCancel");
break;
}
limitTextWidth(0);
}

32
src/system/modalDialog.h Normal file
View File

@ -0,0 +1,32 @@
/*
Copyright (C) 2015-2016 Parallel Realities
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "../common.h"
extern void clearInput(void);
extern void drawText(int x, int y, int size, int align, SDL_Color c, const char *format, ...);
extern void drawWidgets(char *groupName);
extern Widget *getWidget(const char *name, const char *group);
extern void doWidgets(void);
extern int getWrappedTextHeight(char *text, int size);
extern void limitTextWidth(int width);
extern App app;
extern Colors colors;

View File

@ -159,11 +159,6 @@ void drawWidgets(const char *group)
}
}
void drawConfirmMessage(char *message)
{
drawWidgets("okCancel");
}
static void changeSelectedValue(Widget *w, int dir)
{
int oldOption = w->currentOption;