World of Might and Magic  0.2.0
Open reimplementation of Might and Magic 6 7 8 game engine
UIMainMenu.cpp
См. документацию.
1 #include "GUI/UI/UIMainMenu.h"
2 
3 #include "Engine/Point.h"
4 #include "Engine/Localization.h"
7 
8 #include "IO/Mouse.h"
9 
10 #include "GUI/GUIButton.h"
11 #include "GUI/GUIFont.h"
12 
14 #include "Media/MediaPlayer.h"
15 
16 #include "Platform/OSWindow.h"
17 
19 
21  GUIWindow(WINDOW_MainMenu, 0, 0, window->GetWidth(), window->GetHeight(), 0) {
23 
24  ui_mainmenu_new = assets->GetImage_ColorKey("title_new", 0x7FF);
25  ui_mainmenu_load = assets->GetImage_ColorKey("title_load", 0x7FF);
26  ui_mainmenu_credits = assets->GetImage_ColorKey("title_cred", 0x7FF);
27  ui_mainmenu_exit = assets->GetImage_ColorKey("title_exit", 0x7FF);
28 
30  1, 0, UIMSG_MainMenu_ShowPartyCreationWnd, 0, 'N', "", { { ui_mainmenu_new } });
31  pBtnLoad = CreateButton(495, 227, ui_mainmenu_load->GetWidth(), ui_mainmenu_load->GetHeight(),
32  1, 0, UIMSG_MainMenu_ShowLoadWindow, 1, 'L', "", { { ui_mainmenu_load } });
33  pBtnCredits = CreateButton(495, 282, ui_mainmenu_credits->GetWidth(), ui_mainmenu_credits->GetHeight(),
34  1, 0, UIMSG_ShowCredits, 2, 'C', "", { { ui_mainmenu_credits } });
35  pBtnExit = CreateButton(495, 337, ui_mainmenu_exit->GetWidth(), ui_mainmenu_exit->GetHeight(),
36  1, 0, UIMSG_ExitToWindows, 3, 0, "", { { ui_mainmenu_exit } });
37 }
38 
45 }
46 
48  render->DrawTextureNew(0, 0, main_menu_background);
49 
50  Point pt = mouse->GetCursorPos();
51  GUIWindow *pWindow = this;
52 
53  Image *pTexture = nullptr;
54  if (!pModalWindow) { // ???
55  for (GUIButton *pButton : pWindow->vButtons) {
56  if (pButton->Contains(pt.x, pt.y) && pWindow == pWindow_MainMenu) {
57  auto pControlParam = pButton->msg_param;
58  int pY = 0;
59  switch (pControlParam) { // backlight for buttons
60  case 0:
61  pTexture = assets->GetImage_ColorKey("title_new", 0x7FF);
62  pY = 172;
63  break;
64  case 1:
65  pTexture = assets->GetImage_ColorKey("title_load", 0x7FF);
66  pY = 227;
67  break;
68  case 2:
69  pTexture = assets->GetImage_ColorKey("title_cred", 0x7FF);
70  pY = 282;
71  break;
72  case 3:
73  pTexture = assets->GetImage_ColorKey("title_exit", 0x7FF);
74  pY = 337;
75  break;
76  }
77  render->DrawTextureAlphaNew(495 / 640.0f, pY / 480.0f, pTexture);
78  }
79  }
80  }
81 }
82 
84  while (!pMessageQueue_50CBD0->Empty()) {
85  UIMessageType pUIMessageType;
86  int pParam;
87  int param2;
88  pMessageQueue_50CBD0->PopMessage(&pUIMessageType, &pParam, &param2);
89 
90  switch (pUIMessageType) { // For buttons of window MainMenu
92  new OnButtonClick2(495, 172, 0, 0, (int)pBtnNew);
94  break;
96  new OnButtonClick2(495, 227, 0, 0, (int)pBtnLoad);
98  break;
99  case UIMSG_ShowCredits:
100  new OnButtonClick2(495, 282, 0, 0, (int)pBtnCredits);
102  break;
103  case UIMSG_ExitToWindows:
104  new OnButtonClick2(495, 337, 0, 0, (int)pBtnExit);
106  break;
109  break;
110  default:
111  break;
112  }
113  }
114 }
115 
116 static bool first_initialization = true;
117 
119  pAudioPlayer->StopChannels(-1, -1);
121 
122  if (first_initialization) {
123  first_initialization = false;
124 
125  Image *tex = assets->GetImage_PCXFromIconsLOD("mm6title.pcx");
126 
127  render->ResetUIClipRect();
128  render->BeginScene();
129  {
130  render->DrawTextureNew(0, 0, tex);
132  }
133  render->EndScene();
134  render->Present();
135 
136  engine->SecondaryInitialization();
138 
139  tex->Release();
140  }
141 
143 
144  pGUIWindow2 = nullptr;
145 
147 
149  // window->Activate();
150 
151  while (GetCurrentMenuID() == MENU_MAIN) {
152  window->PeekMessageLoop();
153  if (dword_6BE364_game_settings_1 & GAME_SETTINGS_APP_INACTIVE) {
154  OS_WaitMessage();
155  continue;
156  }
157 
158  render->BeginScene();
159  {
162  }
163  render->EndScene();
164  render->Present();
165  }
166 
168  delete pWindow_MainMenu;
169  pWindow_MainMenu = nullptr;
170 }
171 
173  GUIWindow Dst;
174  Dst.uFrameWidth = 624;
175  Dst.uFrameHeight = 256;
176  Dst.uFrameX = 8;
177  Dst.uFrameY = 30; // c 1999 The 3DO Company.
179  + 2 * (unsigned char)pFontSmallnum->GetHeight()
180  + 24;
181  Dst.uFrameY = 470 - Dst.uFrameHeight;
182  Dst.uFrameZ = Dst.uFrameX + Dst.uFrameWidth - 1;
183  Dst.uFrameW = 469;
184  Dst.DrawMessageBox(0);
185 
186  Dst.uFrameWidth -= 24;
187  Dst.uFrameX += 12;
188  Dst.uFrameY += 12;
189  Dst.uFrameHeight -= 12;
190  Dst.uFrameZ = Dst.uFrameX + Dst.uFrameWidth - 1;
191  Dst.uFrameW = Dst.uFrameY + Dst.uFrameHeight - 1;
193 }
OSWindow.h
MENU_SAVELOAD
@ MENU_SAVELOAD
Definition: GUIWindow.h:254
pWindow_MainMenu
GUIWindow_MainMenu * pWindow_MainMenu
Definition: UIMainMenu.cpp:18
OnButtonClick2
Definition: GUIWindow.h:523
GUIWindow_MainMenu::GUIWindow_MainMenu
GUIWindow_MainMenu()
Definition: UIMainMenu.cpp:20
ui_mainmenu_copyright_color
unsigned int ui_mainmenu_copyright_color
Definition: UICharacter.cpp:40
GUIWindow::uFrameW
unsigned int uFrameW
Definition: GUIWindow.h:473
UIMessageType
UIMessageType
Definition: GUIWindow.h:13
GUIMessageQueue::Empty
bool Empty()
Definition: GUIWindow.h:659
Localization::GetString
const char * GetString(unsigned int index) const
Definition: Localization.cpp:13
GUIWindow_MainMenu::ui_mainmenu_exit
Image * ui_mainmenu_exit
Definition: UIMainMenu.h:26
Image::GetHeight
unsigned int GetHeight()
Definition: Image.cpp:230
FinalInitialization
void FinalInitialization()
Definition: Engine.cpp:852
Mouse::GetCursorPos
Point GetCursorPos()
Definition: Mouse.cpp:108
GUIWindow
Definition: GUIWindow.h:433
uGameState
unsigned int uGameState
Definition: mm7_data.cpp:695
GUIWindow_MainMenu::EventLoop
void EventLoop()
Definition: UIMainMenu.cpp:83
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
SetCurrentMenuID
void SetCurrentMenuID(MENU_STATE uMenu)
Definition: GUIWindow.cpp:128
GAME_FINISHED
@ GAME_FINISHED
Definition: Engine.h:33
Point.h
engine
std::shared_ptr< Engine > engine
Definition: Engine.cpp:130
AudioPlayer::MusicPlayTrack
void MusicPlayTrack(enum MusicID eTrack)
Definition: AudioPlayer.cpp:109
localization
Localization * localization
Definition: Localization.cpp:11
Point::x
unsigned int x
Definition: Point.h:7
MENU_MAIN
@ MENU_MAIN
Definition: GUIWindow.h:251
UIMSG_ExitToWindows
@ UIMSG_ExitToWindows
Definition: GUIWindow.h:43
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
AssetsManager::GetImage_PCXFromIconsLOD
Texture * GetImage_PCXFromIconsLOD(const String &name)
Definition: AssetsManager.cpp:81
GUIWindow::Release
virtual void Release()
Definition: GUIWindow.cpp:292
GUIFont.h
GUIFont::GetHeight
unsigned int GetHeight() const
Definition: GUIFont.cpp:84
GUIWindow::uFrameWidth
unsigned int uFrameWidth
Definition: GUIWindow.h:470
DrawMM7CopyrightWindow
void DrawMM7CopyrightWindow()
Definition: UIMainMenu.cpp:172
GUIButton
Definition: GUIButton.h:11
GUIWindow::uFrameZ
unsigned int uFrameZ
Definition: GUIWindow.h:472
current_screen_type
enum CURRENT_SCREEN current_screen_type
Definition: GUIWindow.cpp:83
Image.h
GUIWindow::vButtons
std::vector< GUIButton * > vButtons
Definition: GUIWindow.h:489
GUIWindow_MainMenu::pBtnExit
GUIButton * pBtnExit
Definition: UIMainMenu.h:16
GetCurrentMenuID
MENU_STATE GetCurrentMenuID()
Definition: GUIWindow.cpp:133
GUIButton::Contains
bool Contains(unsigned int x, unsigned int y)
Definition: GUIButton.cpp:113
Localization.h
MENU_NEWGAME
@ MENU_NEWGAME
Definition: GUIWindow.h:252
MENU_EXIT_GAME
@ MENU_EXIT_GAME
Definition: GUIWindow.h:255
Image::GetWidth
unsigned int GetWidth()
Definition: Image.cpp:217
pGUIWindow2
GUIWindow * pGUIWindow2
Definition: GUIWindow.cpp:60
GUIButton.h
Image
Definition: Image.h:19
IRender.h
UIMSG_MainMenu_ShowLoadWindow
@ UIMSG_MainMenu_ShowLoadWindow
Definition: GUIWindow.h:41
GUIWindow::DrawMessageBox
void DrawMessageBox(bool inside_game_viewport)
Definition: GUIWindow.cpp:319
MUSIC_MainMenu
@ MUSIC_MainMenu
Definition: AudioPlayer.h:109
UIMSG_ShowCredits
@ UIMSG_ShowCredits
Definition: GUIWindow.h:42
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
GUIWindow_MainMenu::Loop
static void Loop()
Definition: UIMainMenu.cpp:118
GUIWindow_MainMenu::ui_mainmenu_new
Image * ui_mainmenu_new
Definition: UIMainMenu.h:23
AudioPlayer::StopChannels
void StopChannels(int uStartChannel, int uEndChannel)
Definition: AudioPlayer.cpp:331
GUIFont::CalcTextHeight
unsigned int CalcTextHeight(const String &str, unsigned int width, int x_offset, bool return_on_carriage=false)
Definition: GUIFont.cpp:246
MediaPlayer.h
window
EGLSurface EGLNativeWindowType * window
Definition: SDL_egl.h:1580
f
GLfloat f
Definition: SDL_opengl_glext.h:1873
GUI_UpdateWindows
void GUI_UpdateWindows()
Definition: GUIWindow.cpp:956
UIMainMenu.h
UIMSG_MainMenu_ShowPartyCreationWnd
@ UIMSG_MainMenu_ShowPartyCreationWnd
Definition: GUIWindow.h:40
GUIWindow_MainMenu::ui_mainmenu_load
Image * ui_mainmenu_load
Definition: UIMainMenu.h:24
GUIWindow_MainMenu::Update
virtual void Update()
Definition: UIMainMenu.cpp:47
GUIMessageQueue::PopMessage
void PopMessage(UIMessageType *pMsg, int *pParam, int *a4)
Definition: GUIWindow.cpp:174
first_initialization
static bool first_initialization
Definition: UIMainMenu.cpp:116
GUIWindow::uFrameY
unsigned int uFrameY
Definition: GUIWindow.h:469
GUIWindow_MainMenu::pBtnLoad
GUIButton * pBtnLoad
Definition: UIMainMenu.h:18
GUIWindow_MainMenu::~GUIWindow_MainMenu
virtual ~GUIWindow_MainMenu()
Definition: UIMainMenu.cpp:39
AudioPlayer.h
CURRENT_SCREEN::SCREEN_GAME
@ SCREEN_GAME
GUIWindow_MainMenu::pBtnNew
GUIButton * pBtnNew
Definition: UIMainMenu.h:19
GUIWindow_MainMenu::ui_mainmenu_credits
Image * ui_mainmenu_credits
Definition: UIMainMenu.h:25
Point::y
unsigned int y
Definition: Point.h:8
GUIButton::msg_param
unsigned int msg_param
Definition: GUIButton.h:30
WINDOW_MainMenu
@ WINDOW_MainMenu
Definition: GUIWindow.h:292
GUIWindow::mouse
Mouse * mouse
Definition: GUIWindow.h:491
MENU_CREDITS
@ MENU_CREDITS
Definition: GUIWindow.h:253
assets
AssetsManager * assets
Definition: AssetsManager.cpp:12
UIMSG_ChangeGameState
@ UIMSG_ChangeGameState
Definition: GUIWindow.h:16
GUIWindow_MainMenu
Definition: UIMainMenu.h:5
dword_6BE364_game_settings_1
int dword_6BE364_game_settings_1
Definition: mm7_data.cpp:714
GUIWindow_MainMenu::pBtnCredits
GUIButton * pBtnCredits
Definition: UIMainMenu.h:17
GUIWindow::uFrameX
unsigned int uFrameX
Definition: GUIWindow.h:468
pAudioPlayer
AudioPlayer * pAudioPlayer
Definition: AudioPlayer.cpp:20
pModalWindow
GUIWindow * pModalWindow
Definition: GUIWindow.cpp:57
Point
Definition: Point.h:3
pMessageQueue_50CBD0
struct GUIMessageQueue * pMessageQueue_50CBD0
Definition: GUIWindow.cpp:86
OS_WaitMessage
void OS_WaitMessage()
Definition: Lin.cpp:32
Image::Release
bool Release()
Definition: Image.cpp:335
pFontSmallnum
GUIFont * pFontSmallnum
Definition: GUIFont.cpp:25
Mouse.h
GUIWindow_MainMenu::main_menu_background
Image * main_menu_background
Definition: UIMainMenu.h:21
render
std::shared_ptr< IRender > render
Definition: RenderOpenGL.cpp:52