TBTR: Fix palette recolouring of templates

Fix group overrides affecting template image when cloning vehicle
Update template when changing company colours

Update template images on demand instead of at load
This commit is contained in:
Jonathan G Rennison
2020-12-26 09:37:26 +00:00
parent 369c98e3e0
commit 78b06ddc40
13 changed files with 98 additions and 44 deletions

View File

@@ -2670,15 +2670,16 @@ LiveryScheme GetEngineLiveryScheme(EngineID engine_type, EngineID parent_engine_
* @param parent_engine_type EngineID of the front vehicle. INVALID_VEHICLE if vehicle is at front itself.
* @param v the vehicle. nullptr if in purchase list etc.
* @param livery_setting The livery settings to use for acquiring the livery information.
* @param ignore_group Ignore group overrides.
* @return livery to use
*/
const Livery *GetEngineLivery(EngineID engine_type, CompanyID company, EngineID parent_engine_type, const Vehicle *v, byte livery_setting)
const Livery *GetEngineLivery(EngineID engine_type, CompanyID company, EngineID parent_engine_type, const Vehicle *v, byte livery_setting, bool ignore_group)
{
const Company *c = Company::Get(company);
LiveryScheme scheme = LS_DEFAULT;
if (livery_setting == LIT_ALL || (livery_setting == LIT_COMPANY && company == _local_company)) {
if (v != nullptr) {
if (v != nullptr && !ignore_group) {
const Group *g = Group::GetIfValid(v->First()->group_id);
if (g != nullptr) {
/* Traverse parents until we find a livery or reach the top */
@@ -2701,9 +2702,9 @@ const Livery *GetEngineLivery(EngineID engine_type, CompanyID company, EngineID
}
static PaletteID GetEngineColourMap(EngineID engine_type, CompanyID company, EngineID parent_engine_type, const Vehicle *v)
static PaletteID GetEngineColourMap(EngineID engine_type, CompanyID company, EngineID parent_engine_type, const Vehicle *v, bool ignore_group = false)
{
PaletteID map = (v != nullptr) ? v->colourmap : PAL_NONE;
PaletteID map = (v != nullptr && !ignore_group) ? v->colourmap : PAL_NONE;
/* Return cached value if any */
if (map != PAL_NONE) return map;
@@ -2734,13 +2735,13 @@ static PaletteID GetEngineColourMap(EngineID engine_type, CompanyID company, Eng
/* Spectator has news shown too, but has invalid company ID - as well as dedicated server */
if (!Company::IsValidID(company)) return map;
const Livery *livery = GetEngineLivery(engine_type, company, parent_engine_type, v, _settings_client.gui.liveries);
const Livery *livery = GetEngineLivery(engine_type, company, parent_engine_type, v, _settings_client.gui.liveries, ignore_group);
map += livery->colour1;
if (twocc) map += livery->colour2 * 16;
/* Update cache */
if (v != nullptr) const_cast<Vehicle *>(v)->colourmap = map;
if (v != nullptr && !ignore_group) const_cast<Vehicle *>(v)->colourmap = map;
return map;
}
@@ -2769,6 +2770,16 @@ PaletteID GetVehiclePalette(const Vehicle *v)
return GetEngineColourMap(v->engine_type, v->owner, INVALID_ENGINE, v);
}
/**
* Get the uncached colour map for a train, ignoring the vehicle's group.
* @param v Vehicle to get colour map for
* @return A ready-to-use palette modifier
*/
PaletteID GetUncachedTrainPaletteIgnoringGroup(const Train *v)
{
return GetEngineColourMap(v->engine_type, v->owner, v->GetGroundVehicleCache()->first_engine, v, true);
}
/**
* Delete all implicit orders which were not reached.
*/