YAPOG
0.0.1
Yet Another Pokemon Online Game
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
BattleInteface.cpp
Go to the documentation of this file.
1
#include "
YAPOG/Graphics/Gui/DialogBoxWidget.hpp
"
2
3
#include "
YAPOG/Graphics/Gui/WidgetBackground.hpp
"
4
#include "
YAPOG/Graphics/Gui/Padding.hpp
"
5
#include "
YAPOG/Graphics/Texture.hpp
"
6
#include "
YAPOG/Graphics/Game/Sprite/Sprite.hpp
"
7
#include "
YAPOG/Game/Factory/ObjectFactory.hpp
"
8
#include "
YAPOG/Graphics/Gui/GridMenu.hpp
"
9
10
#include "
YAPOG/Graphics/Gui/WidgetBorder.hpp
"
11
12
#include "Game.hpp"
13
14
#include "
Battle/BattleInterface.hpp
"
15
#include "
Battle/PokemonBattleInfoWidget.hpp
"
16
#include "
Battle/OpponentBattleInfoWidget.hpp
"
17
18
#include "Game.hpp"
19
20
namespace
ycl
21
{
22
const
bool
BattleInterface::DEFAULT_ADDED_WIDGET_STATE
=
false
;
23
24
BattleInterface::BattleInterface
()
25
: battleInfoDialogBox_ (nullptr)
26
, pokemonInfoWidget_ (nullptr)
27
, opponentInfoWidget_ (nullptr)
28
, battleMenu_ ()
29
, battleMoveMenu_ ()
30
, currentWidgetName_ ()
31
, currentWidget_ (nullptr)
32
, battleWidgets_ ()
33
{
34
battleInfoDialogBox_
=
new
yap::DialogBoxWidget
();
35
36
// Init Battle Text Dialog
37
battleInfoDialogBox_
->
SetSize
(
38
yap::Vector2
(
Game::SCREEN_SIZE
.x,
Game::SCREEN_SIZE
.y / 4));
39
40
battleInfoDialogBox_
->
SetPosition
(
41
yap::Vector2
(0,
Game::SCREEN_SIZE
.y -
battleInfoDialogBox_
->
GetSize
().y));
42
43
battleInfoDialogBox_
->
SetPadding
(
yap::Padding
(35, 35, 25, 25));
44
battleInfoDialogBox_
->
SetBackground
(
45
*(
new
yap::WidgetBackground
(
46
"WindowSkins/BasicSkin/Global/DialogBoxBackground.png"
,
true
)));
47
48
battleInfoDialogBox_
->
SetDefaultColor
(sf::Color::White);
49
50
pokemonInfoWidget_
=
new
PokemonBattleInfoWidget
();
51
opponentInfoWidget_
=
new
OpponentBattleInfoWidget
();
52
53
pokemonInfoWidget_
->
Init
();
54
opponentInfoWidget_
->
Init
();
55
56
pokemonInfoWidget_
->
Show
(
false
);
57
opponentInfoWidget_
->
Show
(
false
);
58
59
battleMenu_
.
SetPosition
(
yap::Vector2
(
60
Game::SCREEN_SIZE
.x -
battleMenu_
.
GetSize
().x ,
61
Game::SCREEN_SIZE
.y -
battleMenu_
.
GetSize
().y ));
62
63
battleMoveMenu_
.
SetPosition
(
yap::Vector2
(
64
0 ,
65
Game::SCREEN_SIZE
.y -
battleMenu_
.
GetSize
().y ));
66
67
battleMoveInfoMenu_
.
SetPosition
(
yap::Vector2
(
68
Game::SCREEN_SIZE
.x -
battleMoveInfoMenu_
.
GetSize
().x - 20,
69
Game::SCREEN_SIZE
.y -
battleMoveInfoMenu_
.
GetSize
().y - 20));
70
71
battleMenu_
.
Close
();
72
battleMoveMenu_
.
Close
();
73
battleMoveInfoMenu_
.
Close
();
74
75
// Affect events
76
battleMenu_
.
GetItem
(0).
OnActivated
+=
77
[&] (
const
yap::MenuItem
& sender,
const
yap::EmptyEventArgs
& args)
78
{
79
battleMenu_
.
Close
();
80
OpenBattleMoveMenu
();
81
};
82
83
battleMoveMenu_
.
OnDesactivated
+=
84
[&] (
const
yap::GridMenu
& sender,
const
yap::EmptyEventArgs
& args)
85
{
86
battleMoveMenu_
.
Close
();
87
battleMoveInfoMenu_
.
Close
();
88
battleMenu_
.
Open
();
89
};
90
91
this->
AddBattleWidget
(
"PokemonInfo"
,
pokemonInfoWidget_
);
92
this->
AddBattleWidget
(
"OpponentInfo"
,
opponentInfoWidget_
);
93
this->
AddBattleWidget
(
"BattleInfo"
,
battleInfoDialogBox_
);
94
this->
AddBattleWidget
(
"Menu"
, &
battleMenu_
);
95
this->
AddBattleWidget
(
"MoveMenu"
, &
battleMoveMenu_
);
96
this->
AddBattleWidget
(
"MoveInfo"
, &
battleMoveInfoMenu_
);
97
}
98
99
void
BattleInterface::AddBattleWidget
(
100
const
yap::String
& name,
101
yap::IWidget
* battleWidget)
102
{
103
DEFAULT_ADDED_WIDGET_STATE
? battleWidget->
Open
() : battleWidget->
Close
();
104
105
AddChild
(*battleWidget);
106
battleWidgets_
.
Add
(name, battleWidget);
107
}
108
109
void
BattleInterface::SetCurrentWidget
(
const
yap::String
& name)
110
{
111
currentWidgetName_
= name;
112
113
currentWidget_
=
battleWidgets_
[
currentWidgetName_
];
114
115
eventHandlers_
.
Remove
(
currentWidget_
);
116
eventHandlers_
.
AddFront
(
currentWidget_
);
117
118
drawables_
.
Remove
(
currentWidget_
);
119
drawables_
.
Add
(
currentWidget_
);
120
121
currentWidget_
->
Open
();
122
}
123
124
bool
BattleInterface::UnsetCurrentWidget
()
125
{
126
if
(
currentWidget_
==
nullptr
)
127
return
false
;
128
129
currentWidget_
->
Close
();
130
131
currentWidget_
=
nullptr
;
132
133
return
true
;
134
}
135
137
yap::DialogBoxWidget
&
BattleInterface::GetBattleInfoDialogBox
()
138
{
139
return
*
battleInfoDialogBox_
;
140
}
141
142
PokemonBattleInfoWidget
&
BattleInterface::GetPokemonInfoWidget
()
143
{
144
return
*
pokemonInfoWidget_
;
145
}
146
147
OpponentBattleInfoWidget
&
BattleInterface::GetOpponentInfoWidget
()
148
{
149
return
*
opponentInfoWidget_
;
150
}
151
152
BattleMenu
&
BattleInterface::GetBattleMenu
()
153
{
154
return
battleMenu_
;
155
}
156
157
BattleMoveMenu
&
BattleInterface::GetBattleMoveMenu
()
158
{
159
return
battleMoveMenu_
;
160
}
161
162
BattleMoveInfoMenu
&
BattleInterface::GetBattleMoveInfoMenu
()
163
{
164
return
battleMoveInfoMenu_
;
165
}
166
167
void
BattleInterface::OpenBattleMoveMenu
()
168
{
169
battleMoveMenu_
.
Open
();
170
battleMoveInfoMenu_
.
Open
();
171
}
172
173
void
BattleInterface::Reset
()
174
{
175
battleMoveMenu_
.
Close
();
176
battleMoveInfoMenu_
.
Close
();
177
battleMenu_
.
Close
();
178
179
battleInfoDialogBox_
->
Open
();
180
pokemonInfoWidget_
->
Close
();
181
opponentInfoWidget_
->
Close
();
182
}
183
}
YAPOG.Client
src
Battle
BattleInteface.cpp
Generated on Mon Sep 17 2012 22:24:21 for YAPOG by
1.8.1.1