+
+
+
+static char * get_kb_line_and_iterate(struct World * world,
+ struct KeyBinding ** kb_pp)
+{
+ char * f_name = "get_kb_line_and_iterate()";
+ struct KeyBinding * kb_p = * kb_pp;
+ char * keyname = get_name_to_keycode(world, kb_p->key);
+ char * cmd_dsc = get_command_longdsc(world, kb_p->name);
+ uint16_t size = 9 + 1 + strlen(cmd_dsc) + 1;
+ char * line = try_malloc(size, world, f_name);
+ sprintf(line, "%-9s %s", keyname, cmd_dsc);
+ free(keyname);
+ * kb_pp = kb_p->next;
+ return line;
+}
+
+
+
+static void draw_kb_view(struct World * world, struct Win * w,
+ struct KeyBiData * kb, uint8_t start)
+{
+ if (0 == kb->kbs)
+ {
+ add_line(world, w, "(none)", 0, 0);
+ return;
+ }
+ struct KeyBinding * kb_p = kb->kbs;
+ uint16_t y;
+ for (y = start; 0 != kb_p; y++)
+ {
+ attr_t attri = 0;
+ if (y - start == kb->select)
+ {
+ attri = A_REVERSE;
+ if (1 == kb->edit)
+ {
+ attri = attri | A_BLINK;
+ }
+ }
+ char * kb_line = get_kb_line_and_iterate(world, &kb_p);
+ add_line(world, w, kb_line, attri, 1);
+ free(kb_line);
+ }
+}
+
+
+
+static uint16_t draw_titled_keybinding_list(struct World * world, char * title,
+ struct Win * w, uint16_t start,
+ struct KeyBinding * kb_p)
+{
+ uint16_t y;
+ uint8_t state = 0;
+ for (y = start; (0 == state || 0 != kb_p); y++)
+ {
+ if (0 == state)
+ {
+ add_line(world, w, title, 0, 0);
+ y++;
+ add_line(world, w, " ", 0, 0);
+ state = 1 + (0 == kb_p);
+ continue;
+ }
+ char * kb_line = get_kb_line_and_iterate(world, &kb_p);
+ add_line(world, w, kb_line, 0, 0);
+ free(kb_line);
+ }
+ if (2 == state)
+ {
+ char * none = "(none)";
+ add_line(world, w, none, 0, 0);
+ y++;
+ }
+ return y;
+}
+
+
+
+extern void draw_win_log(struct Win * win)
+{
+ struct World * world = (struct World *) win->data;
+ draw_text_from_bottom(world, win, world->log);
+}
+
+
+
+extern void draw_win_map(struct Win * win)
+{
+ struct World * world = (struct World *) win->data;
+ struct Map * map = world->map;
+ char * cells = map->cells;
+ try_resize_winmap(world, win, map->size.y, map->size.x);
+ uint16_t z = 0;
+ uint16_t x, y;
+ for (y = 0; y < map->size.y; y++)
+ {
+ for (x = 0; x < map->size.x; x++)
+ {
+ set_ch_on_yx(win, y, x, cells[z]);
+ z++;
+ }
+ }
+ draw_map_objects(world, world->map_objs, map, win);
+}
+
+
+
+extern void draw_win_info(struct Win * win)
+{
+ struct World * world = (struct World *) win->data;
+ char * dsc_turn = "Turn: ";
+ char * dsc_hitpoints = "\nHitpoints: ";
+ char * dsc_score = "\nScore: ";
+ uint16_t maxl = strlen(dsc_turn) + strlen(dsc_hitpoints) + strlen(dsc_score)
+ + 10 + 5 + 10; /* max strlens of numbers to be used */
+ char text[maxl + 1];
+ struct MapObj * player = get_player(world);
+ sprintf(text, "%s%d%s%d%s%d",
+ dsc_turn, world->turn,
+ dsc_hitpoints, player->lifepoints,
+ dsc_score, world->score);
+ add_text_with_linebreaks(world, win, text);
+}
+
+
+
+extern void draw_win_inventory(struct Win * win)
+{
+ struct World * world = (struct World *) win->data;
+ struct MapObj * player = get_player(world);
+ if (NULL == player->owns)
+ {
+ add_line(world, win, "(none)", 0, 0);
+ return;
+ }
+ win->center.y = world->inventory_select;
+ struct MapObj * owned = player->owns;
+ uint8_t y;
+ for (y = 0; NULL != owned; y++)
+ {
+ attr_t attri = 0;
+ if (y == world->inventory_select)
+ {
+ attri = A_REVERSE;
+ }
+ struct MapObjDef * mod = get_map_object_def(world, owned->type);
+ add_line(world, win, mod->name, attri, 0);
+ owned = owned->next;
+ }
+}
+
+
+
+extern void draw_win_available_keybindings(struct Win * win)
+{
+ struct World * world = (struct World *) win->data;
+ char * title = "Active window's keybindings:";
+ struct KeyBinding * kb_p;
+ struct WinConf * wc = get_winconf_by_win(world, world->wmeta->active);
+ if (0 == wc->view)
+ {
+ kb_p = wc->kb.kbs;
+ }
+ else if (1 == wc->view)
+ {
+ kb_p = world->kb_wingeom.kbs;
+ }
+ else if (2 == wc->view)
+ {
+ kb_p = world->kb_winkeys.kbs;
+ }
+ uint16_t offset = draw_titled_keybinding_list(world, title, win, 0, kb_p);
+ add_line(world, win, " ", 0, 0);
+ draw_titled_keybinding_list(world, "Global keybindings", win, offset + 1,
+ world->kb_global.kbs);
+}
+
+
+
+extern void draw_win_keybindings_global(struct Win * win)
+{
+ struct World * world = (struct World *) win->data;
+ win->center.y = world->kb_global.select;
+ draw_kb_view(world, win, &world->kb_global, 0);
+}
+
+
+
+extern void draw_win_keybindings_winconf_geometry(struct Win * win)
+{
+ struct World * world = (struct World *) win->data;
+ win->center.y = world->kb_wingeom.select;
+ draw_kb_view(world, win, &world->kb_wingeom, 0);
+}
+
+
+
+extern void draw_win_keybindings_winconf_keybindings(struct Win * win)
+{
+ struct World * world = (struct World *) win->data;
+ win->center.y = world->kb_winkeys.select;
+ draw_kb_view(world, win, &world->kb_winkeys, 0);
+}
+
+
+
+extern void draw_winconf_keybindings(struct Win * win)
+{
+ struct World * world = (struct World *) win->data;
+ struct WinConf * wc = get_winconf_by_win(world, win);
+ char * title = "Window's keybindings:";
+ add_line(world, win, title, 0, 0);
+ add_line(world, win, " ", 0, 0);
+ draw_kb_view(world, win, &wc->kb, 2);
+ win->center.y = wc->kb.select + 2;
+}
+
+
+
+extern void draw_winconf_geometry(struct Win * win)
+{
+ struct World * world = (struct World *) win->data;
+ struct WinConf * wcp = get_winconf_by_win(world, win);
+ char * title = "Window's geometry:\n";
+ char * h_d = "\nHeight to save: ";
+ char * h_pos = " (width in cells)";
+ char * h_neg = " (negative diff: cells to maximum width)";
+ char * w_d = "\n\nWidth to save: ";
+ char * w_pos = " (height in cells)";
+ char * w_neg = " (negative diff: cells to maximum height)";
+ char * h_t = h_pos;
+ char * w_t = w_pos;
+ if (1 == wcp->height_type)
+ {
+ h_t = h_neg;
+ }
+ if (1 == wcp->width_type)
+ {
+ w_t = w_neg;
+ }
+ uint16_t maxl = strlen(title)
+ + strlen(h_t) + strlen(h_d) + 6
+ + strlen(w_t) + strlen(w_d) + 6 + 1;
+ char text[maxl + 1];
+ sprintf(text, "%s%s%d%s%s%d%s", title, h_d, wcp->height, h_t,
+ w_d, wcp->width, w_t);
+ add_text_with_linebreaks(world, win, text);
+}