2003-05-14 21:17:32 +00:00
|
|
|
#include "draw.h"
|
|
|
|
#include "debug.h"
|
|
|
|
#include "gib.h"
|
2003-05-15 06:49:10 +00:00
|
|
|
#include "string.h"
|
2003-05-23 04:29:01 +00:00
|
|
|
#include "system.h"
|
2003-05-14 21:17:32 +00:00
|
|
|
#include "HUD.h"
|
|
|
|
|
2011-03-25 07:46:32 +00:00
|
|
|
int HUDHandleClass;
|
2003-05-14 21:17:32 +00:00
|
|
|
|
|
|
|
@implementation HUDObject
|
2011-03-25 07:46:32 +00:00
|
|
|
- (id) initWithComponents: (int) x : (int) y
|
2003-05-14 21:17:32 +00:00
|
|
|
{
|
2003-05-15 06:49:10 +00:00
|
|
|
self = [super init];
|
2010-11-17 06:50:07 +00:00
|
|
|
origin = makePoint (x, y);
|
2003-05-14 21:17:32 +00:00
|
|
|
visible = YES;
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2003-07-29 19:55:41 +00:00
|
|
|
- (void) dealloc
|
2003-05-14 21:17:32 +00:00
|
|
|
{
|
2003-07-29 19:55:41 +00:00
|
|
|
[super dealloc];
|
2003-05-14 21:17:32 +00:00
|
|
|
}
|
|
|
|
|
2011-03-25 07:46:32 +00:00
|
|
|
- (int) handle
|
2003-05-14 21:17:32 +00:00
|
|
|
{
|
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (Point) origin
|
|
|
|
{
|
|
|
|
return origin;
|
|
|
|
}
|
|
|
|
|
2010-11-17 06:50:07 +00:00
|
|
|
- (Size) size
|
2003-05-15 06:49:10 +00:00
|
|
|
{
|
2010-11-17 06:50:07 +00:00
|
|
|
return makeSize (0, 0);
|
2003-05-15 06:49:10 +00:00
|
|
|
}
|
|
|
|
|
2003-05-14 21:17:32 +00:00
|
|
|
- (void) setOrigin: (Point) newPoint
|
|
|
|
{
|
2010-11-17 06:50:07 +00:00
|
|
|
origin = newPoint;
|
2003-05-14 21:17:32 +00:00
|
|
|
}
|
|
|
|
|
2010-11-17 06:50:07 +00:00
|
|
|
- (void) translate: (Point) offset
|
2003-05-14 21:17:32 +00:00
|
|
|
{
|
2010-11-17 06:50:07 +00:00
|
|
|
origin = addPoint(origin, offset);
|
2003-05-14 21:17:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) isVisible
|
|
|
|
{
|
|
|
|
return visible;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setVisible: (BOOL) _visible
|
|
|
|
{
|
|
|
|
visible = _visible;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) display
|
|
|
|
{
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation HUDText : HUDObject
|
2011-03-25 07:46:32 +00:00
|
|
|
- (id) initWithComponents: (int) x :(int) y :(string) _text
|
2003-05-14 21:17:32 +00:00
|
|
|
{
|
|
|
|
self = [super initWithComponents :x :y];
|
2003-05-15 06:49:10 +00:00
|
|
|
[self setText :_text];
|
2003-05-14 21:17:32 +00:00
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2010-11-17 06:50:07 +00:00
|
|
|
- (Size) size
|
2003-05-23 04:29:01 +00:00
|
|
|
{
|
2011-03-25 07:46:32 +00:00
|
|
|
return makeSize (8*(int) strlen (text), 8);
|
2003-05-23 04:29:01 +00:00
|
|
|
}
|
|
|
|
|
2003-05-14 21:17:32 +00:00
|
|
|
- (string) text
|
|
|
|
{
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setText: (string) _text
|
|
|
|
{
|
|
|
|
text = _text;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) display
|
|
|
|
{
|
|
|
|
if (visible)
|
2010-11-17 06:50:07 +00:00
|
|
|
Draw_String (origin.x, origin.y, text);
|
2003-05-14 21:17:32 +00:00
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation HUDGraphic : HUDObject
|
2011-03-25 07:46:32 +00:00
|
|
|
- (id) initWithComponents: (int)x :(int)y :(string) _file
|
2003-05-14 21:17:32 +00:00
|
|
|
{
|
|
|
|
self = [super initWithComponents :x :y];
|
2003-05-15 06:49:10 +00:00
|
|
|
[self setFile :_file];
|
2003-05-14 21:17:32 +00:00
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2003-07-29 19:55:41 +00:00
|
|
|
- (void) dealloc
|
2003-05-14 21:17:32 +00:00
|
|
|
{
|
2004-11-18 05:08:00 +00:00
|
|
|
[picture release];
|
2003-07-29 19:55:41 +00:00
|
|
|
[super dealloc];
|
2003-05-14 21:17:32 +00:00
|
|
|
}
|
|
|
|
|
2010-11-17 06:50:07 +00:00
|
|
|
- (Size) size
|
2003-05-23 04:29:01 +00:00
|
|
|
{
|
2010-11-17 06:50:07 +00:00
|
|
|
return makeSize ([picture width], [picture height]);
|
2003-05-23 04:29:01 +00:00
|
|
|
}
|
|
|
|
|
2003-05-14 21:17:32 +00:00
|
|
|
- (void) setFile: (string) _file
|
|
|
|
{
|
2004-11-18 05:08:00 +00:00
|
|
|
[picture release];
|
2003-05-14 21:17:32 +00:00
|
|
|
picture = [[QPic alloc] initName :_file];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) display
|
|
|
|
{
|
|
|
|
if (visible)
|
2010-11-17 06:50:07 +00:00
|
|
|
[picture draw :origin.x :origin.y];
|
2003-05-14 21:17:32 +00:00
|
|
|
}
|
|
|
|
@end
|
2003-05-23 04:29:01 +00:00
|
|
|
|
|
|
|
@implementation HUDAnimation : HUDObject
|
|
|
|
|
2011-03-25 07:46:32 +00:00
|
|
|
- (id) initWithComponents: (int) x :(int) y
|
2003-05-23 04:29:01 +00:00
|
|
|
{
|
|
|
|
self = [super initWithComponents :x :y];
|
|
|
|
frames = [[Array alloc] init];
|
|
|
|
currentFrame = 0;
|
|
|
|
nextFrameTime = 0;
|
|
|
|
looping = NO;
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2003-07-29 19:55:41 +00:00
|
|
|
- (void) dealloc
|
2003-05-23 04:29:01 +00:00
|
|
|
{
|
2004-11-18 05:08:00 +00:00
|
|
|
[frames release];
|
2003-07-29 19:55:41 +00:00
|
|
|
[super dealloc];
|
2003-05-23 04:29:01 +00:00
|
|
|
}
|
|
|
|
|
2010-11-17 06:50:07 +00:00
|
|
|
- (Size) size
|
2003-05-23 04:29:01 +00:00
|
|
|
{
|
2011-02-14 14:08:18 +00:00
|
|
|
local Frame *frame;
|
2003-05-23 04:29:01 +00:00
|
|
|
|
2010-12-12 01:27:51 +00:00
|
|
|
frame = [frames objectAtIndex: currentFrame];
|
2003-05-23 04:29:01 +00:00
|
|
|
return [frame size];
|
|
|
|
}
|
|
|
|
|
2011-02-14 14:08:18 +00:00
|
|
|
- (void) addFrame: (Frame*) frame
|
2003-05-23 04:29:01 +00:00
|
|
|
{
|
2010-12-12 10:40:24 +00:00
|
|
|
[frames addObject: frame];
|
2003-05-23 04:29:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) changeFrame
|
|
|
|
{
|
|
|
|
while (time >= nextFrameTime) {
|
2011-02-14 14:08:18 +00:00
|
|
|
local Frame *f;
|
2003-05-23 04:29:01 +00:00
|
|
|
if (++currentFrame == [frames count]) {
|
|
|
|
if (looping)
|
|
|
|
currentFrame = 0;
|
|
|
|
else {
|
2020-02-15 09:17:18 +00:00
|
|
|
nextFrameTime = 0.0f;
|
2003-05-23 04:29:01 +00:00
|
|
|
currentFrame = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2010-12-12 01:27:51 +00:00
|
|
|
f = [frames objectAtIndex: currentFrame];
|
2003-05-23 04:29:01 +00:00
|
|
|
nextFrameTime += [f duration];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) display
|
|
|
|
{
|
2011-02-14 14:08:18 +00:00
|
|
|
local Frame *f;
|
2003-05-23 04:29:01 +00:00
|
|
|
|
|
|
|
if (!visible)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (nextFrameTime)
|
|
|
|
[self changeFrame];
|
|
|
|
|
2010-12-12 01:27:51 +00:00
|
|
|
f = [frames objectAtIndex: currentFrame];
|
2010-11-17 06:50:07 +00:00
|
|
|
[f draw :origin.x :origin.y];
|
2003-05-23 04:29:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) start
|
|
|
|
{
|
2011-02-14 14:08:18 +00:00
|
|
|
local Frame *f;
|
2003-05-23 04:29:01 +00:00
|
|
|
|
|
|
|
currentFrame = 0;
|
2010-12-12 01:27:51 +00:00
|
|
|
f = [frames objectAtIndex: 0];
|
2003-05-23 04:29:01 +00:00
|
|
|
nextFrameTime = time + [f duration];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) stop
|
|
|
|
{
|
2020-02-15 09:17:18 +00:00
|
|
|
nextFrameTime = 0.0f;
|
2003-05-23 04:29:01 +00:00
|
|
|
currentFrame = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setLooping: (BOOL) _looping
|
|
|
|
{
|
|
|
|
looping = _looping;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|