MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / DrawNewObjectTileInGUI

Function DrawNewObjectTileInGUI

src/newgrf_object.cpp:492–523  ·  view source on GitHub ↗

* Draw representation of an object (tile) for GUI purposes. * @param x Position x of image. * @param y Position y of image. * @param spec Object spec to draw. * @param view The object's view. */

Source from the content-addressed store, hash-verified

490 * @param view The object's view.
491 */
492void DrawNewObjectTileInGUI(int x, int y, const ObjectSpec *spec, uint8_t view)
493{
494 ObjectResolverObject object(spec, nullptr, INVALID_TILE, view);
495 const auto *group = object.Resolve<TileLayoutSpriteGroup>();
496 if (group == nullptr) return;
497
498 auto processor = group->ProcessRegisters(object, nullptr);
499 auto dts = processor.GetLayout();
500
501 PaletteID palette;
502 if (Company::IsValidID(_local_company)) {
503 /* Get the colours of our company! */
504 if (spec->flags.Test(ObjectFlag::Uses2CC)) {
505 const Livery &l = Company::Get(_local_company)->livery[0];
506 palette = SPR_2CCMAP_BASE + l.colour1 + l.colour2 * 16;
507 } else {
508 palette = GetCompanyPalette(_local_company);
509 }
510 } else {
511 /* There's no company, so just take the base palette. */
512 palette = spec->flags.Test(ObjectFlag::Uses2CC) ? SPR_2CCMAP_BASE : PALETTE_RECOLOUR_START;
513 }
514
515 SpriteID image = dts.ground.sprite;
516 PaletteID pal = dts.ground.pal;
517
518 if (GB(image, 0, SPRITE_WIDTH) != 0) {
519 DrawSprite(image, GroundSpritePaletteTransform(image, pal, palette), x, y);
520 }
521
522 DrawNewGRFTileSeqInGUI(x, y, &dts, 0, palette);
523}
524
525/**
526 * Perform a callback for an object.

Callers 2

DrawTypeMethod · 0.85
DrawWidgetMethod · 0.85

Calls 8

GetCompanyPaletteFunction · 0.85
GBFunction · 0.85
DrawSpriteFunction · 0.85
DrawNewGRFTileSeqInGUIFunction · 0.85
GetLayoutMethod · 0.80
TestMethod · 0.80
ProcessRegistersMethod · 0.45

Tested by

no test coverage detected