/** * Returns box option under given position. * Requires text font to be set properly before running. */ struct GuiBoxOption *gui_get_box_option_point_over(struct GuiBox *gbox, long x, long y) { long sx,sy,lnheight; long width,height; struct GuiBoxOption *gboptn; sx = gbox->pos_x + 8; sy = gbox->pos_y + 8; gboptn = gbox->optn_list; lnheight = LbTextLineHeight()*((long)pixel_size) + 2; while (gboptn->label[0] != '!') { height = LbTextStringHeight(gboptn->label)*((long)pixel_size); if ((y >= sy) && (y < sy+height)) { width = LbTextStringWidth(gboptn->label)*((long)pixel_size); if ((x >= sx) && (x < sx+width)) { if ((gboptn->numfield_4 == 2) || (gboptn->field_26 == 0)) return NULL; return gboptn; } } gboptn++; sy += lnheight; } return NULL; }
void draw_high_score_entry(int idx, long pos_x, long pos_y, int col1_width, int col2_width, int col3_width, int col4_width, int units_per_px) { struct HighScore *hscore; char str[64]; int i; if ((idx >= campaign.hiscore_count) || (campaign.hiscore_table == NULL)) return; hscore = &campaign.hiscore_table[idx]; lbDisplay.DrawFlags = Lb_TEXT_HALIGN_RIGHT; i = pos_x + col1_width; LbTextNumberDraw(i, pos_y, units_per_px, idx+1, Fnt_RightJustify); i += col2_width; LbTextNumberDraw(i, pos_y, units_per_px, hscore->score, Fnt_RightJustify); i += col3_width; LbTextNumberDraw(i, pos_y, units_per_px, hscore->lvnum, Fnt_RightJustify); i += col4_width; if (idx == high_score_entry_input_active) { memcpy(str,high_score_entry,sizeof(str)); str[sizeof(str)-1] = '\0'; LbTextStringDraw(i, pos_y, units_per_px, str, Fnt_LeftJustify); str[high_score_entry_index] = '\0'; i += LbTextStringWidth(str) * units_per_px / 16; // Blinking cursor if ((LbTimerClock() & 0x0100) != 0) { LbTextStringDraw(i, pos_y, units_per_px, "_", Fnt_LeftJustify); } } else { LbTextStringDraw(i, pos_y, units_per_px, hscore->name, Fnt_LeftJustify); } }
long gui_calculate_box_width(struct GuiBox *gbox) { struct GuiBoxOption *goptn; int w,maxw; maxw = 0; goptn = gbox->optn_list; while (goptn->label[0] != '!') { w = pixel_size * LbTextStringWidth(goptn->label); if (w > maxw) maxw = w; goptn++; } return maxw+16; }
TbBool draw_text_box(const char *text) { long spritesy,spritesx; long box_width,box_height; long startx,starty; long n; LbTextSetFont(frontend_font[1]); n = LbTextStringWidth(text); if (n < (4*108)) { spritesy = 1; spritesx = n / 108; } else { spritesx = 4; spritesy = n / (3*108); } if (spritesy > 4) { ERRORLOG("Text too long for error box"); } if (spritesx < 2) { spritesx = 2; } else if (spritesx > 4) { spritesx = 4; } box_width = (108 * spritesx + 18) * units_per_pixel / 16; box_height = 92 * units_per_pixel / 16; startx = (lbDisplay.PhysicalScreenWidth - box_width) / 2; starty = (lbDisplay.PhysicalScreenHeight - box_height) / 2; draw_message_box_at(startx, starty, box_width, box_height, spritesx, spritesy); // Draw the text inside box lbDisplay.DrawFlags = Lb_TEXT_HALIGN_CENTER; int tx_units_per_px; tx_units_per_px = ((box_height/4)*13/11) * 16 / LbTextLineHeight(); LbTextSetWindow(startx, starty, box_width, box_height); n = LbTextLineHeight() * tx_units_per_px / 16; return LbTextDrawResized(0, (box_height - spritesy * n) / 2, tx_units_per_px, text); }
/** * Displays easter egg messages on screen. */ void draw_eastegg(void) { char *text; static long px[2]={0,0},py[2]={0,0}; static long vx[2]={0,0},vy[2]={0,0}; long i,k; SYNCDBG(5,"Starting"); LbTextSetWindow(0, 0, MyScreenWidth, MyScreenHeight); if (eastegg_skeksis_cntr >= eastegg_skeksis_codes.length) { unsigned char pos; eastegg_skeksis_cntr++; LbTextSetFont(winfont); text=buf_sprintf("Dene says a big 'Hello' to Goth Buns, Tarts and Barbies"); lbDisplay.DrawFlags = Lb_TEXT_ONE_COLOR; for (i=0; i<30; i+=2) { pos = game.play_gameturn - i; lbDisplay.DrawColour = pos; LbTextDraw((LbCosL(16*(long)pos) / 512 + 120) / pixel_size, (LbSinL(32*(long)pos) / 512 + 200) / pixel_size, text); } set_flag_word(&lbDisplay.DrawFlags,Lb_TEXT_ONE_COLOR,false); pos=game.play_gameturn; LbTextDraw((LbCosL(16*(long)pos) / 512 + 120) / pixel_size, (LbSinL(32*(long)pos) / 512 + 200) / pixel_size, text); if (eastegg_skeksis_cntr >= 255) eastegg_skeksis_cntr = 0; } if (game.eastegg01_cntr >= eastegg_feckoff_codes.length) { LbTextSetWindow(0/pixel_size, 0/pixel_size, MyScreenWidth/pixel_size, MyScreenHeight/pixel_size); lbDisplay.DrawFlags &= ~Lb_TEXT_ONE_COLOR; LbTextSetFont(winfont); i = 0; text = buf_sprintf("Simon says Hi to everyone he knows..."); px[i] += vx[i]; if (px[i] < 0) { px[i] = 0; vx[i] = -vx[i]; } py[i] += vy[i]; if (py[i] < 0) { py[i] = 0; vy[i] = -vy[i]; } k = pixel_size*LbTextStringWidth(text); if (px[i]+k >= MyScreenWidth) { vx[i] = -vx[i]; px[i] = MyScreenWidth-k-1; } k = pixel_size*LbTextStringHeight(text); if (py[i]+k >= MyScreenHeight) { vy[i] = -vy[i]; py[i] = MyScreenHeight-k-1; } if (LbScreenIsLocked()) { LbTextDraw(px[i]/pixel_size, py[i]/pixel_size, text); } play_non_3d_sample_no_overlap(90); } if ((game.flags_font & FFlg_AlexCheat) == 0) return; if (game.eastegg02_cntr >= eastegg_jlw_codes.length) { LbTextSetWindow(0/pixel_size, 0/pixel_size, MyScreenWidth/pixel_size, MyScreenHeight/pixel_size); lbDisplay.DrawFlags &= ~Lb_TEXT_ONE_COLOR; LbTextSetFont(winfont); i = 1; text = buf_sprintf("Alex, hopefully lying on a beach with Jo, says Hi"); px[i] += vx[i]; if (px[i] < 0) { px[i] = 0; vx[i] = -vx[i]; } py[i] += vy[i]; if (py[i] < 0) { py[i] = 0; vy[i] = -vy[i]; } k = pixel_size * LbTextStringWidth(text); if (px[i]+k >= MyScreenWidth) { vx[i] = -vx[i]; px[i] = MyScreenWidth-k-1; } k = pixel_size * LbTextStringHeight(text); if (py[i]+k >= MyScreenHeight) { vy[i] = -vy[i]; py[i] = MyScreenHeight-k-1; } if (LbScreenIsLocked()) LbTextDraw(px[i]/pixel_size, py[i]/pixel_size, text); play_non_3d_sample_no_overlap(90); } }
void frontend_draw_high_score_table(struct GuiButton *gbtn) { struct TbSprite *spr; struct TbSprite *swpspr; long pos_x,pos_y; long col1_width,col2_width,col3_width,col4_width; long i,k; // Detect scaling factor is quite complicated for this item int fs_units_per_px; { int orig_size; orig_size = 0; spr = &frontend_sprite[33]; for (i=0; i < 6; i++) { orig_size += spr->SWidth; spr++; } fs_units_per_px = (gbtn->width * 16 + orig_size/2) / orig_size; } // Draw the high scores area - top pos_x = gbtn->scr_pos_x; pos_y = gbtn->scr_pos_y; spr = &frontend_sprite[25]; swpspr = spr; for (i=6; i > 0; i--) { LbSpriteDrawResized(pos_x, pos_y, fs_units_per_px, swpspr); pos_x += swpspr->SWidth * fs_units_per_px / 16; swpspr++; } pos_y += spr->SHeight * fs_units_per_px / 16; // Draw the high scores area - filling k = 12; while (k > 0) { if (k < 3) i = 33; else i = 40; spr = &frontend_sprite[i]; pos_x = gbtn->scr_pos_x; swpspr = spr; for (i=6; i > 0; i--) { LbSpriteDrawResized(pos_x, pos_y, fs_units_per_px, swpspr); pos_x += swpspr->SWidth * fs_units_per_px / 16; swpspr++; } pos_y += spr->SHeight * fs_units_per_px / 16; if (k < 3) k--; else k -= 3; } // Draw the high scores area - bottom pos_x = gbtn->scr_pos_x; spr = &frontend_sprite[47]; swpspr = spr; for (i=6; i > 0; i--) { LbSpriteDrawResized(pos_x, pos_y, fs_units_per_px, swpspr); pos_x += swpspr->SWidth * fs_units_per_px / 16; swpspr++; } LbTextSetFont(frontend_font[1]); lbDisplay.DrawFlags = 0; spr = &frontend_sprite[33]; pos_x = gbtn->scr_pos_x + spr->SWidth * fs_units_per_px / 16; spr = &frontend_sprite[25]; pos_y = gbtn->scr_pos_y + (spr->SHeight + 3) * fs_units_per_px / 16; int tx_units_per_px; // The GUI item height should be 11 lines of text tx_units_per_px = gbtn->height * 16 / (11*(LbTextLineHeight())); col1_width = LbTextStringWidth("99") * tx_units_per_px / 16; col2_width = LbTextStringWidth(" 99999") * tx_units_per_px / 16; col3_width = LbTextStringWidth(" 999") * tx_units_per_px / 16; col4_width = LbTextCharWidth('-') * tx_units_per_px / 16; for (k=0; k < VISIBLE_HIGH_SCORES_COUNT-1; k++) { draw_high_score_entry(k, pos_x, pos_y, col1_width, col2_width, col3_width, col4_width, tx_units_per_px); pos_y += LbTextLineHeight() * tx_units_per_px / 16; } if (high_score_entry_input_active > k) draw_high_score_entry(high_score_entry_input_active, pos_x, pos_y, col1_width, col2_width, col3_width, col4_width, tx_units_per_px); else draw_high_score_entry(k, pos_x, pos_y, col1_width, col2_width, col3_width, col4_width, tx_units_per_px); }
/** * Does high score table new entry input. * @return True if the entry input is active, false otherwise. */ TbBool frontend_high_score_table_input(void) { struct HighScore *hscore; char chr; long i; if (high_score_entry_input_active >= campaign.hiscore_count) high_score_entry_input_active = -1; if (high_score_entry_input_active < 0) return false; if (lbInkey == KC_BACK) { // Delete previous character if (high_score_entry_index > 0) { i = high_score_entry_index-1; while (high_score_entry[i] != '\0') { high_score_entry[i] = high_score_entry[i+1]; i++; } high_score_entry_index -= 1; } clear_key_pressed(KC_BACK); return true; } if (lbInkey == KC_DELETE) { // Delete next character i = high_score_entry_index; while (high_score_entry[i] != '\0') { high_score_entry[i] = high_score_entry[i+1]; i++; } clear_key_pressed(KC_DELETE); return true; } if (lbInkey == KC_LEFT) { // Move cursor left if (high_score_entry_index > 0) { high_score_entry_index--; } clear_key_pressed(KC_LEFT); return true; } if (lbInkey == KC_RIGHT) { // Move cursor right i = high_score_entry_index; if (high_score_entry[i] != '\0') { high_score_entry_index++; } clear_key_pressed(KC_RIGHT); return true; } if ((lbInkey == KC_HOME) || (lbInkey == KC_PGUP)) { // Move cursor to beginning. high_score_entry_index = 0; clear_key_pressed(lbInkey); } if ((lbInkey == KC_END) || (lbInkey == KC_PGDOWN)) { // Move cursor to end. while (high_score_entry[high_score_entry_index] != '\0') { high_score_entry_index++; } clear_key_pressed(lbInkey); } if ((lbInkey == KC_RETURN) || (lbInkey == KC_NUMPADENTER) || (lbInkey == KC_ESCAPE)) { hscore = &campaign.hiscore_table[high_score_entry_input_active]; if (lbInkey == KC_ESCAPE) { strncpy(hscore->name, get_string(GUIStr_TeamLeader), HISCORE_NAME_LENGTH); } else { strncpy(hscore->name, high_score_entry, HISCORE_NAME_LENGTH); } high_score_entry_input_active = -1; save_high_score_table(); clear_key_pressed(lbInkey); return true; } if (high_score_entry_index < HISCORE_NAME_LENGTH) { chr = key_to_ascii(lbInkey, key_modifiers); if (chr != 0) { int entry_len; entry_len = strlen(high_score_entry); LbTextSetFont(frontend_font[1]); i = LbTextCharWidth(chr); if ((entry_len < (HISCORE_NAME_LENGTH - 1)) && ((i > 0) && (i + LbTextStringWidth(high_score_entry) < 308))) { i = entry_len; high_score_entry[i+1] = '\0'; while (i > high_score_entry_index) { high_score_entry[i] = high_score_entry[i-1]; i--; } high_score_entry[i] = chr; high_score_entry_index = i + 1; clear_key_pressed(lbInkey); return true; } } } // No input, but return true to make sure other input functions are skipped return true; }