src/extprocs.c
author ali@juiblex.co.uk
Mon Jan 29 20:22:01 2007 +0000 (2007-01-29)
changeset 0 acc07f1f4b1e
permissions -rw-r--r--
Initial check-in. Mostly sort of works. Ish.
     1 /*
     2  * $Id: extprocs.c,v 1.5 2004/12/30 09:07:47 ali Exp $
     3  * Copyright (C) 2007 J. Ali Harlow
     4  * Min Hack may be freely redistributed.  See license for details. 
     5  */
     6 
     7 #include <stdlib.h>
     8 #include <stdio.h>
     9 #include <string.h>
    10 #include "minhack.h"
    11 
    12 struct nhproxy_cb_get_glyph_mapping_res *glyph_map;
    13 struct minhack_window *windows=NULL;
    14 int no_windows=0;
    15 
    16 static int v_hook(void)
    17 {
    18     fprintf(stderr,"v_hook called\n");
    19 }
    20 
    21 struct nhproxy_clnt_ext_procs minhack_ext_procs = {
    22     "minhack",
    23     minhack_init_nhwindows,
    24     minhack_player_selection,
    25     minhack_askname,
    26     NULL,			/* get_nh_event */
    27     minhack_exit_nhwindows,
    28     NULL,			/* suspend_nhwindows */
    29     NULL,			/* resume_nhwindows */
    30     minhack_create_nhwindow,
    31     minhack_clear_nhwindow,
    32     minhack_display_nhwindow,
    33     minhack_destroy_nhwindow,
    34     minhack_curs,
    35     minhack_putstr,
    36     minhack_display_file,
    37     minhack_start_menu,
    38     minhack_add_menu,
    39     minhack_end_menu,
    40     minhack_select_menu,
    41     minhack_message_menu,
    42     NULL,			/* update_inventory */
    43     NULL,			/* mark_sync */
    44     NULL,			/* wait_sync */
    45     NULL,			/* cliparound */
    46     NULL,			/* update_positionbar */
    47     minhack_print_glyph,
    48     minhack_raw_print,
    49     minhack_raw_print_bold,
    50     minhack_nhgetch,
    51     minhack_nh_poskey,
    52     NULL,			/* nhbell */
    53     NULL,			/* doprev_message */
    54     minhack_yn_function,
    55     minhack_getlin,
    56     minhack_get_ext_cmd,
    57     NULL,			/* number_pad */
    58     NULL,			/* delay_output */
    59     NULL,			/* change_color */
    60     NULL,			/* change_background */
    61     NULL,			/* set_font_name */
    62     NULL,			/* get_color_string */
    63     NULL,			/* start_screen,*/
    64     NULL,			/* end_screen,*/
    65     minhack_outrip,
    66     minhack_preference_update,
    67     NULL,			/* status */
    68     v_hook,			/* print_glyph_layered */
    69     minhack_send_config_file,
    70 };
    71 
    72 int minhack_init_nhwindows(int *argc, char **argv, char ***capv)
    73 {
    74     initscr();
    75     nonl();
    76     cbreak();
    77     noecho();
    78     refresh();
    79     glyph_map=nhproxy_cb_get_glyph_mapping();
    80     return nhproxy_true;
    81 }
    82 
    83 int minhack_player_selection(int *role, int *race, int *gend, int *align)
    84 {
    85     return nhproxy_false;
    86 }
    87 
    88 char *minhack_askname(void)
    89 {
    90     return "ali";
    91 }
    92 
    93 void minhack_exit_nhwindows(const char *str)
    94 {
    95     endwin();
    96     minhack_raw_print(str);
    97 }
    98 
    99 void minhack_curs(int window, int x, int y)
   100 {
   101     wmove(windows[window].win,y,x);
   102 }
   103 
   104 void minhack_putstr(int window, int attr, const char *str)
   105 {
   106     waddstr(windows[window].win,str);
   107 }
   108 
   109 void minhack_display_file(int fh)
   110 {
   111     /* FIXME: Implement */
   112 }
   113 
   114 void minhack_print_glyph(int id, int x, int y, int glyph)
   115 {
   116     struct nhproxy_glyph_map_info info;
   117     struct nhproxy_glyph_mapping *map;
   118     map=nhproxy_glyph_map_first(&info,glyph_map);
   119     while(glyph--)
   120 	map=nhproxy_glyph_map_next(&info);
   121     mvwaddch(windows[id].win,y,x,map->rgbsym&0xFF);
   122     nhproxy_glyph_map_close(&info);
   123 }
   124 
   125 void minhack_raw_print(const char *str)
   126 {
   127     if (*str)
   128 	puts(str);
   129 }
   130 
   131 void minhack_raw_print_bold(const char *str)
   132 {
   133     minhack_raw_print(str);
   134 }
   135 
   136 int minhack_nhgetch(void)
   137 {
   138     int i;
   139     for(i=0;i<no_windows;i++)
   140 	if (windows[i].win && windows[i].type!=NHPROXY_EXT_NHW_MENU &&
   141 	  windows[i].type!=NHPROXY_EXT_NHW_TEXT)
   142 	    wrefresh(windows[i].win);
   143     return getch();
   144 }
   145 
   146 int minhack_nh_poskey(int *x, int *y, int *mod)
   147 {
   148     return minhack_nhgetch();
   149 }
   150 
   151 int minhack_outrip(int window, char *killed_by)
   152 {
   153     return nhproxy_false;
   154 }
   155 
   156 void minhack_preference_update(const char *optnam, const char *value)
   157 {
   158 }
   159 
   160 void minhack_send_config_file(int fh)
   161 {
   162 }