|
@@ -7,24 +7,25 @@
|
|
|
#include "gui.h"
|
|
|
#include "window_gui.h"
|
|
|
#include "player_base.h"
|
|
|
#include "player_gui.h"
|
|
|
#include "economy_func.h"
|
|
|
#include "variables.h"
|
|
|
#include "cargotype.h"
|
|
|
#include "strings_func.h"
|
|
|
#include "core/alloc_func.hpp"
|
|
|
#include "window_func.h"
|
|
|
#include "date_func.h"
|
|
|
#include "gfx_func.h"
|
|
|
#include "sortlist_type.h"
|
|
|
|
|
|
#include "table/strings.h"
|
|
|
#include "table/sprites.h"
|
|
|
|
|
|
/* Bitmasks of player and cargo indices that shouldn't be drawn. */
|
|
|
static uint _legend_excluded_players;
|
|
|
static uint _legend_excluded_cargo;
|
|
|
|
|
|
/* Apparently these don't play well with enums. */
|
|
|
static const OverflowSafeInt64 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.
|
|
|
|
|
@@ -749,61 +750,97 @@ static const StringID _performance_title
|
|
|
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;
|
|
|
class CompanyLeagueWindow : public Window {
|
|
|
private:
|
|
|
GUIList<const Player*> players;
|
|
|
|
|
|
/**
|
|
|
* (Re)Build the company league list
|
|
|
*/
|
|
|
void BuildPlayerList()
|
|
|
{
|
|
|
if (!this->players.NeedRebuild()) return;
|
|
|
|
|
|
this->players.Clear();
|
|
|
|
|
|
return p2->old_economy[1].performance_history - p1->old_economy[1].performance_history;
|
|
|
}
|
|
|
const Player *p;
|
|
|
FOR_ALL_PLAYERS(p) {
|
|
|
if (p->is_active) {
|
|
|
*this->players.Append() = p;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
struct CompanyLeagueWindow : Window {
|
|
|
this->players.Compact();
|
|
|
this->players.RebuildDone();
|
|
|
}
|
|
|
|
|
|
/** Sort the company league by performance history */
|
|
|
static int CDECL PerformanceSorter(const Player* const *p1, const Player* const *p2)
|
|
|
{
|
|
|
return (*p2)->old_economy[1].performance_history - (*p1)->old_economy[1].performance_history;
|
|
|
}
|
|
|
|
|
|
public:
|
|
|
CompanyLeagueWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number)
|
|
|
{
|
|
|
this->players.ForceRebuild();
|
|
|
this->players.NeedResort();
|
|
|
|
|
|
this->FindWindowPlacementAndResize(desc);
|
|
|
}
|
|
|
|
|
|
virtual void OnPaint()
|
|
|
{
|
|
|
const Player *plist[MAX_PLAYERS];
|
|
|
const Player *p;
|
|
|
this->BuildPlayerList();
|
|
|
this->players.Sort(&PerformanceSorter);
|
|
|
|
|
|
this->DrawWidgets();
|
|
|
|
|
|
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];
|
|
|
for (uint i = 0; i != this->players.Length(); i++) {
|
|
|
const Player *p = this->players[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);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
virtual void OnTick()
|
|
|
{
|
|
|
if (this->players.NeedResort()) {
|
|
|
this->SetDirty();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
virtual void OnInvalidateData(int data)
|
|
|
{
|
|
|
if (data == 0) {
|
|
|
this->players.ForceRebuild();
|
|
|
} else {
|
|
|
this->players.ForceResort();
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
|
|
|
|
|
|
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 = {
|