(svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed

-CodeMotion: moved 'Company performancerating detail' to the end of the file; it fits there
replace/41b28d7194a279bdc17475d4fbe2ea6ec885a466
darkvater 20 years ago
parent 6e17ee9fe2
commit 7c28bafba9

@ -334,19 +334,19 @@ static void OperatingProfitWndProc(Window *w, WindowEvent *e)
SetupGraphDrawerForPlayers(&gd);
numd = -1;
numd = 0;
FOR_ALL_PLAYERS(p) {
numd++;
if (!p->is_active)
continue;
gd.colors[numd] = _color_list[p->player_color].window_color_bgb;
for(j=gd.num_on_x_axis,i=0; --j >= 0;) {
gd.cost[numd][i] = (j >= p->num_valid_stat_ent) ? INVALID_VALUE : (uint64)(p->old_economy[j].income + p->old_economy[j].expenses);
i++;
if (p->is_active) {
gd.colors[numd] = _color_list[p->player_color].window_color_bgb;
for(j=gd.num_on_x_axis,i=0; --j >= 0;) {
gd.cost[numd][i] = (j >= p->num_valid_stat_ent) ? INVALID_VALUE : (uint64)(p->old_economy[j].income + p->old_economy[j].expenses);
i++;
}
}
numd++;
}
gd.num_dataset = numd + 1;
gd.num_dataset = numd;
DrawGraph(&gd);
} break;
@ -407,19 +407,19 @@ static void IncomeGraphWndProc(Window *w, WindowEvent *e)
gd.bg_line_color = 0xE;
SetupGraphDrawerForPlayers(&gd);
numd = -1;
numd = 0;
FOR_ALL_PLAYERS(p) {
numd++;
if (!p->is_active)
continue;
gd.colors[numd] = _color_list[p->player_color].window_color_bgb;
for(j=gd.num_on_x_axis,i=0; --j >= 0;) {
gd.cost[numd][i] = (j >= p->num_valid_stat_ent) ? INVALID_VALUE : (uint64)p->old_economy[j].income;
i++;
if (p->is_active) {
gd.colors[numd] = _color_list[p->player_color].window_color_bgb;
for(j=gd.num_on_x_axis,i=0; --j >= 0;) {
gd.cost[numd][i] = (j >= p->num_valid_stat_ent) ? INVALID_VALUE : (uint64)p->old_economy[j].income;
i++;
}
}
numd++;
}
gd.num_dataset = numd + 1;
gd.num_dataset = numd;
DrawGraph(&gd);
break;
@ -480,19 +480,19 @@ static void DeliveredCargoGraphWndProc(Window *w, WindowEvent *e)
gd.bg_line_color = 0xE;
SetupGraphDrawerForPlayers(&gd);
numd = -1;
numd = 0;
FOR_ALL_PLAYERS(p) {
numd++;
if (!p->is_active)
continue;
gd.colors[numd] = _color_list[p->player_color].window_color_bgb;
for(j=gd.num_on_x_axis,i=0; --j >= 0;) {
gd.cost[numd][i] = (j >= p->num_valid_stat_ent) ? INVALID_VALUE : (uint64)p->old_economy[j].delivered_cargo;
i++;
if (p->is_active) {
gd.colors[numd] = _color_list[p->player_color].window_color_bgb;
for(j=gd.num_on_x_axis,i=0; --j >= 0;) {
gd.cost[numd][i] = (j >= p->num_valid_stat_ent) ? INVALID_VALUE : (uint64)p->old_economy[j].delivered_cargo;
i++;
}
}
numd++;
}
gd.num_dataset = numd + 1;
gd.num_dataset = numd;
DrawGraph(&gd);
break;
@ -528,226 +528,6 @@ void ShowDeliveredCargoGraph()
}
}
/*****************************/
/* PERFORMANCE RATING DETAIL */
/*****************************/
static void PerformanceRatingDetailWndProc(Window *w, WindowEvent *e)
{
switch(e->event) {
case WE_PAINT: {
int val, needed, score, i;
byte owner, x;
uint16 y=14;
int total_score = 0;
int color_done, color_notdone;
// Draw standard stuff
DrawWindowWidgets(w);
// The player of which we check the detail performance rating
owner = FindFirstBit(w->click_state) - 13;
// Paint the player icons
for (i=0;i<MAX_PLAYERS;i++) {
if (!DEREF_PLAYER(i)->is_active) {
// Check if we have the player as an active player
if (!(w->disabled_state & (1 << (i+13)))) {
// Bah, player gone :(
w->disabled_state += 1 << (i+13);
// Is this player selected? If so, select first player (always save? :s)
if (w->click_state == 1U << (i + 13))
w->click_state = 1 << 13;
// We need a repaint
SetWindowDirty(w);
}
continue;
}
// Check if we have the player marked as inactive
if ((w->disabled_state & (1 << (i+13)))) {
// New player! Yippie :p
w->disabled_state -= 1 << (i+13);
// We need a repaint
SetWindowDirty(w);
}
if (i == owner) x = 1; else x = 0;
DrawPlayerIcon(i, i * 37 + 13 + x, 16 + x);
}
// The colors used to show how the progress is going
color_done = _color_list[6].window_color_1b;
color_notdone = _color_list[4].window_color_1b;
// Draw all the score parts
for (i=0;i<NUM_SCORE;i++) {
y += 20;
val = _score_part[owner][i];
needed = score_info[i].needed;
score = score_info[i].score;
// SCORE_TOTAL has his own rulez ;)
if (i == SCORE_TOTAL) {
needed = total_score;
score = SCORE_MAX;
} else
total_score += score;
DrawString(7, y, STR_PERFORMANCE_DETAIL_VEHICLES + i, 0);
// Draw the score
SetDParam(0, score);
DrawStringRightAligned(107, y, SET_PERFORMANCE_DETAIL_INT, 0);
// Calculate the %-bar
if (val > needed) x = 50;
else if (val == 0) x = 0;
else x = ((val * 50) / needed);
// SCORE_LOAN is inversed
if (val < 0 && i == SCORE_LOAN)
x = 0;
// Draw the bar
if (x != 0)
GfxFillRect(112, y-2, x + 112, y+10, color_done);
if (x != 50)
GfxFillRect(x + 112, y-2, 50 + 112, y+10, color_notdone);
// Calculate the %
if (val > needed) x = 100;
else x = ((val * 100) / needed);
// SCORE_LOAN is inversed
if (val < 0 && i == SCORE_LOAN)
x = 0;
// Draw it
SetDParam(0, x);
DrawStringCentered(137, y, STR_PERFORMANCE_DETAIL_PERCENT, 0);
// SCORE_LOAN is inversed
if (i == SCORE_LOAN)
val = needed - val;
// Draw the amount we have against what is needed
// For some of them it is in currency format
SetDParam(0, val);
SetDParam(1, needed);
switch (i) {
case SCORE_MIN_PROFIT:
case SCORE_MIN_INCOME:
case SCORE_MAX_INCOME:
case SCORE_MONEY:
case SCORE_LOAN:
DrawString(167, y, STR_PERFORMANCE_DETAIL_AMOUNT_CURRENCY, 0);
break;
default:
DrawString(167, y, STR_PERFORMANCE_DETAIL_AMOUNT_INT, 0);
}
}
break;
}
case WE_CLICK:
// Check which button is clicked
if (IS_INT_INSIDE(e->click.widget, 13, 21)) {
// Is it no on disable?
if ((w->disabled_state & (1 << e->click.widget)) == 0) {
w->click_state = 1 << e->click.widget;
SetWindowDirty(w);
}
}
break;
case WE_CREATE:
{
int i;
Player *p2;
w->hidden_state = 0;
w->disabled_state = 0;
// Hide the player who are not active
for (i=0;i<MAX_PLAYERS;i++) {
if (!DEREF_PLAYER(i)->is_active) {
w->disabled_state += 1 << (i+13);
}
}
// Update all player stats with the current data
// (this is because _score_info is not saved to a savegame)
FOR_ALL_PLAYERS(p2)
if (p2->is_active)
UpdateCompanyRatingAndValue(p2, false);
w->custom[0] = DAY_TICKS;
w->custom[1] = 5;
w->click_state = 1 << 13;
SetWindowDirty(w);
}
break;
case WE_TICK:
{
// Update the player score every 5 days
if (--w->custom[0] == 0) {
w->custom[0] = DAY_TICKS;
if (--w->custom[1] == 0) {
Player *p2;
w->custom[1] = 5;
FOR_ALL_PLAYERS(p2)
// Skip if player is not active
if (p2->is_active)
UpdateCompanyRatingAndValue(p2, false);
SetWindowDirty(w);
}
}
}
break;
}
}
static const Widget _performance_rating_detail_widgets[] = {
{ WWT_TEXTBTN, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_CAPTION, RESIZE_NONE, 14, 11, 298, 0, 13, STR_PERFORMANCE_DETAIL, STR_018C_WINDOW_TITLE_DRAG_THIS},
{ WWT_IMGBTN, RESIZE_NONE, 14, 0, 298, 14, 27, 0x0, STR_NULL},
{ WWT_IMGBTN, RESIZE_NONE, 14, 0, 298, 28, 47, 0x0,STR_PERFORMANCE_DETAIL_VEHICLES_TIP},
{ WWT_IMGBTN, RESIZE_NONE, 14, 0, 298, 48, 67, 0x0,STR_PERFORMANCE_DETAIL_STATIONS_TIP},
{ WWT_IMGBTN, RESIZE_NONE, 14, 0, 298, 68, 87, 0x0,STR_PERFORMANCE_DETAIL_MIN_PROFIT_TIP},
{ WWT_IMGBTN, RESIZE_NONE, 14, 0, 298, 88, 107, 0x0,STR_PERFORMANCE_DETAIL_MIN_INCOME_TIP},
{ WWT_IMGBTN, RESIZE_NONE, 14, 0, 298, 108, 127, 0x0,STR_PERFORMANCE_DETAIL_MAX_INCOME_TIP},
{ WWT_IMGBTN, RESIZE_NONE, 14, 0, 298, 128, 147, 0x0,STR_PERFORMANCE_DETAIL_DELIVERED_TIP},
{ WWT_IMGBTN, RESIZE_NONE, 14, 0, 298, 148, 167, 0x0,STR_PERFORMANCE_DETAIL_CARGO_TIP},
{ WWT_IMGBTN, RESIZE_NONE, 14, 0, 298, 168, 187, 0x0,STR_PERFORMANCE_DETAIL_MONEY_TIP},
{ WWT_IMGBTN, RESIZE_NONE, 14, 0, 298, 188, 207, 0x0,STR_PERFORMANCE_DETAIL_LOAN_TIP},
{ WWT_IMGBTN, RESIZE_NONE, 14, 0, 298, 208, 227, 0x0,STR_PERFORMANCE_DETAIL_TOTAL_TIP},
{ WWT_IMGBTN, RESIZE_NONE, 14, 2, 38, 14, 26, 0x0,STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY},
{ WWT_IMGBTN, RESIZE_NONE, 14, 39, 75, 14, 26, 0x0,STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY},
{ WWT_IMGBTN, RESIZE_NONE, 14, 76, 112, 14, 26, 0x0,STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY},
{ WWT_IMGBTN, RESIZE_NONE, 14, 113, 149, 14, 26, 0x0,STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY},
{ WWT_IMGBTN, RESIZE_NONE, 14, 150, 186, 14, 26, 0x0,STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY},
{ WWT_IMGBTN, RESIZE_NONE, 14, 187, 223, 14, 26, 0x0,STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY},
{ WWT_IMGBTN, RESIZE_NONE, 14, 224, 260, 14, 26, 0x0,STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY},
{ WWT_IMGBTN, RESIZE_NONE, 14, 261, 297, 14, 26, 0x0,STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY},
{ WIDGETS_END},
};
static const WindowDesc _performance_rating_detail_desc = {
-1, -1, 299, 228,
WC_PERFORMANCE_DETAIL,0,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
_performance_rating_detail_widgets,
PerformanceRatingDetailWndProc
};
void ShowPerformanceRatingDetail()
{
AllocateWindowDescFront(&_performance_rating_detail_desc, 0);
}
/***********************/
/* PERFORMANCE HISTORY */
/***********************/
@ -773,19 +553,19 @@ static void PerformanceHistoryWndProc(Window *w, WindowEvent *e)
gd.bg_line_color = 0xE;
SetupGraphDrawerForPlayers(&gd);
numd = -1;
numd = 0;
FOR_ALL_PLAYERS(p) {
numd++;
if (!p->is_active)
continue;
gd.colors[numd] = _color_list[p->player_color].window_color_bgb;
for(j=gd.num_on_x_axis,i=0; --j >= 0;) {
gd.cost[numd][i] = (j >= p->num_valid_stat_ent) ? INVALID_VALUE : (uint64)p->old_economy[j].performance_history;
i++;
if (p->is_active) {
gd.colors[numd] = _color_list[p->player_color].window_color_bgb;
for(j=gd.num_on_x_axis,i=0; --j >= 0;) {
gd.cost[numd][i] = (j >= p->num_valid_stat_ent) ? INVALID_VALUE : (uint64)p->old_economy[j].performance_history;
i++;
}
}
numd++;
}
gd.num_dataset = numd + 1;
gd.num_dataset = numd;
DrawGraph(&gd);
break;
@ -849,20 +629,19 @@ static void CompanyValueGraphWndProc(Window *w, WindowEvent *e)
gd.bg_line_color = 0xE;
SetupGraphDrawerForPlayers(&gd);
numd = -1;
numd = 0;
FOR_ALL_PLAYERS(p) {
numd++;
if (!p->is_active)
continue;
gd.colors[numd] = _color_list[p->player_color].window_color_bgb;
for(j=gd.num_on_x_axis,i=0; --j >= 0;) {
gd.cost[numd][i] = (j >= p->num_valid_stat_ent) ? INVALID_VALUE : (uint64)p->old_economy[j].company_value;
i++;
if (p->is_active) {
gd.colors[numd] = _color_list[p->player_color].window_color_bgb;
for(j=gd.num_on_x_axis,i=0; --j >= 0;) {
gd.cost[numd][i] = (j >= p->num_valid_stat_ent) ? INVALID_VALUE : (uint64)p->old_economy[j].company_value;
i++;
}
}
numd++;
}
gd.num_dataset = numd + 1;
gd.num_dataset = numd;
DrawGraph(&gd);
break;
@ -934,7 +713,7 @@ static void CargoPaymentRatesWndProc(Window *w, WindowEvent *e)
gd.color_3 = 16;
gd.color_2 = 215;
gd.bg_line_color = 14;
gd.num_dataset = 12;
gd.num_dataset = NUM_CARGO;
gd.num_on_x_axis = 20;
gd.num_vert_lines = 20;
gd.month = 0xFF;
@ -1099,3 +878,223 @@ void ShowCompanyLeagueTable()
{
AllocateWindowDescFront(&_company_league_desc,0);
}
/*****************************/
/* PERFORMANCE RATING DETAIL */
/*****************************/
static void PerformanceRatingDetailWndProc(Window *w, WindowEvent *e)
{
switch(e->event) {
case WE_PAINT: {
int val, needed, score, i;
byte owner, x;
uint16 y=14;
int total_score = 0;
int color_done, color_notdone;
// Draw standard stuff
DrawWindowWidgets(w);
// The player of which we check the detail performance rating
owner = FindFirstBit(w->click_state) - 13;
// Paint the player icons
for (i=0;i<MAX_PLAYERS;i++) {
if (!DEREF_PLAYER(i)->is_active) {
// Check if we have the player as an active player
if (!(w->disabled_state & (1 << (i+13)))) {
// Bah, player gone :(
w->disabled_state += 1 << (i+13);
// Is this player selected? If so, select first player (always save? :s)
if (w->click_state == 1U << (i + 13))
w->click_state = 1 << 13;
// We need a repaint
SetWindowDirty(w);
}
continue;
}
// Check if we have the player marked as inactive
if ((w->disabled_state & (1 << (i+13)))) {
// New player! Yippie :p
w->disabled_state -= 1 << (i+13);
// We need a repaint
SetWindowDirty(w);
}
if (i == owner) x = 1; else x = 0;
DrawPlayerIcon(i, i * 37 + 13 + x, 16 + x);
}
// The colors used to show how the progress is going
color_done = _color_list[6].window_color_1b;
color_notdone = _color_list[4].window_color_1b;
// Draw all the score parts
for (i=0;i<NUM_SCORE;i++) {
y += 20;
val = _score_part[owner][i];
needed = score_info[i].needed;
score = score_info[i].score;
// SCORE_TOTAL has his own rulez ;)
if (i == SCORE_TOTAL) {
needed = total_score;
score = SCORE_MAX;
} else
total_score += score;
DrawString(7, y, STR_PERFORMANCE_DETAIL_VEHICLES + i, 0);
// Draw the score
SetDParam(0, score);
DrawStringRightAligned(107, y, SET_PERFORMANCE_DETAIL_INT, 0);
// Calculate the %-bar
if (val > needed) x = 50;
else if (val == 0) x = 0;
else x = ((val * 50) / needed);
// SCORE_LOAN is inversed
if (val < 0 && i == SCORE_LOAN)
x = 0;
// Draw the bar
if (x != 0)
GfxFillRect(112, y-2, x + 112, y+10, color_done);
if (x != 50)
GfxFillRect(x + 112, y-2, 50 + 112, y+10, color_notdone);
// Calculate the %
if (val > needed) x = 100;
else x = ((val * 100) / needed);
// SCORE_LOAN is inversed
if (val < 0 && i == SCORE_LOAN)
x = 0;
// Draw it
SetDParam(0, x);
DrawStringCentered(137, y, STR_PERFORMANCE_DETAIL_PERCENT, 0);
// SCORE_LOAN is inversed
if (i == SCORE_LOAN)
val = needed - val;
// Draw the amount we have against what is needed
// For some of them it is in currency format
SetDParam(0, val);
SetDParam(1, needed);
switch (i) {
case SCORE_MIN_PROFIT:
case SCORE_MIN_INCOME:
case SCORE_MAX_INCOME:
case SCORE_MONEY:
case SCORE_LOAN:
DrawString(167, y, STR_PERFORMANCE_DETAIL_AMOUNT_CURRENCY, 0);
break;
default:
DrawString(167, y, STR_PERFORMANCE_DETAIL_AMOUNT_INT, 0);
}
}
break;
}
case WE_CLICK:
// Check which button is clicked
if (IS_INT_INSIDE(e->click.widget, 13, 21)) {
// Is it no on disable?
if ((w->disabled_state & (1 << e->click.widget)) == 0) {
w->click_state = 1 << e->click.widget;
SetWindowDirty(w);
}
}
break;
case WE_CREATE:
{
int i;
Player *p2;
w->hidden_state = 0;
w->disabled_state = 0;
// Hide the player who are not active
for (i=0;i<MAX_PLAYERS;i++) {
if (!DEREF_PLAYER(i)->is_active) {
w->disabled_state += 1 << (i+13);
}
}
// Update all player stats with the current data
// (this is because _score_info is not saved to a savegame)
FOR_ALL_PLAYERS(p2)
if (p2->is_active)
UpdateCompanyRatingAndValue(p2, false);
w->custom[0] = DAY_TICKS;
w->custom[1] = 5;
w->click_state = 1 << 13;
SetWindowDirty(w);
}
break;
case WE_TICK:
{
// Update the player score every 5 days
if (--w->custom[0] == 0) {
w->custom[0] = DAY_TICKS;
if (--w->custom[1] == 0) {
Player *p2;
w->custom[1] = 5;
FOR_ALL_PLAYERS(p2)
// Skip if player is not active
if (p2->is_active)
UpdateCompanyRatingAndValue(p2, false);
SetWindowDirty(w);
}
}
}
break;
}
}
static const Widget _performance_rating_detail_widgets[] = {
{ WWT_TEXTBTN, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_CAPTION, RESIZE_NONE, 14, 11, 298, 0, 13, STR_PERFORMANCE_DETAIL, STR_018C_WINDOW_TITLE_DRAG_THIS},
{ WWT_IMGBTN, RESIZE_NONE, 14, 0, 298, 14, 27, 0x0, STR_NULL},
{ WWT_IMGBTN, RESIZE_NONE, 14, 0, 298, 28, 47, 0x0,STR_PERFORMANCE_DETAIL_VEHICLES_TIP},
{ WWT_IMGBTN, RESIZE_NONE, 14, 0, 298, 48, 67, 0x0,STR_PERFORMANCE_DETAIL_STATIONS_TIP},
{ WWT_IMGBTN, RESIZE_NONE, 14, 0, 298, 68, 87, 0x0,STR_PERFORMANCE_DETAIL_MIN_PROFIT_TIP},
{ WWT_IMGBTN, RESIZE_NONE, 14, 0, 298, 88, 107, 0x0,STR_PERFORMANCE_DETAIL_MIN_INCOME_TIP},
{ WWT_IMGBTN, RESIZE_NONE, 14, 0, 298, 108, 127, 0x0,STR_PERFORMANCE_DETAIL_MAX_INCOME_TIP},
{ WWT_IMGBTN, RESIZE_NONE, 14, 0, 298, 128, 147, 0x0,STR_PERFORMANCE_DETAIL_DELIVERED_TIP},
{ WWT_IMGBTN, RESIZE_NONE, 14, 0, 298, 148, 167, 0x0,STR_PERFORMANCE_DETAIL_CARGO_TIP},
{ WWT_IMGBTN, RESIZE_NONE, 14, 0, 298, 168, 187, 0x0,STR_PERFORMANCE_DETAIL_MONEY_TIP},
{ WWT_IMGBTN, RESIZE_NONE, 14, 0, 298, 188, 207, 0x0,STR_PERFORMANCE_DETAIL_LOAN_TIP},
{ WWT_IMGBTN, RESIZE_NONE, 14, 0, 298, 208, 227, 0x0,STR_PERFORMANCE_DETAIL_TOTAL_TIP},
{ WWT_IMGBTN, RESIZE_NONE, 14, 2, 38, 14, 26, 0x0,STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY},
{ WWT_IMGBTN, RESIZE_NONE, 14, 39, 75, 14, 26, 0x0,STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY},
{ WWT_IMGBTN, RESIZE_NONE, 14, 76, 112, 14, 26, 0x0,STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY},
{ WWT_IMGBTN, RESIZE_NONE, 14, 113, 149, 14, 26, 0x0,STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY},
{ WWT_IMGBTN, RESIZE_NONE, 14, 150, 186, 14, 26, 0x0,STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY},
{ WWT_IMGBTN, RESIZE_NONE, 14, 187, 223, 14, 26, 0x0,STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY},
{ WWT_IMGBTN, RESIZE_NONE, 14, 224, 260, 14, 26, 0x0,STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY},
{ WWT_IMGBTN, RESIZE_NONE, 14, 261, 297, 14, 26, 0x0,STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY},
{ WIDGETS_END},
};
static const WindowDesc _performance_rating_detail_desc = {
-1, -1, 299, 228,
WC_PERFORMANCE_DETAIL,0,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
_performance_rating_detail_widgets,
PerformanceRatingDetailWndProc
};
void ShowPerformanceRatingDetail()
{
AllocateWindowDescFront(&_performance_rating_detail_desc, 0);
}

Loading…
Cancel
Save