Skip to content

Commit 1be2d46

Browse files
NetsuNegiCrimRecya
andauthored
Ground line for select box (#1717)
- `Grounded` has been abandoned, 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`. - `Grounded` 已经被废弃了,你现在可以通过 `GroundShape` 指定一个始终绘制在地面的图像,若 `Ground.AlwaysDraw=false` ,那么它只会在单位位于空中时绘制,这也影响 `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. - 若 `GroundLine=true` ,那么游戏将会绘制一条从单位的位置到其垂直投影的线,`GroundLine.Dashed=true` 意味着投影线为虚线。 In `rulesmd.ini`: ```ini [SOMESELECTBOXTYPE] ; Select box Type name 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 ``` ![W@`N 6J G9@UM4MURW`LFIF](https://github.com/user-attachments/assets/d446947f-4afc-444d-91ee-b4ed35d7d387) --------- Co-authored-by: CrimRecya <[email protected]>
1 parent cb3a281 commit 1be2d46

File tree

8 files changed

+89
-30
lines changed

8 files changed

+89
-30
lines changed

CREDITS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,7 @@ This page lists all the individual contributions to the project by their author.
417417
- Fix the bug that damaged particle dont disappear after building has repaired by engineer
418418
- Display banner improvement
419419
- Electric/RadBeam trail for laser tails
420+
- Ground line for select box
420421
- **Apollo** - Translucent SHP drawing patches
421422
- **ststl**:
422423
- Customizable `ShowTimer` priority of superweapons

YRpp

docs/User-Interface.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,12 +284,16 @@ RealTimeTimers.Adaptive=false ; boolean
284284

285285
### Select Box
286286

287+
![selectbox](_static/images/selectbox.png)
288+
287289
- 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.
288290
- `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.
289291
- If `Grounded` set to true, the select box will be drawn on the ground below the TechnoType.
290292
- Select box's translucency setting can be adjusted via `Translucency`.
291293
- `VisibleToHouses` and `VisibleToHouses.Observer` can limit visibility to specific players.
292294
- `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`.
295+
- 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`.
296+
- 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.
293297

294298
In `rulesmd.ini`:
295299
```ini
@@ -304,12 +308,21 @@ DefaultUnitSelectBox= ; Select box for vehicle and aircraft
304308
Shape=select.shp ; filename with .shp extension
305309
Palette=palette.pal ; filename with .pal extension
306310
Frames= ; List of integer, default 1,1,1 for infantry, 0,0,0 for vehicle and aircraft
307-
Grounded=false ; boolean
308311
Offset=0,0 ; integers - horizontal, vertical
309312
Translucency=0 ; translucency level (0/25/50/75)
310313
VisibleToHouses=all ; Affected House Enumeration (none|owner/self|allies/ally|team|enemies/enemy|all)
311314
VisibleToHouses.Observer=true ; boolean
312315
DrawAboveTechno=true ; boolean
316+
GroundShape= ; filename with .shp extension
317+
GroundPalette=palette.pal ; filename with .pal extension
318+
GroundFrames= ; List of integer, default 1,1,1 for infantry, 0,0,0 for vehicle and aircraft
319+
GroundOffset=0,0 ; integers - horizontal, vertical
320+
Ground.AlwaysDraw=true ; boolean
321+
GroundLine=false ; boolean
322+
GroundLineColor=0,255,0 ; R, G, B
323+
GroundLineColor.ConditionYellow= ; R, G, B
324+
GroundLineColor.ConditionRed= ; R, G, B
325+
GroundLine.Dashed=false ; boolean
313326

314327
[SOMETECHNO] ; TechnoType
315328
SelectBox= ; Select box

docs/Whats-New.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,12 @@ New:
406406
- [Display banner](AI-Scripting-and-Mapping.md#display-banner) (by Morton & ststl)
407407
- [Allows refineries to use multiple ActiveAnim simultaneously](Fixed-or-Improved-Logics.md#allows-refineries-to-use-multiple-activeanim-simultaneously) (by TaranDahl)
408408
- Electric/RadBeam trail for laser tails (by NetsuNegi)
409+
<<<<<<< HEAD
410+
- Ground line for select box (by NetsuNegi)
411+
=======
409412
- Add `DebrisMinimums` to keep the count of debris within a certain range (by CrimRecya)
410413
- Several attackmove related enhancement (by TaranDahl)
414+
>>>>>>> upstream/develop
411415
412416
Vanilla fixes:
413417
- Fixed sidebar not updating queued unit numbers when adding or removing units when the production is on hold (by CrimRecya)

docs/_static/images/selectbox.png

252 KB
Loading

src/Ext/Techno/Body.Visuals.cpp

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -350,50 +350,63 @@ void TechnoExt::DrawSelectBox(TechnoClass* pThis, const Point2D* pLocation, cons
350350
if (!pSelectBox || pSelectBox->DrawAboveTechno == drawBefore)
351351
return;
352352

353-
const auto pShape = pSelectBox->Shape.Get();
354-
355-
if (!pShape)
356-
return;
357-
358353
const bool canSee = HouseClass::IsCurrentPlayerObserver() ? pSelectBox->VisibleToHouses_Observer : EnumFunctions::CanTargetHouse(pSelectBox->VisibleToHouses, pThis->Owner, HouseClass::CurrentPlayer);
359354

360355
if (!canSee)
361356
return;
362357

363-
const auto pPalette = pSelectBox->Palette.GetOrDefaultConvert(FileSystem::PALETTE_PAL);
364-
365358
const double healthPercentage = pThis->GetHealthPercentage();
366-
const Vector3D<int> frames = pSelectBox->Frames.Get(whatAmI == AbstractType::Infantry ? CoordStruct { 1,1,1 } : CoordStruct { 0,0,0 });
367-
const int frame = healthPercentage > RulesClass::Instance->ConditionYellow ? frames.X : healthPercentage > RulesClass::Instance->ConditionRed ? frames.Y : frames.Z;
359+
const auto defaultFrame = whatAmI == InfantryClass::AbsID ? Vector3D<int> { 1, 1, 1 } : Vector3D<int> { 0, 0, 0 };
368360

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

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

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

378-
if (!visible)
379-
return;
376+
const Vector3D<int> frames = pSelectBox->GroundFrames.Get(defaultFrame);
377+
const int frame = healthPercentage > RulesClass::Instance->ConditionYellow ? frames.X : healthPercentage > RulesClass::Instance->ConditionRed ? frames.Y : frames.Z;
378+
379+
const Point2D drawPoint = point + pSelectBox->GroundOffset;
380+
pSurface->DrawSHP(pPalette, pGroundShape, frame, &drawPoint, pBounds, flags, 0, zAdjust, ZGradient::Ground, 1000, 0, nullptr, 0, 0, 0);
381+
}
380382

381-
drawPoint = outClient;
383+
if (pSelectBox->GroundLine)
384+
{
385+
Point2D start = *pLocation; // Copy to prevent be modified
386+
const int color = Drawing::RGB_To_Int(pSelectBox->GroundLineColor.Get(healthPercentage));
387+
388+
if (pSelectBox->GroundLine_Dashed)
389+
pSurface->DrawDashed(&start, &point, color, 0);
390+
else
391+
pSurface->DrawLine(&start, &point, color);
392+
}
382393
}
383394

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

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

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

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

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

399412
void TechnoExt::ProcessDigitalDisplays(TechnoClass* pThis)

src/New/Type/SelectBoxTypeClass.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,19 @@ void SelectBoxTypeClass::LoadFromINI(CCINIClass* pINI)
1818
this->Shape.Read(exINI, pSection, "Shape");
1919
this->Palette.LoadFromINI(pINI, pSection, "Palette");
2020
this->Frames.Read(exINI, pSection, "Frames");
21-
this->Grounded.Read(exINI, pSection, "Grounded");
2221
this->Offset.Read(exINI, pSection, "Offset");
2322
this->Translucency.Read(exINI, pSection, "Translucency");
2423
this->VisibleToHouses.Read(exINI, pSection, "VisibleToHouses");
2524
this->VisibleToHouses_Observer.Read(exINI, pSection, "VisibleToHouses.Observer");
2625
this->DrawAboveTechno.Read(exINI, pSection, "DrawAboveTechno");
26+
this->GroundShape.Read(exINI, pSection, "GroundShape");
27+
this->GroundPalette.LoadFromINI(pINI, pSection, "GroundPalette");
28+
this->GroundFrames.Read(exINI, pSection, "GroundFrames");
29+
this->GroundOffset.Read(exINI, pSection, "GroundOffset");
30+
this->Ground_AlwaysDraw.Read(exINI, pSection, "Ground.AlwaysDraw");
31+
this->GroundLine.Read(exINI, pSection, "GroundLine");
32+
this->GroundLineColor.Read(exINI, pSection, "GroundLineColor.%s");
33+
this->GroundLine_Dashed.Read(exINI, pSection, "GroundLine.Dashed");
2734
}
2835

2936
template <typename T>
@@ -33,12 +40,19 @@ void SelectBoxTypeClass::Serialize(T& Stm)
3340
.Process(this->Shape)
3441
.Process(this->Palette)
3542
.Process(this->Frames)
36-
.Process(this->Grounded)
3743
.Process(this->Offset)
3844
.Process(this->Translucency)
3945
.Process(this->VisibleToHouses)
4046
.Process(this->VisibleToHouses_Observer)
4147
.Process(this->DrawAboveTechno)
48+
.Process(this->GroundShape)
49+
.Process(this->GroundPalette)
50+
.Process(this->GroundFrames)
51+
.Process(this->GroundOffset)
52+
.Process(this->Ground_AlwaysDraw)
53+
.Process(this->GroundLine)
54+
.Process(this->GroundLineColor)
55+
.Process(this->GroundLine_Dashed)
4256
;
4357
}
4458

src/New/Type/SelectBoxTypeClass.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,37 @@ class SelectBoxTypeClass final : public Enumerable<SelectBoxTypeClass>
1010
Valueable<SHPStruct*> Shape;
1111
CustomPalette Palette;
1212
Nullable<Vector3D<int>> Frames;
13-
Valueable<bool> Grounded;
1413
Valueable<Point2D> Offset;
1514
TranslucencyLevel Translucency;
1615
Valueable<AffectedHouse> VisibleToHouses;
1716
Valueable<bool> VisibleToHouses_Observer;
1817
Valueable<bool> DrawAboveTechno;
18+
Valueable<SHPStruct*> GroundShape;
19+
CustomPalette GroundPalette;
20+
Nullable<Vector3D<int>> GroundFrames;
21+
Valueable<Point2D> GroundOffset;
22+
Valueable<bool> Ground_AlwaysDraw;
23+
Valueable<bool> GroundLine;
24+
Damageable<ColorStruct> GroundLineColor;
25+
Valueable<bool> GroundLine_Dashed;
1926

2027
SelectBoxTypeClass(const char* pTitle = NONE_STR) : Enumerable<SelectBoxTypeClass>(pTitle)
2128
, Shape { FileSystem::LoadSHPFile("select.shp") }
2229
, Palette {}
2330
, Frames {}
24-
, Grounded { false }
2531
, Offset { Point2D::Empty }
2632
, Translucency { 0 }
2733
, VisibleToHouses { AffectedHouse::All }
2834
, VisibleToHouses_Observer { true }
2935
, DrawAboveTechno { true }
36+
, GroundShape { nullptr }
37+
, GroundPalette {}
38+
, GroundFrames {}
39+
, GroundOffset { Point2D::Empty }
40+
, Ground_AlwaysDraw { true }
41+
, GroundLine { false }
42+
, GroundLineColor { { 0,255,0 } }
43+
, GroundLine_Dashed { false}
3044
{ }
3145

3246
void LoadFromINI(CCINIClass* pINI);

0 commit comments

Comments
 (0)