diff --git a/include/QF/console.h b/include/QF/console.h index 49c3bb091..9f241ba97 100644 --- a/include/QF/console.h +++ b/include/QF/console.h @@ -136,6 +136,7 @@ struct view_s; void Menu_Init (void); void Menu_Load (void); void Menu_Draw (struct view_s *view); +void Menu_Draw_Hud (struct view_s *view); void Menu_KeyEvent (knum_t key, short unicode, qboolean down); void Menu_Enter (void); void Menu_Leave (void); diff --git a/libs/console/client.c b/libs/console/client.c index fcf36de9f..bfb71df57 100644 --- a/libs/console/client.c +++ b/libs/console/client.c @@ -98,6 +98,7 @@ static view_t *console_view; static view_t *say_view; static view_t *notify_view; static view_t *menu_view; +static view_t *hud_view; static qboolean con_initialized; @@ -741,6 +742,18 @@ C_NewMap (void) old_gamedir[sizeof (old_gamedir) - 1] = 0; } +static void +C_GIB_HUD_Show_f (void) +{ + hud_view->visible = 1; +} + +static void +C_GIB_HUD_Hide_f (void) +{ + hud_view->visible = 0; +} + static void C_Init (void) { @@ -763,9 +776,11 @@ C_Init (void) say_view = view_new (0, 0, 320, 8, grav_northwest); notify_view = view_new (0, 8, 320, 32, grav_northwest); menu_view = view_new (0, 0, 320, 200, grav_center); + hud_view = view_new (0, 0, vid.conwidth, vid.conheight, grav_northeast); view_add (con_data.view, say_view); view_add (con_data.view, notify_view); + view_add (con_data.view, hud_view); view_add (con_data.view, console_view); view_add (con_data.view, menu_view); @@ -783,6 +798,9 @@ C_Init (void) menu_view->draw = Menu_Draw; menu_view->visible = 0; + hud_view->draw = Menu_Draw_Hud; + hud_view->visible = 0; + view = view_new (0, 0, 320, 170, grav_northwest); view->draw = draw_console_text; view->resize_x = view->resize_y = 1; @@ -841,7 +859,9 @@ C_Init (void) // register GIB builtins GIB_Builtin_Add ("print::center", C_GIB_Print_Center_f); - + GIB_Builtin_Add ("HUD::show", C_GIB_HUD_Show_f); + GIB_Builtin_Add ("HUD::hide", C_GIB_HUD_Hide_f); + con_initialized = true; } diff --git a/libs/console/menu.c b/libs/console/menu.c index 61d758fde..c3ecc433b 100644 --- a/libs/console/menu.c +++ b/libs/console/menu.c @@ -83,6 +83,7 @@ static menu_item_t *menu; static hashtab_t *menu_hash; static func_t menu_init; static func_t menu_quit; +static func_t menu_draw_hud; static const char *top_menu; static int @@ -94,6 +95,9 @@ menu_resolve_globals (void) if (!(f = ED_FindFunction (&menu_pr_state, sym = "menu_init"))) goto error; menu_init = (func_t)(f - menu_pr_state.pr_functions); + if (!(f = ED_FindFunction (&menu_pr_state, sym = "menu_draw_hud"))) + goto error; + menu_draw_hud = (func_t)(f - menu_pr_state.pr_functions); return 1; error: Con_Printf ("%s: undefined function %s\n", menu_pr_state.progs_name, sym); @@ -461,6 +465,7 @@ Menu_Init (void) Cmd_AddCommand ("togglemenu", togglemenu_f, "Toggle the display of the menu"); Cmd_AddCommand ("quit", quit_f, "Exit the program"); + } void @@ -561,6 +566,12 @@ Menu_Draw (view_t *view) } } +void +Menu_Draw_Hud (view_t *view) +{ + PR_ExecuteProgram (&menu_pr_state, menu_draw_hud); +} + void Menu_KeyEvent (knum_t key, short unicode, qboolean down) { diff --git a/ruamoko/cl_menu/HUD.h b/ruamoko/cl_menu/HUD.h new file mode 100644 index 000000000..e12adf3e6 --- /dev/null +++ b/ruamoko/cl_menu/HUD.h @@ -0,0 +1,45 @@ +#include "Point.h" + +@interface HUDObject : Object +{ + Point origin; + BOOL visible; + integer handle; +} + ++ (void) initClass; +- (id) initWithComponents: (integer) x : (integer) y; +- (void) free; +- (integer) handle; +- (Point) origin; +- (void) setOrigin: (Point) newPoint; +- (void) translate: (Point) addPoint; +- (BOOL) isVisible; +- (void) setVisible: (BOOL) _visible; +- (void) display; +@end + +@interface HUDText : HUDObject +{ + string text; +} + +- (id) initWithComponents: (integer) x :(integer) y :(string) _text; +- (string) text; +- (void) setText: (string) _text; +- (void) display; +@end + +@interface HUDGraphic : HUDObject +{ + QPic picture; +} + +- (id) initWithComponents: (integer)x :(integer)y :(string) _file; +- (void) free; +- (void) setFile: (string) _file; +- (void) display; +@end + +@extern void () HUD_Init; +@extern integer HUDHandleClass; diff --git a/ruamoko/cl_menu/HUD.r b/ruamoko/cl_menu/HUD.r new file mode 100644 index 000000000..3d9c88c60 --- /dev/null +++ b/ruamoko/cl_menu/HUD.r @@ -0,0 +1,117 @@ +#include "draw.h" +#include "debug.h" +#include "gib.h" +#include "HUD.h" + +integer HUDHandleClass; + +@implementation HUDObject ++ (void) initClass +{ + HUDHandleClass = GIB_Handle_Class_New (); +} + +- (id) initWithComponents: (integer) x : (integer) y +{ + origin = [[Point alloc] initWithComponents: x :y]; + visible = YES; + handle = GIB_Handle_New (self, HUDHandleClass); + + return self; +} + +- (void) free +{ + [origin free]; + GIB_Handle_Free (handle, HUDHandleClass); + [super free]; +} + +- (integer) handle +{ + return handle; +} + +- (Point) origin +{ + return origin; +} + +- (void) setOrigin: (Point) newPoint +{ + [origin setPoint :newPoint]; +} + +- (void) translate: (Point) addPoint +{ + [origin addPoint :addPoint]; +} + +- (BOOL) isVisible +{ + return visible; +} + +- (void) setVisible: (BOOL) _visible +{ + visible = _visible; +} + +- (void) display +{ +} +@end + +@implementation HUDText : HUDObject +- (id) initWithComponents: (integer) x :(integer) y :(string) _text +{ + self = [super initWithComponents :x :y]; + text = _text; + + return self; +} + +- (string) text +{ + return text; +} + +- (void) setText: (string) _text +{ + text = _text; +} + +- (void) display +{ + if (visible) + Draw_String ([origin x], [origin y], text); +} +@end + +@implementation HUDGraphic : HUDObject +- (id) initWithComponents: (integer)x :(integer)y :(string) _file +{ + self = [super initWithComponents :x :y]; + picture = [[QPic alloc] initName :_file]; + + return self; +} + +- (void) free +{ + [super free]; + [picture free]; +} + +- (void) setFile: (string) _file +{ + [picture free]; + picture = [[QPic alloc] initName :_file]; +} + +- (void) display +{ + if (visible) + [picture draw :[origin x] :[origin y]]; +} +@end diff --git a/ruamoko/cl_menu/Makefile.am b/ruamoko/cl_menu/Makefile.am index 842f622ba..ed6e64210 100644 --- a/ruamoko/cl_menu/Makefile.am +++ b/ruamoko/cl_menu/Makefile.am @@ -30,7 +30,8 @@ EXTRA_DATA= $(menu_data) menu_src= \ client_menu.qc controls_o.qc \ - inputline_util.qc menu.r options.qc \ + inputline_util.qc menu.r HUD.r \ + hud_interface.qc options.qc \ options_util.qc servlist.qc %.qfo: %.r diff --git a/ruamoko/cl_menu/client_menu.qc b/ruamoko/cl_menu/client_menu.qc index f8208d2a4..647437859 100644 --- a/ruamoko/cl_menu/client_menu.qc +++ b/ruamoko/cl_menu/client_menu.qc @@ -13,6 +13,7 @@ #include "servlist.h" #include "system.h" #include "debug.h" +#include "HUD.h" #include "client_menu.h" //FIXME shouldn't need these @@ -483,16 +484,6 @@ void () main_menu = Menu_End (); }; -void (integer argc, string [] argv) gib_hello_world = -{ - GIB_Return ("Hello, world!"); -}; - -void () gib_menu = -{ - GIB_Builtin_Add ("Ruamoko::helloWorld", gib_hello_world); -}; - void () menu_init = { lanConfig_port_il = [[InputLine alloc] initWithBounds:[[Rect alloc] initWithComponents:126 :lanConfig_cursor_table[0] :8 :4] promptCharacter:' ']; @@ -513,7 +504,9 @@ void () menu_init = quit_menu (); load_menu (); save_menu (); - gib_menu (); + Menu_TopMenu ("main"); Menu_SetQuit (quit); + + HUD_Init (); }; diff --git a/ruamoko/cl_menu/hud_interface.qc b/ruamoko/cl_menu/hud_interface.qc new file mode 100644 index 000000000..3c67a792a --- /dev/null +++ b/ruamoko/cl_menu/hud_interface.qc @@ -0,0 +1,154 @@ +#include "gib.h" +#include "draw.h" +#include "Array.h" +#include "HUD.h" +#include "string.h" +#include "debug.h" + +@static Array HUDObjects; + +void (integer argc, string [] argv) gib_hud_new_text_f = +{ + local HUDObject newText; + + if (argc != 4) + return; + + newText = [[HUDText alloc] initWithComponents + :(integer) stof (argv[1]) + :(integer) stof (argv[2]) + :argv[3] + ]; + + [HUDObjects addItem :newText]; + + GIB_Return (itos ([newText handle])); +}; + +void (integer argc, string [] argv) gib_hud_new_graphic_f = +{ + local HUDGraphic newGraphic; + + if (argc != 4) + return; + + newGraphic = [[HUDGraphic alloc] initWithComponents + :(integer) stof (argv[1]) + :(integer) stof (argv[2]) + :argv[3] + ]; + + [HUDObjects addItem :newGraphic]; + + GIB_Return (itos ([newGraphic handle])); +}; + + +void (integer argc, string [] argv) gib_hud_delete_f = +{ + local integer i; + local HUDObject trashObject; + + if (argc < 2) + return; + + for (i = 1; i < argc; i++) { + trashObject = GIB_Handle_Get ((integer) stof (argv[i]), HUDHandleClass); + if (trashObject) { + [HUDObjects removeItem :trashObject]; + [trashObject free]; + } else + dprint (sprintf ("Warning: no HUD object associated with handle %i\n", (integer) stof (argv[i]))); + } +}; + +void (integer argc, string [] argv) gib_hud_get_origin_f = +{ + local HUDObject myObject; + local Point myOrigin; + + if (argc != 2) + return; + + myObject = GIB_Handle_Get ((integer) stof (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 = +{ + local integer i; + local Point p; + + if (argc < 4) + return; + + p = [[Point alloc] initWithComponents :(integer) stof (argv[argc-2]) :(integer) stof (argv[argc-1])]; + + if (argv[0] == "HUD::translate") + for (i = 1; i < argc - 2; i++) + [(HUDObject) GIB_Handle_Get ((integer) stof (argv[i]), HUDHandleClass) translate :p]; + else + for (i = 1; i < argc - 2; i++) + [(HUDObject) GIB_Handle_Get ((integer) stof (argv[i]), HUDHandleClass) setOrigin :p]; + [p free]; +}; + +void (integer argc, string [] argv) gib_hud_set_text_f = +{ + local HUDText myObject; + + if (argc != 3) + return; + + myObject = GIB_Handle_Get ((integer) stof (argv[1]), HUDHandleClass); + if (!myObject || ![myObject isKindOf :[HUDText class]]) + return; + [myObject setText :argv[2]]; +}; + +void (integer argc, string [] argv) gib_hud_set_file_f = +{ + local HUDGraphic myObject; + + if (argc != 3) + return; + + myObject = GIB_Handle_Get ((integer) stof (argv[1]), HUDHandleClass); + if (!myObject || ![myObject isKindOf :[HUDGraphic class]]) + return; + [myObject setFile :argv[2]]; +}; + +void () HUD_Init = +{ + GIB_Builtin_Add ("HUD::newText", gib_hud_new_text_f); + GIB_Builtin_Add ("HUD::newGraphic", gib_hud_new_graphic_f); + GIB_Builtin_Add ("HUD::delete", gib_hud_delete_f); + GIB_Builtin_Add ("HUD::getOrigin", gib_hud_get_origin_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::setText", gib_hud_set_text_f); + GIB_Builtin_Add ("HUD::setFile", gib_hud_set_file_f); + + // Initialize HUDObject class + [HUDObject initClass]; + + // Create array of HUD objects + HUDObjects = [[Array alloc] init]; +}; + +void () menu_draw_hud = +{ + local integer i; + local HUDObject myHUDObject; + + for (i = 0; i < [HUDObjects count]; i++) { + myHUDObject = [HUDObjects getItemAt :i]; + [myHUDObject display]; + } +};