From e9e06263a87906af308c2f5cfefdd6b717386f6f Mon Sep 17 00:00:00 2001 From: Maikel de Vries Date: Wed, 20 Jan 2016 15:40:19 +0100 Subject: [PATCH] fix shape of basement construction preview and site (#1586) --- .../ConstructionPreviewer.ocd/Script.c | 6 ++-- .../ConstructionSite.ocd/Script.c | 36 +++++++++---------- .../Structures.ocd/Basement.ocd/Script.c | 26 +++++++++++++- 3 files changed, 46 insertions(+), 22 deletions(-) diff --git a/planet/Objects.ocd/Libraries.ocd/Constructor.ocd/ConstructionPreviewer.ocd/Script.c b/planet/Objects.ocd/Libraries.ocd/Constructor.ocd/ConstructionPreviewer.ocd/Script.c index f35a5b5b5..936235547 100644 --- a/planet/Objects.ocd/Libraries.ocd/Constructor.ocd/ConstructionPreviewer.ocd/Script.c +++ b/planet/Objects.ocd/Libraries.ocd/Constructor.ocd/ConstructionPreviewer.ocd/Script.c @@ -31,11 +31,12 @@ func Set(id to_construct, object constructing_clonk) extra_overlay = to_construct->~ConstructionPreview(this, GFX_PreviewerPictureOverlay, direction); dimension_x = to_construct->GetDefWidth(); dimension_y = to_construct->GetDefHeight(); - clonk = constructing_clonk; structure = to_construct; direction = DIR_Left; blocked = true; + // Allow the definition to draw an alternative preview. + to_construct->~AlternativeConstructionPreview(this, direction); AdjustPreview(structure->~IsBelowSurfaceConstruction()); return; } @@ -160,7 +161,8 @@ func Reposition(int x, int y) dir = 0; SetObjDrawTransform(1000, 0, dimension_x/2 * 1000 * dir, 0, 1000, 0, GFX_CombineIconOverlay); } - + // Update alternative preview in the definition to be placed. + structure->~AlternativeConstructionPreview(this, direction, stick_to); SetPosition(x, y); AdjustPreview(structure->~IsBelowSurfaceConstruction()); } diff --git a/planet/Objects.ocd/Libraries.ocd/Constructor.ocd/ConstructionSite.ocd/Script.c b/planet/Objects.ocd/Libraries.ocd/Constructor.ocd/ConstructionSite.ocd/Script.c index e01a73e15..b0023c1e5 100644 --- a/planet/Objects.ocd/Libraries.ocd/Constructor.ocd/ConstructionSite.ocd/Script.c +++ b/planet/Objects.ocd/Libraries.ocd/Constructor.ocd/ConstructionSite.ocd/Script.c @@ -133,13 +133,19 @@ public func Set(id def, int dir, object stick) definition = def; direction = dir; stick_to = stick; + + // Set the shape of the construction site. + var w = def->~GetSiteWidth(direction, stick_to) ?? def->GetDefWidth(); + var h = def->~GetSiteHeight(direction, stick_to) ?? def->GetDefHeight(); + // Height of construction site needs to exceed 12 pixels for the clonk to be able to add materials. + var site_h = Max(12, h); + SetShape(-w/2, -site_h, w, site_h); + // Increase shape for below surface constructions to allow for adding materials. + if (definition->~IsBelowSurfaceConstruction()) + SetShape(-w/2, -2 * site_h, w, 2 * site_h); - var xw = (1 - dir * 2) * 1000; - var w, h; - w = def->GetDefWidth(); - h = def->GetDefHeight(); // Draw the building with a wired frame and large alpha unless site graphics is overloaded by definition - if (!def->~SetConstructionSiteOverlay(this, direction, stick_to)) + if (!definition->~SetConstructionSiteOverlay(this, direction, stick_to)) { SetGraphics(nil, nil, 0); SetGraphics(nil, def, 1, GFXOV_MODE_Base); @@ -151,22 +157,14 @@ public func Set(id def, int dir, object stick) SetClrModulation(RGBa(255, 255, 255, 50), 1); SetGraphics(nil, def, 2, GFXOV_MODE_Base, nil, GFX_BLIT_Wireframe); } - SetGraphics("", GetID(), 3, GFXOV_MODE_ExtraGraphics); + SetObjDrawTransform((1 - dir * 2) * 1000, 0, 0, 0, 1000, -h * 500, 1); + SetObjDrawTransform((1 - dir * 2) * 1000, 0, 0, 0, 1000, -h * 500, 2); } - SetObjDrawTransform(xw,0,0,0,1000, -h*500,1); - SetObjDrawTransform(xw,0,0,0,1000, -h*500,2); - // Height of construction site needs to exceed 12 pixels for the clonk to be able to add materials. - h = Max(12, h); - SetShape(-w/2, -h, w, h); - // Increase shape for below surface constructions to allow for adding materials. - if (definition->~IsBelowSurfaceConstruction()) - SetShape(-w/2, -2 * h, w, 2 * h); - - SetName(Format(Translate("TxtConstruction"),def->GetName())); - - this.visibility = VIS_Owner | VIS_Allies; - + + SetName(Format(Translate("TxtConstruction"), def->GetName())); + this.visibility = VIS_Owner | VIS_Allies; ShowMissingComponents(); + return; } // Scenario saving diff --git a/planet/Objects.ocd/Structures.ocd/Basement.ocd/Script.c b/planet/Objects.ocd/Structures.ocd/Basement.ocd/Script.c index 57cfc182a..b539a14f0 100644 --- a/planet/Objects.ocd/Structures.ocd/Basement.ocd/Script.c +++ b/planet/Objects.ocd/Structures.ocd/Basement.ocd/Script.c @@ -54,7 +54,7 @@ public func CombineWith(object stick_to) return; } -public func SetParent(object to_parent) +public func SetParent(object to_parent) { parent = to_parent; SetWidth(BoundBy(parent->GetObjWidth(), 8, 120)); @@ -74,6 +74,30 @@ public func ConstructionCombineDirection() { return CONSTRUCTION_STICK_Bottom; } public func NoConstructionFlip() { return true; } +public func AlternativeConstructionPreview(object previewer, int direction, object combine_with) +{ + var wdt = GetSiteWidth(direction, combine_with); + previewer->SetObjDrawTransform(1000 * wdt / 40, 0, 0, 0, 1000, 0, previewer.GFX_StructureOverlay); + return; +} + +public func GetSiteWidth(int direction, object combine_with) +{ + var wdt = GetDefWidth(); + if (combine_with) + wdt = combine_with->GetObjWidth(); + return BoundBy(wdt, 8, 120); +} + +public func SetConstructionSiteOverlay(object site, int direction, object combine_with) +{ + var wdt = GetSiteWidth(direction, combine_with); + site->SetGraphics(nil, Basement, 1, GFXOV_MODE_Base); + site->SetClrModulation(RGBa(255, 255, 255, 128), 1); + site->SetObjDrawTransform(1000 * wdt / 40, 0, 0, 0, 1000, -4000, 1); + return true; +} + // Don't stick to itself, so it should not be a structure. public func IsStructure() { return false; }