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
987d6913
Commit
987d6913
authored
4 months ago
by
Max Cherris
Browse files
Options
Downloads
Patches
Plain Diff
Got the actual recruiting to work :)
parent
fa847edb
No related branches found
No related tags found
1 merge request
!24
Ui interaction/building
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/game/Level.cpp
+25
-19
25 additions, 19 deletions
src/game/Level.cpp
src/game/ui/Recruitingmenu.cpp
+8
-1
8 additions, 1 deletion
src/game/ui/Recruitingmenu.cpp
src/game/ui/Recruitingmenu.hpp
+5
-6
5 additions, 6 deletions
src/game/ui/Recruitingmenu.hpp
with
38 additions
and
26 deletions
src/game/Level.cpp
+
25
−
19
View file @
987d6913
...
...
@@ -277,17 +277,22 @@ Effect Level::removeEffect(int id)
void
Level
::
handleRecruitingEvent
(
Engine
&
engine
,
SDL_Event
&
event
)
{
switch
(
event
.
type
)
{
case
SDL_KEYDOWN
:
if
(
event
.
key
.
keysym
.
sym
==
SDLK_ESCAPE
)
{
m_state
=
LevelState
::
MENUACTIVE_STATE
;
}
if
(
event
.
key
.
keysym
.
sym
==
SDLK_UP
||
event
.
key
.
keysym
.
sym
==
SDLK_DOWN
)
{
m_recruitingMenu
.
handleEvent
(
engine
,
event
);
}
if
(
event
.
key
.
keysym
.
sym
==
SDLK_RETURN
)
{
Building
&
b
=
m_buildings
.
at
(
m_selectedBuilding
);
UnitFaction
u_faction
=
static_cast
<
UnitFaction
>
(
b
.
m_faction
);
std
::
vector
<
UnitId
>
recruitableUnits
=
b
.
recruitableUnits
();
//m_recruitingmenu.setoptions(recruitableUnits)
//show appropriate interface -> provide vector of UnitId
//show Interface here
//select UnitId
UnitId
unit_id
=
UnitId
::
INFANTERY
;
UnitId
unit_id
=
m_recruitingMenu
.
getSelectedOption
();
if
(
b
.
check_money
(
500
))
{
if
(
b
.
check_spawn
(
m_units
)){
...
...
@@ -297,6 +302,7 @@ void Level::handleRecruitingEvent(Engine& engine, SDL_Event& event) {
}
}
}
}}
//*******************helper functions for event Handling*************************************
...
...
This diff is collapsed.
Click to expand it.
src/game/ui/Recruitingmenu.cpp
+
8
−
1
View file @
987d6913
...
...
@@ -84,6 +84,9 @@ namespace advanced_wars
for
(
auto
&
[
render_name
,
cost
]
:
m_options
)
{
//std::pair<std::string, int> unit_option = unitNames.at(cost2UnitId.at(cost));
if
(
i
==
m_selectedOption
)
{
m_selectedId
=
cost2UnitId
.
at
(
cost
);
}
SDL_Surface
*
textSurface
=
TTF_RenderText_Solid
(
font
,
render_name
.
c_str
(),
(
i
==
m_selectedOption
)
?
yellow
:
white
);
...
...
@@ -169,4 +172,8 @@ void RecruitingMenu::update(int x, int y)
this
->
m_y
=
y
;
}
UnitId
RecruitingMenu
::
getSelectedOption
(){
return
m_selectedId
;
}
}
//namespace advance_wars
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/game/ui/Recruitingmenu.hpp
+
5
−
6
View file @
987d6913
...
...
@@ -16,17 +16,16 @@ namespace advanced_wars
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
);
UnitId
m_selectedId
;
void
selectSprite
();
std
::
string
getSelectedOption
();
public:
UnitId
getSelectedOption
();
void
handleEvent
(
Engine
&
engine
,
SDL_Event
&
event
);
void
update
(
int
x
,
int
y
);
RecruitingMenu
();
...
...
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