World of Might and Magic  0.2.0
Open reimplementation of Might and Magic 6 7 8 game engine
GUIButton.cpp
См. документацию.
1 #include "GUI/GUIButton.h"
2 
3 #include <vector>
4 
5 #include "Engine/Engine.h"
6 #include "Engine/LOD.h"
7 #include "Engine/Localization.h"
8 
9 #include "GUI/GUIFont.h"
10 #include "GUI/GUIWindow.h"
11 
12 #include "Platform/OSWindow.h"
13 
24 
25 
32 
33 
39 
40 
48 
49 
61 
62 
68 
69 
73 
80 
83 
84 
89 
90 std::array<GUIButton *, 4> pCreationUI_BtnPressRight2;
91 std::array<GUIButton *, 4> pCreationUI_BtnPressLeft2;
92 std::array<GUIButton *, 4> pCreationUI_BtnPressLeft;
93 std::array<GUIButton *, 4> pCreationUI_BtnPressRight;
94 
96  std::vector<GUIButton *>::iterator it =
97  std::find(pParent->vButtons.begin(), pParent->vButtons.end(), this);
98  if (it != pParent->vButtons.end()) {
99  pParent->vButtons.erase(it);
100  }
101  delete this;
102 }
103 
104 void GUIButton::DrawLabel(const String &label_text, GUIFont *pFont, int a5,
105  int uFontShadowColor) {
106  return pParent->DrawText(
107  pFont,
108  this->uX + (int)(this->uWidth - pFont->GetLineWidth(label_text)) / 2,
109  this->uY + (int)(this->uHeight - pFont->GetHeight()) / 2, a5,
110  label_text, 0, 0, uFontShadowColor);
111 }
112 
113 bool GUIButton::Contains(unsigned int x, unsigned int y) {
114  return (x >= uX && x <= uZ && y >= uY && y <= uW);
115 }
116 
117 void CreateButtonInColumn(int column_pos, unsigned int control_id) {
118  pDialogueWindow->CreateButton(480, 30 * column_pos + 146, 140, 30, 1, 0,
119  UIMSG_SelectShopDialogueOption, control_id, 0,
120  "");
121 }
122 
126  ptr_507BA4->Release();
127  pBtn_Up->Release();
128  pBtn_Down->Release();
129  pBtn_Down = 0;
130  pBtn_Up = 0;
131  for (GUIButton *pButton : pGUIWindow_CurrentMenu->vButtons) {
132  if (pButton->msg == UIMSG_InventoryLeftClick) {
133  pButton->uX = dword_50698C_uX;
134  pButton->uY = dword_506988_uY;
135  pButton->uZ = dword_506984_uZ;
136  pButton->uW = dword_506980_uW;
138  1, 0, 0, 0);
139  }
140  }
141  }
142 }
143 
147  for (GUIButton *pButton : pGUIWindow_CurrentMenu->vButtons) {
148  if (pButton->msg == UIMSG_InventoryLeftClick) {
149  dword_50698C_uX = pButton->uX;
150  dword_506988_uY = pButton->uY;
151  dword_506984_uZ = pButton->uZ;
152  dword_506980_uW = pButton->uW;
153  pButton->uW = 0;
154  pButton->uZ = 0;
155  pButton->uY = 0;
156  pButton->uX = 0;
157  }
158  }
160  438, 46, ui_ar_up_up->GetWidth(), ui_ar_up_up->GetHeight(), 1, 0,
161  UIMSG_ClickAwardsUpBtn, 0, 0, "", {{ui_ar_up_up, ui_ar_up_dn}});
163  438, 292, ui_ar_dn_up->GetWidth(), ui_ar_dn_up->GetHeight(), 1, 0,
164  UIMSG_ClickAwardsDownBtn, 0, 0, "", {{ui_ar_dn_up, ui_ar_dn_dn}});
166  440, 62, 16, 232, 1, 0, UIMSG_ClickAwardScrollBar, 0, 0, "");
167  }
168 }
169 
172  pDialogueWindow = new GUIWindow(WINDOW_Dialogue, 0, 0, window->GetWidth(), 345, 0);
174  471, 445, 169, 35, 1, 0, UIMSG_Escape, 0, 0,
175  localization->GetString(74), // "End Conversation"
176  {{ui_exit_cancel_button_background}});
177  pDialogueWindow->CreateButton(8, 8, 450, 320, 1, 0, UIMSG_BuyInShop_Identify_Repair, 0, 0, "");
178 }
OSWindow.h
pButton_RestUI_Exit
GUIButton * pButton_RestUI_Exit
Definition: GUIButton.cpp:35
pButton_RestUI_Main
GUIButton * pButton_RestUI_Main
Definition: GUIButton.cpp:34
pBtn_Rest
GUIButton * pBtn_Rest
Definition: GUIButton.cpp:55
GUIWindow::DrawText
void DrawText(GUIFont *font, int x, int y, unsigned short uFontColor, const char *str, bool present_time_transparency=false, int max_text_height=0, int uFontShadowColor=0)
Definition: GUIWindow.cpp:694
pCreationUI_BtnPressLeft2
std::array< GUIButton *, 4 > pCreationUI_BtnPressLeft2
Definition: GUIButton.cpp:91
pBtn_NewGame
GUIButton * pBtn_NewGame
Definition: GUIButton.cpp:79
Localization::GetString
const char * GetString(unsigned int index) const
Definition: Localization.cpp:13
UIMSG_ClickAwardsDownBtn
@ UIMSG_ClickAwardsDownBtn
Definition: GUIWindow.h:137
UIMSG_Escape
@ UIMSG_Escape
Definition: GUIWindow.h:96
pBtnArrowUp
GUIButton * pBtnArrowUp
Definition: GUIButton.cpp:86
LOD.h
Image::GetHeight
unsigned int GetHeight()
Definition: Image.cpp:230
GUIFont
Definition: GUIFont.h:8
GUIWindow
Definition: GUIWindow.h:433
pBtnCancel
GUIButton * pBtnCancel
Definition: GUIButton.cpp:87
pPlayerCreationUI_BtnMinus
GUIButton * pPlayerCreationUI_BtnMinus
Definition: GUIButton.cpp:31
pCharacterScreen_InventoryBtn
GUIButton * pCharacterScreen_InventoryBtn
Definition: GUIButton.cpp:43
GUIButton::pParent
GUIWindow * pParent
Definition: GUIButton.h:33
pGUIWindow_CurrentMenu
GUIWindow * pGUIWindow_CurrentMenu
Definition: GUIWindow.cpp:54
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
GUIButton::uZ
unsigned int uZ
Definition: GUIButton.h:25
pBtn_CloseBook
GUIButton * pBtn_CloseBook
Definition: GUIButton.cpp:14
CreateButtonInColumn
void CreateButtonInColumn(int column_pos, unsigned int control_id)
Definition: GUIButton.cpp:117
pBtn_Autonotes
GUIButton * pBtn_Autonotes
Definition: GUIButton.cpp:59
pCharacterScreen_StatsBtn
GUIButton * pCharacterScreen_StatsBtn
Definition: GUIButton.cpp:45
pBtn_Book_1
GUIButton * pBtn_Book_1
Definition: GUIButton.cpp:23
dword_506984_uZ
int dword_506984_uZ
Definition: mm7_data.cpp:537
localization
Localization * localization
Definition: Localization.cpp:11
pBtn_Calendar
GUIButton * pBtn_Calendar
Definition: GUIButton.cpp:57
GUIFont::GetLineWidth
unsigned int GetLineWidth(const String &str)
Definition: GUIFont.cpp:278
GUIWindow::Release
virtual void Release()
Definition: GUIWindow.cpp:292
GUIFont.h
pCreationUI_BtnPressRight
std::array< GUIButton *, 4 > pCreationUI_BtnPressRight
Definition: GUIButton.cpp:93
GUIFont::GetHeight
unsigned int GetHeight() const
Definition: GUIFont.cpp:84
UIMSG_SelectShopDialogueOption
@ UIMSG_SelectShopDialogueOption
Definition: GUIWindow.h:194
pCreationUI_BtnPressLeft
std::array< GUIButton *, 4 > pCreationUI_BtnPressLeft
Definition: GUIButton.cpp:92
GUIButton
Definition: GUIButton.h:11
pMMT_MainMenu_BtnContinue
GUIButton * pMMT_MainMenu_BtnContinue
Definition: GUIButton.cpp:66
Engine.h
pBtn_Quests
GUIButton * pBtn_Quests
Definition: GUIButton.cpp:60
ui_ar_up_up
Image * ui_ar_up_up
Definition: GUIWindow.cpp:103
GUIWindow::vButtons
std::vector< GUIButton * > vButtons
Definition: GUIWindow.h:489
awards_scroll_bar_created
int awards_scroll_bar_created
Definition: mm7_data.cpp:557
GUIWindow::_41D08F_set_keyboard_control_group
void _41D08F_set_keyboard_control_group(int num_buttons, int a3, int a4, int a5)
Definition: GUIWindow.cpp:273
pBtn_Book_4
GUIButton * pBtn_Book_4
Definition: GUIButton.cpp:20
GUIButton::Contains
bool Contains(unsigned int x, unsigned int y)
Definition: GUIButton.cpp:113
pCreationUI_BtnPressRight2
std::array< GUIButton *, 4 > pCreationUI_BtnPressRight2
Definition: GUIButton.cpp:90
Localization.h
y
EGLSurface EGLint EGLint y
Definition: SDL_egl.h:1596
Image::GetWidth
unsigned int GetWidth()
Definition: Image.cpp:217
pBtn_Book_5
GUIButton * pBtn_Book_5
Definition: GUIButton.cpp:19
GUIButton.h
pBtn_ExitCancel
GUIButton * pBtn_ExitCancel
Definition: GUIButton.cpp:28
pBtn_YES
GUIButton * pBtn_YES
Definition: GUIButton.cpp:29
CreateAwardsScrollBar
void CreateAwardsScrollBar()
Definition: GUIButton.cpp:144
pButton_RestUI_Wait1Hour
GUIButton * pButton_RestUI_Wait1Hour
Definition: GUIButton.cpp:38
x
EGLSurface EGLint x
Definition: SDL_egl.h:1596
UIMSG_ClickAwardScrollBar
@ UIMSG_ClickAwardScrollBar
Definition: GUIWindow.h:159
pCharacterScreen_SkillsBtn
GUIButton * pCharacterScreen_SkillsBtn
Definition: GUIButton.cpp:44
WINDOW_Dialogue
@ WINDOW_Dialogue
Definition: GUIWindow.h:298
GUIButton::msg
UIMessageType msg
Definition: GUIButton.h:29
pBtn_Book_2
GUIButton * pBtn_Book_2
Definition: GUIButton.cpp:22
ReleaseAwardsScrollBar
void ReleaseAwardsScrollBar()
Definition: GUIButton.cpp:123
window
EGLSurface EGLNativeWindowType * window
Definition: SDL_egl.h:1580
pBtn_NPCLeft
GUIButton * pBtn_NPCLeft
Definition: GUIButton.cpp:51
UIMSG_InventoryLeftClick
@ UIMSG_InventoryLeftClick
Definition: GUIWindow.h:103
pButton_RestUI_WaitUntilDawn
GUIButton * pButton_RestUI_WaitUntilDawn
Definition: GUIButton.cpp:37
GUIButton::uWidth
unsigned int uWidth
Definition: GUIButton.h:23
pBtn_InstallRemoveSpell
GUIButton * pBtn_InstallRemoveSpell
Definition: GUIButton.cpp:15
UIMSG_BuyInShop_Identify_Repair
@ UIMSG_BuyInShop_Identify_Repair
Definition: GUIWindow.h:66
UIMSG_ClickAwardsUpBtn
@ UIMSG_ClickAwardsUpBtn
Definition: GUIWindow.h:136
dword_506988_uY
int dword_506988_uY
Definition: mm7_data.cpp:538
pBtn_Down
GUIButton * pBtn_Down
Definition: GUIButton.cpp:71
GUIButton::uX
unsigned int uX
Definition: GUIButton.h:21
pBtn_GameSettings
GUIButton * pBtn_GameSettings
Definition: GUIButton.cpp:52
GUIButton::uW
unsigned int uW
Definition: GUIButton.h:26
pBtnLoadSlot
GUIButton * pBtnLoadSlot
Definition: GUIButton.cpp:88
pButton_RestUI_Wait5Minutes
GUIButton * pButton_RestUI_Wait5Minutes
Definition: GUIButton.cpp:36
pBtnDownArrow
GUIButton * pBtnDownArrow
Definition: GUIButton.cpp:85
pBtn_Resume
GUIButton * pBtn_Resume
Definition: GUIButton.cpp:74
pMMT_MainMenu_BtnMM7
GUIButton * pMMT_MainMenu_BtnMM7
Definition: GUIButton.cpp:64
pPlayerCreationUI_BtnOK
GUIButton * pPlayerCreationUI_BtnOK
Definition: GUIButton.cpp:27
pBtn_Book_3
GUIButton * pBtn_Book_3
Definition: GUIButton.cpp:21
pPlayerCreationUI_BtnReset
GUIButton * pPlayerCreationUI_BtnReset
Definition: GUIButton.cpp:26
pBtn_Maps
GUIButton * pBtn_Maps
Definition: GUIButton.cpp:58
pBtn_Autonotes_Misc
GUIButton * pBtn_Autonotes_Misc
Definition: GUIButton.cpp:17
pBtn_QuickReference
GUIButton * pBtn_QuickReference
Definition: GUIButton.cpp:53
GUIButton::DrawLabel
void DrawLabel(const String &label_text, GUIFont *pFont, int a5, int uFontShadowColor)
Definition: GUIButton.cpp:104
GUIButton::uY
unsigned int uY
Definition: GUIButton.h:22
pBtn_SliderLeft
GUIButton * pBtn_SliderLeft
Definition: GUIButton.cpp:82
GUIButton::Release
void Release()
Definition: GUIButton.cpp:95
pBtn_Autonotes_Instructors
GUIButton * pBtn_Autonotes_Instructors
Definition: GUIButton.cpp:16
pBtn_SliderRight
GUIButton * pBtn_SliderRight
Definition: GUIButton.cpp:81
ptr_507BA4
GUIButton * ptr_507BA4
Definition: GUIButton.cpp:72
pCharacterScreen_ExitBtn
GUIButton * pCharacterScreen_ExitBtn
Definition: GUIButton.cpp:41
pCharacterScreen_DetalizBtn
GUIButton * pCharacterScreen_DetalizBtn
Definition: GUIButton.cpp:47
dword_50698C_uX
int dword_50698C_uX
Definition: mm7_data.cpp:539
pCharacterScreen_AwardsBtn
GUIButton * pCharacterScreen_AwardsBtn
Definition: GUIButton.cpp:42
dword_506980_uW
int dword_506980_uW
Definition: mm7_data.cpp:536
pCharacterScreen_DollBtn
GUIButton * pCharacterScreen_DollBtn
Definition: GUIButton.cpp:46
UI_CreateEndConversationButton
void UI_CreateEndConversationButton()
Definition: GUIButton.cpp:170
pMMT_MainMenu_BtnExit
GUIButton * pMMT_MainMenu_BtnExit
Definition: GUIButton.cpp:67
pBtn_NPCRight
GUIButton * pBtn_NPCRight
Definition: GUIButton.cpp:50
GUIWindow.h
pMMT_MainMenu_BtnMM8
GUIButton * pMMT_MainMenu_BtnMM8
Definition: GUIButton.cpp:65
pDialogueWindow
GUIWindow * pDialogueWindow
Definition: GUIWindow.cpp:50
pBtn_Up
GUIButton * pBtn_Up
Definition: GUIButton.cpp:70
pBtn_CastSpell
GUIButton * pBtn_CastSpell
Definition: GUIButton.cpp:54
pBtn_LoadGame
GUIButton * pBtn_LoadGame
Definition: GUIButton.cpp:77
pBtn_History
GUIButton * pBtn_History
Definition: GUIButton.cpp:56
pPlayerCreationUI_BtnPlus
GUIButton * pPlayerCreationUI_BtnPlus
Definition: GUIButton.cpp:30
ui_ar_dn_up
Image * ui_ar_dn_up
Definition: GUIWindow.cpp:101
pBtn_Book_6
GUIButton * pBtn_Book_6
Definition: GUIButton.cpp:18
String
std::string String
Definition: Strings.h:10
pBtn_SaveGame
GUIButton * pBtn_SaveGame
Definition: GUIButton.cpp:78
pBtn_GameControls
GUIButton * pBtn_GameControls
Definition: GUIButton.cpp:76
pBtn_QuitGame
GUIButton * pBtn_QuitGame
Definition: GUIButton.cpp:75
pMMT_MainMenu_BtnMM6
GUIButton * pMMT_MainMenu_BtnMM6
Definition: GUIButton.cpp:63