bool CONSOLE::on_input(INPUT_EVENT e) { if (e.flags&INPFLAG_PRESS) { if (e.key == KEY_PAGEUP) { page++; return false; } else if (e.key == KEY_PAGEDOWN && page > 0) { page--; return false; } else page = 0; } if(console_state == CONSOLE_CLOSED) return false; if(e.key >= KEY_F1 && e.key <= KEY_F15) return false; if(e.key == KEY_ESCAPE && (e.flags&INPFLAG_PRESS)) toggle(console_type); else current_console()->on_input(e); return true; }
bool CONSOLE::on_input(INPUT_EVENT e) { if(console_state == CONSOLE_CLOSED) return false; if(e.key >= KEY_F1 && e.key <= KEY_F15) return false; if(e.key == KEY_ESCAPE && (e.flags&INPFLAG_PRESS)) toggle(console_type); else current_console()->on_input(e); return true; }
void CONSOLE::on_render() { RECT screen = *ui_screen(); float console_max_height = screen.h*3/5.0f; float console_height; float progress = (time_now()-(state_change_end-state_change_duration))/float(state_change_duration); if (progress >= 1.0f) { if (console_state == CONSOLE_CLOSING) console_state = CONSOLE_CLOSED; else if (console_state == CONSOLE_OPENING) console_state = CONSOLE_OPEN; progress = 1.0f; } if (console_state == CONSOLE_CLOSED) return; if (console_state == CONSOLE_OPEN) inp_mouse_mode_absolute(); float console_height_scale; if (console_state == CONSOLE_OPENING) console_height_scale = console_scale_func(progress); else if (console_state == CONSOLE_CLOSING) console_height_scale = console_scale_func(1.0f-progress); else //if (console_state == CONSOLE_OPEN) console_height_scale = console_scale_func(1.0f); console_height = console_height_scale*console_max_height; gfx_mapscreen(screen.x, screen.y, screen.w, screen.h); // do console shadow gfx_texture_set(-1); gfx_quads_begin(); gfx_setcolorvertex(0, 0,0,0, 0.5f); gfx_setcolorvertex(1, 0,0,0, 0.5f); gfx_setcolorvertex(2, 0,0,0, 0.0f); gfx_setcolorvertex(3, 0,0,0, 0.0f); gfx_quads_drawTL(0,console_height,screen.w,10.0f); gfx_quads_end(); // do background gfx_texture_set(data->images[IMAGE_CONSOLE_BG].id); gfx_quads_begin(); gfx_setcolor(0.2f, 0.2f, 0.2f,0.9f); if(console_type != 0) gfx_setcolor(0.4f, 0.2f, 0.2f,0.9f); gfx_quads_setsubset(0,-console_height*0.075f,screen.w*0.075f*0.5f,0); gfx_quads_drawTL(0,0,screen.w,console_height); gfx_quads_end(); // do small bar shadow gfx_texture_set(-1); gfx_quads_begin(); gfx_setcolorvertex(0, 0,0,0, 0.0f); gfx_setcolorvertex(1, 0,0,0, 0.0f); gfx_setcolorvertex(2, 0,0,0, 0.25f); gfx_setcolorvertex(3, 0,0,0, 0.25f); gfx_quads_drawTL(0,console_height-20,screen.w,10); gfx_quads_end(); // do the lower bar gfx_texture_set(data->images[IMAGE_CONSOLE_BAR].id); gfx_quads_begin(); gfx_setcolor(1.0f, 1.0f, 1.0f, 0.9f); gfx_quads_setsubset(0,0.1f,screen.w*0.015f,1-0.1f); gfx_quads_drawTL(0,console_height-10.0f,screen.w,10.0f); gfx_quads_end(); console_height -= 22.0f; INSTANCE *console = current_console(); { float font_size = 10.0f; float row_height = font_size*1.25f; float x = 3; float y = console_height - row_height - 2; // render prompt TEXT_CURSOR cursor; gfx_text_set_cursor(&cursor, x, y, font_size, TEXTFLAG_RENDER); RENDERINFO info; info.wanted_completion = console->completion_chosen; info.enum_count = 0; info.current_cmd = console->completion_buffer; gfx_text_set_cursor(&info.cursor, x, y+12.0f, font_size, TEXTFLAG_RENDER); const char *prompt = "> "; if(console_type) { if(client_state() == CLIENTSTATE_ONLINE) { if(client_rcon_authed()) prompt = "rcon> "; else prompt = "ENTER PASSWORD> "; } else prompt = "NOT CONNECTED> "; } gfx_text_ex(&cursor, prompt, -1); // render console input gfx_text_ex(&cursor, console->input.get_string(), console->input.cursor_offset()); TEXT_CURSOR marker = cursor; gfx_text_ex(&marker, "|", -1); gfx_text_ex(&cursor, console->input.get_string()+console->input.cursor_offset(), -1); // render version char buf[128]; str_format(buf, sizeof(buf), "v%s", GAME_VERSION); float version_width = gfx_text_width(0, font_size, buf, -1); gfx_text(0, screen.w-version_width-5, y, font_size, buf, -1); // render possible commands if(console->input.get_string()[0] != 0) { console_possible_commands(console->completion_buffer, console->completion_flagmask, possible_commands_render_callback, &info); if(info.enum_count <= 0) { if(console->command) { char buf[512]; str_format(buf, sizeof(buf), "Help: %s ", console->command->help); gfx_text_ex(&info.cursor, buf, -1); gfx_text_color(0.75f, 0.75f, 0.75f, 1); str_format(buf, sizeof(buf), "Syntax: %s %s", console->command->name, console->command->params); gfx_text_ex(&info.cursor, buf, -1); } } } gfx_text_color(1,1,1,1); // render log y -= row_height; char *entry = (char *)ringbuf_last(console->backlog); while (y > 0.0f && entry) { gfx_text(0, x, y, font_size, entry, -1); y -= row_height; entry = (char *)ringbuf_prev(console->backlog, entry); } } }
void init_consoles(void) { // get current tty fd = getfd(0); start_console=current_console(); }