fix shape of basement construction preview and site (#1586)

objectmenu
Maikel de Vries 2016-01-20 15:40:19 +01:00
parent 4114738b45
commit d500218a02
3 changed files with 46 additions and 22 deletions

View File

@ -26,11 +26,12 @@ func Set(id to_construct, object constructing_clonk)
SetGraphics(nil, to_construct, 3, GFXOV_MODE_Picture, nil, GFX_BLIT_Wireframe);
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;
}
@ -143,7 +144,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());
}

View File

@ -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

View File

@ -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; }