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
4abb8ad5
Commit
4abb8ad5
authored
5 months ago
by
Max Cherris
Browse files
Options
Downloads
Patches
Plain Diff
Add correct sprite rendering for all unit types
parent
143fe0c1
Branches
Branches containing commit
No related tags found
2 merge requests
!24
Ui interaction/building
,
!21
Ui components
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/game/Level.cpp
+12
-1
12 additions, 1 deletion
src/game/Level.cpp
src/game/ui/Recruitingmenu.cpp
+54
-39
54 additions, 39 deletions
src/game/ui/Recruitingmenu.cpp
src/game/ui/Recruitingmenu.hpp
+5
-4
5 additions, 4 deletions
src/game/ui/Recruitingmenu.hpp
with
71 additions
and
44 deletions
src/game/Level.cpp
+
12
−
1
View file @
4abb8ad5
...
@@ -450,7 +450,18 @@ void Level::handleMenuActiveEvents(Engine& engine, SDL_Event& event)
...
@@ -450,7 +450,18 @@ void Level::handleMenuActiveEvents(Engine& engine, SDL_Event& event)
m_recruitingMenu
.
update
(
m_recruitingMenu
.
update
(
(
tilePos
.
first
*
16
+
15
)
*
RENDERING_SCALE
,
(
tilePos
.
first
*
16
+
15
)
*
RENDERING_SCALE
,
(
tilePos
.
second
*
16
+
15
)
*
RENDERING_SCALE
);
(
tilePos
.
second
*
16
+
15
)
*
RENDERING_SCALE
);
m_recruitingMenu
.
setOptions
();
m_recruitingMenu
.
setOptions
({
UnitId
::
INFANTERY
,
UnitId
::
MECHANIZED_INFANTERY
,
UnitId
::
RECON
,
UnitId
::
APC
,
UnitId
::
ARTILLERY
,
UnitId
::
ANTI_AIR_TANK
,
UnitId
::
ANTI_AIR_MISSILE_LAUNCHER
,
UnitId
::
ROCKET_ARTILLERY
,
UnitId
::
MEDIUM_TANK
,
UnitId
::
NEO_TANK
,
UnitId
::
HEAVY_TANK
});
std
::
cout
<<
"no training here"
<<
std
::
endl
;
std
::
cout
<<
"no training here"
<<
std
::
endl
;
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
src/game/ui/Recruitingmenu.cpp
+
54
−
39
View file @
4abb8ad5
#include
"Recruitingmenu.hpp"
#include
"Recruitingmenu.hpp"
#include
<iostream>
#include
<iostream>
#include
<SDL_ttf.h>
#include
<SDL_ttf.h>
#include
"../Unit.hpp"
namespace
advanced_wars
namespace
advanced_wars
{
{
RecruitingMenu
::
RecruitingMenu
()
:
m_selectedOption
(
0
)
{
RecruitingMenu
::
RecruitingMenu
()
:
m_selectedOption
(
0
),
unitNames
({
{
UnitId
::
INFANTERY
,
{
"Infantry"
,
100
}},
{
UnitId
::
MECHANIZED_INFANTERY
,
{
"Bazooka"
,
200
}},
{
UnitId
::
RECON
,
{
"Recon"
,
300
}},
{
UnitId
::
APC
,
{
"APC"
,
400
}},
{
UnitId
::
ARTILLERY
,
{
"Artillery"
,
500
}},
{
UnitId
::
ANTI_AIR_TANK
,
{
"AA Tank"
,
600
}},
{
UnitId
::
ANTI_AIR_MISSILE_LAUNCHER
,
{
"Rocket AA"
,
700
}},
{
UnitId
::
ROCKET_ARTILLERY
,
{
"MLRS"
,
800
}},
{
UnitId
::
MEDIUM_TANK
,
{
"Medium Tank"
,
900
}},
{
UnitId
::
NEO_TANK
,
{
"Neo Tank"
,
1000
}},
{
UnitId
::
HEAVY_TANK
,
{
"Heavy Tank"
,
1100
}},
{
UnitId
::
LANDER
,
{
"Lander"
,
1200
}},
{
UnitId
::
CRUISER
,
{
"Cruiser"
,
1300
}},
{
UnitId
::
SUBMARINE
,
{
"Submarine"
,
1400
}},
{
UnitId
::
BATTLESHIP
,
{
"Battleship"
,
1500
}},
{
UnitId
::
TRANSPORT_HELICOPTER
,
{
"Chinook"
,
1600
}},
{
UnitId
::
BATTLE_HELICOPTER
,
{
"Helicopter"
,
1700
}},
{
UnitId
::
FIGHTER
,
{
"Fighter"
,
1800
}},
{
UnitId
::
BOMBER
,
{
"Bomber"
,
1900
}}
})
{
}
}
void
RecruitingMenu
::
setOptions
(
const
std
::
vector
<
UnitId
>
recruitableUnits
)
{
void
RecruitingMenu
::
setOptions
(
const
std
::
vector
<
UnitId
>
recruitableUnits
)
{
std
::
vector
<
std
::
string
>
options
;
std
::
vector
<
std
::
pair
<
std
::
string
,
int
>>
options
;
for
(
UnitId
id
:
recruitableUnits
)
{
for
(
UnitId
id
:
recruitableUnits
)
{
options
.
push_back
(
unitIdToString
(
id
));
options
.
push_back
(
unitNames
.
at
(
id
));
cost2UnitId
.
insert
(
std
::
make_pair
(
unitNames
.
at
(
id
).
second
,
id
));
}
}
m_options
=
options
;
m_options
=
options
;
m_selectedOption
=
0
;
m_selectedOption
=
0
;
}
}
std
::
string
RecruitingMenu
::
unitIdToString
(
UnitId
id
)
{
static
const
std
::
unordered_map
<
UnitId
,
std
::
string
>
unitNames
=
{
{
UnitId
::
INFANTERY
,
"Infantry"
},
{
UnitId
::
MECHANIZED_INFANTERY
,
"Mechanized Infantry"
},
{
UnitId
::
RECON
,
"Recon"
},
{
UnitId
::
APC
,
"APC"
},
{
UnitId
::
ARTILLERY
,
"Artillery"
},
{
UnitId
::
ANTI_AIR_TANK
,
"Anti-Air Tank"
},
{
UnitId
::
ANTI_AIR_MISSILE_LAUNCHER
,
"Missile Launcher"
},
{
UnitId
::
ROCKET_ARTILLERY
,
"Rocket Artillery"
},
{
UnitId
::
MEDIUM_TANK
,
"Medium Tank"
},
{
UnitId
::
NEO_TANK
,
"Neo Tank"
},
{
UnitId
::
HEAVY_TANK
,
"Heavy Tank"
},
{
UnitId
::
LANDER
,
"Lander"
},
{
UnitId
::
CRUISER
,
"Cruiser"
},
{
UnitId
::
SUBMARINE
,
"Submarine"
},
{
UnitId
::
BATTLESHIP
,
"Battleship"
},
{
UnitId
::
TRANSPORT_HELICOPTER
,
"Transport Helicopter"
},
{
UnitId
::
BATTLE_HELICOPTER
,
"Battle Helicopter"
},
{
UnitId
::
FIGHTER
,
"Fighter"
},
{
UnitId
::
BOMBER
,
"Bomber"
}
};
}
void
RecruitingMenu
::
render
(
Engine
&
engine
)
void
RecruitingMenu
::
render
(
Engine
&
engine
)
{
{
...
@@ -78,15 +75,18 @@ namespace advanced_wars
...
@@ -78,15 +75,18 @@ namespace advanced_wars
int
spacing
=
20
;
// Abstand zwischen den Optionen
int
spacing
=
20
;
// Abstand zwischen den Optionen
// box around options
// box around options
SDL_SetRenderDrawColor
(
engine
.
renderer
(),
0
,
0
,
255
,
255
);
SDL_SetRenderDrawColor
(
engine
.
renderer
(),
0
,
0
,
255
,
255
);
SDL_Rect
box
=
{
m_x
,
m_y
-
3
,
1
2
5
,
static_cast
<
int
>
(
m_options
.
size
()
*
spacing
)};
SDL_Rect
box
=
{
m_x
,
m_y
-
3
,
15
0
,
static_cast
<
int
>
(
m_options
.
size
()
*
spacing
)};
SDL_RenderFillRect
(
engine
.
renderer
(),
&
box
);
SDL_RenderFillRect
(
engine
.
renderer
(),
&
box
);
SDL_SetRenderDrawColor
(
engine
.
renderer
(),
0
,
0
,
0
,
255
);
SDL_SetRenderDrawColor
(
engine
.
renderer
(),
0
,
0
,
0
,
255
);
int
i
=
0
;
for
(
size_t
i
=
0
;
i
<
m_options
.
size
();
++
i
)
for
(
auto
&
[
render_name
,
cost
]
:
m_options
)
{
{
//std::pair<std::string, int> unit_option = unitNames.at(cost2UnitId.at(cost));
SDL_Surface
*
textSurface
=
TTF_RenderText_Solid
(
SDL_Surface
*
textSurface
=
TTF_RenderText_Solid
(
font
,
m_options
[
i
]
.
c_str
(),
(
i
==
m_selectedOption
)
?
yellow
:
white
);
font
,
render_name
.
c_str
(),
(
i
==
m_selectedOption
)
?
yellow
:
white
);
if
(
!
textSurface
)
if
(
!
textSurface
)
{
{
continue
;
continue
;
...
@@ -100,7 +100,7 @@ namespace advanced_wars
...
@@ -100,7 +100,7 @@ namespace advanced_wars
SDL_Texture
*
unit_texture
=
spritesheet
->
getUnitTextures
()
SDL_Texture
*
unit_texture
=
spritesheet
->
getUnitTextures
()
.
at
(
static_cast
<
int
>
(
UnitFaction
::
URED
))
.
at
(
static_cast
<
int
>
(
UnitFaction
::
URED
))
.
at
(
static_cast
<
int
>
(
UnitId
::
INFANTERY
))
.
at
(
static_cast
<
int
>
(
cost2
UnitId
.
at
(
cost
)
))
.
at
(
static_cast
<
int
>
(
UnitState
::
IDLE
))
.
at
(
static_cast
<
int
>
(
UnitState
::
IDLE
))
.
first
;
.
first
;
...
@@ -120,8 +120,28 @@ namespace advanced_wars
...
@@ -120,8 +120,28 @@ namespace advanced_wars
SDL_RenderCopy
(
engine
.
renderer
(),
unit_texture
,
&
src_rect
,
&
trgt_rect
);
SDL_RenderCopy
(
engine
.
renderer
(),
unit_texture
,
&
src_rect
,
&
trgt_rect
);
SDL_Surface
*
costSurface
=
TTF_RenderText_Solid
(
font
,
std
::
to_string
(
cost
).
c_str
(),
(
i
==
m_selectedOption
)
?
yellow
:
white
);
if
(
!
textSurface
)
{
continue
;
}
SDL_Texture
*
costTexture
=
SDL_CreateTextureFromSurface
(
engine
.
renderer
(),
costSurface
);
SDL_Rect
cost_rect
{
m_x
+
120
,
m_y
+
static_cast
<
int
>
(
i
*
spacing
),
costSurface
->
w
,
costSurface
->
h
};
SDL_RenderCopy
(
engine
.
renderer
(),
costTexture
,
nullptr
,
&
cost_rect
);
SDL_DestroyTexture
(
costTexture
);
SDL_FreeSurface
(
costSurface
);
SDL_DestroyTexture
(
textTexture
);
SDL_DestroyTexture
(
textTexture
);
SDL_FreeSurface
(
textSurface
);
SDL_FreeSurface
(
textSurface
);
i
++
;
}
}
TTF_CloseFont
(
font
);
TTF_CloseFont
(
font
);
...
@@ -143,11 +163,6 @@ void RecruitingMenu::handleEvent(Engine& engine, SDL_Event& event)
...
@@ -143,11 +163,6 @@ void RecruitingMenu::handleEvent(Engine& engine, SDL_Event& event)
}
}
}
}
std
::
string
RecruitingMenu
::
getSelectedOption
()
{
return
m_options
[
m_selectedOption
];
}
void
RecruitingMenu
::
update
(
int
x
,
int
y
)
void
RecruitingMenu
::
update
(
int
x
,
int
y
)
{
{
this
->
m_x
=
x
;
this
->
m_x
=
x
;
...
...
This diff is collapsed.
Click to expand it.
src/game/ui/Recruitingmenu.hpp
+
5
−
4
View file @
4abb8ad5
#pragma once
#pragma once
#include
"../Scene.hpp"
#include
"../Scene.hpp"
#include
"../Unit.hpp"
namespace
advanced_wars
namespace
advanced_wars
{
{
...
@@ -10,9 +11,11 @@ namespace advanced_wars
...
@@ -10,9 +11,11 @@ namespace advanced_wars
private:
private:
size_t
m_selectedOption
;
size_t
m_selectedOption
;
std
::
vector
<
std
::
string
>
m_options
;
std
::
vector
<
std
::
pair
<
std
::
string
,
int
>
>
m_options
;
int
m_x
;
int
m_x
;
int
m_y
;
int
m_y
;
const
std
::
unordered_map
<
UnitId
,
std
::
pair
<
std
::
string
,
int
>>
unitNames
;
std
::
unordered_map
<
int
,
UnitId
>
cost2UnitId
;
void
handleEvent
(
Engine
&
engine
,
SDL_Event
&
event
);
void
handleEvent
(
Engine
&
engine
,
SDL_Event
&
event
);
...
@@ -22,8 +25,6 @@ namespace advanced_wars
...
@@ -22,8 +25,6 @@ namespace advanced_wars
std
::
string
getSelectedOption
();
std
::
string
getSelectedOption
();
std
::
string
unitIdToString
(
UnitId
id
);
public:
public:
void
update
(
int
x
,
int
y
);
void
update
(
int
x
,
int
y
);
...
...
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