mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-03-20 17:31:08 +00:00
Break out all the classes into their own files.
This commit is contained in:
parent
2b3ba0633e
commit
7ce1fc3be5
30 changed files with 682 additions and 545 deletions
11
ruamoko/cl_menu/CrosshairCvar.h
Normal file
11
ruamoko/cl_menu/CrosshairCvar.h
Normal file
|
@ -0,0 +1,11 @@
|
|||
#ifndef __CrosshairCvar_h
|
||||
#define __CrosshairCvar_h
|
||||
|
||||
#include "CvarObject.h"
|
||||
|
||||
@interface CrosshairCvar : CvarObject
|
||||
-(void) next;
|
||||
-(integer) crosshair;
|
||||
@end
|
||||
|
||||
#endif//__CrosshairCvar_h
|
16
ruamoko/cl_menu/CrosshairCvar.r
Normal file
16
ruamoko/cl_menu/CrosshairCvar.r
Normal file
|
@ -0,0 +1,16 @@
|
|||
#include "cvar.h"
|
||||
|
||||
#include "CrosshairCvar.h"
|
||||
|
||||
@implementation CrosshairCvar
|
||||
-(void) next
|
||||
{
|
||||
local integer val = Cvar_GetInteger (name);
|
||||
Cvar_SetInteger (name, (val + 1) % 4);
|
||||
}
|
||||
|
||||
-(integer) crosshair
|
||||
{
|
||||
return Cvar_GetInteger (name);
|
||||
}
|
||||
@end
|
15
ruamoko/cl_menu/CrosshairView.h
Normal file
15
ruamoko/cl_menu/CrosshairView.h
Normal file
|
@ -0,0 +1,15 @@
|
|||
#ifndef __CrosshairView_h
|
||||
#define __CrosshairView_h
|
||||
|
||||
#include "gui/View.h"
|
||||
#include "CrosshairCvar.h"
|
||||
|
||||
@interface CrosshairView : View
|
||||
{
|
||||
CrosshairCvar crosshair;
|
||||
}
|
||||
-(id)initWithBounds:(Rect)aRect :(CrosshairCvar)_crosshair;
|
||||
-(void) next;
|
||||
@end
|
||||
|
||||
#endif//__CrosshairView_h
|
42
ruamoko/cl_menu/CrosshairView.r
Normal file
42
ruamoko/cl_menu/CrosshairView.r
Normal file
|
@ -0,0 +1,42 @@
|
|||
#include "draw.h"
|
||||
#include "key.h"
|
||||
#include "sound.h"
|
||||
|
||||
#include "CrosshairView.h"
|
||||
|
||||
@implementation CrosshairView
|
||||
{
|
||||
CrosshairCvar crosshair;
|
||||
}
|
||||
|
||||
-(id)initWithBounds:(Rect)aRect :(CrosshairCvar)_crosshair
|
||||
{
|
||||
self = [self initWithBounds:aRect];
|
||||
crosshair = _crosshair;
|
||||
return self;
|
||||
}
|
||||
|
||||
-(void) next
|
||||
{
|
||||
[crosshair next];
|
||||
S_LocalSound ("misc/menu2.wav");
|
||||
}
|
||||
|
||||
-(void) draw
|
||||
{
|
||||
Draw_Fill (xabs, yabs, xlen, ylen, 0);
|
||||
Draw_Crosshair ([crosshair crosshair], xabs + xlen / 2, yabs + ylen / 2);
|
||||
}
|
||||
|
||||
- (integer) keyEvent:(integer)key unicode:(integer)unicode down:(integer)down
|
||||
{
|
||||
switch (key) {
|
||||
case QFK_RETURN:
|
||||
case QFM_BUTTON1:
|
||||
[self next];
|
||||
return 1;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@end
|
12
ruamoko/cl_menu/CvarColor.h
Normal file
12
ruamoko/cl_menu/CvarColor.h
Normal file
|
@ -0,0 +1,12 @@
|
|||
#ifndef __CvarColor_h
|
||||
#define __CvarColor_h
|
||||
|
||||
#include "CvarObject.h"
|
||||
|
||||
@interface CvarColor : CvarObject
|
||||
-(void)next;
|
||||
-(void)prev;
|
||||
-(integer)value;
|
||||
@end
|
||||
|
||||
#endif//__CvarColor_h
|
25
ruamoko/cl_menu/CvarColor.r
Normal file
25
ruamoko/cl_menu/CvarColor.r
Normal file
|
@ -0,0 +1,25 @@
|
|||
#include "cvar.h"
|
||||
|
||||
#include "options_util.h"
|
||||
#include "CvarColor.h"
|
||||
|
||||
@implementation CvarColor
|
||||
-(void)next
|
||||
{
|
||||
local float val = Cvar_GetFloat (name);
|
||||
val = min_max_cnt (0, 13, 1, val, 1);
|
||||
Cvar_SetFloat (name, val);
|
||||
}
|
||||
|
||||
-(void)prev
|
||||
{
|
||||
local float val = Cvar_GetFloat (name);
|
||||
val = min_max_cnt (0, 13, 1, val, 0);
|
||||
Cvar_SetFloat (name, val);
|
||||
}
|
||||
|
||||
-(integer)value
|
||||
{
|
||||
return Cvar_GetInteger (name);
|
||||
}
|
||||
@end
|
17
ruamoko/cl_menu/CvarColorView.h
Normal file
17
ruamoko/cl_menu/CvarColorView.h
Normal file
|
@ -0,0 +1,17 @@
|
|||
#ifndef __CvarColorView_h
|
||||
#define __CvarColorView_h
|
||||
|
||||
#include "gui/View.h"
|
||||
|
||||
@class CvarColor;
|
||||
|
||||
@interface CvarColorView : View
|
||||
{
|
||||
CvarColor color;
|
||||
}
|
||||
-(id)initWithBounds:(Rect)aRect :(CvarColor)_color;
|
||||
-(void)next;
|
||||
-(void)prev;
|
||||
@end
|
||||
|
||||
#endif//__CvarColorView_h
|
51
ruamoko/cl_menu/CvarColorView.r
Normal file
51
ruamoko/cl_menu/CvarColorView.r
Normal file
|
@ -0,0 +1,51 @@
|
|||
#include "draw.h"
|
||||
#include "key.h"
|
||||
#include "sound.h"
|
||||
|
||||
#include "CvarColorView.h"
|
||||
#include "CvarColor.h"
|
||||
|
||||
@implementation CvarColorView
|
||||
-(id)initWithBounds:(Rect)aRect :(CvarColor)_color
|
||||
{
|
||||
self = [self initWithBounds:aRect];
|
||||
color = _color;
|
||||
return self;
|
||||
}
|
||||
|
||||
-(void)next
|
||||
{
|
||||
[color next];
|
||||
S_LocalSound ("misc/menu2.wav");
|
||||
}
|
||||
|
||||
-(void)prev
|
||||
{
|
||||
[color prev];
|
||||
S_LocalSound ("misc/menu2.wav");
|
||||
}
|
||||
|
||||
-(void)draw
|
||||
{
|
||||
local integer xl;
|
||||
xl = xlen / 8 - 2;
|
||||
text_box (xabs, yabs, xl, ylen / 8 - 2);
|
||||
xl = (xl + 1) & ~1; // text_box does only multiples of 2
|
||||
Draw_Fill (xabs + 8, yabs + 8, xl * 8, ylen - 16,
|
||||
[color value] * 16 + 8);
|
||||
}
|
||||
|
||||
- (integer) keyEvent:(integer)key unicode:(integer)unicode down:(integer)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;
|
||||
}
|
||||
}
|
||||
@end
|
13
ruamoko/cl_menu/CvarObject.h
Normal file
13
ruamoko/cl_menu/CvarObject.h
Normal file
|
@ -0,0 +1,13 @@
|
|||
#ifndef __CvarObject_h
|
||||
#define __CvarObject_h
|
||||
|
||||
#include "Object.h"
|
||||
|
||||
@interface CvarObject : Object
|
||||
{
|
||||
string name;
|
||||
}
|
||||
-(id)initWithCvar:(string)cvname;
|
||||
@end
|
||||
|
||||
#endif//__CvarObject_h
|
24
ruamoko/cl_menu/CvarObject.r
Normal file
24
ruamoko/cl_menu/CvarObject.r
Normal file
|
@ -0,0 +1,24 @@
|
|||
#include "string.h"
|
||||
|
||||
#include "CvarObject.h"
|
||||
|
||||
@implementation CvarObject
|
||||
-(id)init
|
||||
{
|
||||
self = [super init];
|
||||
name = str_new ();
|
||||
return self;
|
||||
}
|
||||
|
||||
-(id)initWithCvar:(string)cvname
|
||||
{
|
||||
self = [self init];
|
||||
str_copy (name, cvname);
|
||||
return self;
|
||||
}
|
||||
|
||||
-(void)dealloc
|
||||
{
|
||||
str_free (name);
|
||||
}
|
||||
@end
|
17
ruamoko/cl_menu/CvarRange.h
Normal file
17
ruamoko/cl_menu/CvarRange.h
Normal file
|
@ -0,0 +1,17 @@
|
|||
#ifndef __CvarRange_h
|
||||
#define __CvarRange_h
|
||||
|
||||
#include "CvarObject.h"
|
||||
|
||||
@interface CvarRange : CvarObject
|
||||
{
|
||||
float min, max, step;
|
||||
}
|
||||
-(id)initWithCvar:(string)cvname min:(float)_min max:(float)_max step:(float)_step;
|
||||
-(void)inc;
|
||||
-(void)dec;
|
||||
-(float)value;
|
||||
-(integer)percentage;
|
||||
@end
|
||||
|
||||
#endif//__CvarRange_h
|
43
ruamoko/cl_menu/CvarRange.r
Normal file
43
ruamoko/cl_menu/CvarRange.r
Normal file
|
@ -0,0 +1,43 @@
|
|||
#include "cvar.h"
|
||||
|
||||
#include "options_util.h"
|
||||
#include "CvarRange.h"
|
||||
|
||||
@implementation CvarRange
|
||||
|
||||
-(id)initWithCvar:(string)cvname min:(float)_min max:(float)_max step:(float)_step
|
||||
{
|
||||
self = [super initWithCvar: cvname];
|
||||
|
||||
min = _min;
|
||||
max = _max;
|
||||
step = _step;
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
-(void)inc
|
||||
{
|
||||
local float val = Cvar_GetFloat (name);
|
||||
val = min_max_cnt (min, max, step, val, 1);
|
||||
Cvar_SetFloat (name, val);
|
||||
}
|
||||
|
||||
-(void)dec
|
||||
{
|
||||
local float val = Cvar_GetFloat (name);
|
||||
val = min_max_cnt (min, max, step, val, 0);
|
||||
Cvar_SetFloat (name, val);
|
||||
}
|
||||
|
||||
-(float)value
|
||||
{
|
||||
return Cvar_GetFloat (name);
|
||||
}
|
||||
|
||||
-(integer)percentage
|
||||
{
|
||||
return to_percentage(min, max, Cvar_GetFloat (name));
|
||||
}
|
||||
|
||||
@end
|
22
ruamoko/cl_menu/CvarRangeView.h
Normal file
22
ruamoko/cl_menu/CvarRangeView.h
Normal file
|
@ -0,0 +1,22 @@
|
|||
#ifndef __CvarRangeView_h
|
||||
#define __CvarRangeView_h
|
||||
|
||||
#include "gui/Group.h"
|
||||
|
||||
@class Text;
|
||||
@class Slider;
|
||||
@class CvarRange;
|
||||
|
||||
@interface CvarRangeView : Group
|
||||
{
|
||||
Text title;
|
||||
Text value;
|
||||
Slider slider;
|
||||
CvarRange range;
|
||||
}
|
||||
-(id)initWithBounds:(Rect)aRect title:(string)_title sliderWidth:(integer)width :(CvarRange)_range;
|
||||
-(void)inc;
|
||||
-(void)dec;
|
||||
@end
|
||||
|
||||
#endif//__CvarRangeView_h
|
74
ruamoko/cl_menu/CvarRangeView.r
Normal file
74
ruamoko/cl_menu/CvarRangeView.r
Normal file
|
@ -0,0 +1,74 @@
|
|||
#include "key.h"
|
||||
#include "sound.h"
|
||||
#include "string.h"
|
||||
|
||||
#include "gui/Text.h"
|
||||
#include "gui/Slider.h"
|
||||
#include "CvarRangeView.h"
|
||||
#include "CvarRange.h"
|
||||
|
||||
@implementation CvarRangeView
|
||||
|
||||
-(void)update
|
||||
{
|
||||
[slider setIndex:[range percentage]];
|
||||
[value setText:ftos ([range value])];
|
||||
}
|
||||
|
||||
-(id)initWithBounds:(Rect)aRect title:(string)_title sliderWidth:(integer)width :(CvarRange)_range
|
||||
{
|
||||
local Rect rect;
|
||||
|
||||
self = [super initWithBounds:aRect];
|
||||
|
||||
range = _range;
|
||||
|
||||
rect = makeRect (0, 0, strlen (_title) * 8, 8);
|
||||
title = [[Text alloc] initWithBounds:rect text:_title];
|
||||
|
||||
rect.origin.x += rect.size.width + 8;
|
||||
rect.size.width = width;
|
||||
if (rect.origin.x + rect.size.width > xlen)
|
||||
rect.size.width = xlen - rect.origin.x;
|
||||
slider = [[Slider alloc] initWithBounds:rect size:100];
|
||||
|
||||
rect.origin.x += rect.size.width + 8;
|
||||
rect.size.width = xlen - rect.origin.x;
|
||||
value = [[Text alloc] initWithBounds:rect];
|
||||
|
||||
[self addView:title];
|
||||
[self addView:slider];
|
||||
[self addView:value];
|
||||
|
||||
[self update];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
-(void)inc
|
||||
{
|
||||
[range inc];
|
||||
[self update];
|
||||
S_LocalSound ("misc/menu3.wav");
|
||||
}
|
||||
|
||||
-(void)dec
|
||||
{
|
||||
[range dec];
|
||||
[self update];
|
||||
S_LocalSound ("misc/menu3.wav");
|
||||
}
|
||||
|
||||
- (integer) keyEvent:(integer)key unicode:(integer)unicode down:(integer)down
|
||||
{
|
||||
switch (key) {
|
||||
case QFK_RIGHT:
|
||||
[self inc];
|
||||
return 1;
|
||||
case QFK_LEFT:
|
||||
[self dec];
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
11
ruamoko/cl_menu/CvarToggle.h
Normal file
11
ruamoko/cl_menu/CvarToggle.h
Normal file
|
@ -0,0 +1,11 @@
|
|||
#ifndef __CvarToggle_h
|
||||
#define __CvarToggle_h
|
||||
|
||||
#include "CvarObject.h"
|
||||
|
||||
@interface CvarToggle : CvarObject
|
||||
-(void)toggle;
|
||||
-(BOOL)value;
|
||||
@end
|
||||
|
||||
#endif//__CvarToggle_h
|
15
ruamoko/cl_menu/CvarToggle.r
Normal file
15
ruamoko/cl_menu/CvarToggle.r
Normal file
|
@ -0,0 +1,15 @@
|
|||
#include "cvar.h"
|
||||
|
||||
#include "CvarToggle.h"
|
||||
|
||||
@implementation CvarToggle
|
||||
-(void)toggle
|
||||
{
|
||||
Cvar_Toggle (name);
|
||||
}
|
||||
|
||||
-(BOOL)value
|
||||
{
|
||||
return Cvar_GetInteger (name);
|
||||
}
|
||||
@end
|
19
ruamoko/cl_menu/CvarToggleView.h
Normal file
19
ruamoko/cl_menu/CvarToggleView.h
Normal file
|
@ -0,0 +1,19 @@
|
|||
#ifndef __CvarToggleView_h
|
||||
#define __CvarToggleView_h
|
||||
|
||||
#include "gui/Group.h"
|
||||
|
||||
@class Text;
|
||||
@class CvarToggle;
|
||||
|
||||
@interface CvarToggleView : Group
|
||||
{
|
||||
Text title;
|
||||
Text value;
|
||||
CvarToggle toggle;
|
||||
}
|
||||
-(id)initWithBounds:(Rect)aRect title:(string)_title :(CvarToggle)_toggle;
|
||||
-(void)toggle;
|
||||
@end
|
||||
|
||||
#endif//__CvarToggleView_h
|
57
ruamoko/cl_menu/CvarToggleView.r
Normal file
57
ruamoko/cl_menu/CvarToggleView.r
Normal file
|
@ -0,0 +1,57 @@
|
|||
#include "key.h"
|
||||
#include "sound.h"
|
||||
#include "string.h"
|
||||
|
||||
#include "gui/Text.h"
|
||||
#include "CvarToggleView.h"
|
||||
|
||||
@implementation CvarToggleView
|
||||
|
||||
-(void)update
|
||||
{
|
||||
[value setText:[toggle value] ? "On" : "Off"];
|
||||
}
|
||||
|
||||
-(id)initWithBounds:(Rect)aRect title:(string)_title :(CvarToggle)_toggle
|
||||
{
|
||||
local Rect rect;
|
||||
|
||||
self = [super initWithBounds:aRect];
|
||||
|
||||
toggle = _toggle;
|
||||
|
||||
rect = makeRect (0, 0, strlen (_title) * 8, 8);
|
||||
title = [[Text alloc] initWithBounds:rect text:_title];
|
||||
|
||||
rect.size.width = 3 * 8;
|
||||
rect.origin.x = xlen - rect.size.width;
|
||||
value = [[Text alloc] initWithBounds:rect];
|
||||
|
||||
[self addView:title];
|
||||
[self addView:value];
|
||||
|
||||
[self update];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
-(void)toggle
|
||||
{
|
||||
[toggle toggle];
|
||||
[self update];
|
||||
S_LocalSound ("misc/menu3.wav");
|
||||
}
|
||||
|
||||
- (integer) keyEvent:(integer)key unicode:(integer)unicode down:(integer)down
|
||||
{
|
||||
switch (key) {
|
||||
case QFK_RETURN:
|
||||
case QFM_BUTTON1:
|
||||
[self toggle];
|
||||
return 1;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
|
@ -28,7 +28,11 @@ EXTRA_DATA= $(menu_data)
|
|||
|
||||
menu_src= \
|
||||
client_menu.qc controls_o.qc options.qc options_util.qc servlist.qc \
|
||||
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 \
|
||||
CvarObject.r CvarRange.r CvarRangeView.r CvarToggle.r CvarToggleView.r \
|
||||
MenuGroup.r MouseToggle.r ProxyView.r RunToggle.r
|
||||
|
||||
%.qfo: %.r
|
||||
$(QFCC) $(QCFLAGS) $(QCPPFLAGS) -c -o $@ $<
|
||||
|
|
14
ruamoko/cl_menu/MenuGroup.h
Normal file
14
ruamoko/cl_menu/MenuGroup.h
Normal file
|
@ -0,0 +1,14 @@
|
|||
#ifndef __MenuGroup_h
|
||||
#define __MenuGroup_h
|
||||
|
||||
#include "gui/Group.h"
|
||||
|
||||
@interface MenuGroup : Group
|
||||
{
|
||||
integer base;
|
||||
integer current;
|
||||
}
|
||||
-(void)setBase:(integer)b;
|
||||
@end
|
||||
|
||||
#endif//__MenuGroup_h
|
66
ruamoko/cl_menu/MenuGroup.r
Normal file
66
ruamoko/cl_menu/MenuGroup.r
Normal file
|
@ -0,0 +1,66 @@
|
|||
#include "key.h"
|
||||
#include "sound.h"
|
||||
|
||||
#include "Array.h"
|
||||
|
||||
#include "options_util.h"
|
||||
#include "MenuGroup.h"
|
||||
|
||||
@implementation MenuGroup
|
||||
-(id) init
|
||||
{
|
||||
if ((self = [super init]))
|
||||
current = base = 0;
|
||||
}
|
||||
|
||||
-(void)setBase:(integer)b
|
||||
{
|
||||
if (b >= [views count])
|
||||
b = [views count] - 1;
|
||||
if (b < 0)
|
||||
b = 0;
|
||||
current = base = b;
|
||||
}
|
||||
|
||||
- (integer) keyEvent:(integer)key unicode:(integer)unicode down:(integer)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 getItemAt:current]
|
||||
keyEvent:key
|
||||
unicode:unicode
|
||||
down:down];
|
||||
}
|
||||
}
|
||||
|
||||
-(void) next
|
||||
{
|
||||
if (++current >= [views count])
|
||||
current = base;
|
||||
S_LocalSound ("misc/menu1.wav");
|
||||
}
|
||||
|
||||
-(void) prev
|
||||
{
|
||||
if (--current < base)
|
||||
current = [views count] - 1;
|
||||
S_LocalSound ("misc/menu1.wav");
|
||||
}
|
||||
|
||||
- (void) draw
|
||||
{
|
||||
local View cur;
|
||||
|
||||
[super draw];
|
||||
cur = (View) [views getItemAt:current];
|
||||
opt_cursor (cur.xabs - 8, cur.yabs);
|
||||
}
|
||||
@end
|
10
ruamoko/cl_menu/MouseToggle.h
Normal file
10
ruamoko/cl_menu/MouseToggle.h
Normal file
|
@ -0,0 +1,10 @@
|
|||
#ifndef __MouseToggle_h
|
||||
#define __MouseToggle_h
|
||||
|
||||
#include "CvarObject.h"
|
||||
|
||||
|
||||
@interface MouseToggle : CvarObject
|
||||
@end
|
||||
|
||||
#endif//__MouseToggle_h
|
19
ruamoko/cl_menu/MouseToggle.r
Normal file
19
ruamoko/cl_menu/MouseToggle.r
Normal file
|
@ -0,0 +1,19 @@
|
|||
#include "cvar.h"
|
||||
|
||||
#include "MouseToggle.h"
|
||||
|
||||
@implementation MouseToggle
|
||||
-(void)toggle
|
||||
{
|
||||
if (Cvar_GetFloat ("m_pitch") < 0) {
|
||||
Cvar_SetFloat ("m_pitch", 0.022);
|
||||
} else {
|
||||
Cvar_SetFloat ("m_pitch", -0.022);
|
||||
}
|
||||
}
|
||||
|
||||
-(BOOL)value
|
||||
{
|
||||
return Cvar_GetFloat ("m_pitch") < 0;
|
||||
}
|
||||
@end
|
14
ruamoko/cl_menu/ProxyView.h
Normal file
14
ruamoko/cl_menu/ProxyView.h
Normal file
|
@ -0,0 +1,14 @@
|
|||
#ifndef __ProxyView_h
|
||||
#define __ProxyView_h
|
||||
|
||||
#include "gui/View.h"
|
||||
|
||||
@interface ProxyView : View
|
||||
{
|
||||
View title;
|
||||
View view;
|
||||
}
|
||||
-(id)initWithBounds:(Rect)aRect title:(View)aTitle view:(View)aView;
|
||||
@end
|
||||
|
||||
#endif//__ProxyView_h
|
34
ruamoko/cl_menu/ProxyView.r
Normal file
34
ruamoko/cl_menu/ProxyView.r
Normal file
|
@ -0,0 +1,34 @@
|
|||
#include "ProxyView.h"
|
||||
|
||||
@implementation ProxyView
|
||||
|
||||
-(id)initWithBounds:(Rect)aRect title:(View)aTitle view:(View)aView
|
||||
{
|
||||
self = [super initWithBounds:aRect];
|
||||
if (!self)
|
||||
return self;
|
||||
|
||||
title = aTitle;
|
||||
view = aView;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (integer) keyEvent:(integer)key unicode:(integer)unicode down:(integer)down
|
||||
{
|
||||
return [view keyEvent:key unicode:unicode down:down];
|
||||
}
|
||||
|
||||
- (void) draw
|
||||
{
|
||||
[title draw];
|
||||
[view draw];
|
||||
}
|
||||
|
||||
- (void) setBasePosFromView: (View) aview
|
||||
{
|
||||
[super setBasePosFromView:aview];
|
||||
[title setBasePosFromView:self];
|
||||
[view setBasePosFromView:self];
|
||||
}
|
||||
|
||||
@end
|
9
ruamoko/cl_menu/RunToggle.h
Normal file
9
ruamoko/cl_menu/RunToggle.h
Normal file
|
@ -0,0 +1,9 @@
|
|||
#ifndef __RunToggle_h
|
||||
#define __RunToggle_h
|
||||
|
||||
#include "CvarObject.h"
|
||||
|
||||
@interface RunToggle : CvarObject
|
||||
@end
|
||||
|
||||
#endif//__RunToggle_h
|
21
ruamoko/cl_menu/RunToggle.r
Normal file
21
ruamoko/cl_menu/RunToggle.r
Normal file
|
@ -0,0 +1,21 @@
|
|||
#include "cvar.h"
|
||||
|
||||
#include "RunToggle.h"
|
||||
|
||||
@implementation RunToggle
|
||||
-(void)toggle
|
||||
{
|
||||
if (Cvar_GetFloat ("cl_forwardspeed") < 400) {
|
||||
Cvar_SetFloat ("cl_forwardspeed", 400);
|
||||
Cvar_SetFloat ("cl_backspeed", 400);
|
||||
} else {
|
||||
Cvar_SetFloat ("cl_forwardspeed", 200);
|
||||
Cvar_SetFloat ("cl_backspeed", 200);
|
||||
}
|
||||
}
|
||||
|
||||
-(BOOL)value
|
||||
{
|
||||
return Cvar_GetFloat ("cl_forwardspeed") >= 400;
|
||||
}
|
||||
@end
|
|
@ -39,12 +39,17 @@
|
|||
|
||||
#include "plistmenu.h"
|
||||
|
||||
#include "gui/Group.h"
|
||||
#include "gui/InputLine.h"
|
||||
#include "gui/Pic.h"
|
||||
#include "gui/Rect.h"
|
||||
#include "gui/Slider.h"
|
||||
#include "gui/Text.h"
|
||||
|
||||
#include "CvarToggleView.h"
|
||||
#include "CvarRangeView.h"
|
||||
#include "CvarColorView.h"
|
||||
|
||||
Group video_options;
|
||||
Group audio_options;
|
||||
|
||||
|
|
|
@ -1,107 +1,6 @@
|
|||
#ifndef __options_util_h
|
||||
#define __options_util_h
|
||||
|
||||
#include "gui/Group.h"
|
||||
|
||||
@class Text;
|
||||
@class Slider;
|
||||
|
||||
@interface MenuGroup : Group
|
||||
{
|
||||
integer base;
|
||||
integer current;
|
||||
}
|
||||
-(void)setBase:(integer)b;
|
||||
@end
|
||||
|
||||
@interface CvarObject : Object
|
||||
{
|
||||
string name;
|
||||
}
|
||||
-(id)initWithCvar:(string)cvname;
|
||||
@end
|
||||
|
||||
@interface CvarToggle : CvarObject
|
||||
-(void)toggle;
|
||||
-(BOOL)value;
|
||||
@end
|
||||
|
||||
@interface MouseToggle : CvarObject
|
||||
@end
|
||||
|
||||
@interface RunToggle : CvarObject
|
||||
@end
|
||||
|
||||
@interface CvarToggleView : Group
|
||||
{
|
||||
Text title;
|
||||
Text value;
|
||||
CvarToggle toggle;
|
||||
}
|
||||
-(id)initWithBounds:(Rect)aRect title:(string)_title :(CvarToggle)_toggle;
|
||||
-(void)toggle;
|
||||
@end
|
||||
|
||||
@interface CvarColor : CvarObject
|
||||
-(void)next;
|
||||
-(void)prev;
|
||||
-(integer)value;
|
||||
@end
|
||||
|
||||
@interface CvarColorView : View
|
||||
{
|
||||
CvarColor color;
|
||||
}
|
||||
-(id)initWithBounds:(Rect)aRect :(CvarColor)_color;
|
||||
-(void)next;
|
||||
-(void)prev;
|
||||
@end
|
||||
|
||||
@interface CvarRange : CvarObject
|
||||
{
|
||||
float min, max, step;
|
||||
}
|
||||
-(id)initWithCvar:(string)cvname min:(float)_min max:(float)_max step:(float)_step;
|
||||
-(void)inc;
|
||||
-(void)dec;
|
||||
-(float)value;
|
||||
-(integer)percentage;
|
||||
@end
|
||||
|
||||
@interface CvarRangeView : Group
|
||||
{
|
||||
Text title;
|
||||
Text value;
|
||||
Slider slider;
|
||||
CvarRange range;
|
||||
}
|
||||
-(id)initWithBounds:(Rect)aRect title:(string)_title sliderWidth:(integer)width :(CvarRange)_range;
|
||||
-(void)inc;
|
||||
-(void)dec;
|
||||
@end
|
||||
|
||||
@interface CrosshairCvar : CvarObject
|
||||
-(void) next;
|
||||
-(integer) crosshair;
|
||||
@end
|
||||
|
||||
@interface CrosshairView : View
|
||||
{
|
||||
CrosshairCvar crosshair;
|
||||
}
|
||||
-(id)initWithBounds:(Rect)aRect :(CrosshairCvar)_crosshair;
|
||||
-(void) next;
|
||||
@end
|
||||
|
||||
@interface ProxyView : View
|
||||
{
|
||||
View title;
|
||||
View view;
|
||||
}
|
||||
-(id)initWithBounds:(Rect)aRect title:(View)aTitle view:(View)aView;
|
||||
@end
|
||||
|
||||
|
||||
@extern void (integer x, integer y) opt_cursor;
|
||||
@extern void (integer x, integer y, integer spacing, string spacechar, string label, string valstr) draw_item;
|
||||
@extern void (integer x, integer y, integer spacing, string label, string valstr) draw_val_item;
|
||||
|
|
|
@ -24,454 +24,12 @@
|
|||
Boston, MA 02111-1307, USA
|
||||
*/
|
||||
|
||||
#include "debug.h"
|
||||
#include "cvar.h"
|
||||
#include "draw.h"
|
||||
#include "system.h"
|
||||
#include "string.h"
|
||||
#include "key.h"
|
||||
#include "sound.h"
|
||||
#include "system.h"
|
||||
|
||||
#include "Array.h"
|
||||
#include "gui/Text.h"
|
||||
#include "gui/Rect.h"
|
||||
#include "gui/Slider.h"
|
||||
#include "options_util.h"
|
||||
|
||||
@implementation MenuGroup
|
||||
-(id) init
|
||||
{
|
||||
if ((self = [super init]))
|
||||
current = base = 0;
|
||||
}
|
||||
|
||||
-(void)setBase:(integer)b
|
||||
{
|
||||
if (b >= [views count])
|
||||
b = [views count] - 1;
|
||||
if (b < 0)
|
||||
b = 0;
|
||||
current = base = b;
|
||||
}
|
||||
|
||||
- (integer) keyEvent:(integer)key unicode:(integer)unicode down:(integer)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 getItemAt:current]
|
||||
keyEvent:key
|
||||
unicode:unicode
|
||||
down:down];
|
||||
}
|
||||
}
|
||||
|
||||
-(void) next
|
||||
{
|
||||
if (++current >= [views count])
|
||||
current = base;
|
||||
S_LocalSound ("misc/menu1.wav");
|
||||
}
|
||||
|
||||
-(void) prev
|
||||
{
|
||||
if (--current < base)
|
||||
current = [views count] - 1;
|
||||
S_LocalSound ("misc/menu1.wav");
|
||||
}
|
||||
|
||||
- (void) draw
|
||||
{
|
||||
local View cur;
|
||||
|
||||
[super draw];
|
||||
cur = (View) [views getItemAt:current];
|
||||
opt_cursor (cur.xabs - 8, cur.yabs);
|
||||
}
|
||||
@end
|
||||
|
||||
|
||||
@implementation CvarObject
|
||||
-(id)init
|
||||
{
|
||||
self = [super init];
|
||||
name = str_new ();
|
||||
return self;
|
||||
}
|
||||
|
||||
-(id)initWithCvar:(string)cvname
|
||||
{
|
||||
self = [self init];
|
||||
str_copy (name, cvname);
|
||||
return self;
|
||||
}
|
||||
|
||||
-(void)dealloc
|
||||
{
|
||||
str_free (name);
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation CvarToggle
|
||||
-(void)toggle
|
||||
{
|
||||
Cvar_Toggle (name);
|
||||
}
|
||||
|
||||
-(BOOL)value
|
||||
{
|
||||
return Cvar_GetInteger (name);
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation MouseToggle
|
||||
-(void)toggle
|
||||
{
|
||||
if (Cvar_GetFloat ("m_pitch") < 0) {
|
||||
Cvar_SetFloat ("m_pitch", 0.022);
|
||||
} else {
|
||||
Cvar_SetFloat ("m_pitch", -0.022);
|
||||
}
|
||||
}
|
||||
|
||||
-(BOOL)value
|
||||
{
|
||||
return Cvar_GetFloat ("m_pitch") < 0;
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation RunToggle
|
||||
-(void)toggle
|
||||
{
|
||||
if (Cvar_GetFloat ("cl_forwardspeed") < 400) {
|
||||
Cvar_SetFloat ("cl_forwardspeed", 400);
|
||||
Cvar_SetFloat ("cl_backspeed", 400);
|
||||
} else {
|
||||
Cvar_SetFloat ("cl_forwardspeed", 200);
|
||||
Cvar_SetFloat ("cl_backspeed", 200);
|
||||
}
|
||||
}
|
||||
|
||||
-(BOOL)value
|
||||
{
|
||||
return Cvar_GetFloat ("cl_forwardspeed") >= 400;
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation CvarToggleView
|
||||
|
||||
-(void)update
|
||||
{
|
||||
[value setText:[toggle value] ? "On" : "Off"];
|
||||
}
|
||||
|
||||
-(id)initWithBounds:(Rect)aRect title:(string)_title :(CvarToggle)_toggle
|
||||
{
|
||||
local Rect rect;
|
||||
|
||||
self = [super initWithBounds:aRect];
|
||||
|
||||
toggle = _toggle;
|
||||
|
||||
rect = makeRect (0, 0, strlen (_title) * 8, 8);
|
||||
title = [[Text alloc] initWithBounds:rect text:_title];
|
||||
|
||||
rect.size.width = 3 * 8;
|
||||
rect.origin.x = xlen - rect.size.width;
|
||||
value = [[Text alloc] initWithBounds:rect];
|
||||
|
||||
[self addView:title];
|
||||
[self addView:value];
|
||||
|
||||
[self update];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
-(void)toggle
|
||||
{
|
||||
[toggle toggle];
|
||||
[self update];
|
||||
S_LocalSound ("misc/menu3.wav");
|
||||
}
|
||||
|
||||
- (integer) keyEvent:(integer)key unicode:(integer)unicode down:(integer)down
|
||||
{
|
||||
switch (key) {
|
||||
case QFK_RETURN:
|
||||
case QFM_BUTTON1:
|
||||
[self toggle];
|
||||
return 1;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation CvarColor
|
||||
-(void)next
|
||||
{
|
||||
local float val = Cvar_GetFloat (name);
|
||||
val = min_max_cnt (0, 13, 1, val, 1);
|
||||
Cvar_SetFloat (name, val);
|
||||
}
|
||||
|
||||
-(void)prev
|
||||
{
|
||||
local float val = Cvar_GetFloat (name);
|
||||
val = min_max_cnt (0, 13, 1, val, 0);
|
||||
Cvar_SetFloat (name, val);
|
||||
}
|
||||
|
||||
-(integer)value
|
||||
{
|
||||
return Cvar_GetInteger (name);
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation CvarColorView
|
||||
-(id)initWithBounds:(Rect)aRect :(CvarColor)_color
|
||||
{
|
||||
self = [self initWithBounds:aRect];
|
||||
color = _color;
|
||||
return self;
|
||||
}
|
||||
|
||||
-(void)next
|
||||
{
|
||||
[color next];
|
||||
S_LocalSound ("misc/menu2.wav");
|
||||
}
|
||||
|
||||
-(void)prev
|
||||
{
|
||||
[color prev];
|
||||
S_LocalSound ("misc/menu2.wav");
|
||||
}
|
||||
|
||||
-(void)draw
|
||||
{
|
||||
local integer xl;
|
||||
xl = xlen / 8 - 2;
|
||||
text_box (xabs, yabs, xl, ylen / 8 - 2);
|
||||
xl = (xl + 1) & ~1; // text_box does only multiples of 2
|
||||
Draw_Fill (xabs + 8, yabs + 8, xl * 8, ylen - 16,
|
||||
[color value] * 16 + 8);
|
||||
}
|
||||
|
||||
- (integer) keyEvent:(integer)key unicode:(integer)unicode down:(integer)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;
|
||||
}
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation CvarRange
|
||||
|
||||
-(id)initWithCvar:(string)cvname min:(float)_min max:(float)_max step:(float)_step
|
||||
{
|
||||
self = [super init];
|
||||
|
||||
name = str_new ();
|
||||
str_copy (name, cvname);
|
||||
min = _min;
|
||||
max = _max;
|
||||
step = _step;
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
-(void)inc
|
||||
{
|
||||
local float val = Cvar_GetFloat (name);
|
||||
val = min_max_cnt (min, max, step, val, 1);
|
||||
Cvar_SetFloat (name, val);
|
||||
}
|
||||
|
||||
-(void)dec
|
||||
{
|
||||
local float val = Cvar_GetFloat (name);
|
||||
val = min_max_cnt (min, max, step, val, 0);
|
||||
Cvar_SetFloat (name, val);
|
||||
}
|
||||
|
||||
-(float)value
|
||||
{
|
||||
return Cvar_GetFloat (name);
|
||||
}
|
||||
|
||||
-(integer)percentage
|
||||
{
|
||||
return to_percentage(min, max, Cvar_GetFloat (name));
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation CvarRangeView
|
||||
|
||||
-(void)update
|
||||
{
|
||||
[slider setIndex:[range percentage]];
|
||||
[value setText:ftos ([range value])];
|
||||
}
|
||||
|
||||
-(id)initWithBounds:(Rect)aRect title:(string)_title sliderWidth:(integer)width :(CvarRange)_range
|
||||
{
|
||||
local Rect rect;
|
||||
|
||||
self = [super initWithBounds:aRect];
|
||||
|
||||
range = _range;
|
||||
|
||||
rect = makeRect (0, 0, strlen (_title) * 8, 8);
|
||||
title = [[Text alloc] initWithBounds:rect text:_title];
|
||||
|
||||
rect.origin.x += rect.size.width + 8;
|
||||
rect.size.width = width;
|
||||
if (rect.origin.x + rect.size.width > xlen)
|
||||
rect.size.width = xlen - rect.origin.x;
|
||||
slider = [[Slider alloc] initWithBounds:rect size:100];
|
||||
|
||||
rect.origin.x += rect.size.width + 8;
|
||||
rect.size.width = xlen - rect.origin.x;
|
||||
value = [[Text alloc] initWithBounds:rect];
|
||||
|
||||
[self addView:title];
|
||||
[self addView:slider];
|
||||
[self addView:value];
|
||||
|
||||
[self update];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
-(void)inc
|
||||
{
|
||||
[range inc];
|
||||
[self update];
|
||||
S_LocalSound ("misc/menu3.wav");
|
||||
}
|
||||
|
||||
-(void)dec
|
||||
{
|
||||
[range dec];
|
||||
[self update];
|
||||
S_LocalSound ("misc/menu3.wav");
|
||||
}
|
||||
|
||||
- (integer) keyEvent:(integer)key unicode:(integer)unicode down:(integer)down
|
||||
{
|
||||
switch (key) {
|
||||
case QFK_RIGHT:
|
||||
[self inc];
|
||||
return 1;
|
||||
case QFK_LEFT:
|
||||
[self dec];
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation CrosshairCvar
|
||||
-(void) next
|
||||
{
|
||||
local integer val = Cvar_GetInteger (name);
|
||||
Cvar_SetInteger (name, (val + 1) % 4);
|
||||
}
|
||||
|
||||
-(integer) crosshair
|
||||
{
|
||||
return Cvar_GetInteger (name);
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation CrosshairView
|
||||
{
|
||||
CrosshairCvar crosshair;
|
||||
}
|
||||
|
||||
-(id)initWithBounds:(Rect)aRect :(CrosshairCvar)_crosshair
|
||||
{
|
||||
self = [self initWithBounds:aRect];
|
||||
crosshair = _crosshair;
|
||||
return self;
|
||||
}
|
||||
|
||||
-(void) next
|
||||
{
|
||||
[crosshair next];
|
||||
S_LocalSound ("misc/menu2.wav");
|
||||
}
|
||||
|
||||
-(void) draw
|
||||
{
|
||||
Draw_Fill (xabs, yabs, xlen, ylen, 0);
|
||||
Draw_Crosshair ([crosshair crosshair], xabs + xlen / 2, yabs + ylen / 2);
|
||||
}
|
||||
|
||||
- (integer) keyEvent:(integer)key unicode:(integer)unicode down:(integer)down
|
||||
{
|
||||
switch (key) {
|
||||
case QFK_RETURN:
|
||||
case QFM_BUTTON1:
|
||||
[self next];
|
||||
return 1;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation ProxyView
|
||||
|
||||
-(id)initWithBounds:(Rect)aRect title:(View)aTitle view:(View)aView
|
||||
{
|
||||
self = [super initWithBounds:aRect];
|
||||
if (!self)
|
||||
return self;
|
||||
|
||||
title = aTitle;
|
||||
view = aView;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (integer) keyEvent:(integer)key unicode:(integer)unicode down:(integer)down
|
||||
{
|
||||
return [view keyEvent:key unicode:unicode down:down];
|
||||
}
|
||||
|
||||
- (void) draw
|
||||
{
|
||||
[title draw];
|
||||
[view draw];
|
||||
}
|
||||
|
||||
- (void) setBasePosFromView: (View) aview
|
||||
{
|
||||
[super setBasePosFromView:aview];
|
||||
[title setBasePosFromView:self];
|
||||
[view setBasePosFromView:self];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
/*
|
||||
opt_cursor
|
||||
|
||||
|
|
Loading…
Reference in a new issue