Added the HUDAnimation class and GIB bindings to use it, as well as other

enhancements and cleanups to the scriptable HUD system.
This commit is contained in:
Brian Koropoff 2003-05-23 04:29:01 +00:00
parent f9ff908157
commit 3205f0f672
6 changed files with 288 additions and 36 deletions

14
ruamoko/cl_menu/Frame.h Normal file
View file

@ -0,0 +1,14 @@
#include "Point.h"
#include "draw.h"
@interface Frame : Object
{
QPic picture;
float duration;
}
- (id) initWithFile: (string) file duration: (float) time;
- (void) free;
- (Point) size;
- (float) duration;
- (void) draw: (integer) x :(integer) y;
@end

34
ruamoko/cl_menu/Frame.r Normal file
View file

@ -0,0 +1,34 @@
#include "Frame.h"
#include "debug.h"
@implementation Frame : Object
- (id) initWithFile: (string) file duration: (float) time
{
self = [super init];
picture = [[QPic alloc] initName: file];
duration = time;
return self;
}
- (void) free
{
[picture free];
[super free];
}
- (Point) size
{
return [[Point alloc] initWithComponents :[picture width] :[picture height]];
}
- (float) duration
{
return duration;
}
- (void) draw: (integer) x :(integer) y
{
[picture draw :x :y];
}
@end

View file

@ -1,8 +1,10 @@
#include "Point.h" #include "Point.h"
#include "Frame.h"
#include "Array.h"
@interface HUDObject : Object @interface HUDObject : Object
{ {
Point origin, size; Point origin;
BOOL visible; BOOL visible;
integer handle; integer handle;
} }
@ -12,10 +14,9 @@
- (void) free; - (void) free;
- (integer) handle; - (integer) handle;
- (Point) origin; - (Point) origin;
- (Point) size;
- (void) setOrigin: (Point) newPoint; - (void) setOrigin: (Point) newPoint;
- (void) translate: (Point) addPoint; - (void) translate: (Point) addPoint;
- (Point) size;
//- (void) center Horizontal: (BOOL) h Vertical: (BOOL) v;
- (BOOL) isVisible; - (BOOL) isVisible;
- (void) setVisible: (BOOL) _visible; - (void) setVisible: (BOOL) _visible;
- (void) display; - (void) display;
@ -27,6 +28,7 @@
} }
- (id) initWithComponents: (integer) x :(integer) y :(string) _text; - (id) initWithComponents: (integer) x :(integer) y :(string) _text;
- (Point) size;
- (string) text; - (string) text;
- (void) setText: (string) _text; - (void) setText: (string) _text;
- (void) display; - (void) display;
@ -39,9 +41,28 @@
- (id) initWithComponents: (integer)x :(integer)y :(string) _file; - (id) initWithComponents: (integer)x :(integer)y :(string) _file;
- (void) free; - (void) free;
- (Point) size;
- (void) setFile: (string) _file; - (void) setFile: (string) _file;
- (void) display; - (void) display;
@end @end
@extern void () HUD_Init; @extern void () HUD_Init;
@extern integer HUDHandleClass; @extern integer HUDHandleClass;
@interface HUDAnimation : HUDObject
{
Array frames;
integer currentFrame;
float nextFrameTime;
BOOL looping;
}
- (id) initWithComponents: (integer) x :(integer) y;
- (void) free;
- (Point) size;
- (void) addFrame: (Frame) frame;
- (void) changeFrame;
- (void) display;
- (void) start;
- (void) stop;
- (void) setLooping: (BOOL) _looping;
@end

View file

@ -2,6 +2,7 @@
#include "debug.h" #include "debug.h"
#include "gib.h" #include "gib.h"
#include "string.h" #include "string.h"
#include "system.h"
#include "HUD.h" #include "HUD.h"
integer HUDHandleClass; integer HUDHandleClass;
@ -25,7 +26,6 @@ integer HUDHandleClass;
- (void) free - (void) free
{ {
[origin free]; [origin free];
[size free];
GIB_Handle_Free (handle, HUDHandleClass); GIB_Handle_Free (handle, HUDHandleClass);
[super free]; [super free];
} }
@ -42,7 +42,7 @@ integer HUDHandleClass;
- (Point) size - (Point) size
{ {
return size; return NIL;
} }
- (void) setOrigin: (Point) newPoint - (void) setOrigin: (Point) newPoint
@ -55,16 +55,6 @@ integer HUDHandleClass;
[origin addPoint :addPoint]; [origin addPoint :addPoint];
} }
/*
- (void) center Horizontal: (BOOL) h Vertical: (BOOL) v
{
Point newCoords;
integer newX, newY;
if (h) {
newX = X
*/
- (BOOL) isVisible - (BOOL) isVisible
{ {
return visible; return visible;
@ -89,6 +79,11 @@ integer HUDHandleClass;
return self; return self;
} }
- (Point) size
{
return [[Point alloc] initWithComponents :8*(integer) strlen (text) :8];
}
- (string) text - (string) text
{ {
return text; return text;
@ -97,8 +92,6 @@ integer HUDHandleClass;
- (void) setText: (string) _text - (void) setText: (string) _text
{ {
text = _text; text = _text;
[size free];
size = [[Point alloc] initWithComponents :8*(integer) strlen (text) :8];
} }
- (void) display - (void) display
@ -123,12 +116,15 @@ integer HUDHandleClass;
[super free]; [super free];
} }
- (Point) size
{
return [[Point alloc] initWithComponents :[picture width] :[picture height]];
}
- (void) setFile: (string) _file - (void) setFile: (string) _file
{ {
[picture free]; [picture free];
picture = [[QPic alloc] initName :_file]; picture = [[QPic alloc] initName :_file];
[size free];
size = [[Point alloc] initWithComponents :[picture width] :[picture height]];
} }
- (void) display - (void) display
@ -137,3 +133,89 @@ integer HUDHandleClass;
[picture draw :[origin x] :[origin y]]; [picture draw :[origin x] :[origin y]];
} }
@end @end
@implementation HUDAnimation : HUDObject
- (id) initWithComponents: (integer) x :(integer) y
{
self = [super initWithComponents :x :y];
frames = [[Array alloc] init];
currentFrame = 0;
nextFrameTime = 0;
looping = NO;
return self;
}
- (void) free
{
[frames free];
[super free];
}
- (Point) size
{
local Frame frame;
frame = [frames getItemAt :currentFrame];
return [frame size];
}
- (void) addFrame: (Frame) frame
{
[frames addItem :frame];
}
- (void) changeFrame
{
while (time >= nextFrameTime) {
local Frame f;
if (++currentFrame == [frames count]) {
if (looping)
currentFrame = 0;
else {
nextFrameTime = 0.0;
currentFrame = 0;
return;
}
}
f = [frames getItemAt :currentFrame];
nextFrameTime += [f duration];
}
}
- (void) display
{
local Frame f;
if (!visible)
return;
if (nextFrameTime)
[self changeFrame];
f = [frames getItemAt :currentFrame];
[f draw :[origin x] :[origin y]];
}
- (void) start
{
local Frame f;
currentFrame = 0;
f = [frames getItemAt :0];
nextFrameTime = time + [f duration];
}
- (void) stop
{
nextFrameTime = 0.0;
currentFrame = 0;
}
- (void) setLooping: (BOOL) _looping
{
looping = _looping;
}
@end

View file

@ -30,7 +30,7 @@ EXTRA_DATA= $(menu_data)
menu_src= \ menu_src= \
client_menu.qc controls_o.qc \ client_menu.qc controls_o.qc \
inputline_util.qc menu.r HUD.r \ Frame.r inputline_util.qc menu.r HUD.r \
hud_interface.qc options.qc \ hud_interface.qc options.qc \
options_util.qc servlist.qc options_util.qc servlist.qc

View file

@ -43,6 +43,82 @@ void (integer argc, string [] argv) gib_hud_new_graphic_f =
GIB_Return (itos ([newGraphic handle])); GIB_Return (itos ([newGraphic handle]));
}; };
void (integer argc, string [] argv) gib_hud_new_anim_f =
{
local HUDAnimation newAnim;
local Frame frame;
local integer i;
if (argc < 5)
return;
newAnim = [[HUDAnimation alloc] initWithComponents
:stoi (argv[1])
:stoi (argv[2])
];
for (i = 3; i < argc; i += 2) {
frame = [[Frame alloc] initWithFile: argv[i] duration: stof (argv[i+1])];
[newAnim addFrame :frame];
}
[HUDObjects addItem :newAnim];
GIB_Return (itos ([newAnim handle]));
};
void (integer argc, string [] argv) gib_hud_start_anim_f =
{
local integer i;
local HUDAnimation anim;
if (argc < 2)
return;
for (i = 1; i < argc; i++) {
anim = GIB_Handle_Get (stoi (argv[i]), HUDHandleClass);
if (anim && [anim isKindOf :[HUDAnimation class]])
[anim start];
}
};
void (integer argc, string [] argv) gib_hud_stop_anim_f =
{
local integer i;
local HUDAnimation anim;
if (argc < 2)
return;
for (i = 1; i < argc; i++) {
anim = GIB_Handle_Get (stoi (argv[i]), HUDHandleClass);
if (anim && [anim isKindOf :[HUDAnimation class]])
[anim stop];
}
};
void (integer argc, string [] argv) gib_hud_set_looping_f =
{
local HUDAnimation anim;
if (argc < 3)
return;
anim = GIB_Handle_Get (stoi (argv[1]), HUDHandleClass);
if (anim && [anim isKindOf :[HUDAnimation class]]) {
switch (argv[2]) {
case "yes":
case "true":
[anim setLooping :YES];
break;
case "no":
case "false":
[anim setLooping :NO];
break;
default:
break;
}
}
};
void (integer argc, string [] argv) gib_hud_delete_f = void (integer argc, string [] argv) gib_hud_delete_f =
{ {
@ -80,24 +156,9 @@ void (integer argc, string [] argv) gib_hud_get_rect_f =
myPoint = [myObject size]; myPoint = [myObject size];
GIB_Return (itos ([myPoint x])); GIB_Return (itos ([myPoint x]));
GIB_Return (itos ([myPoint y])); GIB_Return (itos ([myPoint y]));
[myPoint free];
}; };
void (integer argc, string [] argv) gib_hud_get_size_f =
{
local HUDObject myObject;
local Point myOrigin;
if (argc != 2)
return;
myObject = GIB_Handle_Get (stoi (argv[1]), HUDHandleClass);
if (!myObject)
return;
myOrigin = [myObject origin];
GIB_Return (itos ([myOrigin x]));
GIB_Return (itos ([myOrigin y]));
};
void (integer argc, string [] argv) gib_hud_set_translate_f = void (integer argc, string [] argv) gib_hud_set_translate_f =
{ {
@ -144,16 +205,56 @@ void (integer argc, string [] argv) gib_hud_set_file_f =
[myObject setFile :argv[2]]; [myObject setFile :argv[2]];
}; };
void (integer argc, string [] argv) gib_hud_show_f =
{
local integer i;
local HUDObject object;
if (argc < 2)
return;
for (i = 1; i < argc; i++) {
object = GIB_Handle_Get (stoi (argv[i]), HUDHandleClass);
if (object)
[object setVisible :YES];
else
dprint (sprintf ("Warning: no HUD object associated with handle %i\n", stoi (argv[i])));
}
};
void (integer argc, string [] argv) gib_hud_hide_f =
{
local integer i;
local HUDObject object;
if (argc < 2)
return;
for (i = 1; i < argc; i++) {
object = GIB_Handle_Get (stoi (argv[i]), HUDHandleClass);
if (object)
[object setVisible :NO];
else
dprint (sprintf ("Warning: no HUD object associated with handle %i\n", stoi (argv[i])));
}
};
void () HUD_Init = void () HUD_Init =
{ {
GIB_Builtin_Add ("HUD::newText", gib_hud_new_text_f); GIB_Builtin_Add ("HUD::newText", gib_hud_new_text_f);
GIB_Builtin_Add ("HUD::newGraphic", gib_hud_new_graphic_f); GIB_Builtin_Add ("HUD::newGraphic", gib_hud_new_graphic_f);
GIB_Builtin_Add ("HUD::newAnim", gib_hud_new_anim_f);
GIB_Builtin_Add ("HUD::delete", gib_hud_delete_f); GIB_Builtin_Add ("HUD::delete", gib_hud_delete_f);
GIB_Builtin_Add ("HUD::show", gib_hud_show_f);
GIB_Builtin_Add ("HUD::hide", gib_hud_hide_f);
GIB_Builtin_Add ("HUD::getRect", gib_hud_get_rect_f); GIB_Builtin_Add ("HUD::getRect", gib_hud_get_rect_f);
GIB_Builtin_Add ("HUD::setOrigin", gib_hud_set_translate_f); GIB_Builtin_Add ("HUD::setOrigin", gib_hud_set_translate_f);
GIB_Builtin_Add ("HUD::translate", gib_hud_set_translate_f); GIB_Builtin_Add ("HUD::translate", gib_hud_set_translate_f);
GIB_Builtin_Add ("HUD::setText", gib_hud_set_text_f); GIB_Builtin_Add ("HUD::setText", gib_hud_set_text_f);
GIB_Builtin_Add ("HUD::setFile", gib_hud_set_file_f); GIB_Builtin_Add ("HUD::setFile", gib_hud_set_file_f);
GIB_Builtin_Add ("HUD::startAnim", gib_hud_start_anim_f);
GIB_Builtin_Add ("HUD::stopAnim", gib_hud_stop_anim_f);
GIB_Builtin_Add ("HUD::setLooping", gib_hud_set_looping_f);
// Initialize HUDObject class // Initialize HUDObject class
[HUDObject initClass]; [HUDObject initClass];