Further custom control integration.
This commit is contained in:
parent
7979b175a2
commit
acd53f6b97
|
@ -0,0 +1,111 @@
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"name" : "fire",
|
||||||
|
"group" : "controls",
|
||||||
|
"type" : "WT_CONTROL_CONFIG",
|
||||||
|
"x" : 0,
|
||||||
|
"y" : 0,
|
||||||
|
"w" : 175,
|
||||||
|
"h": 34
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name" : "accelerate",
|
||||||
|
"group" : "controls",
|
||||||
|
"type" : "WT_CONTROL_CONFIG",
|
||||||
|
"x" : 0,
|
||||||
|
"y" : 0,
|
||||||
|
"w" : 175,
|
||||||
|
"h": 34
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name" : "missile",
|
||||||
|
"group" : "controls",
|
||||||
|
"type" : "WT_CONTROL_CONFIG",
|
||||||
|
"x" : 0,
|
||||||
|
"y" : 0,
|
||||||
|
"w" : 175,
|
||||||
|
"h": 34
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name" : "boost",
|
||||||
|
"group" : "controls",
|
||||||
|
"type" : "WT_CONTROL_CONFIG",
|
||||||
|
"x" : 0,
|
||||||
|
"y" : 0,
|
||||||
|
"w" : 175,
|
||||||
|
"h": 34
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name" : "brake",
|
||||||
|
"group" : "controls",
|
||||||
|
"type" : "WT_CONTROL_CONFIG",
|
||||||
|
"x" : 0,
|
||||||
|
"y" : 0,
|
||||||
|
"w" : 175,
|
||||||
|
"h": 34
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name" : "ecm",
|
||||||
|
"group" : "controls",
|
||||||
|
"type" : "WT_CONTROL_CONFIG",
|
||||||
|
"x" : 0,
|
||||||
|
"y" : 0,
|
||||||
|
"w" : 175,
|
||||||
|
"h": 34
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name" : "target",
|
||||||
|
"group" : "controls",
|
||||||
|
"type" : "WT_CONTROL_CONFIG",
|
||||||
|
"x" : 0,
|
||||||
|
"y" : 0,
|
||||||
|
"w" : 175,
|
||||||
|
"h": 34
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name" : "radar",
|
||||||
|
"group" : "controls",
|
||||||
|
"type" : "WT_CONTROL_CONFIG",
|
||||||
|
"x" : 0,
|
||||||
|
"y" : 0,
|
||||||
|
"w" : 175,
|
||||||
|
"h": 34
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name" : "guns",
|
||||||
|
"group" : "controls",
|
||||||
|
"type" : "WT_CONTROL_CONFIG",
|
||||||
|
"x" : 0,
|
||||||
|
"y" : 0,
|
||||||
|
"w" : 175,
|
||||||
|
"h": 34
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name" : "prevFighter",
|
||||||
|
"group" : "controls",
|
||||||
|
"type" : "WT_CONTROL_CONFIG",
|
||||||
|
"x" : 0,
|
||||||
|
"y" : 0,
|
||||||
|
"w" : 175,
|
||||||
|
"h": 34
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name" : "nextFighter",
|
||||||
|
"group" : "controls",
|
||||||
|
"type" : "WT_CONTROL_CONFIG",
|
||||||
|
"x" : 0,
|
||||||
|
"y" : 0,
|
||||||
|
"w" : 175,
|
||||||
|
"h": 34
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name" : "ok",
|
||||||
|
"group" : "controls",
|
||||||
|
"type" : "WT_BUTTON",
|
||||||
|
"text" : "OK",
|
||||||
|
"x" : -1,
|
||||||
|
"y" : 650,
|
||||||
|
"w" : 100,
|
||||||
|
"h": 34
|
||||||
|
}
|
||||||
|
]
|
|
@ -128,8 +128,8 @@ enum
|
||||||
CONTROL_MISSILE,
|
CONTROL_MISSILE,
|
||||||
CONTROL_GUNS,
|
CONTROL_GUNS,
|
||||||
CONTROL_RADAR,
|
CONTROL_RADAR,
|
||||||
CONTROL_NEXT_FIGHTER,
|
|
||||||
CONTROL_PREV_FIGHTER,
|
CONTROL_PREV_FIGHTER,
|
||||||
|
CONTROL_NEXT_FIGHTER,
|
||||||
CONTROL_MAX
|
CONTROL_MAX
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -271,8 +271,7 @@ enum
|
||||||
WT_IMG_BUTTON,
|
WT_IMG_BUTTON,
|
||||||
WT_SELECT,
|
WT_SELECT,
|
||||||
WT_SELECT_BUTTON,
|
WT_SELECT_BUTTON,
|
||||||
WT_KEY_CONFIG,
|
WT_CONTROL_CONFIG
|
||||||
WT_MOUSE_CONFIG
|
|
||||||
};
|
};
|
||||||
|
|
||||||
enum
|
enum
|
||||||
|
|
|
@ -1,71 +0,0 @@
|
||||||
/*
|
|
||||||
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 "controls.h"
|
|
||||||
|
|
||||||
int isKeyControl(int type)
|
|
||||||
{
|
|
||||||
return app.keyboard[app.keyControls[type]];
|
|
||||||
}
|
|
||||||
|
|
||||||
void clearControl(int type)
|
|
||||||
{
|
|
||||||
app.keyboard[app.keyControls[type]] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void initControlsDisplay(void)
|
|
||||||
{
|
|
||||||
getWidget("keyMissile", "controls")->value = app.keyControls[CONTROL_MISSILE];
|
|
||||||
getWidget("keyBoost", "controls")->value = app.keyControls[CONTROL_BOOST];
|
|
||||||
getWidget("keyECM", "controls")->value = app.keyControls[CONTROL_ECM];
|
|
||||||
getWidget("keyBrake", "controls")->value = app.keyControls[CONTROL_BRAKE];
|
|
||||||
getWidget("keyRadar", "controls")->value = app.keyControls[CONTROL_RADAR];
|
|
||||||
getWidget("keyTarget", "controls")->value = app.keyControls[CONTROL_TARGET];
|
|
||||||
getWidget("keyGuns", "controls")->value = app.keyControls[CONTROL_GUNS];
|
|
||||||
getWidget("keyPrevFighter", "controls")->value = app.keyControls[CONTROL_PREV_FIGHTER];
|
|
||||||
getWidget("keyNextFighter", "controls")->value = app.keyControls[CONTROL_NEXT_FIGHTER];
|
|
||||||
}
|
|
||||||
|
|
||||||
void drawControls(void)
|
|
||||||
{
|
|
||||||
SDL_Rect r;
|
|
||||||
|
|
||||||
SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_BLEND);
|
|
||||||
SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 128);
|
|
||||||
SDL_RenderFillRect(app.renderer, NULL);
|
|
||||||
SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_NONE);
|
|
||||||
|
|
||||||
r.w = 800;
|
|
||||||
r.h = 650;
|
|
||||||
r.x = (SCREEN_WIDTH / 2) - r.w / 2;
|
|
||||||
r.y = (SCREEN_HEIGHT / 2) - r.h / 2;
|
|
||||||
|
|
||||||
SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 0);
|
|
||||||
SDL_RenderFillRect(app.renderer, &r);
|
|
||||||
SDL_SetRenderDrawColor(app.renderer, 200, 200, 200, 255);
|
|
||||||
SDL_RenderDrawRect(app.renderer, &r);
|
|
||||||
|
|
||||||
drawText(SCREEN_WIDTH / 2, 50, 28, TA_CENTER, colors.white, _("Controls"));
|
|
||||||
|
|
||||||
SDL_SetRenderDrawColor(app.renderer, 128, 128, 128, 255);
|
|
||||||
SDL_RenderDrawLine(app.renderer, r.x, r.y + 65, r.x + r.w, r.y + 65);
|
|
||||||
|
|
||||||
drawWidgets("controls");
|
|
||||||
}
|
|
|
@ -0,0 +1,128 @@
|
||||||
|
/*
|
||||||
|
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 "controls.h"
|
||||||
|
|
||||||
|
static const char *controlName[CONTROL_MAX];
|
||||||
|
static Widget *controlWidget[CONTROL_MAX];
|
||||||
|
static const char *widgetNames[] = {"fire", "accelerate", "boost", "ecm", "brake", "target", "missile", "guns", "radar", "nextFighter", "prevFighter"};
|
||||||
|
|
||||||
|
void initControls(void)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
controlName[CONTROL_FIRE] = _("Fire");
|
||||||
|
controlName[CONTROL_ACCELERATE] = _("Accelerate");
|
||||||
|
controlName[CONTROL_BOOST] = _("Boost");
|
||||||
|
controlName[CONTROL_ECM] = _("ECM");
|
||||||
|
controlName[CONTROL_BRAKE] = _("Brake");
|
||||||
|
controlName[CONTROL_TARGET] = _("Select Target");
|
||||||
|
controlName[CONTROL_MISSILE] = _("Fire Missile");
|
||||||
|
controlName[CONTROL_GUNS] = _("Cycle Guns");
|
||||||
|
controlName[CONTROL_RADAR] = _("Cycle Radar");
|
||||||
|
controlName[CONTROL_NEXT_FIGHTER] = _("Next Fighter");
|
||||||
|
controlName[CONTROL_PREV_FIGHTER] = _("Previous Fighter");
|
||||||
|
|
||||||
|
for (i = 0 ; i < CONTROL_MAX ; i++)
|
||||||
|
{
|
||||||
|
controlWidget[i] = getWidget(widgetNames[i], "controls");
|
||||||
|
controlWidget[i]->numOptions = 2;
|
||||||
|
controlWidget[i]->options = malloc(2 * sizeof(char*));
|
||||||
|
controlWidget[i]->options[0] = malloc(sizeof(char) * MAX_NAME_LENGTH);
|
||||||
|
controlWidget[i]->options[1] = malloc(sizeof(char) * MAX_NAME_LENGTH);
|
||||||
|
strcpy(controlWidget[i]->options[0], "");
|
||||||
|
strcpy(controlWidget[i]->options[1], "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int isKeyControl(int type)
|
||||||
|
{
|
||||||
|
return app.keyboard[app.keyControls[type]];
|
||||||
|
}
|
||||||
|
|
||||||
|
void clearControl(int type)
|
||||||
|
{
|
||||||
|
app.keyboard[app.keyControls[type]] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void initControlsDisplay(void)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0 ; i < CONTROL_MAX ; i++)
|
||||||
|
{
|
||||||
|
if (app.mouseControls[i] != 0)
|
||||||
|
{
|
||||||
|
sprintf(controlWidget[i]->options[0], "%s", SDL_GetScancodeName(app.keyControls[i]));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (app.mouseControls[i] != -1)
|
||||||
|
{
|
||||||
|
sprintf(controlWidget[i]->options[1], "Btn %d", app.mouseControls[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void drawControls(void)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
SDL_Rect r;
|
||||||
|
|
||||||
|
SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_BLEND);
|
||||||
|
SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 128);
|
||||||
|
SDL_RenderFillRect(app.renderer, NULL);
|
||||||
|
SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_NONE);
|
||||||
|
|
||||||
|
r.w = 800;
|
||||||
|
r.h = 650;
|
||||||
|
r.x = (SCREEN_WIDTH / 2) - r.w / 2;
|
||||||
|
r.y = (SCREEN_HEIGHT / 2) - r.h / 2;
|
||||||
|
|
||||||
|
SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 0);
|
||||||
|
SDL_RenderFillRect(app.renderer, &r);
|
||||||
|
SDL_SetRenderDrawColor(app.renderer, 200, 200, 200, 255);
|
||||||
|
SDL_RenderDrawRect(app.renderer, &r);
|
||||||
|
|
||||||
|
drawText(SCREEN_WIDTH / 2, 50, 28, TA_CENTER, colors.white, _("Controls"));
|
||||||
|
|
||||||
|
SDL_SetRenderDrawColor(app.renderer, 128, 128, 128, 255);
|
||||||
|
SDL_RenderDrawLine(app.renderer, r.x, r.y + 65, r.x + r.w, r.y + 65);
|
||||||
|
|
||||||
|
r.x += 25;
|
||||||
|
r.y = 125;
|
||||||
|
|
||||||
|
for (i = 0 ; i < CONTROL_MAX ; i++)
|
||||||
|
{
|
||||||
|
drawText(r.x, r.y, 20, TA_LEFT, colors.white, controlName[i]);
|
||||||
|
|
||||||
|
controlWidget[i]->rect.x = r.x + 175;
|
||||||
|
controlWidget[i]->rect.y = r.y;
|
||||||
|
|
||||||
|
r.y += 50;
|
||||||
|
|
||||||
|
if (r.y > 400)
|
||||||
|
{
|
||||||
|
r.y = 125;
|
||||||
|
r.x += 400;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
drawWidgets("controls");
|
||||||
|
}
|
|
@ -133,7 +133,8 @@ void initGameSystem(void)
|
||||||
initStats,
|
initStats,
|
||||||
initBattle,
|
initBattle,
|
||||||
initModalDialog,
|
initModalDialog,
|
||||||
initBackground
|
initBackground,
|
||||||
|
initControls
|
||||||
};
|
};
|
||||||
|
|
||||||
numInitFuns = sizeof(initFuncs) / sizeof(void*);
|
numInitFuns = sizeof(initFuncs) / sizeof(void*);
|
||||||
|
|
|
@ -48,6 +48,7 @@ extern void initChallenges(void);
|
||||||
extern void initWidgets(void);
|
extern void initWidgets(void);
|
||||||
extern void initBackground(void);
|
extern void initBackground(void);
|
||||||
extern void initResources(void);
|
extern void initResources(void);
|
||||||
|
extern void initControls(void);
|
||||||
extern void destroyLookups(void);
|
extern void destroyLookups(void);
|
||||||
extern void destroyFonts(void);
|
extern void destroyFonts(void);
|
||||||
extern void destroySounds(void);
|
extern void destroySounds(void);
|
||||||
|
|
|
@ -91,8 +91,7 @@ void initLookups(void)
|
||||||
addLookup("WT_BUTTON", WT_BUTTON);
|
addLookup("WT_BUTTON", WT_BUTTON);
|
||||||
addLookup("WT_SELECT", WT_SELECT);
|
addLookup("WT_SELECT", WT_SELECT);
|
||||||
addLookup("WT_IMG_BUTTON", WT_IMG_BUTTON);
|
addLookup("WT_IMG_BUTTON", WT_IMG_BUTTON);
|
||||||
addLookup("WT_KEY_CONFIG", WT_KEY_CONFIG);
|
addLookup("WT_CONTROL_CONFIG", WT_CONTROL_CONFIG);
|
||||||
addLookup("WT_MOUSE_CONFIG", WT_MOUSE_CONFIG);
|
|
||||||
|
|
||||||
addLookup("SIDE_ALLIES", SIDE_ALLIES);
|
addLookup("SIDE_ALLIES", SIDE_ALLIES);
|
||||||
addLookup("SIDE_PIRATE", SIDE_PIRATE);
|
addLookup("SIDE_PIRATE", SIDE_PIRATE);
|
||||||
|
|
|
@ -147,16 +147,24 @@ void drawWidgets(const char *group)
|
||||||
drawText(w->rect.x + w->rect.w - 10, w->rect.y + 2, 20, TA_RIGHT, colors.white, w->options[w->currentOption]);
|
drawText(w->rect.x + w->rect.w - 10, w->rect.y + 2, 20, TA_RIGHT, colors.white, w->options[w->currentOption]);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WT_KEY_CONFIG:
|
case WT_CONTROL_CONFIG:
|
||||||
SDL_RenderDrawRect(app.renderer, &w->rect);
|
SDL_RenderDrawRect(app.renderer, &w->rect);
|
||||||
drawText(w->rect.x + 25, w->rect.y + 2, 20, TA_LEFT, colors.white, w->text);
|
if (strlen(w->options[0]) && strlen(w->options[1]))
|
||||||
drawText(w->rect.x + w->rect.w - 25, w->rect.y + 2, 20, TA_RIGHT, colors.white, "%d", w->value);
|
{
|
||||||
break;
|
drawText(w->rect.x + (w->rect.w / 2), w->rect.y + 2, 20, TA_CENTER, colors.white, "%s or %s", w->options[0], w->options[1]);
|
||||||
|
}
|
||||||
case WT_MOUSE_CONFIG:
|
else if (strlen(w->options[0]))
|
||||||
SDL_RenderDrawRect(app.renderer, &w->rect);
|
{
|
||||||
drawText(w->rect.x + 25, w->rect.y + 2, 20, TA_LEFT, colors.white, w->text);
|
drawText(w->rect.x + (w->rect.w / 2), w->rect.y + 2, 20, TA_CENTER, colors.white, "%s", w->options[0]);
|
||||||
drawText(w->rect.x + w->rect.w - 25, w->rect.y + 2, 20, TA_RIGHT, colors.white, "%d", w->value);
|
}
|
||||||
|
else if (strlen(w->options[1]))
|
||||||
|
{
|
||||||
|
drawText(w->rect.x + (w->rect.w / 2), w->rect.y + 2, 20, TA_CENTER, colors.white, "%s", w->options[1]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
drawText(w->rect.x + (w->rect.w / 2), w->rect.y + 2, 20, TA_CENTER, colors.white, "");
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -335,9 +343,7 @@ static void loadWidgetSet(char *filename)
|
||||||
createOptions(w, cJSON_GetObjectItem(node, "options")->valuestring);
|
createOptions(w, cJSON_GetObjectItem(node, "options")->valuestring);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WT_KEY_CONFIG:
|
case WT_CONTROL_CONFIG:
|
||||||
case WT_MOUSE_CONFIG:
|
|
||||||
STRNCPY(w->text, _(cJSON_GetObjectItem(node, "text")->valuestring), MAX_NAME_LENGTH);
|
|
||||||
w->rect.w = cJSON_GetObjectItem(node, "w")->valueint;
|
w->rect.w = cJSON_GetObjectItem(node, "w")->valueint;
|
||||||
w->rect.h = cJSON_GetObjectItem(node, "h")->valueint;
|
w->rect.h = cJSON_GetObjectItem(node, "h")->valueint;
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue