Skip to content

Ground line for select box #1717

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 20 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CREDITS.md
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ This page lists all the individual contributions to the project by their author.
- Fix the bug that damaged particle dont disappear after building has repaired by engineer
- Display banner improvement
- Electric/RadBeam trail for laser tails
- Ground line for select box
- **Apollo** - Translucent SHP drawing patches
- **ststl**:
- Customizable `ShowTimer` priority of superweapons
Expand Down
2 changes: 1 addition & 1 deletion YRpp
Submodule YRpp updated 2 files
+1 −1 FootClass.h
+17 −0 Surface.h
15 changes: 14 additions & 1 deletion docs/User-Interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -284,12 +284,16 @@ RealTimeTimers.Adaptive=false ; boolean

### Select Box

![selectbox](_static/images/selectbox.png)

- Now you can use and customize select box for infantry, vehicle and aircraft. No select box for buildings in default case, but you still can specific for some building if you want.
- `Frames` can be used to list frames of `Shape` file that'll be drawn as a select box when the TechnoType's health is at or below full health/the percentage defined in `[AudioVisual] -> ConditionYellow/ConditionRed`, respectively.
- If `Grounded` set to true, the select box will be drawn on the ground below the TechnoType.
- Select box's translucency setting can be adjusted via `Translucency`.
- `VisibleToHouses` and `VisibleToHouses.Observer` can limit visibility to specific players.
- `DrawAboveTechno` specific whether the select box will be drawn before drawing the TechnoType. If set to false, the select box can be obscured by the TechnoType, and the draw location will ignore `PixelSelectionBracketDelta`.
- You can now use `GroundShape` to specific a image which always draw on ground, it will only draw when techno is in air if set `Ground.AlwaysDraw=false`, this also affect on `GroundLine`.
- If `GroundLine=true` , the game will draw a line from techno's position to its vertical projection, `GroundLine.Dashed=true` means the projection line is a dashed line.

In `rulesmd.ini`:
```ini
Expand All @@ -304,12 +308,21 @@ DefaultUnitSelectBox= ; Select box for vehicle and aircraft
Shape=select.shp ; filename with .shp extension
Palette=palette.pal ; filename with .pal extension
Frames= ; List of integer, default 1,1,1 for infantry, 0,0,0 for vehicle and aircraft
Grounded=false ; boolean
Offset=0,0 ; integers - horizontal, vertical
Translucency=0 ; translucency level (0/25/50/75)
VisibleToHouses=all ; Affected House Enumeration (none|owner/self|allies/ally|team|enemies/enemy|all)
VisibleToHouses.Observer=true ; boolean
DrawAboveTechno=true ; boolean
GroundShape= ; filename with .shp extension
GroundPalette=palette.pal ; filename with .pal extension
GroundFrames= ; List of integer, default 1,1,1 for infantry, 0,0,0 for vehicle and aircraft
GroundOffset=0,0 ; integers - horizontal, vertical
Ground.AlwaysDraw=true ; boolean
GroundLine=false ; boolean
GroundLineColor=0,255,0 ; R, G, B
GroundLineColor.ConditionYellow= ; R, G, B
GroundLineColor.ConditionRed= ; R, G, B
GroundLine.Dashed=false ; boolean

[SOMETECHNO] ; TechnoType
SelectBox= ; Select box
Expand Down
1 change: 1 addition & 0 deletions docs/Whats-New.md
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ New:
- [Display banner](AI-Scripting-and-Mapping.md#display-banner) (by Morton & ststl)
- Allows refineries to use multiple ActiveAnim simultaneously (by TaranDahl)
- Electric/RadBeam trail for laser tails (by NetsuNegi)
- Ground line for select box (by NetsuNegi)

Vanilla fixes:
- Fixed sidebar not updating queued unit numbers when adding or removing units when the production is on hold (by CrimRecya)
Expand Down
Binary file added docs/_static/images/selectbox.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
61 changes: 37 additions & 24 deletions src/Ext/Techno/Body.Visuals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,50 +350,63 @@ void TechnoExt::DrawSelectBox(TechnoClass* pThis, const Point2D* pLocation, cons
if (!pSelectBox || pSelectBox->DrawAboveTechno == drawBefore)
return;

const auto pShape = pSelectBox->Shape.Get();

if (!pShape)
return;

const bool canSee = HouseClass::IsCurrentPlayerObserver() ? pSelectBox->VisibleToHouses_Observer : EnumFunctions::CanTargetHouse(pSelectBox->VisibleToHouses, pThis->Owner, HouseClass::CurrentPlayer);

if (!canSee)
return;

const auto pPalette = pSelectBox->Palette.GetOrDefaultConvert(FileSystem::PALETTE_PAL);

const double healthPercentage = pThis->GetHealthPercentage();
const Vector3D<int> frames = pSelectBox->Frames.Get(whatAmI == AbstractType::Infantry ? CoordStruct { 1,1,1 } : CoordStruct { 0,0,0 });
const int frame = healthPercentage > RulesClass::Instance->ConditionYellow ? frames.X : healthPercentage > RulesClass::Instance->ConditionRed ? frames.Y : frames.Z;
const auto defaultFrame = whatAmI == InfantryClass::AbsID ? Vector3D<int> { 1, 1, 1 } : Vector3D<int> { 0,0,0 };

Point2D drawPoint = *pLocation;
const auto pSurface = DSurface::Temp;
const auto flags = (drawBefore ? BlitterFlags::Flat | BlitterFlags::Alpha : BlitterFlags::Nonzero | BlitterFlags::MultiPass) | BlitterFlags::Centered | pSelectBox->Translucency;
const int zAdjust = drawBefore ? pThis->GetZAdjustment() - 2 : 0;
const auto pGroundShape = pSelectBox->GroundShape.Get();

if (pSelectBox->Grounded && whatAmI != BuildingClass::AbsID)
if ((pGroundShape || pSelectBox->GroundLine) && whatAmI != BuildingClass::AbsID && (pSelectBox->Ground_AlwaysDraw || pThis->IsInAir()))
{
CoordStruct coords = pThis->GetCenterCoords();
coords.Z = MapClass::Instance.GetCellFloorHeight(coords);
auto [point, visible] = TacticalClass::Instance->CoordsToClient(coords);

const auto& [outClient, visible] = TacticalClass::Instance->CoordsToClient(coords);
if (visible && pGroundShape)
{
const auto pPalette = pSelectBox->GroundPalette.GetOrDefaultConvert(FileSystem::PALETTE_PAL);

if (!visible)
return;
const Vector3D<int> frames = pSelectBox->GroundFrames.Get(defaultFrame);
const int frame = healthPercentage > RulesClass::Instance->ConditionYellow ? frames.X : healthPercentage > RulesClass::Instance->ConditionRed ? frames.Y : frames.Z;

const Point2D drawPoint = point + pSelectBox->GroundOffset;
pSurface->DrawSHP(pPalette, pGroundShape, frame, &drawPoint, pBounds, flags, 0, zAdjust, ZGradient::Ground, 1000, 0, nullptr, 0, 0, 0);
}

drawPoint = outClient;
if (pSelectBox->GroundLine)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggest to add GroundLine.AlwaysDraw too and maybe make the pattern customisable

{
Point2D start = *pLocation; // Copy to prevent be modified
const int color = Drawing::RGB_To_Int(pSelectBox->GroundLineColor.Get(healthPercentage));

if (pSelectBox->GroundLine_Dashed)
pSurface->DrawDashed(&start, &point, color, 0);
else
pSurface->DrawLine(&start, &point, color);
}
}

drawPoint += pSelectBox->Offset;
if (const auto pShape = pSelectBox->Shape.Get())
{
const auto pPalette = pSelectBox->Palette.GetOrDefaultConvert(FileSystem::PALETTE_PAL);

if (pSelectBox->DrawAboveTechno)
drawPoint.Y += pType->PixelSelectionBracketDelta;
const Vector3D<int> frames = pSelectBox->Frames.Get(defaultFrame);
const int frame = healthPercentage > RulesClass::Instance->ConditionYellow ? frames.X : healthPercentage > RulesClass::Instance->ConditionRed ? frames.Y : frames.Z;

if (whatAmI == AbstractType::Infantry)
drawPoint += { 8, -3 };
else
drawPoint += { 1, -4 };
const Point2D offset = whatAmI == InfantryClass::AbsID ? Point2D { 8, -3 } : Point2D { 1, -4 };
Point2D drawPoint = *pLocation + offset + pSelectBox->Offset;

const auto flags = BlitterFlags::Centered | BlitterFlags::Nonzero | BlitterFlags::MultiPass | pSelectBox->Translucency;
if (pSelectBox->DrawAboveTechno)
drawPoint.Y += pType->PixelSelectionBracketDelta;

DSurface::Composite->DrawSHP(pPalette, pShape, frame, &drawPoint, pBounds, flags, 0, 0, ZGradient::Ground, 1000, 0, nullptr, 0, 0, 0);
pSurface->DrawSHP(pPalette, pShape, frame, &drawPoint, pBounds, flags, 0, zAdjust, ZGradient::Ground, 1000, 0, nullptr, 0, 0, 0);
}
}

void TechnoExt::ProcessDigitalDisplays(TechnoClass* pThis)
Expand Down
18 changes: 16 additions & 2 deletions src/New/Type/SelectBoxTypeClass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,19 @@ void SelectBoxTypeClass::LoadFromINI(CCINIClass* pINI)
this->Shape.Read(exINI, pSection, "Shape");
this->Palette.LoadFromINI(pINI, pSection, "Palette");
this->Frames.Read(exINI, pSection, "Frames");
this->Grounded.Read(exINI, pSection, "Grounded");
this->Offset.Read(exINI, pSection, "Offset");
this->Translucency.Read(exINI, pSection, "Translucency");
this->VisibleToHouses.Read(exINI, pSection, "VisibleToHouses");
this->VisibleToHouses_Observer.Read(exINI, pSection, "VisibleToHouses.Observer");
this->DrawAboveTechno.Read(exINI, pSection, "DrawAboveTechno");
this->GroundShape.Read(exINI, pSection, "GroundShape");
this->GroundPalette.LoadFromINI(pINI, pSection, "GroundPalette");
this->GroundFrames.Read(exINI, pSection, "GroundFrames");
this->GroundOffset.Read(exINI, pSection, "GroundOffset");
this->Ground_AlwaysDraw.Read(exINI, pSection, "Ground.AlwaysDraw");
this->GroundLine.Read(exINI, pSection, "GroundLine");
this->GroundLineColor.Read(exINI, pSection, "GroundLineColor.%s");
this->GroundLine_Dashed.Read(exINI, pSection, "GroundLine.Dashed");
}

template <typename T>
Expand All @@ -33,12 +40,19 @@ void SelectBoxTypeClass::Serialize(T& Stm)
.Process(this->Shape)
.Process(this->Palette)
.Process(this->Frames)
.Process(this->Grounded)
.Process(this->Offset)
.Process(this->Translucency)
.Process(this->VisibleToHouses)
.Process(this->VisibleToHouses_Observer)
.Process(this->DrawAboveTechno)
.Process(this->GroundShape)
.Process(this->GroundPalette)
.Process(this->GroundFrames)
.Process(this->GroundOffset)
.Process(this->Ground_AlwaysDraw)
.Process(this->GroundLine)
.Process(this->GroundLineColor)
.Process(this->GroundLine_Dashed)
;
}

Expand Down
18 changes: 16 additions & 2 deletions src/New/Type/SelectBoxTypeClass.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,37 @@ class SelectBoxTypeClass final : public Enumerable<SelectBoxTypeClass>
Valueable<SHPStruct*> Shape;
CustomPalette Palette;
Nullable<Vector3D<int>> Frames;
Valueable<bool> Grounded;
Valueable<Point2D> Offset;
TranslucencyLevel Translucency;
Valueable<AffectedHouse> VisibleToHouses;
Valueable<bool> VisibleToHouses_Observer;
Valueable<bool> DrawAboveTechno;
Valueable<SHPStruct*> GroundShape;
CustomPalette GroundPalette;
Nullable<Vector3D<int>> GroundFrames;
Valueable<Point2D> GroundOffset;
Valueable<bool> Ground_AlwaysDraw;
Valueable<bool> GroundLine;
Damageable<ColorStruct> GroundLineColor;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the fact that it's Damageable is not indicated in docs, maybe Shape and GroundShape should also be Damageable then too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, I did

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh I missed that, pardon
what about the shapes being Damageable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need that just control by frame index

Valueable<bool> GroundLine_Dashed;

SelectBoxTypeClass(const char* pTitle = NONE_STR) : Enumerable<SelectBoxTypeClass>(pTitle)
, Shape { FileSystem::LoadSHPFile("select.shp") }
, Palette {}
, Frames {}
, Grounded { false }
, Offset { Point2D::Empty }
, Translucency { 0 }
, VisibleToHouses { AffectedHouse::All }
, VisibleToHouses_Observer { true }
, DrawAboveTechno { true }
, GroundShape { nullptr }
, GroundPalette {}
, GroundFrames {}
, GroundOffset { Point2D::Empty }
, Ground_AlwaysDraw { true }
, GroundLine { false }
, GroundLineColor { { 0,255,0 } }
, GroundLine_Dashed { false}
{ }

void LoadFromINI(CCINIClass* pINI);
Expand Down