Skip to content

Commit

Permalink
Merge pull request #466 from Wargus/enum
Browse files Browse the repository at this point in the history
Use even more enum class
  • Loading branch information
Jarod42 committed Aug 14, 2023
2 parents 3858165 + 949828d commit 1d38b6c
Show file tree
Hide file tree
Showing 13 changed files with 205 additions and 205 deletions.
32 changes: 16 additions & 16 deletions src/editor/editloop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1060,7 +1060,7 @@ void EditorUpdateDisplay()
UI.Fillers[i].G->DrawClip(UI.Fillers[i].X, UI.Fillers[i].Y);
}

if (CursorOn == CursorOnMap && Gui->getTop() == editorContainer && !GamePaused) {
if (CursorOn == ECursorOn::Map && Gui->getTop() == editorContainer && !GamePaused) {
DrawMapCursor(); // cursor on map
}

Expand Down Expand Up @@ -1089,7 +1089,7 @@ void EditorUpdateDisplay()
}
DrawEditorPanel();

if (CursorOn == CursorOnMap) {
if (CursorOn == ECursorOn::Map) {
DrawEditorInfo();
}

Expand Down Expand Up @@ -1198,14 +1198,14 @@ static void EditorCallbackButtonDown(unsigned button)
return;
}
// Click on menu button
if (CursorOn == CursorOnButton && ButtonAreaUnderCursor == ButtonArea::Menu &&
if (CursorOn == ECursorOn::Button && ButtonAreaUnderCursor == ButtonArea::Menu &&
(MouseButtons & LeftButton) && !GameMenuButtonClicked) {
PlayGameSound(GameSounds.Click.Sound, MaxSampleVolume);
GameMenuButtonClicked = true;
return;
}
// Click on minimap
if (CursorOn == CursorOnMinimap) {
if (CursorOn == ECursorOn::Minimap) {
if (MouseButtons & LeftButton) { // enter move mini-mode
const Vec2i tilePos = UI.Minimap.ScreenToTilePos(CursorScreenPos);
UI.SelectedViewport->Center(Map.TilePosToMapPixelPos_Center(tilePos));
Expand All @@ -1214,7 +1214,7 @@ static void EditorCallbackButtonDown(unsigned button)
}
// Click on tile area
if (Editor.State == EditorStateType::EditTile) {
if (CursorOn == CursorOnButton && ButtonUnderCursor >= 100) {
if (CursorOn == ECursorOn::Button && ButtonUnderCursor >= 100) {
switch (ButtonUnderCursor) {
case 300: TileCursorSize = 1; return;
case 301: TileCursorSize = 2; return;
Expand Down Expand Up @@ -1318,7 +1318,7 @@ static void EditorCallbackButtonDown(unsigned button)
}

// Click on map area
if (CursorOn == CursorOnMap) {
if (CursorOn == ECursorOn::Map) {
if (MouseButtons & RightButton) {
if (Editor.State == EditorStateType::EditUnit && Editor.SelectedUnitIndex != -1) {
Editor.SelectedUnitIndex = -1;
Expand Down Expand Up @@ -1661,7 +1661,7 @@ static bool EditorCallbackMouse_EditTileArea(const PixelPos &screenPos)
bool noHit = forEachTileOptionArea([screenPos](bool active, std::string &label, int i, int x, int y, int w, int h) {
if (x < screenPos.x && screenPos.x < x + w && y < screenPos.y && screenPos.y < y + h) {
ButtonUnderCursor = i + 300;
CursorOn = CursorOnButton;
CursorOn = ECursorOn::Button;
return false;
}
return true;
Expand Down Expand Up @@ -1740,7 +1740,7 @@ static void EditorCallbackMouse(const PixelPos &pos)
UnitPlacedThisPress = false;
}
// Drawing tiles on map.
if (CursorOn == CursorOnMap && (MouseButtons & LeftButton)
if (CursorOn == ECursorOn::Map && (MouseButtons & LeftButton)
&& (Editor.State == EditorStateType::EditTile || Editor.State == EditorStateType::EditUnit)) {
Vec2i vpTilePos = UI.SelectedViewport->MapPos;
// Scroll the map
Expand Down Expand Up @@ -1779,7 +1779,7 @@ static void EditorCallbackMouse(const PixelPos &pos)
}

// Minimap move viewpoint
if (CursorOn == CursorOnMinimap && (MouseButtons & LeftButton)) {
if (CursorOn == ECursorOn::Minimap && (MouseButtons & LeftButton)) {
RestrictCursorToMinimap();
const Vec2i tilePos = UI.Minimap.ScreenToTilePos(CursorScreenPos);

Expand All @@ -1789,7 +1789,7 @@ static void EditorCallbackMouse(const PixelPos &pos)

MouseScrollState = ScrollNone;
GameCursor = UI.Point.Cursor;
CursorOn = CursorOnUnknown;
CursorOn = ECursorOn::Unknown;
Editor.CursorPlayer = -1;
Editor.CursorUnitIndex = -1;
Editor.CursorTileIndex = -1;
Expand All @@ -1798,7 +1798,7 @@ static void EditorCallbackMouse(const PixelPos &pos)

// Minimap
if (UI.Minimap.Contains(screenPos)) {
CursorOn = CursorOnMinimap;
CursorOn = ECursorOn::Minimap;
}
// Handle edit unit area
if (Editor.State == EditorStateType::EditUnit || Editor.State == EditorStateType::SetStartLocation) {
Expand All @@ -1817,15 +1817,15 @@ static void EditorCallbackMouse(const PixelPos &pos)
if (UI.MenuButton.X != -1 && UI.MenuButton.Contains(screenPos)) {
ButtonAreaUnderCursor = ButtonArea::Menu;
ButtonUnderCursor = ButtonUnderMenu;
CursorOn = CursorOnButton;
CursorOn = ECursorOn::Button;
return;
} else {
ButtonAreaUnderCursor.reset();
}

// Minimap
if (UI.Minimap.Contains(screenPos)) {
CursorOn = CursorOnMinimap;
CursorOn = ECursorOn::Minimap;
return;
}

Expand All @@ -1839,7 +1839,7 @@ static void EditorCallbackMouse(const PixelPos &pos)
DebugPrint("active viewport changed to %ld.\n" _C_
static_cast<long int>(UI.Viewports - vp));
}
CursorOn = CursorOnMap;
CursorOn = ECursorOn::Map;

// Look if there is an unit under the cursor.
const PixelPos cursorMapPos = UI.MouseViewport->ScreenToMapPixelPos(CursorScreenPos);
Expand Down Expand Up @@ -2253,10 +2253,10 @@ void EditorMainLoop()
}
}
if (UI.KeyScroll) {
if (CursorOn == CursorOnMap) {
if (CursorOn == ECursorOn::Map) {
DoScrollArea(KeyScrollState, (KeyModifiers & ModifierControl) != 0, MouseScrollState == 0 && KeyScrollState > 0);
}
if (CursorOn == CursorOnMap && (MouseButtons & LeftButton) &&
if (CursorOn == ECursorOn::Map && (MouseButtons & LeftButton) &&
(Editor.State == EditorStateType::EditTile ||
Editor.State == EditorStateType::EditUnit)) {
EditorCallbackButtonDown(0);
Expand Down
28 changes: 14 additions & 14 deletions src/include/interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,19 +173,19 @@ constexpr unsigned int MiddleAndRightButton =
(MiddleButton | RightButton); /// Middle + Right button on mouse

/// Where is our cursor ?
enum _cursor_on_ {
CursorOnUnknown = -1, /// not known
CursorOnMinimap, /// minimap area
CursorOnButton, /// button area see: ButtonUnderCursor
CursorOnMap, /// over map area
CursorOnScrollUp, /// in scroll up area
CursorOnScrollDown, /// in scroll down area
CursorOnScrollLeft, /// in scroll left area
CursorOnScrollRight, /// in scroll right area
CursorOnScrollLeftUp, /// in scroll left+up area
CursorOnScrollLeftDown, /// in scroll left+down area
CursorOnScrollRightUp, /// in scroll right+up area
CursorOnScrollRightDown /// in scroll right+down area
enum class ECursorOn {
Unknown = -1, /// not known
Minimap, /// minimap area
Button, /// button area see: ButtonUnderCursor
Map, /// over map area
ScrollUp, /// in scroll up area
ScrollDown, /// in scroll down area
ScrollLeft, /// in scroll left area
ScrollRight, /// in scroll right area
ScrollLeftUp, /// in scroll left+up area
ScrollLeftDown, /// in scroll left+down area
ScrollRightUp, /// in scroll right+up area
ScrollRightDown /// in scroll right+down area
};

/// Are We Scrolling With the Keyboard ?
Expand Down Expand Up @@ -248,7 +248,7 @@ extern bool GameDiplomacyButtonClicked;
/// Mouse leaves windows stops scroll
extern bool LeaveStops;
/// current CursorOn field
extern enum _cursor_on_ CursorOn;
extern ECursorOn CursorOn;

/// vladi: used for unit buttons sub-menus etc
extern int CurrentButtonLevel;
Expand Down
7 changes: 0 additions & 7 deletions src/include/iolib.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,6 @@ class CFile
PImpl *pimpl;
};

enum {
CLF_TYPE_INVALID, /// invalid file handle
CLF_TYPE_PLAIN, /// plain text file handle
CLF_TYPE_GZIP, /// gzip file handle
CLF_TYPE_BZIP2 /// bzip2 file handle
};

#define CL_OPEN_READ 0x1
#define CL_OPEN_WRITE 0x2
#define CL_WRITE_GZ 0x4
Expand Down
45 changes: 23 additions & 22 deletions src/include/missile.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
**
** Class of the missile-type, defines the basic effects of the
** missile. Look at the different class identifiers for more
** information (::MissileClassNone, ...).
** information (::MissileClass::None, ...).
**
** MissileType::NumBounces
**
Expand Down Expand Up @@ -134,7 +134,7 @@
** animation step. The real use of this member depends on the
** MissileType::Class
** @note This is currently only used by the point-to-point
** missiles (::MissileClassPointToPoint, ...). Perhaps we should
** missiles (::MissileClass::PointToPoint, ...). Perhaps we should
** later allow animation scripts for more complex animations.
**
** MissileType::Range
Expand Down Expand Up @@ -318,25 +318,26 @@ class LuaCallback;
/**
** Missile-class this defines how a missile-type reacts.
*/
enum {
MissileClassNone, /// Missile does nothing
MissileClassPointToPoint, /// Missile flies from x,y to x1,y1
MissileClassPointToPointWithHit, /// Missile flies from x,y to x1,y1 than shows hit animation.
MissileClassPointToPointCycleOnce, /// Missile flies from x,y to x1,y1 and animates ONCE from start to finish and back
MissileClassPointToPointBounce, /// Missile flies from x,y to x1,y1 than bounces three times.
MissileClassStay, /// Missile appears at x,y, does it's anim and vanishes.
MissileClassCycleOnce, /// Missile appears at x,y, then cycle through the frames once.
MissileClassFire, /// Missile doesn't move, than checks the source unit for HP.
MissileClassHit, /// Missile shows the hit points.
MissileClassParabolic, /// Missile flies from x,y to x1,y1 using a parabolic path
MissileClassLandMine, /// Missile wait on x,y until a non-air unit comes by, the explodes.
MissileClassWhirlwind, /// Missile appears at x,y, is whirlwind
MissileClassFlameShield, /// Missile surround x,y
MissileClassDeathCoil, /// Missile is death coil.
MissileClassTracer, /// Missile seeks towards to target unit
MissileClassClipToTarget, /// Missile remains clipped to target's current goal and plays his animation once
MissileClassContinious, /// Missile stays and plays it's animation several times
MissileClassStraightFly /// Missile flies from x,y to x1,y1 then continues to fly, until incompatible terrain is detected
enum class MissileClass
{
None, /// Missile does nothing
PointToPoint, /// Missile flies from x,y to x1,y1
PointToPointWithHit, /// Missile flies from x,y to x1,y1 than shows hit animation.
PointToPointCycleOnce, /// Missile flies from x,y to x1,y1 and animates ONCE from start to finish and back
PointToPointBounce, /// Missile flies from x,y to x1,y1 than bounces three times.
Stay, /// Missile appears at x,y, does it's anim and vanishes.
CycleOnce, /// Missile appears at x,y, then cycle through the frames once.
Fire, /// Missile doesn't move, than checks the source unit for HP.
Hit, /// Missile shows the hit points.
Parabolic, /// Missile flies from x,y to x1,y1 using a parabolic path
LandMine, /// Missile wait on x,y until a non-air unit comes by, the explodes.
Whirlwind, /// Missile appears at x,y, is whirlwind
FlameShield, /// Missile surround x,y
DeathCoil, /// Missile is death coil.
Tracer, /// Missile seeks towards to target unit
ClipToTarget, /// Missile remains clipped to target's current goal and plays his animation once
Continuous, /// Missile stays and plays it's animation several times
StraightFly /// Missile flies from x,y to x1,y1 then continues to fly, until incompatible terrain is detected
};

/// Base structure of missile-types
Expand Down Expand Up @@ -380,7 +381,7 @@ class MissileType
bool IgnoreWalls; /// missile ignores Wall units on it's way
bool KillFirstUnit; /// missile kills first unit blocking it's way

int Class; /// missile class
MissileClass Class; /// missile class
int NumBounces; /// number of bounces
int ParabolCoefficient; /// parabol coefficient in parabolic missile
int StartDelay; /// missile start delay
Expand Down
2 changes: 1 addition & 1 deletion src/map/map_draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ void CViewport::Draw(const fieldHighlightChecker highlightChecker /* = nullptr *
//
// Draw unit's name popup
//
if (CursorOn == CursorOnMap && Preference.ShowNameDelay && (ShowNameDelay < GameCycle) && (GameCycle < ShowNameTime)) {
if (CursorOn == ECursorOn::Map && Preference.ShowNameDelay && (ShowNameDelay < GameCycle) && (GameCycle < ShowNameTime)) {
const Vec2i tilePos = this->ScreenToTilePos(CursorScreenPos);
const bool isMapFieldVisile = Map.Field(tilePos)->playerInfo.IsTeamVisible(*ThisPlayer);

Expand Down
40 changes: 20 additions & 20 deletions src/missile/missile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,58 +175,58 @@ Missile::Missile() :
Missile *missile = nullptr;

switch (mtype.Class) {
case MissileClassNone :
case MissileClass::None :
missile = new MissileNone;
break;
case MissileClassPointToPoint :
case MissileClass::PointToPoint :
missile = new MissilePointToPoint;
break;
case MissileClassPointToPointWithHit :
case MissileClass::PointToPointWithHit :
missile = new MissilePointToPointWithHit;
break;
case MissileClassPointToPointCycleOnce :
case MissileClass::PointToPointCycleOnce :
missile = new MissilePointToPointCycleOnce;
break;
case MissileClassPointToPointBounce :
case MissileClass::PointToPointBounce :
missile = new MissilePointToPointBounce;
break;
case MissileClassStay :
case MissileClass::Stay :
missile = new MissileStay;
break;
case MissileClassCycleOnce :
case MissileClass::CycleOnce :
missile = new MissileCycleOnce;
break;
case MissileClassFire :
case MissileClass::Fire :
missile = new MissileFire;
break;
case MissileClassHit :
case MissileClass::Hit :
missile = new ::MissileHit;
break;
case MissileClassParabolic :
case MissileClass::Parabolic :
missile = new MissileParabolic;
break;
case MissileClassLandMine :
case MissileClass::LandMine :
missile = new MissileLandMine;
break;
case MissileClassWhirlwind :
case MissileClass::Whirlwind :
missile = new MissileWhirlwind;
break;
case MissileClassFlameShield :
case MissileClass::FlameShield :
missile = new MissileFlameShield;
break;
case MissileClassDeathCoil :
case MissileClass::DeathCoil :
missile = new MissileDeathCoil;
break;
case MissileClassTracer :
case MissileClass::Tracer :
missile = new MissileTracer;
break;
case MissileClassClipToTarget :
case MissileClass::ClipToTarget :
missile = new MissileClipToTarget;
break;
case MissileClassContinious :
case MissileClass::Continuous :
missile = new MissileContinious;
break;
case MissileClassStraightFly :
case MissileClass::StraightFly :
missile = new MissileStraightFly;
break;
}
Expand Down Expand Up @@ -370,7 +370,7 @@ void FireMissile(CUnit &unit, CUnit *goal, const Vec2i &goalPos)

// No missile hits immediately!
if (
unit.Type->Missile.Missile->Class == MissileClassNone
unit.Type->Missile.Missile->Class == MissileClass::None
|| (unit.Type->Animations && unit.Type->Animations->Attack && unit.Type->Animations->RangedAttack && !unit.IsAttackRanged(goal, goalPos)) // treat melee attacks from units that have both attack and ranged attack animations as having missile class none
) {
// No goal, take target coordinates
Expand Down Expand Up @@ -548,7 +548,7 @@ void Missile::DrawMissile(const CViewport &vp) const
const PixelPos screenPixelPos = vp.MapToScreenPixelPos(this->position);

switch (this->Type->Class) {
case MissileClassHit:
case MissileClass::Hit:
CLabel(GetGameFont()).DrawClip(screenPixelPos.x, screenPixelPos.y, this->Damage);
break;
default:
Expand Down
Loading

0 comments on commit 1d38b6c

Please sign in to comment.