From 52c11267bcdb8d1da0c6d8c17bc6af2d75b4e977 Mon Sep 17 00:00:00 2001 From: Ted John Date: Sat, 2 Jul 2016 11:35:46 +0100 Subject: [PATCH] add small scenery preview --- src/object.c | 4 +-- src/object/ObjectRepository.cpp | 8 +++-- src/object/SmallSceneryObject.cpp | 53 +++++++++++++++++++++++++++++++ src/object/SmallSceneryObject.h | 2 ++ src/paint/map_element/scenery.c | 2 +- src/windows/scenery.c | 4 +-- src/windows/top_toolbar.c | 2 +- src/world/scenery.h | 4 +-- 8 files changed, 69 insertions(+), 10 deletions(-) diff --git a/src/object.c b/src/object.c index 0f0c4def05..2c6592b8e6 100644 --- a/src/object.c +++ b/src/object.c @@ -809,7 +809,7 @@ static void object_type_small_scenery_paint(void *objectEntry, rct_drawpixelinfo } gfx_draw_sprite(&clipDPI, imageId, x, y, 0); - if (sceneryEntry->small_scenery.flags & SMALL_SCENERY_FLAG10) { + if (sceneryEntry->small_scenery.flags & SMALL_SCENERY_FLAG_HAS_GLASS) { imageId = sceneryEntry->image + 0x44500004; if (sceneryEntry->small_scenery.flags & SMALL_SCENERY_FLAG_HAS_SECONDARY_COLOUR) { imageId |= 0x92000000; @@ -818,7 +818,7 @@ static void object_type_small_scenery_paint(void *objectEntry, rct_drawpixelinfo gfx_draw_sprite(&clipDPI, imageId, x, y, 0); } - if (sceneryEntry->small_scenery.flags & SMALL_SCENERY_FLAG8) { + if (sceneryEntry->small_scenery.flags & SMALL_SCENERY_FLAG_ANIMATED_FG) { imageId = sceneryEntry->image + 4; if (sceneryEntry->small_scenery.flags & SMALL_SCENERY_FLAG_HAS_SECONDARY_COLOUR) { imageId |= 0x92000000; diff --git a/src/object/ObjectRepository.cpp b/src/object/ObjectRepository.cpp index 2b24bc1ca4..d700dfd18c 100644 --- a/src/object/ObjectRepository.cpp +++ b/src/object/ObjectRepository.cpp @@ -668,7 +668,9 @@ extern "C" void * object_repository_load_object(const rct_object_entry * objectEntry) { IObjectRepository * objRepository = GetObjectRepository(); - return (void *)objRepository->LoadObject(objectEntry); + Object * object = objRepository->LoadObject(objectEntry); + object->Load(); + return (void *)object; } void object_repository_unload(size_t itemIndex) @@ -791,7 +793,9 @@ extern "C" void object_delete(void * object) { - delete ((Object *)object); + Object * baseObject = (Object *)object; + baseObject->Unload(); + delete baseObject; } const utf8 * object_get_description(const void * object) diff --git a/src/object/SmallSceneryObject.cpp b/src/object/SmallSceneryObject.cpp index d025bcd274..34d3e6111d 100644 --- a/src/object/SmallSceneryObject.cpp +++ b/src/object/SmallSceneryObject.cpp @@ -15,6 +15,7 @@ #pragma endregion #include "../core/IStream.hpp" +#include "../core/Math.hpp" #include "../core/Memory.hpp" #include "SmallSceneryObject.h" @@ -89,6 +90,58 @@ void SmallSceneryObject::Unload() gfx_object_free_images(_legacyType.image, GetImageTable()->GetCount()); } +void SmallSceneryObject::DrawPreview(rct_drawpixelinfo * dpi) const +{ + // rct_drawpixelinfo clipDPI; + // if (!clip_drawpixelinfo(&clipDPI, dpi, x - 56, y - 56, 112, 112)) { + // return; + // } + + uint32 flags = _legacyType.small_scenery.flags; + uint32 imageId = _legacyType.image; + if (flags & SMALL_SCENERY_FLAG_HAS_PRIMARY_COLOUR) + { + imageId |= 0x20D00000; + if (flags & SMALL_SCENERY_FLAG_HAS_SECONDARY_COLOUR) + { + imageId |= 0x92000000; + } + } + + int x = dpi->width / 2; + int y = (dpi->height / 2) + (_legacyType.small_scenery.height / 2); + y = Math::Min(y, dpi->height - 16); + + if ((flags & SMALL_SCENERY_FLAG_FULL_TILE) && + (flags & SMALL_SCENERY_FLAG_VOFFSET_CENTRE)) + { + y -= 12; + } + + gfx_draw_sprite(dpi, imageId, x, y, 0); + + if (_legacyType.small_scenery.flags & SMALL_SCENERY_FLAG_HAS_GLASS) + { + imageId = _legacyType.image + 0x44500004; + if (flags & SMALL_SCENERY_FLAG_HAS_SECONDARY_COLOUR) + { + imageId |= 0x92000000; + } + gfx_draw_sprite(dpi, imageId, x, y, 0); + } + + if (flags & SMALL_SCENERY_FLAG_ANIMATED_FG) + { + imageId = _legacyType.image + 4; + if (flags & SMALL_SCENERY_FLAG_HAS_SECONDARY_COLOUR) + { + imageId |= 0x92000000; + } + gfx_draw_sprite(dpi, imageId, x, y, 0); + } +} + + const utf8 * SmallSceneryObject::GetName() const { const utf8 * name = GetStringTable()->GetString(OBJ_STRING_ID_NAME); diff --git a/src/object/SmallSceneryObject.h b/src/object/SmallSceneryObject.h index 0420f70cc7..a21a447756 100644 --- a/src/object/SmallSceneryObject.h +++ b/src/object/SmallSceneryObject.h @@ -40,6 +40,8 @@ public: void Load() override; void Unload() override; + void DrawPreview(rct_drawpixelinfo * dpi) const; + const utf8 * GetName() const override; private: diff --git a/src/paint/map_element/scenery.c b/src/paint/map_element/scenery.c index 7873700b1a..474a39a66c 100644 --- a/src/paint/map_element/scenery.c +++ b/src/paint/map_element/scenery.c @@ -130,7 +130,7 @@ void scenery_paint(uint8 direction, int height, rct_map_element* mapElement) { sub_98197C(baseImageid, x_offset, y_offset, boxlength.x, boxlength.y, boxlength.z - 1, height, boxoffset.x, boxoffset.y, boxoffset.z, get_current_rotation()); } - if (entry->small_scenery.flags & SMALL_SCENERY_FLAG10) { + if (entry->small_scenery.flags & SMALL_SCENERY_FLAG_HAS_GLASS) { if (dword_F64EB0 == 0) { // Draw translucent overlay: int image_id = (baseImageid & 0x7FFFF) + (((mapElement->properties.scenery.colour_1 & 0x1F) + 112) << 19) + 0x40000004; diff --git a/src/windows/scenery.c b/src/windows/scenery.c index dcc3b93c81..ab95070966 100644 --- a/src/windows/scenery.c +++ b/src/windows/scenery.c @@ -986,7 +986,7 @@ void window_scenery_invalidate(rct_window *w) } else if (tabSelectedSceneryId < 0x100) { sceneryEntry = get_small_scenery_entry(tabSelectedSceneryId); - if (sceneryEntry->small_scenery.flags & (SMALL_SCENERY_FLAG_HAS_PRIMARY_COLOUR | SMALL_SCENERY_FLAG10)) { + if (sceneryEntry->small_scenery.flags & (SMALL_SCENERY_FLAG_HAS_PRIMARY_COLOUR | SMALL_SCENERY_FLAG_HAS_GLASS)) { window_scenery_widgets[WIDX_SCENERY_PRIMARY_COLOUR_BUTTON].type = WWT_COLOURBTN; if (sceneryEntry->small_scenery.flags & SMALL_SCENERY_FLAG_HAS_SECONDARY_COLOUR) @@ -1210,7 +1210,7 @@ void window_scenery_scrollpaint(rct_window *w, rct_drawpixelinfo *dpi, int scrol gfx_draw_sprite(&clipdpi, imageId, 0x20, spriteTop, w->colours[1]); } - if (sceneryEntry->small_scenery.flags & SMALL_SCENERY_FLAG8) { + if (sceneryEntry->small_scenery.flags & SMALL_SCENERY_FLAG_ANIMATED_FG) { imageId = (sceneryEntry->image + gWindowSceneryRotation) + 4; gfx_draw_sprite(&clipdpi, imageId, 0x20, spriteTop, w->colours[1]); } diff --git a/src/windows/top_toolbar.c b/src/windows/top_toolbar.c index 7eaf2913b0..ebcc082b6b 100644 --- a/src/windows/top_toolbar.c +++ b/src/windows/top_toolbar.c @@ -910,7 +910,7 @@ static void repaint_scenery_tool_down(sint16 x, sint16 y, sint16 widgetIndex){ // If can't repaint if (!(scenery_entry->small_scenery.flags & (SMALL_SCENERY_FLAG_HAS_PRIMARY_COLOUR | - SMALL_SCENERY_FLAG10))) + SMALL_SCENERY_FLAG_HAS_GLASS))) return; gGameCommandErrorTitle = STR_CANT_REPAINT_THIS; diff --git a/src/world/scenery.h b/src/world/scenery.h index 0f46018a55..5914e695b8 100644 --- a/src/world/scenery.h +++ b/src/world/scenery.h @@ -44,9 +44,9 @@ typedef enum { SMALL_SCENERY_FLAG_ANIMATED = (1 << 4), // 0x10 SMALL_SCENERY_FLAG6 = (1 << 5), // 0x20 SMALL_SCENERY_FLAG_CAN_BE_WATERED = (1 << 6), // 0x40 - SMALL_SCENERY_FLAG8 = (1 << 7), // 0x80 + SMALL_SCENERY_FLAG_ANIMATED_FG = (1 << 7), // 0x80 SMALL_SCENERY_FLAG9 = (1 << 8), // 0x100 - SMALL_SCENERY_FLAG10 = (1 << 9), // 0x200 + SMALL_SCENERY_FLAG_HAS_GLASS = (1 << 9), // 0x200 SMALL_SCENERY_FLAG_HAS_PRIMARY_COLOUR = (1 << 10), // 0x400 SMALL_SCENERY_FLAG12 = (1 << 11), // 0x800 SMALL_SCENERY_FLAG13 = (1 << 12), // 0x1000