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
Merge requests
!21
Ui components
Code
Review changes
Check out branch
Download
Patches
Plain diff
Expand sidebar
Closed
Ui components
ui-components
into
main
Overview
0
Commits
20
Pipelines
0
Changes
6
Closed
Nicolas Paul Will
requested to merge
ui-components
into
main
5 months ago
Overview
0
Commits
20
Pipelines
0
Changes
6
add tileMarker class this will be used to operate the whole game with keyboard
0
0
Merge request reports
Compare
main
version 10
2cf018df
5 months ago
version 9
2c4e309e
5 months ago
version 8
51fcf1f1
5 months ago
version 7
c0ddc1b7
5 months ago
version 6
835af860
5 months ago
version 5
20608ba7
5 months ago
version 4
e986848d
5 months ago
version 3
693dd23a
5 months ago
version 2
51e8b505
5 months ago
version 1
46477af5
5 months ago
main (base)
and
latest version
latest version
4abb8ad5
20 commits,
5 months ago
version 10
2cf018df
17 commits,
5 months ago
version 9
2c4e309e
16 commits,
5 months ago
version 8
51fcf1f1
15 commits,
5 months ago
version 7
c0ddc1b7
13 commits,
5 months ago
version 6
835af860
11 commits,
5 months ago
version 5
20608ba7
10 commits,
5 months ago
version 4
e986848d
6 commits,
5 months ago
version 3
693dd23a
5 commits,
5 months ago
version 2
51e8b505
4 commits,
5 months ago
version 1
46477af5
3 commits,
5 months ago
6 files
+
473
−
45
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
6
src/game/ui/Recruitingmenu.cpp
0 → 100644
+
172
−
0
View file @ 4abb8ad5
Edit in single-file editor
Open in Web IDE
#include
"Recruitingmenu.hpp"
#include
<iostream>
#include
<SDL_ttf.h>
namespace
advanced_wars
{
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
)
{
std
::
vector
<
std
::
pair
<
std
::
string
,
int
>>
options
;
for
(
UnitId
id
:
recruitableUnits
)
{
options
.
push_back
(
unitNames
.
at
(
id
));
cost2UnitId
.
insert
(
std
::
make_pair
(
unitNames
.
at
(
id
).
second
,
id
));
}
m_options
=
options
;
m_selectedOption
=
0
;
}
void
RecruitingMenu
::
render
(
Engine
&
engine
)
{
Spritesheet
*
spritesheet
=
engine
.
getSpritesheet
();
if
(
TTF_Init
()
==
-
1
)
{
std
::
cerr
<<
"Failed to initialize TTF: "
<<
TTF_GetError
()
<<
std
::
endl
;
return
;
}
if
(
m_options
.
empty
())
{
// TODO handle somehow
return
;
}
std
::
string
basePath
=
SDL_GetBasePath
();
std
::
string
relativePath
=
"res/ARCADECLASSIC.TTF"
;
std
::
string
fullPath
=
basePath
+
relativePath
;
TTF_Font
*
font
=
TTF_OpenFont
(
fullPath
.
c_str
(),
16
);
if
(
!
font
)
{
std
::
cerr
<<
"Failed to load font: "
<<
TTF_GetError
()
<<
std
::
endl
;
return
;
}
SDL_Color
white
=
{
255
,
255
,
255
,
255
};
SDL_Color
yellow
=
{
192
,
255
,
0
,
255
};
int
spacing
=
20
;
// Abstand zwischen den Optionen
// box around options
SDL_SetRenderDrawColor
(
engine
.
renderer
(),
0
,
0
,
255
,
255
);
SDL_Rect
box
=
{
m_x
,
m_y
-
3
,
150
,
static_cast
<
int
>
(
m_options
.
size
()
*
spacing
)};
SDL_RenderFillRect
(
engine
.
renderer
(),
&
box
);
SDL_SetRenderDrawColor
(
engine
.
renderer
(),
0
,
0
,
0
,
255
);
int
i
=
0
;
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
(
font
,
render_name
.
c_str
(),
(
i
==
m_selectedOption
)
?
yellow
:
white
);
if
(
!
textSurface
)
{
continue
;
}
SDL_Texture
*
textTexture
=
SDL_CreateTextureFromSurface
(
engine
.
renderer
(),
textSurface
);
SDL_Rect
textRect
=
{
m_x
+
10
+
16
,
m_y
+
static_cast
<
int
>
(
i
*
spacing
),
textSurface
->
w
,
textSurface
->
h
};
SDL_RenderCopy
(
engine
.
renderer
(),
textTexture
,
nullptr
,
&
textRect
);
SDL_Texture
*
unit_texture
=
spritesheet
->
getUnitTextures
()
.
at
(
static_cast
<
int
>
(
UnitFaction
::
URED
))
.
at
(
static_cast
<
int
>
(
cost2UnitId
.
at
(
cost
)))
.
at
(
static_cast
<
int
>
(
UnitState
::
IDLE
))
.
first
;
SDL_Rect
trgt_rect
=
{
m_x
+
5
,
m_y
+
static_cast
<
int
>
(
i
*
spacing
),
16
,
16
};
SDL_Rect
src_rect
=
{
5
,
0
,
10
,
10
};
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_FreeSurface
(
textSurface
);
i
++
;
}
TTF_CloseFont
(
font
);
TTF_Quit
();
}
void
RecruitingMenu
::
handleEvent
(
Engine
&
engine
,
SDL_Event
&
event
)
{
if
(
event
.
type
==
SDL_KEYDOWN
)
{
if
(
event
.
key
.
keysym
.
sym
==
SDLK_DOWN
)
{
m_selectedOption
=
(
m_selectedOption
+
1
)
%
m_options
.
size
();
}
else
if
(
event
.
key
.
keysym
.
sym
==
SDLK_UP
)
{
m_selectedOption
=
(
m_selectedOption
-
1
+
m_options
.
size
())
%
m_options
.
size
();
}
}
}
void
RecruitingMenu
::
update
(
int
x
,
int
y
)
{
this
->
m_x
=
x
;
this
->
m_y
=
y
;
}
}
//namespace advance_wars
\ No newline at end of file
Loading