static nh_bool curses_list_items_core(struct nh_objitem *items, int icount, nh_bool invent, nh_bool draw) { struct nh_objitem **list; if (invent) { inv_icount = icount; list = &inventory; } else { floor_icount = icount; list = &flooritems; } free(*list); if (!icount) *list = NULL; else { *list = malloc(icount * sizeof(struct nh_objitem)); memcpy(*list, items, icount * sizeof(struct nh_objitem)); } if (draw) draw_sidebar(); return ui_flags.draw_sidebar; }
static void curses_list_items_core(struct nh_objlist *objlist, nh_bool invent, nh_bool draw) { struct nh_objlist *list; if (invent) { list = &inventory; } else { list = &flooritems; } dealloc_objmenulist(list); if (objlist->icount) { list->items = malloc(objlist->icount * sizeof (struct nh_objitem)); list->size = objlist->icount; list->icount = objlist->icount; memcpy(list->items, objlist->items, objlist->icount * sizeof (struct nh_objitem)); } dealloc_objmenulist(objlist); if (draw) draw_sidebar(); }
void scroll_sidebar(int op, int menu) { if (!SidebarWidth) return; if (!CurBuffy) return; switch (op) { case OP_SIDEBAR_NEXT: if (CurBuffy->next == NULL) return; CurBuffy = CurBuffy->next; break; case OP_SIDEBAR_PREV: if (CurBuffy->prev == NULL) return; CurBuffy = CurBuffy->prev; break; case OP_SIDEBAR_SCROLL_UP: CurBuffy = TopBuffy; if (CurBuffy != Incoming) { calc_boundaries(menu); CurBuffy = CurBuffy->prev; } break; case OP_SIDEBAR_SCROLL_DOWN: CurBuffy = BottomBuffy; if (CurBuffy->next) { calc_boundaries(menu); CurBuffy = CurBuffy->next; } break; default: return; } calc_boundaries(menu); draw_sidebar(menu); }
void replay_commandloop(int fd) { int key, move, count; char buf[BUFSZ], qbuf[BUFSZ]; nh_bool ret, firsttime = TRUE; struct nh_replay_info rinfo; struct nh_cmd_arg noarg; struct nh_cmd_desc *cmd; create_game_windows(); if (!nh_view_replay_start(fd, &curses_replay_windowprocs, &rinfo)) return; load_keymap(); while (1) { draw_msgwin(); curses_update_status(NULL); draw_sidebar(); draw_replay_info(&rinfo); if (firsttime) show_replay_help(); firsttime = FALSE; key = get_map_key(TRUE); switch (key) { /* step forward */ case KEY_RIGHT: case ' ': ret = nh_view_replay_step(&rinfo, REPLAY_FORWARD, 1); draw_replay_info(&rinfo); if (ret == FALSE) { key = curses_msgwin("You have reached the end of this game. " "Go back or press ESC to exit."); if (key == KEY_ESC) goto out; } break; /* step backward */ case KEY_LEFT: nh_view_replay_step(&rinfo, REPLAY_BACKWARD, 1); draw_replay_info(&rinfo); break; case KEY_ESC: goto out; case 'g': strncpy(qbuf, "What move do you want to jump to?", BUFSZ); if (rinfo.max_moves > 0) sprintf(qbuf + strlen(qbuf), " (Max: %d)", rinfo.max_moves); curses_getline(qbuf, buf); if (buf[0] == '\033' || !(move = atoi(buf))) break; nh_view_replay_step(&rinfo, REPLAY_GOTO, move); break; case KEY_F(12): /* timetest! */ if (allow_timetest()) timetest(fd, &rinfo); break; default: count = 0; noarg.argtype = CMD_ARG_NONE; cmd = keymap[key]; if (!cmd) break; if (cmd->flags & CMD_UI) handle_internal_cmd(&cmd, &noarg, &count); if (cmd) nh_command(cmd->name, count, &noarg); break; } } out: nh_view_replay_finish(); free_keymap(); destroy_game_windows(); cleanup_messages(); }