World of Might and Magic  0.2.0
Open reimplementation of Might and Magic 6 7 8 game engine
LloydsBook.cpp
См. документацию.
1 #include "Engine/Engine.h"
3 #include "Engine/LOD.h"
4 #include "Engine/Localization.h"
5 #include "Engine/Party.h"
6 #include "Engine/SaveLoad.h"
7 
8 #include "GUI/GUIButton.h"
9 #include "GUI/GUIFont.h"
11 
12 std::array<unsigned int, 5> pLloydsBeaconsPreviewXs = {
13  {61, 281, 61, 281, 171}}; // 004E249C
14 std::array<unsigned int, 5> pLloydsBeaconsPreviewYs = {{84, 84, 228, 228, 155}};
15 std::array<unsigned int, 5> pLloydsBeacons_SomeXs = {{59, 279, 59, 279, 169}};
16 std::array<unsigned int, 5> pLloydsBeacons_SomeYs = {{82, 82, 226, 226, 153}};
17 
19 
21 std::array<Image *, 2> ui_book_lloyds_backgrounds;
22 
24  this->ptr_1C = (void *)WINDOW_LloydsBeacon; // inherited from GUIWindow::GUIWindow
26 
28  if (!ui_book_lloyds_border) {
29  ui_book_lloyds_border = assets->GetImage_ColorKey("lb_bordr", 0x7FF);
30  }
31 
36 
37  pBtn_Book_1 =
38  CreateButton(415, 13, 39, 36, 1, 0, UIMSG_LloydsBeacon_FlippingBtn, 0,
39  0, localization->GetString(375)); // Set Beacon
40  pBtn_Book_2 =
41  CreateButton(415, 48, 39, 36, 1, 0, UIMSG_LloydsBeacon_FlippingBtn, 1,
42  0, localization->GetString(523)); // Recall Beacon
43 
44  int max_beacons = 1;
46  .pActiveSkills[PLAYER_SKILL_WATER];
47  if (water_skill & 0x100 || (water_skill & 0x80))
48  max_beacons = 5;
49  else if (water_skill & 0x40)
50  max_beacons = 3;
51 
52  for (int i = 0; i < max_beacons; ++i) {
54  68, 1, UIMSG_HintBeaconSlot, UIMSG_InstallBeacon, i, 0, "");
55  }
56 
58 }
59 
61  render->DrawTextureAlphaNew(471 / 640.0f, 445 / 480.0f, ui_exit_cancel_button_background);
62 
64  render->DrawTextureAlphaNew(8 / 640.0f, 8 / 480.0f, ui_book_lloyds_backgrounds[bRecallingBeacon ? 1 : 0]);
65  String pText = localization->GetString(523); // Recall Beacon
66 
67  GUIWindow pWindow;
68  pWindow.uFrameX = game_viewport_x;
69  pWindow.uFrameY = game_viewport_y;
70  pWindow.uFrameWidth = 428;
72  pWindow.uFrameZ = 435;
73  pWindow.uFrameW = game_viewport_w;
74  if (!bRecallingBeacon) {
75  pText = localization->GetString(375); // Set Beacon
76  }
77 
78  pWindow.DrawTitleText(pBook2Font, 0, 22, 0, pText, 3);
79  if (bRecallingBeacon) {
80  render->DrawTextureAlphaNew(pBtn_Book_1->uX / 640.0f,
81  pBtn_Book_1->uY / 480.0f,
83  render->DrawTextureAlphaNew(pBtn_Book_2->uX / 640.0f,
84  pBtn_Book_2->uY / 480.0f,
86  } else {
87  render->DrawTextureAlphaNew(pBtn_Book_1->uX / 640.0f,
88  pBtn_Book_1->uY / 480.0f,
90  render->DrawTextureAlphaNew(pBtn_Book_2->uX / 640.0f,
91  pBtn_Book_2->uY / 480.0f,
93  }
94  int uNumMaxBeacons = 1;
95  if ((pPlayer->pActiveSkills[PLAYER_SKILL_WATER] & 0x100) ||
96  (pPlayer->pActiveSkills[PLAYER_SKILL_WATER] & 0x80)) {
97  uNumMaxBeacons = 5;
98  } else if (pPlayer->pActiveSkills[PLAYER_SKILL_WATER] & 0x40) {
99  uNumMaxBeacons = 3;
100  }
101 
102  if (uNumMaxBeacons > 0) {
103  for (size_t BeaconID = 0; BeaconID < uNumMaxBeacons; BeaconID++) {
104  if ((BeaconID >= pPlayer->vBeacons.size()) && bRecallingBeacon) {
105  break;
106  }
107 
108  pWindow.uFrameWidth = 92;
109  pWindow.uFrameHeight = 68;
110  pWindow.uFrameY = pLloydsBeaconsPreviewYs[BeaconID];
111  pWindow.uFrameX = pLloydsBeaconsPreviewXs[BeaconID];
112  pWindow.uFrameW = pWindow.uFrameY + 67;
113  pWindow.uFrameZ = pLloydsBeaconsPreviewXs[BeaconID] + 91;
114 
115  render->DrawTextureAlphaNew(
116  pLloydsBeacons_SomeXs[BeaconID] / 640.0f,
117  pLloydsBeacons_SomeYs[BeaconID] / 480.0f,
119 
120  if (BeaconID < pPlayer->vBeacons.size()) {
121  LloydBeacon &beacon = pPlayer->vBeacons[BeaconID];
122  render->DrawTextureNew(
123  pLloydsBeaconsPreviewXs[BeaconID] / 640.0f,
124  pLloydsBeaconsPreviewYs[BeaconID] / 480.0f,
125  beacon.image);
127  unsigned int pTextHeight = pSpellFont->CalcTextHeight(Str, pWindow.uFrameWidth, 0);
128  pWindow.uFrameY -= 6 + pTextHeight;
129  pWindow.DrawTitleText(pSpellFont, 0, 0, 1, Str, 3);
130 
131  pWindow.uFrameY = pLloydsBeaconsPreviewYs[BeaconID];
132  GameTime RemainingTime = beacon.uBeaconTime - pParty->GetPlayingTime();
133  unsigned int pHours = RemainingTime.GetHoursOfDay();
134  unsigned int pDays = RemainingTime.GetDays();
135  String str;
136  if (pDays > 1) {
137  str = StringPrintf("%lu %s", pDays + 1, localization->GetString(57)); // days
138  } else if (pHours + 1 <= 23) {
139  str = StringPrintf("%lu %s", pHours + 1, localization->GetString((pHours < 1) ? 109 : 110));
140  } else {
141  str = StringPrintf("%lu %s", pDays + 1, localization->GetString(56)); // Day
142  }
143  pWindow.uFrameY = pWindow.uFrameY + pWindow.uFrameHeight + 4;
144  pWindow.DrawTitleText(pSpellFont, 0, 0, 1, str, 3);
145  } else {
146  unsigned int pTextHeight = pSpellFont->CalcTextHeight(localization->GetString(19), pWindow.uFrameWidth, 0);
147  pWindow.DrawTitleText(pSpellFont, 0,
148  (int)pWindow.uFrameHeight / 2 - pTextHeight / 2, 1,
149  localization->GetString(19), 3); // Доступно
150  }
151  }
152  }
153 
156  }
157 }
Player
Definition: Player.h:401
GUIWindow::uFrameW
unsigned int uFrameW
Definition: GUIWindow.h:473
Localization::GetString
const char * GetString(unsigned int index) const
Definition: Localization.cpp:13
MapStats::pInfos
MapInfo pInfos[77]
Definition: MapInfo.h:79
LOD.h
Party::GetPlayingTime
GameTime & GetPlayingTime()
Definition: Party.h:230
GameTime::GetDays
int GetDays() const
Definition: Time.h:32
UIMSG_HintBeaconSlot
@ UIMSG_HintBeaconSlot
Definition: GUIWindow.h:147
GUIWindow
Definition: GUIWindow.h:433
ui_exit_cancel_button_background
Image * ui_exit_cancel_button_background
Definition: GUIWindow.cpp:89
UIMSG_LloydsBeacon_FlippingBtn
@ UIMSG_LloydsBeacon_FlippingBtn
Definition: GUIWindow.h:145
GUIWindow::CreateButton
GUIButton * CreateButton(int x, int y, int width, int height, int a6, int a7, UIMessageType msg, unsigned int msg_param, uint8_t hotkey, const String &label, const std::vector< Image * > &textures=std::vector< Image * >())
Definition: GUIWindow.cpp:717
ui_book_button1_on
Image * ui_book_button1_on
Definition: UIBooks.cpp:34
pBtn_Book_1
GUIButton * pBtn_Book_1
Definition: GUIButton.cpp:23
GUIWindow_LloydsBook::Update
virtual void Update()
Definition: LloydsBook.cpp:60
localization
Localization * localization
Definition: Localization.cpp:11
game_viewport_x
int game_viewport_x
Definition: mm7_data.cpp:196
Party::pPlayers
std::array< Player, 4 > pPlayers
Definition: Party.h:310
GUIWindow::DrawTitleText
void DrawTitleText(GUIFont *font, int horizontal_margin, int vertical_margin, unsigned __int16 uDefaultColor, const char *pInString, int line_spacing)
Definition: GUIWindow.cpp:665
GUIFont.h
Player::pActiveSkills
std::array< unsigned __int16, 37 > pActiveSkills
Definition: Player.h:711
GUIWindow::uFrameWidth
unsigned int uFrameWidth
Definition: GUIWindow.h:470
game_viewport_height
unsigned int game_viewport_height
Definition: mm7_data.cpp:195
GUIWindow::uFrameZ
unsigned int uFrameZ
Definition: GUIWindow.h:472
Engine.h
pMapStats
struct MapStats * pMapStats
Definition: mm7_data.cpp:20
game_viewport_y
int game_viewport_y
Definition: mm7_data.cpp:197
Localization.h
GUIButton.h
pParty
Party * pParty
Definition: Party.cpp:30
Image
Definition: Image.h:19
IRender.h
pSpellFont
GUIFont * pSpellFont
Definition: GUIFont.cpp:17
WINDOW_LloydsBeacon
@ WINDOW_LloydsBeacon
Definition: GUIWindow.h:334
SaveLoad.h
_506360_installing_beacon
bool _506360_installing_beacon
Definition: LloydsBook.cpp:18
AssetsManager::GetImage_ColorKey
Texture * GetImage_ColorKey(const String &name, uint16_t colorkey)
Definition: AssetsManager.cpp:34
GUIWindow::uFrameHeight
unsigned int uFrameHeight
Definition: GUIWindow.h:471
pBook2Font
GUIFont * pBook2Font
Definition: GUIFont.cpp:20
pBtn_Book_2
GUIButton * pBtn_Book_2
Definition: GUIButton.cpp:22
GUIFont::CalcTextHeight
unsigned int CalcTextHeight(const String &str, unsigned int width, int x_offset, bool return_on_carriage=false)
Definition: GUIFont.cpp:246
Party.h
LloydsBook.h
f
GLfloat f
Definition: SDL_opengl_glext.h:1873
PLAYER_SKILL_WATER
@ PLAYER_SKILL_WATER
Definition: Player.h:185
GameTime::GetHoursOfDay
int GetHoursOfDay() const
Definition: Time.h:39
MapInfo::pName
String pName
Definition: MapInfo.h:38
_506348_current_lloyd_playerid
int _506348_current_lloyd_playerid
Definition: mm7_data.cpp:517
UIMSG_InstallBeacon
@ UIMSG_InstallBeacon
Definition: GUIWindow.h:146
GUIWindow::uFrameY
unsigned int uFrameY
Definition: GUIWindow.h:469
GUIButton::uX
unsigned int uX
Definition: GUIButton.h:21
game_viewport_w
int game_viewport_w
Definition: mm7_data.cpp:199
ui_book_button1_off
Image * ui_book_button1_off
Definition: UIBooks.cpp:33
ui_book_lloyds_backgrounds
std::array< Image *, 2 > ui_book_lloyds_backgrounds
Definition: LloydsBook.cpp:21
GUIWindow_LloydsBook::GUIWindow_LloydsBook
GUIWindow_LloydsBook()
Definition: LloydsBook.cpp:23
MapStats::sub_410D99_get_map_index
int sub_410D99_get_map_index(int a1)
Definition: MapInfo.cpp:213
UIMSG_CloseAfterInstallBeacon
@ UIMSG_CloseAfterInstallBeacon
Definition: GUIWindow.h:148
GUIWindow_Book
Definition: UIBooks.h:4
GUIWindow_Book::BasicBookInitialization
void BasicBookInitialization()
Definition: UIBooks.cpp:67
Player::vBeacons
std::vector< LloydBeacon > vBeacons
Definition: Player.h:794
LloydBeacon::image
Image * image
Definition: Player.h:279
assets
AssetsManager * assets
Definition: AssetsManager.cpp:12
GUIButton::uY
unsigned int uY
Definition: GUIButton.h:22
pLloydsBeaconsPreviewXs
std::array< unsigned int, 5 > pLloydsBeaconsPreviewXs
Definition: LloydsBook.cpp:12
ui_book_lloyds_border
Image * ui_book_lloyds_border
Definition: LloydsBook.cpp:20
pLloydsBeaconsPreviewYs
std::array< unsigned int, 5 > pLloydsBeaconsPreviewYs
Definition: LloydsBook.cpp:14
LloydBeacon::SaveFileID
uint16_t SaveFileID
Definition: Player.h:278
GUIWindow::ptr_1C
void * ptr_1C
Definition: GUIWindow.h:476
AssetsManager::GetImage_Alpha
Texture * GetImage_Alpha(const String &name)
Definition: AssetsManager.cpp:66
bRecallingBeacon
bool bRecallingBeacon
Definition: mm7_data.cpp:533
GUIWindow::uFrameX
unsigned int uFrameX
Definition: GUIWindow.h:468
LloydBeacon
Definition: Player.h:254
pMessageQueue_50CBD0
struct GUIMessageQueue * pMessageQueue_50CBD0
Definition: GUIWindow.cpp:86
pLloydsBeacons_SomeXs
std::array< unsigned int, 5 > pLloydsBeacons_SomeXs
Definition: LloydsBook.cpp:15
LloydBeacon::uBeaconTime
GameTime uBeaconTime
Definition: Player.h:271
StringPrintf
String StringPrintf(const char *fmt,...)
Definition: Strings.cpp:9
String
std::string String
Definition: Strings.h:10
pLloydsBeacons_SomeYs
std::array< unsigned int, 5 > pLloydsBeacons_SomeYs
Definition: LloydsBook.cpp:16
GameTime
Definition: Time.h:14
render
std::shared_ptr< IRender > render
Definition: RenderOpenGL.cpp:52