Changeset - r9289:a7fd524a69f5
[Not reviewed]
master
0 1 0
rubidium - 16 years ago 2008-05-18 09:39:40
rubidium@openttd.org
(svn r13155) -Codechange: make a window class of the company league and graph legenda windows.
1 file changed with 65 insertions and 66 deletions:
0 comments (0 inline, 0 general)
src/graph_gui.cpp
Show inline comments
 
@@ -245,122 +245,121 @@ static void DrawGraph(const GraphDrawer 
 

	
 
					/* Draw the point. */
 
					GfxFillRect(x - 1, y - 1, x + 1, y + 1, color);
 

	
 
					/* Draw the line connected to the previous point. */
 
					if (prev_x != INVALID_DATAPOINT_POS) GfxDrawLine(prev_x, prev_y, x, y, color);
 

	
 
					prev_x = x;
 
					prev_y = y;
 
				} else {
 
					prev_x = INVALID_DATAPOINT_POS;
 
					prev_y = INVALID_DATAPOINT_POS;
 
				}
 

	
 
				x += GRAPH_X_POSITION_SEPARATION;
 
			}
 
		}
 
	}
 
}
 

	
 
/****************/
 
/* GRAPH LEGEND */
 
/****************/
 

	
 
static void GraphLegendWndProc(Window *w, WindowEvent *e)
 
{
 
	switch (e->event) {
 
		case WE_CREATE:
 
			for (uint i = 3; i < w->widget_count; i++) {
 
				if (!HasBit(_legend_excluded_players, i - 3)) w->LowerWidget(i);
 
			}
 
			break;
 

	
 
		case WE_PAINT: {
 
			const Player *p;
 

	
 
			FOR_ALL_PLAYERS(p) {
 
				if (p->is_active) continue;
 
struct GraphLegendWindow : Window {
 
	GraphLegendWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number)
 
	{
 
		for (uint i = 3; i < this->widget_count; i++) {
 
			if (!HasBit(_legend_excluded_players, i - 3)) this->LowerWidget(i);
 
		}
 
	}
 

	
 
				SetBit(_legend_excluded_players, p->index);
 
				w->RaiseWidget(p->index + 3);
 
			}
 

	
 
			w->DrawWidgets();
 
	virtual void OnPaint()
 
	{
 
		const Player *p;
 

	
 
			FOR_ALL_PLAYERS(p) {
 
				if (!p->is_active) continue;
 

	
 
				DrawPlayerIcon(p->index, 4, 18 + p->index * 12);
 
		FOR_ALL_PLAYERS(p) {
 
			if (p->is_active) continue;
 

	
 
				SetDParam(0, p->index);
 
				SetDParam(1, p->index);
 
				DrawString(21, 17 + p->index * 12, STR_7021, HasBit(_legend_excluded_players, p->index) ? TC_BLACK : TC_WHITE);
 
			}
 
			break;
 
			SetBit(_legend_excluded_players, p->index);
 
			this->RaiseWidget(p->index + 3);
 
		}
 

	
 
		case WE_CLICK:
 
			if (!IsInsideMM(e->we.click.widget, 3, 11)) return;
 
		this->DrawWidgets();
 

	
 
		FOR_ALL_PLAYERS(p) {
 
			if (!p->is_active) continue;
 

	
 
			DrawPlayerIcon(p->index, 4, 18 + p->index * 12);
 

	
 
			SetDParam(0, p->index);
 
			SetDParam(1, p->index);
 
			DrawString(21, 17 + p->index * 12, STR_7021, HasBit(_legend_excluded_players, p->index) ? TC_BLACK : TC_WHITE);
 
		}
 
	}
 

	
 
			ToggleBit(_legend_excluded_players, e->we.click.widget - 3);
 
			w->ToggleWidgetLoweredState(e->we.click.widget);
 
			w->SetDirty();
 
			InvalidateWindow(WC_INCOME_GRAPH, 0);
 
			InvalidateWindow(WC_OPERATING_PROFIT, 0);
 
			InvalidateWindow(WC_DELIVERED_CARGO, 0);
 
			InvalidateWindow(WC_PERFORMANCE_HISTORY, 0);
 
			InvalidateWindow(WC_COMPANY_VALUE, 0);
 
			break;
 
	virtual void OnClick(Point pt, int widget)
 
	{
 
		if (!IsInsideMM(widget, 3, 11)) return;
 

	
 
		ToggleBit(_legend_excluded_players, widget - 3);
 
		this->ToggleWidgetLoweredState(widget);
 
		this->SetDirty();
 
		InvalidateWindow(WC_INCOME_GRAPH, 0);
 
		InvalidateWindow(WC_OPERATING_PROFIT, 0);
 
		InvalidateWindow(WC_DELIVERED_CARGO, 0);
 
		InvalidateWindow(WC_PERFORMANCE_HISTORY, 0);
 
		InvalidateWindow(WC_COMPANY_VALUE, 0);
 
	}
 
}
 
};
 

	
 
static const Widget _graph_legend_widgets[] = {
 
{   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,                       STR_018B_CLOSE_WINDOW},
 
{    WWT_CAPTION,   RESIZE_NONE,    14,    11,   249,     0,    13, STR_704E_KEY_TO_COMPANY_GRAPHS, STR_018C_WINDOW_TITLE_DRAG_THIS},
 
{      WWT_PANEL,   RESIZE_NONE,    14,     0,   249,    14,   113, 0x0,                            STR_NULL},
 
{      WWT_PANEL,   RESIZE_NONE,    14,     2,   247,    16,    27, 0x0,                            STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY},
 
{      WWT_PANEL,   RESIZE_NONE,    14,     2,   247,    28,    39, 0x0,                            STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY},
 
{      WWT_PANEL,   RESIZE_NONE,    14,     2,   247,    40,    51, 0x0,                            STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY},
 
{      WWT_PANEL,   RESIZE_NONE,    14,     2,   247,    52,    63, 0x0,                            STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY},
 
{      WWT_PANEL,   RESIZE_NONE,    14,     2,   247,    64,    75, 0x0,                            STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY},
 
{      WWT_PANEL,   RESIZE_NONE,    14,     2,   247,    76,    87, 0x0,                            STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY},
 
{      WWT_PANEL,   RESIZE_NONE,    14,     2,   247,    88,    99, 0x0,                            STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY},
 
{      WWT_PANEL,   RESIZE_NONE,    14,     2,   247,   100,   111, 0x0,                            STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY},
 
{   WIDGETS_END},
 
};
 

	
 
static const WindowDesc _graph_legend_desc = {
 
	WDP_AUTO, WDP_AUTO, 250, 114, 250, 114,
 
	WC_GRAPH_LEGEND, WC_NONE,
 
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
 
	_graph_legend_widgets,
 
	GraphLegendWndProc
 
	NULL
 
};
 

	
 
static void ShowGraphLegend()
 
{
 
	AllocateWindowDescFront<Window>(&_graph_legend_desc, 0);
 
	AllocateWindowDescFront<GraphLegendWindow>(&_graph_legend_desc, 0);
 
}
 

	
 
/********************/
 
/* OPERATING PROFIT */
 
/********************/
 

	
 
static void SetupGraphDrawerForPlayers(GraphDrawer *gd)
 
{
 
	const Player* p;
 
	uint excluded_players = _legend_excluded_players;
 
	byte nums;
 
	int mo, yr;
 

	
 
	/* 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;
 

	
 
	nums = 0;
 
	FOR_ALL_PLAYERS(p) {
 
		if (p->is_active) nums = max(nums, p->num_valid_stat_ent);
 
	}
 
@@ -858,98 +857,98 @@ static const StringID _performance_title
 
	STR_7069_ROUTE_SUPERVISOR,
 
	STR_706A_DIRECTOR,
 
	STR_706A_DIRECTOR,
 
	STR_706B_CHIEF_EXECUTIVE,
 
	STR_706B_CHIEF_EXECUTIVE,
 
	STR_706C_CHAIRMAN,
 
	STR_706C_CHAIRMAN,
 
	STR_706D_PRESIDENT,
 
	STR_706E_TYCOON,
 
};
 

	
 
static inline StringID GetPerformanceTitleFromValue(uint value)
 
{
 
	return _performance_titles[minu(value, 1000) >> 6];
 
}
 

	
 
static int CDECL PerfHistComp(const void* elem1, const void* elem2)
 
{
 
	const Player* p1 = *(const Player* const*)elem1;
 
	const Player* p2 = *(const Player* const*)elem2;
 

	
 
	return p2->old_economy[1].performance_history - p1->old_economy[1].performance_history;
 
}
 

	
 
static void CompanyLeagueWndProc(Window *w, WindowEvent *e)
 
{
 
	switch (e->event) {
 
		case WE_PAINT: {
 
			const Player* plist[MAX_PLAYERS];
 
			const Player* p;
 
struct CompanyLeagueWindow : Window {
 
	CompanyLeagueWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number)
 
	{
 
	}
 

	
 
			w->DrawWidgets();
 
	virtual void OnPaint()
 
	{
 
		const Player *plist[MAX_PLAYERS];
 
		const Player *p;
 

	
 
			uint pl_num = 0;
 
			FOR_ALL_PLAYERS(p) if (p->is_active) plist[pl_num++] = p;
 
		this->DrawWidgets();
 

	
 
			qsort((void*)plist, pl_num, sizeof(*plist), PerfHistComp);
 
		uint pl_num = 0;
 
		FOR_ALL_PLAYERS(p) if (p->is_active) plist[pl_num++] = p;
 

	
 
		qsort((void*)plist, pl_num, sizeof(*plist), PerfHistComp);
 

	
 
			for (uint i = 0; i != pl_num; i++) {
 
				p = plist[i];
 
				SetDParam(0, i + STR_01AC_1ST);
 
				SetDParam(1, p->index);
 
				SetDParam(2, p->index);
 
				SetDParam(3, GetPerformanceTitleFromValue(p->old_economy[1].performance_history));
 
		for (uint i = 0; i != pl_num; i++) {
 
			p = plist[i];
 
			SetDParam(0, i + STR_01AC_1ST);
 
			SetDParam(1, p->index);
 
			SetDParam(2, p->index);
 
			SetDParam(3, GetPerformanceTitleFromValue(p->old_economy[1].performance_history));
 

	
 
				DrawString(2, 15 + i * 10, i == 0 ? STR_7054 : STR_7055, TC_FROMSTRING);
 
				DrawPlayerIcon(p->index, 27, 16 + i * 10);
 
			}
 

	
 
			break;
 
			DrawString(2, 15 + i * 10, i == 0 ? STR_7054 : STR_7055, TC_FROMSTRING);
 
			DrawPlayerIcon(p->index, 27, 16 + i * 10);
 
		}
 
	}
 
}
 
};
 

	
 

	
 
static const Widget _company_league_widgets[] = {
 
{   WWT_CLOSEBOX, RESIZE_NONE, 14,   0,  10,  0, 13, STR_00C5,                      STR_018B_CLOSE_WINDOW},
 
{    WWT_CAPTION, RESIZE_NONE, 14,  11, 387,  0, 13, STR_7053_COMPANY_LEAGUE_TABLE, STR_018C_WINDOW_TITLE_DRAG_THIS},
 
{  WWT_STICKYBOX, RESIZE_NONE, 14, 388, 399,  0, 13, STR_NULL,                      STR_STICKY_BUTTON},
 
{      WWT_PANEL, RESIZE_NONE, 14,   0, 399, 14, 96, 0x0,                           STR_NULL},
 
{   WIDGETS_END},
 
};
 

	
 
static const WindowDesc _company_league_desc = {
 
	WDP_AUTO, WDP_AUTO, 400, 97, 400, 97,
 
	WC_COMPANY_LEAGUE, WC_NONE,
 
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON,
 
	_company_league_widgets,
 
	CompanyLeagueWndProc
 
	NULL
 
};
 

	
 
void ShowCompanyLeagueTable()
 
{
 
	AllocateWindowDescFront<Window>(&_company_league_desc, 0);
 
	AllocateWindowDescFront<CompanyLeagueWindow>(&_company_league_desc, 0);
 
}
 

	
 
/*****************************/
 
/* PERFORMANCE RATING DETAIL */
 
/*****************************/
 

	
 
struct PerformanceRatingDetailWindow : Window {
 
	static PlayerID player;
 
	int timeout;
 

	
 
	PerformanceRatingDetailWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number)
 
	{
 
		/* Disable the players who are not active */
 
		for (PlayerID i = PLAYER_FIRST; i < MAX_PLAYERS; i++) {
 
			this->SetWidgetDisabledState(i + 13, !GetPlayer(i)->is_active);
 
		}
 

	
 
		this->UpdatePlayerStats();
 

	
 
		if (player != INVALID_PLAYER) this->LowerWidget(player + 13);
 
		this->SetDirty();
 
	}
 

	
 
	void UpdatePlayerStats()
0 comments (0 inline, 0 general)