DRY item window text drawing
This commit is contained in:
@@ -233,34 +233,45 @@ void put_item_screen(eItemWinMode screen_num) {
|
|||||||
for(auto& flag : item_area_button_active[i])
|
for(auto& flag : item_area_button_active[i])
|
||||||
flag = false;
|
flag = false;
|
||||||
|
|
||||||
TextStyle style;
|
TextStyle title_style;
|
||||||
style.lineHeight = 10;
|
title_style.lineHeight = 10;
|
||||||
style.font = FONT_BOLD;
|
title_style.font = FONT_BOLD;
|
||||||
style.colour = Colours::YELLOW;
|
title_style.colour = Colours::YELLOW;
|
||||||
|
std::string title = "";
|
||||||
switch(screen_num) {
|
switch(screen_num) {
|
||||||
case ITEM_WIN_SPECIAL:
|
case ITEM_WIN_SPECIAL:
|
||||||
win_draw_string(item_stats_gworld(),upper_frame_rect,"Special items:",eTextMode::WRAP,style);
|
title = "Special items:";
|
||||||
break;
|
break;
|
||||||
case ITEM_WIN_QUESTS:
|
case ITEM_WIN_QUESTS:
|
||||||
win_draw_string(item_stats_gworld(),upper_frame_rect,"Quests/Jobs:",eTextMode::WRAP,style);
|
title = "Quests/Jobs:";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default: // on an items page
|
default: // on an items page
|
||||||
pc = screen_num;
|
pc = screen_num;
|
||||||
clear_sstr(sout);
|
clear_sstr(sout);
|
||||||
sout << univ.party[pc].name << " inventory:";
|
sout << univ.party[pc].name << " inventory:";
|
||||||
win_draw_string(item_stats_gworld(),upper_frame_rect,sout.str(),eTextMode::WRAP,style);
|
title = sout.str();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
win_draw_string(item_stats_gworld(),upper_frame_rect,title,eTextMode::WRAP,title_style);
|
||||||
|
|
||||||
|
TextStyle line_style;
|
||||||
|
auto draw_item_string = [&line_style](int i, std::string str, eFont font, sf::Color colour, bool italic = false, location offset = {0, 0}){
|
||||||
|
rectangle dest_rect = item_buttons[i][ITEMBTN_NAME];
|
||||||
|
dest_rect.offset(offset);
|
||||||
|
line_style.font = font;
|
||||||
|
line_style.colour = colour;
|
||||||
|
line_style.italic = italic;
|
||||||
|
win_draw_string(item_stats_gworld(), dest_rect, str, eTextMode::WRAP, line_style);
|
||||||
|
};
|
||||||
|
|
||||||
clip_rect(item_stats_gworld(), erase_rect);
|
clip_rect(item_stats_gworld(), erase_rect);
|
||||||
switch(screen_num) {
|
switch(screen_num) {
|
||||||
case ITEM_WIN_SPECIAL:
|
case ITEM_WIN_SPECIAL:
|
||||||
style.colour = Colours::BLACK;
|
|
||||||
for(short i = 0; i < LINES_IN_ITEM_WIN; i++) {
|
for(short i = 0; i < LINES_IN_ITEM_WIN; i++) {
|
||||||
i_num = i + item_offset;
|
i_num = i + item_offset;
|
||||||
if(i_num < spec_item_array.size()) {
|
if(i_num < spec_item_array.size()) {
|
||||||
win_draw_string(item_stats_gworld(),item_buttons[i][ITEMBTN_NAME],univ.scenario.special_items[spec_item_array[i_num]].name,eTextMode::WRAP,style);
|
draw_item_string(i, univ.scenario.special_items[spec_item_array[i_num]].name, FONT_BOLD, Colours::BLACK);
|
||||||
|
|
||||||
place_item_button(i,ITEMBTN_INFO);
|
place_item_button(i,ITEMBTN_INFO);
|
||||||
if((univ.scenario.special_items[spec_item_array[i_num]].flags % 10 == 1)
|
if((univ.scenario.special_items[spec_item_array[i_num]].flags % 10 == 1)
|
||||||
@@ -273,21 +284,21 @@ void put_item_screen(eItemWinMode screen_num) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ITEM_WIN_QUESTS:
|
case ITEM_WIN_QUESTS:
|
||||||
style.colour = Colours::BLACK;
|
|
||||||
for(short i = 0; i < LINES_IN_ITEM_WIN; i++) {
|
for(short i = 0; i < LINES_IN_ITEM_WIN; i++) {
|
||||||
|
sf::Color colour = Colours::BLACK;
|
||||||
i_num = i + item_offset;
|
i_num = i + item_offset;
|
||||||
if(i_num < spec_item_array.size()) {
|
if(i_num < spec_item_array.size()) {
|
||||||
int which_quest = spec_item_array[i_num] % 10000;
|
int which_quest = spec_item_array[i_num] % 10000;
|
||||||
if(spec_item_array[i_num] / 10000 == 2)
|
if(spec_item_array[i_num] / 10000 == 2)
|
||||||
style.colour = Colours::RED;
|
colour = Colours::RED;
|
||||||
|
|
||||||
win_draw_string(item_stats_gworld(),item_buttons[i][ITEMBTN_NAME],univ.scenario.quests[which_quest].name,eTextMode::WRAP,style);
|
draw_item_string(i, univ.scenario.quests[which_quest].name, FONT_BOLD, colour);
|
||||||
|
|
||||||
if(spec_item_array[i_num] / 10000 == 1) {
|
if(spec_item_array[i_num] / 10000 == 1) {
|
||||||
location from, to;
|
location from, to;
|
||||||
from = to = item_buttons[i][ITEMBTN_NAME].centre();
|
from = to = item_buttons[i][ITEMBTN_NAME].centre();
|
||||||
from.x = item_buttons[i][ITEMBTN_NAME].left;
|
from.x = item_buttons[i][ITEMBTN_NAME].left;
|
||||||
to.x = from.x + string_length(univ.scenario.quests[which_quest].name, style);
|
to.x = from.x + string_length(univ.scenario.quests[which_quest].name, line_style);
|
||||||
draw_line(item_stats_gworld(), from, to, 1, Colours::GREEN);
|
draw_line(item_stats_gworld(), from, to, 1, Colours::GREEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -296,32 +307,31 @@ void put_item_screen(eItemWinMode screen_num) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default: // on an items page
|
default: // on an items page
|
||||||
style.colour = Colours::BLACK;
|
|
||||||
|
|
||||||
for(short i = 0; i < LINES_IN_ITEM_WIN; i++) {
|
for(short i = 0; i < LINES_IN_ITEM_WIN; i++) {
|
||||||
i_num = i + item_offset;
|
i_num = i + item_offset;
|
||||||
clear_sstr(sout);
|
clear_sstr(sout);
|
||||||
sout << i_num + 1 << '.';
|
sout << i_num + 1 << '.';
|
||||||
win_draw_string(item_stats_gworld(),item_buttons[i][ITEMBTN_NAME],sout.str(),eTextMode::WRAP,style);
|
draw_item_string(i, sout.str(), FONT_PLAIN, Colours::BLACK);
|
||||||
|
|
||||||
dest_rect = item_buttons[i][ITEMBTN_NAME];
|
dest_rect = item_buttons[i][ITEMBTN_NAME];
|
||||||
dest_rect.left += 36;
|
dest_rect.left += 36;
|
||||||
dest_rect.top -= 2;
|
dest_rect.top -= 2;
|
||||||
|
|
||||||
const cPlayer& who = univ.party[pc];
|
const cPlayer& who = univ.party[pc];
|
||||||
const cItem& item = who.items[i_num];
|
const cItem& item = who.items[i_num];
|
||||||
|
|
||||||
|
bool italic = false;
|
||||||
|
sf::Color colour = Colours::BLACK;
|
||||||
if(item.variety != eItemType::NO_ITEM) {
|
if(item.variety != eItemType::NO_ITEM) {
|
||||||
style.font = FONT_PLAIN;
|
|
||||||
if(who.equip[i_num]) {
|
if(who.equip[i_num]) {
|
||||||
style.italic = true;
|
italic = true;
|
||||||
if(item.variety == eItemType::ONE_HANDED || item.variety == eItemType::TWO_HANDED)
|
if(item.variety == eItemType::ONE_HANDED || item.variety == eItemType::TWO_HANDED)
|
||||||
style.colour = Colours::PINK;
|
colour = Colours::PINK;
|
||||||
else if((*item.variety).is_armour)
|
else if((*item.variety).is_armour)
|
||||||
style.colour = Colours::GREEN;
|
colour = Colours::GREEN;
|
||||||
else style.colour = Colours::BLUE;
|
else colour = Colours::BLUE;
|
||||||
} else style.colour = Colours::BLACK;
|
}
|
||||||
|
|
||||||
clear_sstr(sout);
|
clear_sstr(sout);
|
||||||
|
|
||||||
@@ -344,9 +354,7 @@ void put_item_screen(eItemWinMode screen_num) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dest_rect.left -= 2;
|
dest_rect.left -= 2;
|
||||||
win_draw_string(item_stats_gworld(),dest_rect,sout.str(),eTextMode::WRAP,style);
|
draw_item_string(i, sout.str(), FONT_PLAIN, colour, italic, {34, -2});
|
||||||
style.italic = false;
|
|
||||||
style.colour = Colours::BLACK;
|
|
||||||
|
|
||||||
place_item_graphic(i,item.graphic_num);
|
place_item_graphic(i,item.graphic_num);
|
||||||
// The info button is harmless and can be useful while shopping, so always show it
|
// The info button is harmless and can be useful while shopping, so always show it
|
||||||
|
|||||||
Reference in New Issue
Block a user