From 30bd1c0134bf1b3fb21aa7187f03c7b01a295e84 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Fri, 25 Mar 2011 18:26:10 +0900 Subject: [PATCH] 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. --- ruamoko/cl_menu/CvarString.h | 11 ++++ ruamoko/cl_menu/CvarString.r | 15 +++++ ruamoko/cl_menu/CvarStringView.h | 21 +++++++ ruamoko/cl_menu/CvarStringView.r | 62 +++++++++++++++++++ ruamoko/cl_menu/Makefile.am | 6 +- ruamoko/cl_menu/MenuGroup.r | 28 ++++----- ruamoko/cl_menu/menu.plist | 56 +++++++++++++++++ ruamoko/cl_menu/options.qc | 103 ++++--------------------------- 8 files changed, 195 insertions(+), 107 deletions(-) create mode 100644 ruamoko/cl_menu/CvarString.h create mode 100644 ruamoko/cl_menu/CvarString.r create mode 100644 ruamoko/cl_menu/CvarStringView.h create mode 100644 ruamoko/cl_menu/CvarStringView.r diff --git a/ruamoko/cl_menu/CvarString.h b/ruamoko/cl_menu/CvarString.h new file mode 100644 index 000000000..9bfaff45c --- /dev/null +++ b/ruamoko/cl_menu/CvarString.h @@ -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 diff --git a/ruamoko/cl_menu/CvarString.r b/ruamoko/cl_menu/CvarString.r new file mode 100644 index 000000000..2f81061c6 --- /dev/null +++ b/ruamoko/cl_menu/CvarString.r @@ -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 diff --git a/ruamoko/cl_menu/CvarStringView.h b/ruamoko/cl_menu/CvarStringView.h new file mode 100644 index 000000000..8c1fcda5d --- /dev/null +++ b/ruamoko/cl_menu/CvarStringView.h @@ -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 diff --git a/ruamoko/cl_menu/CvarStringView.r b/ruamoko/cl_menu/CvarStringView.r new file mode 100644 index 000000000..32a10c674 --- /dev/null +++ b/ruamoko/cl_menu/CvarStringView.r @@ -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 diff --git a/ruamoko/cl_menu/Makefile.am b/ruamoko/cl_menu/Makefile.am index 67f8caa7a..25da215fe 100644 --- a/ruamoko/cl_menu/Makefile.am +++ b/ruamoko/cl_menu/Makefile.am @@ -31,7 +31,8 @@ menu_src= \ Frame.r menu.r HUD.r plistmenu.r ../lib/debug.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 %.qfo: %.r @@ -49,7 +50,8 @@ menu.sym$(GZ): menu.dat$(GZ) EXTRA_DIST= $(menu_src) \ 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 \ controls_o.h menu.h options.h options_util.h plistmenu.h servlist.h \ menu.plist diff --git a/ruamoko/cl_menu/MenuGroup.r b/ruamoko/cl_menu/MenuGroup.r index 9b0477341..5c89382c7 100644 --- a/ruamoko/cl_menu/MenuGroup.r +++ b/ruamoko/cl_menu/MenuGroup.r @@ -25,21 +25,21 @@ - (int) keyEvent:(int)key unicode:(int)unicode down:(int)down { - switch (key) { - case QFK_DOWN: - case QFM_WHEEL_DOWN: - [self next]; - return 1; - case QFK_UP: - case QFM_WHEEL_UP: - [self prev]; - return 1; - default: - return [[views objectAtIndex: current] - keyEvent: key - unicode: unicode - down: down]; + View *cur = [views objectAtIndex: current]; + int ret = [cur keyEvent: key unicode: unicode down: down]; + if (!ret) { + switch (key) { + case QFK_DOWN: + case QFM_WHEEL_DOWN: + [self next]; + return 1; + case QFK_UP: + case QFM_WHEEL_UP: + [self prev]; + return 1; + } } + return ret; } -(void) next diff --git a/ruamoko/cl_menu/menu.plist b/ruamoko/cl_menu/menu.plist index 7e60a1687..2b33e3150 100644 --- a/ruamoko/cl_menu/menu.plist +++ b/ruamoko/cl_menu/menu.plist @@ -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\"") + ); + }; + }, + ); + }; } diff --git a/ruamoko/cl_menu/options.qc b/ruamoko/cl_menu/options.qc index 33e98b679..8291fab4a 100644 --- a/ruamoko/cl_menu/options.qc +++ b/ruamoko/cl_menu/options.qc @@ -57,6 +57,7 @@ Group *video_options; Group *audio_options; Group *control_options; Group *feature_options; +Group *network_options; Group *player_options; InputLine *player_config_plname_il; @@ -65,10 +66,6 @@ InputLine *player_config_iactive; CvarColorView *topcolor_view; CvarColorView *bottomcolor_view; -Group *network_options; -InputLine *network_config_rate_il; -InputLine *network_config_iactive; - /* 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) -KEYEV_network_options = +KEY_network_options = { - switch (key) { - 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; + return [network_options keyEvent:key unicode:unicode down:down]; }; /* @@ -570,27 +527,11 @@ KEYEV_network_options = int (int x, int y) 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 draw]; - - opt_cursor (x + 62, y + network_config_cursor_tbl[network_config_cursor]); 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 @@ -599,39 +540,19 @@ CB_ME_network_options = void 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]; - view = [[Pic alloc] initWithComponents:16 :4 :0 :0]; - [view setPic:"gfx/qplaque.lmp"]; - [network_options addView:view]; + if (plist) { + ret = object_from_plist ([(PLDictionary*) plist getObjectForKey:"network_options"]); + 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 (); };