Changeset 985

Show
Ignore:
Timestamp:
07/12/08 02:11:37 (2 months ago)
Author:
shanoah
Message:

Break up some of the statusbar code in xtra3.c so that ports can easily grab the correct colors for hp, sp, & m. hp, and take advantage of this in the gtk port.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/gtk/main-gtk.c

    r984 r985  
    656656                 
    657657                /* Save the game */ 
    658                 #ifdef ZANGBAND 
    659                 do_cmd_save_game(FALSE); 
    660                 #else 
    661658                do_cmd_save_game(); 
    662                 #endif  
    663659        } 
    664660         
     
    24162412        FREE(race_count); 
    24172413} 
    2418 static byte monst_color(const monster_type *m_ptr) 
    2419 { 
    2420         byte attr = TERM_WHITE; 
    2421         int pct = 0; 
    2422  
    2423         if (m_ptr->maxhp) 
    2424                 pct = (m_ptr->hp * 100) / m_ptr->maxhp; 
    2425  
    2426  
    2427         /* Badly wounded */ 
    2428         if (pct >= 10) attr = TERM_L_RED; 
    2429  
    2430         /* Wounded */ 
    2431         if (pct >= 25) attr = TERM_ORANGE; 
    2432  
    2433         /* Somewhat Wounded */ 
    2434         if (pct >= 60) attr = TERM_YELLOW; 
    2435  
    2436         /* Healthy */ 
    2437         if (pct >= 100) attr = TERM_L_GREEN; 
    2438  
    2439  
    2440         /* Afraid */ 
    2441         if (m_ptr->monfear) attr = TERM_VIOLET; 
    2442  
    2443         /* Confused */ 
    2444         if (m_ptr->confused) attr = TERM_UMBER; 
    2445  
    2446         /* Stunned */ 
    2447         if (m_ptr->stunned) attr = TERM_L_BLUE; 
    2448  
    2449         /* Asleep */ 
    2450         if (m_ptr->csleep) attr = TERM_BLUE; 
    2451                  
    2452         return attr; 
    2453 } 
    24542414 
    24552415static void draw_xtra_cr_text(xtra_win_data *xd, int x, int y, byte color, cptr str) 
     
    25412501static void handle_sidebar(game_event_type type, game_event_data *data, void *user) 
    25422502{ 
    2543         char str[80], str2[80]; 
    2544         byte color; 
     2503        char str[80]/*, str2[80]*/; 
    25452504        cairo_rectangle_t r; 
    25462505         
     
    25482507        long xp = (long)p_ptr->exp; 
    25492508        monster_type *m_ptr = &mon_list[p_ptr->health_who]; 
    2550         int sidebar_length = 12; 
     2509        int i = 0, sidebar_length = 12; 
    25512510 
    25522511        /* Calculate XP for next level */ 
     
    25772536 
    25782537                /* Char Level */ 
    2579                 strnfmt(str, sizeof(str), "Level:");  
    2580                 strnfmt(str2, sizeof(str2), "%i", p_ptr->lev); 
    2581                 cr_aligned_text_print(xd, 0, 4, str, TERM_WHITE, str2, TERM_L_GREEN, sidebar_length); 
     2538                strnfmt(str, sizeof(str), "%i", p_ptr->lev); 
     2539                cr_aligned_text_print(xd, 0, 4, sidebar_text[4], TERM_WHITE, str, TERM_L_GREEN, sidebar_length); 
    25822540                 
    25832541                /* Char xp */ 
    25842542                if (p_ptr->lev != 50)  
    2585                         strnfmt(str, sizeof(str), "Next: "); 
     2543                        strnfmt(sidebar_text[5], sizeof(str), "Next: "); 
    25862544                else                      
    2587                         strnfmt(str, sizeof(str), "XP: ");  
    2588                 strnfmt(str2, sizeof(str2), "%ld", xp);  
    2589                 cr_aligned_text_print(xd, 0, 5, str, TERM_WHITE, str2, TERM_L_GREEN, sidebar_length); 
     2545                        strnfmt(sidebar_text[5], sizeof(str), "XP: ");  
     2546                strnfmt(str, sizeof(str), "%ld", xp);  
     2547                cr_aligned_text_print(xd, 0, 5, sidebar_text[5], TERM_WHITE, str, TERM_L_GREEN, sidebar_length); 
    25902548         
    25912549                /* Char Gold */ 
    2592                 strnfmt(str, sizeof(str), "Gold:");  
    2593                 strnfmt(str2, sizeof(str2), "%ld", p_ptr->au);  
    2594                 cr_aligned_text_print(xd, 0, 6, str, TERM_WHITE, str2, TERM_L_GREEN, sidebar_length); 
     2550                strnfmt(str, sizeof(str), "%ld", p_ptr->au);  
     2551                cr_aligned_text_print(xd, 0, 6, sidebar_text[6], TERM_WHITE, str, TERM_L_GREEN, sidebar_length); 
    25952552                 
    25962553                /* Equippy chars is 0,7 */ 
     
    25982555                 
    25992556                /* Char Stats */ 
    2600                 strnfmt(str, sizeof(str), "STR:");  
    2601                 cnv_stat(p_ptr->stat_use[A_STR], str2, sizeof(str2)); 
    2602                 cr_aligned_text_print(xd, 0, 8, str, TERM_WHITE, str2, TERM_L_GREEN, sidebar_length); 
    2603          
    2604                 strnfmt(str, sizeof(str), "INT:");  
    2605                 cnv_stat(p_ptr->stat_use[A_INT], str2, sizeof(str2)); 
    2606                 cr_aligned_text_print(xd, 0, 9, str, TERM_WHITE, str2, TERM_L_GREEN, sidebar_length); 
    2607          
    2608                 strnfmt(str, sizeof(str), "WIS:");  
    2609                 cnv_stat(p_ptr->stat_use[A_WIS], str2, sizeof(str2)); 
    2610                 cr_aligned_text_print(xd, 0, 10, str, TERM_WHITE, str2, TERM_L_GREEN, sidebar_length); 
    2611          
    2612                 strnfmt(str, sizeof(str), "DEX:");  
    2613                 cnv_stat(p_ptr->stat_use[A_DEX], str2, sizeof(str2)); 
    2614                 cr_aligned_text_print(xd, 0, 11, str, TERM_WHITE, str2, TERM_L_GREEN, sidebar_length); 
    2615          
    2616                 strnfmt(str, sizeof(str), "CON:");  
    2617                 cnv_stat(p_ptr->stat_use[A_CON], str2, sizeof(str2)); 
    2618                 cr_aligned_text_print(xd, 0, 12, str, TERM_WHITE, str2, TERM_L_GREEN, sidebar_length); 
    2619          
    2620                 strnfmt(str, sizeof(str), "CHR:");  
    2621                 cnv_stat(p_ptr->stat_use[A_CHR], str2, sizeof(str2)); 
    2622                 cr_aligned_text_print(xd, 0, 13, str, TERM_WHITE, str2, TERM_L_GREEN, sidebar_length); 
     2557                for (i = A_STR; i <= A_CHR; i++) 
     2558                { 
     2559                        cnv_stat(p_ptr->stat_use[i], str, sizeof(str)); 
     2560                        cr_aligned_text_print(xd, 0, i+8, sidebar_text[i+8], TERM_WHITE, str, TERM_L_GREEN, sidebar_length); 
     2561                } 
    26232562                 
    26242563                /* 14 is a blank row */ 
    26252564                 
    26262565                /* Char AC */ 
    2627                 strnfmt(str, sizeof(str), "AC:");  
    2628                 strnfmt(str2, sizeof(str2), "%i", p_ptr->dis_ac + p_ptr->dis_to_a);  
    2629                 cr_aligned_text_print(xd, 0, 15, str, TERM_WHITE, str2, TERM_L_GREEN, sidebar_length); 
     2566                strnfmt(str, sizeof(str), "%i", p_ptr->dis_ac + p_ptr->dis_to_a);  
     2567                cr_aligned_text_print(xd, 0, 15, sidebar_text[15], TERM_WHITE, str, TERM_L_GREEN, sidebar_length); 
    26302568         
    26312569                /* Char HP */ 
    2632                 strnfmt(str, sizeof(str), "HP:");  
    2633                 strnfmt(str2, sizeof(str2), "%4d/%4d", p_ptr->chp, p_ptr->mhp);  
    2634                 if (p_ptr->chp >= p_ptr->mhp) 
    2635                         color = TERM_L_GREEN; 
    2636                 else if (p_ptr->chp > (p_ptr->mhp * op_ptr->hitpoint_warn) / 10) 
    2637                         color = TERM_YELLOW; 
    2638                 else 
    2639                         color = TERM_RED; 
    2640  
    2641                 cr_aligned_text_print(xd, 0, 16, str, TERM_WHITE, str2, color, sidebar_length); 
    2642                 xtra_drawn_progress_bar(xd, 0, 17, p_ptr->chp, p_ptr->mhp, color, 13); 
     2570                strnfmt(str, sizeof(str), "%4d/%4d", p_ptr->chp, p_ptr->mhp);  
     2571                cr_aligned_text_print(xd, 0, 16, sidebar_text[16], TERM_WHITE, str, player_hp_attr(), sidebar_length); 
     2572                xtra_drawn_progress_bar(xd, 0, 17, p_ptr->chp, p_ptr->mhp, player_hp_attr(), 13); 
    26432573         
    26442574                /* Char MP */ 
    2645                 strnfmt(str, sizeof(str), "SP:");  
    2646                 strnfmt(str2, sizeof(str2), "%4d/%4d", p_ptr->csp, p_ptr->msp);  
    2647                 if (p_ptr->csp >= p_ptr->msp) 
    2648                         color = TERM_L_GREEN; 
    2649                 else if (p_ptr->csp > (p_ptr->msp * op_ptr->hitpoint_warn) / 10) 
    2650                         color = TERM_YELLOW; 
    2651                 else 
    2652                         color = TERM_RED; 
    2653                 cr_aligned_text_print(xd, 0, 18, str, TERM_WHITE, str2, color, sidebar_length); 
    2654                  
    2655                 xtra_drawn_progress_bar(xd, 0, 19, p_ptr->csp, p_ptr->msp, color, 13); 
     2575                strnfmt(str, sizeof(str), "%4d/%4d", p_ptr->csp, p_ptr->msp);  
     2576                cr_aligned_text_print(xd, 0, 18,sidebar_text[18], TERM_WHITE, str, player_sp_attr(), sidebar_length); 
     2577                xtra_drawn_progress_bar(xd, 0, 19, p_ptr->csp, p_ptr->msp, player_sp_attr(), 13); 
    26562578         
    26572579                /* 20 is blank */ 
    26582580         
    2659                 xtra_drawn_progress_bar(xd, 0, 21, m_ptr->hp, m_ptr->maxhp, monst_color(m_ptr), 13); 
     2581                xtra_drawn_progress_bar(xd, 0, 21, m_ptr->hp, m_ptr->maxhp, monster_health_attr(), 13); 
    26602582 
    26612583                /* Print the level */ 
    26622584                strnfmt(str, sizeof(str), "%d' (L%d)", p_ptr->depth * 50, p_ptr->depth);  
    2663                 strnfmt(str2, sizeof(str2), "%-*s", sidebar_length, str); 
    2664                 draw_xtra_cr_text(xd, 0, 22, TERM_WHITE, str2); 
     2585                strnfmt(sidebar_text[22], sizeof(sidebar_text[22]), "%-*s", sidebar_length, str); 
     2586                draw_xtra_cr_text(xd, 0, 22, TERM_WHITE, sidebar_text[22]); 
    26652587                 
    26662588                invalidate_drawing_area(xd->drawing_area, r); 
  • trunk/src/gtk/main-gtk.h

    r984 r985  
    126126char xtra_font_button_names[MAX_XTRA_WIN_DATA][20] = 
    127127{ "message_font", "inv_font", "equip_font", "monst_list_font", "debug_font", "status_font" }; 
     128 
     129char sidebar_text[24][20] = 
     130{ 
     131        "","","","","Level:", "XP: ", "Gold:", "", "STR:", "INT:", "WIS:", "DEX:", "CON:", "CHR:", "", "AC:", "HP:", "", "SP:", "", "","", "", ""  
     132}; 
    128133/* 
    129134 * An array of "term_data" structures, one for each "sub-window" 
     
    400405static void handle_mons_list(game_event_type type, game_event_data *data, void *user); 
    401406 
    402 /* Return the color of the monster bar */ 
    403 static byte monst_color(const monster_type *m_ptr); 
    404  
    405407/* Print the sidebar */ 
    406408static void handle_sidebar(game_event_type type, game_event_data *data, void *user); 
     
    429431 
    430432static void force_redraw(); 
     433 
     434/* From xtra3.h */ 
     435extern byte monster_health_attr(); 
     436extern byte player_sp_attr(); 
     437extern byte player_hp_attr(); 
    431438#endif /* INCLUDED_MAIN_GTK_H */  
  • trunk/src/xtra3.c

    r979 r985  
    275275} 
    276276 
     277/* 
     278 * Calculate the hp color separately, for ports. 
     279 */ 
     280byte player_hp_attr() 
     281{ 
     282        byte attr; 
     283         
     284        if (p_ptr->chp >= p_ptr->mhp) 
     285                attr = TERM_L_GREEN; 
     286        else if (p_ptr->chp > (p_ptr->mhp * op_ptr->hitpoint_warn) / 10) 
     287                attr = TERM_YELLOW; 
     288        else 
     289                attr = TERM_RED; 
     290         
     291        return attr; 
     292} 
    277293 
    278294/* 
     
    282298{ 
    283299        char cur_hp[32], max_hp[32]; 
    284         byte color
     300        byte color = player_hp_attr()
    285301 
    286302        put_str("HP ", row, col); 
     
    288304        strnfmt(max_hp, sizeof(max_hp), "%4d", p_ptr->mhp); 
    289305        strnfmt(cur_hp, sizeof(cur_hp), "%4d", p_ptr->chp); 
    290  
    291         if (p_ptr->chp >= p_ptr->mhp) 
    292                 color = TERM_L_GREEN; 
    293         else if (p_ptr->chp > (p_ptr->mhp * op_ptr->hitpoint_warn) / 10) 
    294                 color = TERM_YELLOW; 
    295         else 
    296                 color = TERM_RED; 
    297  
     306         
    298307        c_put_str(color, cur_hp, row, col + 3); 
    299308        c_put_str(TERM_WHITE, "/", row, col + 7); 
     
    301310} 
    302311 
     312/* 
     313 * Calculate the sp color separately, for ports. 
     314 */ 
     315byte player_sp_attr() 
     316{ 
     317        byte attr; 
     318         
     319        if (p_ptr->csp >= p_ptr->msp) 
     320                attr = TERM_L_GREEN; 
     321        else if (p_ptr->csp > (p_ptr->msp * op_ptr->hitpoint_warn) / 10) 
     322                attr = TERM_YELLOW; 
     323        else 
     324                attr = TERM_RED; 
     325         
     326        return attr; 
     327} 
    303328 
    304329/* 
     
    308333{ 
    309334        char cur_sp[32], max_sp[32]; 
    310         byte color
     335        byte color = player_sp_attr()
    311336 
    312337        /* Do not show mana unless it matters */ 
     
    317342        strnfmt(max_sp, sizeof(max_sp), "%4d", p_ptr->msp); 
    318343        strnfmt(cur_sp, sizeof(cur_sp), "%4d", p_ptr->csp); 
    319  
    320         if (p_ptr->csp >= p_ptr->msp) 
    321                 color = TERM_L_GREEN; 
    322         else if (p_ptr->csp > (p_ptr->msp * op_ptr->hitpoint_warn) / 10) 
    323                 color = TERM_YELLOW; 
    324         else 
    325                 color = TERM_RED; 
    326344 
    327345        /* Show mana */ 
     
    331349} 
    332350 
     351/* 
     352 * Calculate the monster bar color separately, for ports. 
     353 */ 
     354byte monster_health_attr() 
     355{ 
     356        byte attr = TERM_WHITE; 
     357         
     358        /* Not tracking */ 
     359        if (!p_ptr->health_who) 
     360                attr = TERM_DARK; 
     361         
     362        /* Tracking an unseen, hallucinatory, or dead monster */ 
     363        else if ((!mon_list[p_ptr->health_who].ml) || 
     364                    (p_ptr->timed[TMD_IMAGE]) || 
     365                    (!mon_list[p_ptr->health_who].hp < 0)) 
     366        { 
     367                /* The monster health is "unknown" */ 
     368                attr = TERM_WHITE; 
     369        } 
     370         
     371        else 
     372        { 
     373                int pct; 
     374 
     375                monster_type *m_ptr = &mon_list[p_ptr->health_who]; 
     376 
     377                /* Default to almost dead */ 
     378                attr = TERM_RED; 
     379 
     380                /* Extract the "percent" of health */ 
     381                pct = 100L * m_ptr->hp / m_ptr->maxhp; 
     382 
     383                /* Badly wounded */ 
     384                if (pct >= 10) attr = TERM_L_RED; 
     385 
     386                /* Wounded */ 
     387                if (pct >= 25) attr = TERM_ORANGE; 
     388 
     389                /* Somewhat Wounded */ 
     390                if (pct >= 60) attr = TERM_YELLOW; 
     391 
     392                /* Healthy */ 
     393                if (pct >= 100) attr = TERM_L_GREEN; 
     394 
     395                /* Afraid */ 
     396                if (m_ptr->monfear) attr = TERM_VIOLET; 
     397 
     398                /* Confused */ 
     399                if (m_ptr->confused) attr = TERM_UMBER; 
     400 
     401                /* Stunned */ 
     402                if (m_ptr->stunned) attr = TERM_L_BLUE; 
     403 
     404                /* Asleep */ 
     405                if (m_ptr->csleep) attr = TERM_BLUE; 
     406        } 
     407         
     408        return attr; 
     409} 
    333410 
    334411/* 
     
    344421static void prt_health(int row, int col) 
    345422{ 
     423        byte attr = monster_health_attr(); 
     424         
    346425        /* Not tracking */ 
    347426        if (!p_ptr->health_who) 
     
    351430        } 
    352431 
    353         /* Tracking an unseen monster */ 
    354         else if (!mon_list[p_ptr->health_who].ml) 
    355         { 
    356                 /* Indicate that the monster health is "unknown" */ 
    357                 Term_putstr(col, row, 12, TERM_WHITE, "[----------]"); 
    358         } 
    359  
    360         /* Tracking a hallucinatory monster */ 
    361         else if (p_ptr->timed[TMD_IMAGE]) 
    362         { 
    363                 /* Indicate that the monster health is "unknown" */ 
    364                 Term_putstr(col, row, 12, TERM_WHITE, "[----------]"); 
    365         } 
    366  
    367         /* Tracking a dead monster (?) */ 
    368         else if (!mon_list[p_ptr->health_who].hp < 0) 
    369         { 
    370                 /* Indicate that the monster health is "unknown" */ 
    371                 Term_putstr(col, row, 12, TERM_WHITE, "[----------]"); 
     432        /* Tracking an unseen, hallucinatory, or dead monster */ 
     433        else if ((!mon_list[p_ptr->health_who].ml) || /* Unseen */ 
     434                    (p_ptr->timed[TMD_IMAGE]) || /* Hallucination */ 
     435                    (!mon_list[p_ptr->health_who].hp < 0)) /* Dead (?) */ 
     436        { 
     437                /* The monster health is "unknown" */ 
     438                Term_putstr(col, row, 12, attr, "[----------]"); 
    372439        } 
    373440 
     
    379446                monster_type *m_ptr = &mon_list[p_ptr->health_who]; 
    380447 
    381                 /* Default to almost dead */ 
    382                 byte attr = TERM_RED; 
    383  
    384448                /* Extract the "percent" of health */ 
    385449                pct = 100L * m_ptr->hp / m_ptr->maxhp; 
    386  
    387                 /* Badly wounded */ 
    388                 if (pct >= 10) attr = TERM_L_RED; 
    389  
    390                 /* Wounded */ 
    391                 if (pct >= 25) attr = TERM_ORANGE; 
    392  
    393                 /* Somewhat Wounded */ 
    394                 if (pct >= 60) attr = TERM_YELLOW; 
    395  
    396                 /* Healthy */ 
    397                 if (pct >= 100) attr = TERM_L_GREEN; 
    398  
    399                 /* Afraid */ 
    400                 if (m_ptr->monfear) attr = TERM_VIOLET; 
    401  
    402                 /* Confused */ 
    403                 if (m_ptr->confused) attr = TERM_UMBER; 
    404  
    405                 /* Stunned */ 
    406                 if (m_ptr->stunned) attr = TERM_L_BLUE; 
    407  
    408                 /* Asleep */ 
    409                 if (m_ptr->csleep) attr = TERM_BLUE; 
    410450 
    411451                /* Convert percent into "health" */