Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cpp-project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
David Maul
cpp-project
Commits
cfab59a6
Commit
cfab59a6
authored
6 months ago
by
Lorenz Martin Diel
Browse files
Options
Downloads
Patches
Plain Diff
Info now only shows if it is chosen in the context menu
parent
24d94fbc
Branches
Branches containing commit
No related tags found
2 merge requests
!36
Unit info menu
,
!29
Merge main into box2d to implement physics
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/game/Level.cpp
+26
-19
26 additions, 19 deletions
src/game/Level.cpp
src/game/Level.hpp
+2
-0
2 additions, 0 deletions
src/game/Level.hpp
src/game/Unit.hpp
+1
-0
1 addition, 0 deletions
src/game/Unit.hpp
src/game/ui/UnitInfoMenu.cpp
+17
-17
17 additions, 17 deletions
src/game/ui/UnitInfoMenu.cpp
with
46 additions
and
36 deletions
src/game/Level.cpp
+
26
−
19
View file @
cfab59a6
...
...
@@ -138,12 +138,15 @@ std::pair<int, int> Level::calcTilePos(int mouseX, int mouseY)
return
{
tileX
,
tileY
};
}
void
Level
::
selectEntity
(
int
x
,
int
y
)
{
void
Level
::
selectEntity
(
int
x
,
int
y
)
{
std
::
pair
<
int
,
int
>
tilePos
=
calcTilePos
(
x
,
y
);
if
((
m_selectedUnit
=
selectUnit
(
tilePos
.
first
,
tilePos
.
second
))
>=
0
)
{
if
((
m_selectedUnit
=
selectUnit
(
tilePos
.
first
,
tilePos
.
second
))
>=
0
)
{
auto
it
=
m_units
.
find
(
m_selectedUnit
);
if
(
it
!=
m_units
.
end
())
{
if
(
it
!=
m_units
.
end
())
{
Unit
&
unit
=
it
->
second
;
m_unitInfoMenu
.
setUnit
(
unit
);
// Position das Menu rechts neben der ausgewählten Einheit
...
...
@@ -154,7 +157,8 @@ void Level::selectEntity(int x, int y) {
}
return
;
}
if
((
m_selectedBuilding
=
selectBuilding
(
tilePos
.
first
,
tilePos
.
second
))
>=
0
)
{
if
((
m_selectedBuilding
=
selectBuilding
(
tilePos
.
first
,
tilePos
.
second
))
>=
0
)
{
// Optionale Handhabung für Gebäude
return
;
}
...
...
@@ -356,13 +360,10 @@ void Level::render(Engine& engine)
m_recruitingMenu
.
render
(
engine
);
}
if
(
m_showUnitInfoMenu
)
{
m_unitInfoMenu
.
render
(
engine
);
}
m_currentPos
.
render
(
engine
);
}
...
...
@@ -695,6 +696,7 @@ void Level::handleMenuActiveEvents(Engine& engine, SDL_Event& event)
m_state
=
LevelState
::
SELECTING_STATE
;
m_showAttackableTiles
=
false
;
m_showReachableTiles
=
false
;
m_showUnitInfoMenu
=
false
;
}
if
(
event
.
key
.
keysym
.
sym
==
SDLK_UP
||
event
.
key
.
keysym
.
sym
==
SDLK_DOWN
)
{
...
...
@@ -706,15 +708,18 @@ void Level::handleMenuActiveEvents(Engine& engine, SDL_Event& event)
if
(
cmd
==
"Wait"
)
{
m_state
=
LevelState
::
SELECTING_STATE
;
m_showUnitInfoMenu
=
false
;
}
if
(
cmd
==
"Move"
)
{
m_state
=
LevelState
::
MOVEMENT_STATE
;
m_showUnitInfoMenu
=
false
;
// Hier Pathfinding einsetzen
}
if
(
cmd
==
"Attack"
)
{
m_state
=
LevelState
::
ATTACKING_STATE
;
m_showUnitInfoMenu
=
false
;
}
if
(
cmd
==
"Info"
)
{
...
...
@@ -723,6 +728,7 @@ void Level::handleMenuActiveEvents(Engine& engine, SDL_Event& event)
{
Unit
&
u
=
m_units
.
at
(
m_selectedUnit
);
std
::
cout
<<
"Health: "
<<
u
.
m_health
<<
std
::
endl
;
m_showUnitInfoMenu
=
!
m_showUnitInfoMenu
;
}
if
(
m_selectedBuilding
>
-
1
)
{
...
...
@@ -751,6 +757,7 @@ void Level::handleMenuActiveEvents(Engine& engine, SDL_Event& event)
m_showAttackableTiles
=
false
;
m_showReachableTiles
=
false
;
changeTurn
();
m_showUnitInfoMenu
=
false
;
}
}
...
...
This diff is collapsed.
Click to expand it.
src/game/Level.hpp
+
2
−
0
View file @
cfab59a6
...
...
@@ -168,6 +168,8 @@ class Level : public Scene
void
handlePositionMarker
(
Engine
&
engine
,
SDL_Event
&
event
);
UnitInfoMenu
m_unitInfoMenu
;
bool
m_showUnitInfoMenu
=
false
;
};
}
// namespace advanced_wars
This diff is collapsed.
Click to expand it.
src/game/Unit.hpp
+
1
−
0
View file @
cfab59a6
...
...
@@ -125,6 +125,7 @@ class Unit
int
getAmmo
()
const
{
return
m_ammo
;
}
int
getHealth
()
const
{
return
m_health
;
}
UnitId
getId
()
const
{
return
m_id
;}
void
setState
(
UnitState
state
);
...
...
This diff is collapsed.
Click to expand it.
src/game/ui/UnitInfoMenu.cpp
+
17
−
17
View file @
cfab59a6
...
...
@@ -10,20 +10,20 @@ namespace advanced_wars
UnitInfoMenu
::
UnitInfoMenu
()
:
m_currentUnit
(
nullptr
)
{
}
std
::
string
UnitInfoMenu
::
getMovementTypeString
(
MovementType
type
)
{
switch
(
type
)
{
std
::
string
UnitInfoMenu
::
getMovementTypeString
(
MovementType
type
)
{
switch
(
type
)
{
case
MovementType
::
FOOT
:
return
"Foot"
;
case
MovementType
::
WHEELED
:
return
"Wheeled"
;
case
MovementType
::
TREAD
:
return
"Tracked"
;
case
MovementType
::
SEA
:
return
"Ship"
;
case
MovementType
::
AIR
:
return
"Aircraft"
;
case
MovementType
::
SEA
:
return
"Ship"
;
case
MovementType
::
LANDER
:
return
"Lander"
;
default:
return
"Unknown"
;
}
...
...
@@ -84,7 +84,7 @@ void UnitInfoMenu::render(Engine& engine)
Spritesheet
*
spritesheet
=
engine
.
getSpritesheet
();
SDL_Texture
*
unit_texture
=
spritesheet
->
getUnitTextures
()
.
at
(
static_cast
<
int
>
(
m_currentUnit
->
getFaction
()))
.
at
(
static_cast
<
int
>
(
UnitId
::
INFANTERY
))
.
at
(
static_cast
<
int
>
(
m_currentUnit
->
getId
()
))
.
at
(
static_cast
<
int
>
(
UnitState
::
IDLE
))
.
first
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment