|
|
/* $Id$ */
|
|
|
|
|
|
/** @file graph_gui.cpp */
|
|
|
|
|
|
#include "stdafx.h"
|
|
|
#include "openttd.h"
|
|
|
#include "table/strings.h"
|
|
|
#include "table/sprites.h"
|
|
|
#include "functions.h"
|
|
|
#include "window.h"
|
|
@@ -25,27 +27,27 @@ static uint _legend_excluded_cargo;
|
|
|
|
|
|
enum {
|
|
|
GRAPH_MAX_DATASETS = 16,
|
|
|
GRAPH_AXIS_LABEL_COLOUR = 16,
|
|
|
GRAPH_AXIS_LINE_COLOUR = 215,
|
|
|
|
|
|
GRAPH_X_POSITION_BEGINNING = 44, // Start the graph 44 pixels from gw->left
|
|
|
GRAPH_X_POSITION_SEPARATION = 22, // There are 22 pixels between each X value
|
|
|
GRAPH_X_POSITION_BEGINNING = 44, ///< Start the graph 44 pixels from gw->left
|
|
|
GRAPH_X_POSITION_SEPARATION = 22, ///< There are 22 pixels between each X value
|
|
|
|
|
|
/* How many horizontal lines to draw. 9 is convenient as that means the
|
|
|
* distance between them is the height of the graph / 8, which is the same
|
|
|
GRAPH_NUM_LINES_Y = 9, ///< How many horizontal lines to draw.
|
|
|
/* 9 is convenient as that means the distance between them is the height of the graph / 8,
|
|
|
* which is the same
|
|
|
* as height >> 3. */
|
|
|
GRAPH_NUM_LINES_Y = 9,
|
|
|
};
|
|
|
|
|
|
/* Apparently these don't play well with enums. */
|
|
|
static const int64 INVALID_DATAPOINT = INT64_MAX; // Value used for a datapoint that shouldn't be drawn.
|
|
|
static const uint INVALID_DATAPOINT_POS = UINT_MAX; // Used to determine if the previous point was drawn.
|
|
|
|
|
|
typedef struct GraphDrawer {
|
|
|
uint excluded_data; // bitmask of the datasets that shouldn't be displayed.
|
|
|
uint excluded_data; ///< bitmask of the datasets that shouldn't be displayed.
|
|
|
byte num_dataset;
|
|
|
byte num_on_x_axis;
|
|
|
bool has_negative_values;
|
|
|
byte num_vert_lines;
|
|
|
|
|
|
/* The starting month and year that values are plotted against. If month is
|
|
@@ -55,24 +57,24 @@ typedef struct GraphDrawer {
|
|
|
|
|
|
/* These values are used if the graph is being plotted against values
|
|
|
* rather than the dates specified by month and year. */
|
|
|
uint16 x_values_start;
|
|
|
uint16 x_values_increment;
|
|
|
|
|
|
int left, top; // Where to start drawing the graph, in pixels.
|
|
|
uint height; // The height of the graph in pixels.
|
|
|
int left, top; ///< Where to start drawing the graph, in pixels.
|
|
|
uint height; ///< The height of the graph in pixels.
|
|
|
StringID format_str_y_axis;
|
|
|
byte colors[GRAPH_MAX_DATASETS];
|
|
|
int64 cost[GRAPH_MAX_DATASETS][24]; // last 2 years
|
|
|
int64 cost[GRAPH_MAX_DATASETS][24]; ///< last 2 years
|
|
|
} GraphDrawer;
|
|
|
|
|
|
static void DrawGraph(const GraphDrawer *gw)
|
|
|
{
|
|
|
uint x, y; // Reused whenever x and y coordinates are needed.
|
|
|
int64 highest_value; // Highest value to be drawn.
|
|
|
int x_axis_offset; // Distance from the top of the graph to the x axis.
|
|
|
uint x, y; ///< Reused whenever x and y coordinates are needed.
|
|
|
int64 highest_value; ///< Highest value to be drawn.
|
|
|
int x_axis_offset; ///< Distance from the top of the graph to the x axis.
|
|
|
|
|
|
/* the colors and cost array of GraphDrawer must accomodate
|
|
|
* both values for cargo and players. So if any are higher, quit */
|
|
|
assert(GRAPH_MAX_DATASETS >= (int)NUM_CARGO && GRAPH_MAX_DATASETS >= (int)MAX_PLAYERS);
|
|
|
assert(gw->num_vert_lines > 0);
|
|
|
|
|
@@ -327,13 +329,13 @@ static void SetupGraphDrawerForPlayers(G
|
|
|
{
|
|
|
const Player* p;
|
|
|
uint excluded_players = _legend_excluded_players;
|
|
|
byte nums;
|
|
|
int mo,yr;
|
|
|
|
|
|
// Exclude the players which aren't valid
|
|
|
/* Exclude the players which aren't valid */
|
|
|
FOR_ALL_PLAYERS(p) {
|
|
|
if (!p->is_active) SETBIT(excluded_players, p->index);
|
|
|
}
|
|
|
gd->excluded_data = excluded_players;
|
|
|
gd->num_vert_lines = 24;
|
|
|
|
|
@@ -917,13 +919,13 @@ static void PerformanceRatingDetailWndPr
|
|
|
case WE_PAINT: {
|
|
|
byte x;
|
|
|
uint16 y = 14;
|
|
|
int total_score = 0;
|
|
|
int color_done, color_notdone;
|
|
|
|
|
|
// Draw standard stuff
|
|
|
/* Draw standard stuff */
|
|
|
DrawWindowWidgets(w);
|
|
|
|
|
|
/* Check if the currently selected player is still active. */
|
|
|
if (_performance_rating_detail_player == INVALID_PLAYER || !GetPlayer(_performance_rating_detail_player)->is_active) {
|
|
|
if (_performance_rating_detail_player != INVALID_PLAYER) {
|
|
|
/* Raise and disable the widget for the previous selection. */
|
|
@@ -946,94 +948,94 @@ static void PerformanceRatingDetailWndPr
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/* If there are no active players, don't display anything else. */
|
|
|
if (_performance_rating_detail_player == INVALID_PLAYER) break;
|
|
|
|
|
|
// Paint the player icons
|
|
|
/* Paint the player icons */
|
|
|
for (PlayerID i = PLAYER_FIRST; i < MAX_PLAYERS; i++) {
|
|
|
if (!GetPlayer(i)->is_active) {
|
|
|
// Check if we have the player as an active player
|
|
|
/* Check if we have the player as an active player */
|
|
|
if (!IsWindowWidgetDisabled(w, i + 13)) {
|
|
|
// Bah, player gone :(
|
|
|
/* Bah, player gone :( */
|
|
|
DisableWindowWidget(w, i + 13);
|
|
|
|
|
|
// We need a repaint
|
|
|
/* We need a repaint */
|
|
|
SetWindowDirty(w);
|
|
|
}
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
// Check if we have the player marked as inactive
|
|
|
/* Check if we have the player marked as inactive */
|
|
|
if (IsWindowWidgetDisabled(w, i + 13)) {
|
|
|
// New player! Yippie :p
|
|
|
/* New player! Yippie :p */
|
|
|
EnableWindowWidget(w, i + 13);
|
|
|
// We need a repaint
|
|
|
/* We need a repaint */
|
|
|
SetWindowDirty(w);
|
|
|
}
|
|
|
|
|
|
x = (i == _performance_rating_detail_player) ? 1 : 0;
|
|
|
DrawPlayerIcon(i, i * 37 + 13 + x, 16 + x);
|
|
|
}
|
|
|
|
|
|
// The colors used to show how the progress is going
|
|
|
/* The colors used to show how the progress is going */
|
|
|
color_done = _colour_gradient[COLOUR_GREEN][4];
|
|
|
color_notdone = _colour_gradient[COLOUR_RED][4];
|
|
|
|
|
|
// Draw all the score parts
|
|
|
/* Draw all the score parts */
|
|
|
for (ScoreID i = SCORE_BEGIN; i < SCORE_END; i++) {
|
|
|
int val = _score_part[_performance_rating_detail_player][i];
|
|
|
int needed = _score_info[i].needed;
|
|
|
int score = _score_info[i].score;
|
|
|
|
|
|
y += 20;
|
|
|
// SCORE_TOTAL has his own rulez ;)
|
|
|
/* 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
|
|
|
/* Draw the score */
|
|
|
SetDParam(0, score);
|
|
|
DrawStringRightAligned(107, y, SET_PERFORMANCE_DETAIL_INT, 0);
|
|
|
|
|
|
// Calculate the %-bar
|
|
|
/* Calculate the %-bar */
|
|
|
if (val > needed) {
|
|
|
x = 50;
|
|
|
} else if (val == 0) {
|
|
|
x = 0;
|
|
|
} else {
|
|
|
x = val * 50 / needed;
|
|
|
}
|
|
|
|
|
|
// SCORE_LOAN is inversed
|
|
|
/* SCORE_LOAN is inversed */
|
|
|
if (val < 0 && i == SCORE_LOAN) x = 0;
|
|
|
|
|
|
// Draw the bar
|
|
|
/* Draw the bar */
|
|
|
if (x != 0) GfxFillRect(112, y - 2, 112 + x, y + 10, color_done);
|
|
|
if (x != 50) GfxFillRect(112 + x, y - 2, 112 + 50, y + 10, color_notdone);
|
|
|
|
|
|
// Calculate the %
|
|
|
/* Calculate the % */
|
|
|
x = (val <= needed) ? val * 100 / needed : 100;
|
|
|
|
|
|
// SCORE_LOAN is inversed
|
|
|
/* SCORE_LOAN is inversed */
|
|
|
if (val < 0 && i == SCORE_LOAN) x = 0;
|
|
|
|
|
|
// Draw it
|
|
|
/* Draw it */
|
|
|
SetDParam(0, x);
|
|
|
DrawStringCentered(137, y, STR_PERFORMANCE_DETAIL_PERCENT, 0);
|
|
|
|
|
|
// SCORE_LOAN is inversed
|
|
|
/* 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
|
|
|
/* 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:
|
|
@@ -1047,15 +1049,15 @@ static void PerformanceRatingDetailWndPr
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
case WE_CLICK:
|
|
|
// Check which button is clicked
|
|
|
/* Check which button is clicked */
|
|
|
if (IS_INT_INSIDE(e->we.click.widget, 13, 21)) {
|
|
|
// Is it no on disable?
|
|
|
/* Is it no on disable? */
|
|
|
if (!IsWindowWidgetDisabled(w, e->we.click.widget)) {
|
|
|
RaiseWindowWidget(w, _performance_rating_detail_player + 13);
|
|
|
_performance_rating_detail_player = (PlayerID)(e->we.click.widget - 13);
|
|
|
LowerWindowWidget(w, _performance_rating_detail_player + 13);
|
|
|
SetWindowDirty(w);
|
|
|
}
|
|
@@ -1083,21 +1085,21 @@ static void PerformanceRatingDetailWndPr
|
|
|
SetWindowDirty(w);
|
|
|
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
case WE_TICK: {
|
|
|
// Update the player score every 5 days
|
|
|
/* 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
|
|
|
/* Skip if player is not active */
|
|
|
if (p2->is_active) UpdateCompanyRatingAndValue(p2, false);
|
|
|
}
|
|
|
SetWindowDirty(w);
|
|
|
}
|
|
|
}
|
|
|
|