More changes for online key config; config is shown but not editable.

The default key configuration has been slightly modified for easier
display, but the VControl template is still compatible.  The default
keys.cfg prior to this will not render properly but still works.


git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@2425 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
mcmartin
2006-09-02 09:28:02 +00:00
parent e0366a964f
commit 127bf24b30
9 changed files with 339 additions and 98 deletions
+92
View File
@@ -475,6 +475,66 @@ Widget_DrawTextEntry (WIDGET *_self, int x, int y)
SetContextForeGroundColor (oldtext);
}
void
Widget_DrawControlEntry (WIDGET *_self, int x, int y)
{
WIDGET_CONTROLENTRY *self = (WIDGET_CONTROLENTRY *)_self;
COLOR oldtext;
COLOR inactive, default_color, selected;
FONT oldfont = SetContextFont (StarConFont);
FRAME oldFontEffect = SetContextFontEffect (NULL);
TEXT t;
int i, home_x, home_y;
default_color = WIDGET_INACTIVE_SELECTED_COLOR;
selected = WIDGET_ACTIVE_COLOR;
inactive = WIDGET_INACTIVE_COLOR;
t.baseline.x = x;
t.baseline.y = y;
t.align = ALIGN_LEFT;
t.valign = VALIGN_BOTTOM;
t.CharCount = ~0;
t.pStr = self->category;
if (widget_focus == _self)
{
oldtext = SetContextForeGroundColor (selected);
}
else
{
oldtext = SetContextForeGroundColor (default_color);
}
font_DrawText (&t);
// 3 * SCREEN_WIDTH / ((self->maxcolumns + 1) * 2)) as per CHOICE, but only two options.
home_x = t.baseline.x + (SCREEN_WIDTH / 2);
home_y = t.baseline.y;
t.align = ALIGN_CENTER;
for (i = 0; i < 2; i++)
{
t.baseline.x = home_x + ((i % 3) * (SCREEN_WIDTH / 3)); // self->maxcolumns + 1 as per CHOICE.
t.baseline.y = home_y + (8 * (i / 3));
t.pStr = self->controlname[i];
if (!t.pStr[0])
{
t.pStr = "---";
}
if ((widget_focus == _self) &&
(self->highlighted == i))
{
SetContextForeGroundColor (selected);
}
else
{
SetContextForeGroundColor (default_color);
}
font_DrawText (&t);
}
SetContextFontEffect (oldFontEffect);
SetContextFont (oldfont);
SetContextForeGroundColor (oldtext);
}
int
Widget_HeightChoice (WIDGET *_self)
{
@@ -527,6 +587,21 @@ Widget_ReceiveFocusChoice (WIDGET *_self, int event)
return TRUE;
}
int
Widget_ReceiveFocusControlEntry (WIDGET *_self, int event)
{
WIDGET_CONTROLENTRY *self = (WIDGET_CONTROLENTRY *)_self;
int oldval = 0;
if (widget_focus->tag == WIDGET_TYPE_CONTROLENTRY)
{
oldval = ((WIDGET_CONTROLENTRY *)widget_focus)->highlighted;
}
widget_focus = _self;
self->highlighted = oldval;
(void)event;
return TRUE;
}
int
Widget_ReceiveFocusMenuScreen (WIDGET *_self, int event)
{
@@ -688,6 +763,23 @@ Widget_HandleEventTextEntry (WIDGET *_self, int event)
return FALSE;
}
int
Widget_HandleEventControlEntry (WIDGET *_self, int event)
{
WIDGET_CONTROLENTRY *self = (WIDGET_CONTROLENTRY *)_self;
if (event == WIDGET_EVENT_SELECT)
{
/* TODO: Something. */
(void)self;
}
if ((event == WIDGET_EVENT_RIGHT) ||
(event == WIDGET_EVENT_LEFT))
{
self->highlighted = 1-self->highlighted;
}
return FALSE;
}
int
Widget_Event (int event)
{
+36 -1
View File
@@ -31,9 +31,22 @@ enum {
NUM_WIDGET_EVENTS
};
#define WIDGET_TEXTENTRY_WIDTH 30
typedef enum {
WIDGET_TYPE_MENU_SCREEN,
WIDGET_TYPE_CHOICE,
WIDGET_TYPE_BUTTON,
WIDGET_TYPE_LABEL,
WIDGET_TYPE_SLIDER,
WIDGET_TYPE_TEXTENTRY,
WIDGET_TYPE_CONTROLENTRY,
NUM_WIDGET_TYPES
} WIDGET_TYPE;
#define WIDGET_TEXTENTRY_WIDTH 30
#define WIDGET_CONTROLENTRY_WIDTH 16
typedef struct _widget {
WIDGET_TYPE tag;
struct _widget *parent;
int (*handleEvent)(struct _widget *self, int event);
int (*receiveFocus)(struct _widget *self, int event);
@@ -43,6 +56,7 @@ typedef struct _widget {
} WIDGET;
typedef struct _widget_menu_screen {
WIDGET_TYPE tag;
struct _widget *parent;
int (*handleEvent)(struct _widget *self, int event);
int (*receiveFocus)(struct _widget *self, int event);
@@ -63,6 +77,7 @@ typedef struct {
} CHOICE_OPTION;
typedef struct _widget_choice {
WIDGET_TYPE tag;
struct _widget *parent;
int (*handleEvent)(struct _widget *self, int event);
int (*receiveFocus)(struct _widget *self, int event);
@@ -78,6 +93,7 @@ typedef struct _widget_choice {
} WIDGET_CHOICE;
typedef struct _widget_button {
WIDGET_TYPE tag;
struct _widget *parent;
int (*handleEvent)(struct _widget *self, int event);
int (*receiveFocus)(struct _widget *self, int event);
@@ -89,6 +105,7 @@ typedef struct _widget_button {
} WIDGET_BUTTON;
typedef struct _widget_label {
WIDGET_TYPE tag;
struct _widget *parent;
int (*handleEvent)(struct _widget *self, int event);
int (*receiveFocus)(struct _widget *self, int event);
@@ -100,6 +117,7 @@ typedef struct _widget_label {
} WIDGET_LABEL;
typedef struct _widget_slider {
WIDGET_TYPE tag;
struct _widget *parent;
int (*handleEvent)(struct _widget *self, int event);
int (*receiveFocus)(struct _widget *self, int event);
@@ -121,6 +139,7 @@ typedef enum {
} WIDGET_TEXTENTRY_STATE;
typedef struct _widget_textentry {
WIDGET_TYPE tag;
struct _widget *parent;
int (*handleEvent)(struct _widget *self, int event);
int (*receiveFocus)(struct _widget *self, int event);
@@ -139,6 +158,19 @@ typedef struct _widget_textentry {
int cursor_pos;
} WIDGET_TEXTENTRY;
typedef struct _widget_controlentry {
WIDGET_TYPE tag;
struct _widget *parent;
int (*handleEvent)(struct _widget *self, int event);
int (*receiveFocus)(struct _widget *self, int event);
void (*draw)(struct _widget *self, int x, int y);
int (*height)(struct _widget *self);
int (*width)(struct _widget *self);
const char *category;
int highlighted;
char controlname[2][WIDGET_CONTROLENTRY_WIDTH];
} WIDGET_CONTROLENTRY;
void DrawShadowedBox (PRECT r, COLOR bg, COLOR dark, COLOR medium);
int Widget_Event (int event);
@@ -149,12 +181,14 @@ int Widget_ReceiveFocusMenuScreen (WIDGET *_self, int event);
int Widget_ReceiveFocusChoice (WIDGET *_self, int event);
int Widget_ReceiveFocusSimple (WIDGET *_self, int event);
int Widget_ReceiveFocusSlider (WIDGET *_self, int event);
int Widget_ReceiveFocusControlEntry (WIDGET *_self, int event);
int Widget_ReceiveFocusRefuseFocus (WIDGET *_self, int event);
int Widget_HandleEventMenuScreen (WIDGET *_self, int event);
int Widget_HandleEventChoice (WIDGET *_self, int event);
int Widget_HandleEventSlider (WIDGET *_self, int event);
int Widget_HandleEventTextEntry (WIDGET *_self, int event);
int Widget_HandleEventControlEntry (WIDGET *_self, int event);
int Widget_HandleEventIgnoreAll (WIDGET *_self, int event);
int Widget_HeightChoice (WIDGET *_self);
@@ -170,6 +204,7 @@ void Widget_DrawButton (WIDGET *_self, int x, int y);
void Widget_DrawLabel (WIDGET *_self, int x, int y);
void Widget_DrawSlider (WIDGET *_self, int x, int y);
void Widget_DrawTextEntry (WIDGET *_self, int x, int y);
void Widget_DrawControlEntry (WIDGET *_self, int x, int y);
void Widget_Slider_DrawValue (WIDGET_SLIDER *self, int x, int y);
+3
View File
@@ -46,6 +46,9 @@ void DisableCharacterMode (void);
wchar_t GetNextCharacter (void);
wchar_t GetLastCharacter (void);
/* Interrogating the current key configuration */
void InterrogateInputState (int template, int control, int index, char *buffer, int maxlen);
#endif /* _INPLIB_H */
+36
View File
@@ -23,6 +23,7 @@
#include "libs/graphics/sdl/sdl_common.h"
#include "libs/input/input_common.h"
#include "libs/input/sdl/vcontrol.h"
#include "libs/input/sdl/keynames.h"
#include "controls.h"
#include "libs/file.h"
#include "libs/log.h"
@@ -366,4 +367,39 @@ FlushInput (void)
FlushInputState ();
}
void
InterrogateInputState (int template, int control, int index, char *buffer, int maxlen)
{
int i;
VCONTROL_GESTURE g;
VControl_StartIter (&ImmediateInputState.key[template][control]);
i = 0;
while (VControl_NextBinding (&g))
{
if (i++ < index)
{
continue;
}
switch (g.type)
{
case VCONTROL_KEY:
snprintf (buffer, maxlen, "%s", VControl_code2name (g.gesture.key));
buffer[maxlen-1] = 0;
break;
case VCONTROL_JOYBUTTON:
snprintf (buffer, maxlen, "[Button %d]", g.gesture.button.index + 1);
buffer[maxlen-1] = 0;
break;
default:
/* Something we don't handle yet */
buffer[0] = 0;
break;
}
return;
}
/* There aren't that many bindings, so return blank string */
buffer[0] = 0;
}
#endif
+70 -11
View File
@@ -28,6 +28,7 @@
#include "libs/graphics/tfb_draw.h"
#include "libs/strlib.h"
#include "libs/reslib.h"
#include "libs/inplib.h"
#include "libs/sound/sound.h"
#include "libs/resource/stringbank.h"
#include "libs/log.h"
@@ -69,12 +70,13 @@ static void rename_template (WIDGET_TEXTENTRY *self);
#define RES_OPTS 2
#endif
#define MENU_COUNT 8
#define CHOICE_COUNT 21
#define SLIDER_COUNT 3
#define BUTTON_COUNT 10
#define LABEL_COUNT 3
#define TEXTENTRY_COUNT 1
#define MENU_COUNT 8
#define CHOICE_COUNT 21
#define SLIDER_COUNT 3
#define BUTTON_COUNT 10
#define LABEL_COUNT 3
#define TEXTENTRY_COUNT 1
#define CONTROLENTRY_COUNT 7
/* The space for our widgets */
static WIDGET_MENU_SCREEN menus[MENU_COUNT];
@@ -83,6 +85,7 @@ static WIDGET_SLIDER sliders[SLIDER_COUNT];
static WIDGET_BUTTON buttons[BUTTON_COUNT];
static WIDGET_LABEL labels[LABEL_COUNT];
static WIDGET_TEXTENTRY textentries[TEXTENTRY_COUNT];
static WIDGET_CONTROLENTRY controlentries[CONTROLENTRY_COUNT];
/* The hardcoded data that isn't strings */
@@ -105,7 +108,7 @@ static int menu_sizes[MENU_COUNT] = {
#else
4,
#endif
4
11
};
static int menu_bgs[MENU_COUNT] = { 0, 1, 1, 2, 3, 1, 2, 1 };
@@ -167,6 +170,13 @@ static WIDGET *editkeys_widgets[] = {
(WIDGET *)(&choices[20]),
(WIDGET *)(&labels[2]),
(WIDGET *)(&textentries[0]),
(WIDGET *)(&controlentries[0]),
(WIDGET *)(&controlentries[1]),
(WIDGET *)(&controlentries[2]),
(WIDGET *)(&controlentries[3]),
(WIDGET *)(&controlentries[4]),
(WIDGET *)(&controlentries[5]),
(WIDGET *)(&controlentries[6]),
(WIDGET *)(&buttons[9]) };
static WIDGET *incomplete_widgets[] = {
@@ -280,6 +290,23 @@ do_advanced (WIDGET *self, int event)
return FALSE;
}
static void
populate_editkeys (int template)
{
int i, j;
strncpy (textentries[0].value, input_templates[template].name, textentries[0].maxlen);
textentries[0].value[textentries[0].maxlen-1] = 0;
for (i = 0; i < NUM_KEYS; i++)
{
for (j = 0; j < 2; j++)
{
InterrogateInputState (template, i, j, controlentries[i].controlname[j], WIDGET_CONTROLENTRY_WIDTH);
}
}
}
static int
do_editkeys (WIDGET *self, int event)
{
@@ -288,8 +315,8 @@ do_editkeys (WIDGET *self, int event)
next = (WIDGET *)(&menus[7]);
/* Prepare the components */
choices[20].selected = 0;
strncpy (textentries[0].value, input_templates[0].name, textentries[0].maxlen);
textentries[0].value[textentries[0].maxlen] = 0;
populate_editkeys (0);
(*next->receiveFocus) (next, WIDGET_EVENT_DOWN);
return TRUE;
}
@@ -300,8 +327,7 @@ do_editkeys (WIDGET *self, int event)
static void
change_template (WIDGET_CHOICE *self, int oldval)
{
strncpy (textentries[0].value, input_templates[self->selected].name, WIDGET_TEXTENTRY_WIDTH);
textentries[0].value[WIDGET_TEXTENTRY_WIDTH-1] = 0;
populate_editkeys (self->selected);
}
static void
@@ -574,6 +600,7 @@ init_widgets (void)
for (i = 0; i < MENU_COUNT; i++)
{
menus[i].tag = WIDGET_TYPE_MENU_SCREEN;
menus[i].parent = NULL;
menus[i].handleEvent = Widget_HandleEventMenuScreen;
menus[i].receiveFocus = Widget_ReceiveFocusMenuScreen;
@@ -599,6 +626,7 @@ init_widgets (void)
for (i = 0; i < CHOICE_COUNT; i++)
{
choices[i].tag = WIDGET_TYPE_CHOICE;
choices[i].parent = NULL;
choices[i].handleEvent = Widget_HandleEventChoice;
choices[i].receiveFocus = Widget_ReceiveFocusChoice;
@@ -688,6 +716,7 @@ init_widgets (void)
for (i = 0; i < SLIDER_COUNT; i++)
{
sliders[i].tag = WIDGET_TYPE_SLIDER;
sliders[i].parent = NULL;
sliders[i].handleEvent = Widget_HandleEventSlider;
sliders[i].receiveFocus = Widget_ReceiveFocusSimple;
@@ -742,6 +771,7 @@ init_widgets (void)
for (i = 0; i < BUTTON_COUNT; i++)
{
buttons[i].tag = WIDGET_TYPE_BUTTON;
buttons[i].parent = NULL;
buttons[i].handleEvent = button_handlers[i];
buttons[i].receiveFocus = Widget_ReceiveFocusSimple;
@@ -791,6 +821,7 @@ init_widgets (void)
for (i = 0; i < LABEL_COUNT; i++)
{
labels[i].tag = WIDGET_TYPE_LABEL;
labels[i].parent = NULL;
labels[i].handleEvent = Widget_HandleEventIgnoreAll;
labels[i].receiveFocus = Widget_ReceiveFocusRefuseFocus;
@@ -834,6 +865,7 @@ init_widgets (void)
}
for (i = 0; i < TEXTENTRY_COUNT; i++)
{
textentries[i].tag = WIDGET_TYPE_TEXTENTRY;
textentries[i].parent = NULL;
textentries[i].handleEvent = Widget_HandleEventTextEntry;
textentries[i].receiveFocus = Widget_ReceiveFocusSimple;
@@ -867,6 +899,33 @@ init_widgets (void)
}
textentries[0].onChange = rename_template;
/* Control Entry boxes */
if (index >= count)
{
log_add (log_Fatal, "PANIC: String table cut short while reading control entries");
exit (EXIT_FAILURE);
}
if (SplitString (GetStringAddress (SetAbsStringTableIndex (SetupTab, index++)), '\n', 100, buffer, bank) != CONTROLENTRY_COUNT)
{
log_add (log_Fatal, "PANIC: Incorrect number of Control Entries");
exit (EXIT_FAILURE);
}
for (i = 0; i < CONTROLENTRY_COUNT; i++)
{
controlentries[i].tag = WIDGET_TYPE_CONTROLENTRY;
controlentries[i].parent = NULL;
controlentries[i].handleEvent = Widget_HandleEventControlEntry;
controlentries[i].receiveFocus = Widget_ReceiveFocusControlEntry;
controlentries[i].draw = Widget_DrawControlEntry;
controlentries[i].height = Widget_HeightOneLine;
controlentries[i].width = Widget_WidthFullScreen;
controlentries[i].category = buffer[i];
controlentries[i].highlighted = 0;
controlentries[i].controlname[0][0] = 0;
controlentries[i].controlname[0][1] = 0;
}
/* Check for garbage at the end */
if (index < count)
{
+6 -6
View File
@@ -361,7 +361,7 @@ main (int argc, char *argv[])
}
else
{
strcpy (input_templates[0].name, "Keyboard 1");
strcpy (input_templates[0].name, "Arrows");
res_PutString ("config.keys.1.name", input_templates[0].name);
}
if (res_HasKey ("config.keys.2.name"))
@@ -371,7 +371,7 @@ main (int argc, char *argv[])
}
else
{
strcpy (input_templates[1].name, "Keyboard 2");
strcpy (input_templates[1].name, "WASD");
res_PutString ("config.keys.2.name", input_templates[1].name);
}
if (res_HasKey ("config.keys.3.name"))
@@ -381,7 +381,7 @@ main (int argc, char *argv[])
}
else
{
strcpy (input_templates[2].name, "Keyboard 3");
strcpy (input_templates[2].name, "Arrows (2)");
res_PutString ("config.keys.3.name", input_templates[2].name);
}
if (res_HasKey ("config.keys.4.name"))
@@ -391,7 +391,7 @@ main (int argc, char *argv[])
}
else
{
strcpy (input_templates[3].name, "Joystick 1");
strcpy (input_templates[3].name, "ESDF");
res_PutString ("config.keys.4.name", input_templates[3].name);
}
if (res_HasKey ("config.keys.5.name"))
@@ -401,7 +401,7 @@ main (int argc, char *argv[])
}
else
{
strcpy (input_templates[4].name, "Joystick 2");
strcpy (input_templates[4].name, "Joystick 1");
res_PutString ("config.keys.5.name", input_templates[4].name);
}
if (res_HasKey ("config.keys.6.name"))
@@ -411,7 +411,7 @@ main (int argc, char *argv[])
}
else
{
strcpy (input_templates[5].name, "Joystick 3");
strcpy (input_templates[5].name, "Joystick 2");
res_PutString ("config.keys.6.name", input_templates[5].name);
}