Create classes for inputing cvar strings and script the network menu.

Hitting enter after inputting text is currently broken, but that's because
support for it was never put in the inputline wrapper code.
This commit is contained in:
Bill Currie 2011-03-25 18:26:10 +09:00
parent 84afc458fa
commit 30bd1c0134
8 changed files with 195 additions and 107 deletions

View file

@ -0,0 +1,11 @@
#ifndef __CvarString_h
#define __CvarString_h
#include "CvarObject.h"
@interface CvarString : CvarObject
-(void)setString:(string)str;
-(string)value;
@end
#endif//__CvarString_h

View file

@ -0,0 +1,15 @@
#include "cvar.h"
#include "CvarString.h"
@implementation CvarString
-(void)setString: (string) str
{
Cvar_SetString (name, str);
}
-(string)value
{
return Cvar_GetString (name);
}
@end

View file

@ -0,0 +1,21 @@
#ifndef __CvarStringView_h
#define __CvarStringView_h
#include "gui/Group.h"
@class Text;
@class InputLineBox;
@class CvarString;
@interface CvarStringView : Group
{
Text *title;
InputLineBox *ilb;
CvarString *cvstring;
int active;
}
-(void)update;
-(id)initWithBounds:(Rect)aRect title:(string)_title inputLength: (int)length :(CvarString *)_cvstring;
@end
#endif//__CvarStringView_h

View file

@ -0,0 +1,62 @@
#include "key.h"
#include "sound.h"
#include "string.h"
#include "gui/Text.h"
#include "gui/InputLine.h"
#include "CvarStringView.h"
#include "CvarString.h"
@implementation CvarStringView
-(void)update
{
[ilb setText: [cvstring value]];
}
-(id)initWithBounds:(Rect)aRect title:(string)_title inputLength: (int)length :(CvarString *)_cvstring
{
Rect rect;
self = [super initWithBounds:aRect];
cvstring = _cvstring;
rect = makeRect (0, 0, strlen (_title) * 8, 8);
title = [[Text alloc] initWithBounds:rect text:_title];
rect.origin.x += rect.size.width + 8;
rect.origin.y = -8;
rect.size.width = (aRect.size.width - rect.size.width) / 8 - 2;
rect.size.height = 4; // history lines (stupid interface:P)
ilb = [[InputLineBox alloc] initWithBounds:rect promptCharacter:' '];
[self addView:title];
[self addView:ilb];
[self update];
return self;
}
- (int) keyEvent:(int)key unicode:(int)unicode down:(int)down
{
if (active) {
if (key == QFK_ESCAPE) {
[self update];
active = 0;
[ilb cursor: NO];
} else {
[ilb processInput:(key >= 256 ? key : unicode)];
}
return 1;
} else {
if (key == QFK_RETURN) {
active = 1;
[ilb cursor: YES];
}
}
return 0;
}
@end

View file

@ -31,7 +31,8 @@ menu_src= \
Frame.r menu.r HUD.r plistmenu.r ../lib/debug.r \ Frame.r menu.r HUD.r plistmenu.r ../lib/debug.r \
\ \
CrosshairCvar.r CrosshairView.r CvarColor.r CvarColorView.r \ CrosshairCvar.r CrosshairView.r CvarColor.r CvarColorView.r \
CvarObject.r CvarRange.r CvarRangeView.r CvarToggle.r CvarToggleView.r \ CvarObject.r CvarRange.r CvarRangeView.r CvarString.r CvarStringView.r \
CvarToggle.r CvarToggleView.r \
MenuGroup.r MouseToggle.r ProxyView.r RunToggle.r MenuGroup.r MouseToggle.r ProxyView.r RunToggle.r
%.qfo: %.r %.qfo: %.r
@ -49,7 +50,8 @@ menu.sym$(GZ): menu.dat$(GZ)
EXTRA_DIST= $(menu_src) \ EXTRA_DIST= $(menu_src) \
CrosshairCvar.h CrosshairView.h CvarColor.h CvarColorView.h CvarObject.h \ CrosshairCvar.h CrosshairView.h CvarColor.h CvarColorView.h CvarObject.h \
CvarRange.h CvarRangeView.h CvarToggle.h CvarToggleView.h Frame.h HUD.h \ CvarRange.h CvarRangeView.h CvarString.h CvarStringView.h \
CvarToggle.h CvarToggleView.h Frame.h HUD.h \
MenuGroup.h MouseToggle.h ProxyView.h RunToggle.h client_menu.h \ MenuGroup.h MouseToggle.h ProxyView.h RunToggle.h client_menu.h \
controls_o.h menu.h options.h options_util.h plistmenu.h servlist.h \ controls_o.h menu.h options.h options_util.h plistmenu.h servlist.h \
menu.plist menu.plist

View file

@ -25,21 +25,21 @@
- (int) keyEvent:(int)key unicode:(int)unicode down:(int)down - (int) keyEvent:(int)key unicode:(int)unicode down:(int)down
{ {
switch (key) { View *cur = [views objectAtIndex: current];
case QFK_DOWN: int ret = [cur keyEvent: key unicode: unicode down: down];
case QFM_WHEEL_DOWN: if (!ret) {
[self next]; switch (key) {
return 1; case QFK_DOWN:
case QFK_UP: case QFM_WHEEL_DOWN:
case QFM_WHEEL_UP: [self next];
[self prev]; return 1;
return 1; case QFK_UP:
default: case QFM_WHEEL_UP:
return [[views objectAtIndex: current] [self prev];
keyEvent: key return 1;
unicode: unicode }
down: down];
} }
return ret;
} }
-(void) next -(void) next

View file

@ -425,4 +425,60 @@
}, },
); );
}; };
network_options = {
Class = MenuGroup;
Messages = (
(initWithBounds:, $rect),
(addViews:, $views),
(setBase:, 4)
);
rect = "[0, 0, 320, 200]";
views = (
{
Class = Pic;
Messages = (
(initWithBounds:, $rect),
(setPic:, "\"gfx/qplaque.lmp\"")
);
rect = "[16, 4, 0, 0]";
},
{
Class = CenterPic;
Messages = (
(initWithBounds:, $rect),
(setPic:, "\"gfx/p_option.lmp\"")
);
rect = "[160, 4, 0, 0]";
},
{
Class = Text;
Messages = (
(initWithBounds:, $rect),
(setText:, "\"Network\"")
);
rect = "[54, 40, 56, 8]";
},
{
Class = Text;
Messages = (
(initWithBounds:, $rect),
(setText:, "\"-------\"")
);
rect = "[54, 50, 56, 8]";
},
{
Class = CvarStringView;
Messages = (
(initWithBounds:title:inputLength::, $rect, "\"Rate..:\"", 9, $cvstring)
);
rect = "[70, 68, 224, 8]";
cvstring = {
Class = CvarString;
Messages = (
(initWithCvar:, "\"rate\"")
);
};
},
);
};
} }

View file

@ -57,6 +57,7 @@ Group *video_options;
Group *audio_options; Group *audio_options;
Group *control_options; Group *control_options;
Group *feature_options; Group *feature_options;
Group *network_options;
Group *player_options; Group *player_options;
InputLine *player_config_plname_il; InputLine *player_config_plname_il;
@ -65,10 +66,6 @@ InputLine *player_config_iactive;
CvarColorView *topcolor_view; CvarColorView *topcolor_view;
CvarColorView *bottomcolor_view; CvarColorView *bottomcolor_view;
Group *network_options;
InputLine *network_config_rate_il;
InputLine *network_config_iactive;
/* /*
some definitions of border values for different things some definitions of border values for different things
*/ */
@ -517,49 +514,9 @@ string network_config_vals[NUM_NETWORKCONFIG_CMDS] = {
int (int key, int unicode, int down) int (int key, int unicode, int down)
KEYEV_network_options = KEY_network_options =
{ {
switch (key) { return [network_options keyEvent:key unicode:unicode down:down];
case QFK_DOWN:
case QFM_WHEEL_DOWN:
if (!network_config_iactive) {
network_config_cursor ++;
network_config_cursor %= NUM_PLAYERCONFIG_CMDS;
}
break;
case QFK_UP:
case QFM_WHEEL_UP:
if (!network_config_iactive) {
network_config_cursor += NUM_PLAYERCONFIG_CMDS - 1;
network_config_cursor %= NUM_PLAYERCONFIG_CMDS;
}
break;
case QFK_RETURN:
if (network_config_iactive) {
if(network_config_iactive == network_config_rate_il) {
Cvar_SetString ("rate",
[network_config_rate_il text]);
}
network_config_iactive = nil;
} else {
if (network_config_cursor == 0) {
network_config_iactive = network_config_rate_il;
}
}
break;
}
if (key != QFK_RETURN && network_config_iactive) {
[network_config_iactive processInput:(key >= 256 ? key : unicode)];
}
if (!(key == QFK_RIGHT || key == QFK_LEFT )) {
return 1;
}
// switch (network_config_vals[network_config_cursor]) {
// } // none yet
return 1;
}; };
/* /*
@ -570,27 +527,11 @@ KEYEV_network_options =
int (int x, int y) int (int x, int y)
DRAW_network_options = DRAW_network_options =
{ {
local int cursor_pad = 0, spacing = 120;
[network_config_rate_il cursor:network_config_iactive == network_config_rate_il];
[network_options setBasePos:x y:y]; [network_options setBasePos:x y:y];
[network_options draw]; [network_options draw];
opt_cursor (x + 62, y + network_config_cursor_tbl[network_config_cursor]);
return 1; return 1;
}; };
/*
CB_ME_network_options
Entercallback for the networkmenu.
*/
void ()
CB_ME_network_options =
{
[network_config_rate_il setText:Cvar_GetString ("rate")];
};
/* /*
MENU_network_options MENU_network_options
@ -599,39 +540,19 @@ CB_ME_network_options =
void void
MENU_network_options (PLItem *plist) MENU_network_options (PLItem *plist)
{ {
local id view; local @param ret;
Menu_Begin (54, 90, "Network");
Menu_FadeScreen (1);
Menu_KeyEvent (KEY_network_options);
Menu_Draw (DRAW_network_options);
network_options = [[Group alloc] initWithComponents:0 :0 :320 :200]; network_options = [[Group alloc] initWithComponents:0 :0 :320 :200];
view = [[Pic alloc] initWithComponents:16 :4 :0 :0]; if (plist) {
[view setPic:"gfx/qplaque.lmp"]; ret = object_from_plist ([(PLDictionary*) plist getObjectForKey:"network_options"]);
[network_options addView:view]; network_options = ret.pointer_val;
}
view = [[CenterPic alloc] initWithComponents:160 :4 :0 :0];
[view setPic:"gfx/p_option.lmp"];
[network_options addView:view];
view = [[Text alloc] initWithComponents:54 :40 :56 :8];
[view setText:"Network"];
[network_options addView:view];
view = [[Text alloc] initWithComponents:54 :50 :56 :8];
[view setText:"-------"];
[network_options addView:view];
view = [[Text alloc] initWithComponents:70 :NETWORK_CONF_Y_PAD + 8 :56 :8];
[view setText:"Rate..:"];
[network_options addView:view];
network_config_rate_il = [[InputLineBox alloc] initWithBounds:makeRect (120, NETWORK_CONF_Y_PAD, 9, 4) promptCharacter:' '];
[network_config_rate_il setWidth:9];
[network_options addView:network_config_rate_il];
Menu_Begin (54, 90, "Network");
Menu_FadeScreen (1);
Menu_KeyEvent (KEYEV_network_options);
Menu_EnterHook (CB_ME_network_options);
Menu_Draw (DRAW_network_options);
Menu_End (); Menu_End ();
}; };