World of Might and Magic  0.2.0
Open reimplementation of Might and Magic 6 7 8 game engine
GUIProgressBar.cpp
См. документацию.
1 #include "GUI/GUIProgressBar.h"
2 
3 #include <algorithm>
4 
5 #include "Engine/AssetsManager.h"
6 #include "Engine/Engine.h"
7 #include "Engine/LOD.h"
8 #include "Engine/Party.h"
9 
11 
13 
15 
17  progressbar_dungeon = nullptr;
18  progressbar_loading = nullptr;
19  loading_bg = nullptr;
20 }
21 
23  Release();
24 
25  switch (type) {
26  case TYPE_None:
27  return true;
28 
29  case TYPE_Box:
30  case TYPE_Fullscreen:
31  break;
32 
33  default:
34  Error("Invalid GUIProgressBar type: %u", type);
35  }
36 
37  if (loading_bg) {
38  return false;
39  }
40 
41  uType = type;
42 
43  if (uType == TYPE_Fullscreen) {
44  loading_bg = assets->GetImage_PCXFromIconsLOD(StringPrintf("loading%d.pcx", rand() % 5 + 1));
45 
46  uProgressCurrent = 0;
47  uX = 122;
48  uY = 151;
49  uWidth = 449;
50  uHeight = 56;
51  uProgressMax = 26;
52 
54  Draw();
55  return true;
56  } else {
57  switch (pParty->alignment) {
59  progressbar_dungeon = assets->GetImage_ColorKey("bardata-b", 0x7FF);
60  break;
62  progressbar_dungeon = assets->GetImage_ColorKey("bardata", 0x7FF);
63  break;
65  progressbar_dungeon = assets->GetImage_ColorKey("bardata-c", 0x7FF);
66  break;
67  default:
68  Error("Invalid alignment type: %u", pParty->alignment);
69  }
70  }
71 
72  uProgressCurrent = 0;
73  uProgressMax = 26;
74  Draw();
75  return true;
76 }
77 
78 void GUIProgressBar::Reset(uint8_t uMaxProgress) {
79  uProgressCurrent = 0;
80  uProgressMax = uMaxProgress;
81 }
82 
85  Draw();
86 }
87 
89  if (loading_bg != nullptr) {
91  loading_bg = nullptr;
92  }
93 
94  if (progressbar_loading != nullptr) {
96  progressbar_loading = nullptr;
97  }
98 
99  if (progressbar_dungeon != nullptr) {
101  progressbar_dungeon = nullptr;
102  }
103 }
104 
106  render->BeginScene();
107 
108  if (uType != TYPE_Fullscreen) {
109  render->DrawTextureAlphaNew(80 / 640.0f, 122 / 480.0f, progressbar_dungeon);
110  render->DrawTextureAlphaNew(100 / 640.0f, 146 / 480.0f, pIconsFrameTable->GetFrame(uIconID_TurnHour, 0)->GetTexture());
111  render->FillRectFast(174, 164, floorf(((double)(113 * uProgressCurrent) / (double)uProgressMax) + 0.5f), 16, 0xF800);
112  } else {
113  if (loading_bg) {
114  render->DrawTextureNew(0, 0, loading_bg);
115  }
116  render->SetUIClipRect(172, 459, (int)((double)(300 * uProgressCurrent) / (double)uProgressMax) + 172, 471);
117  render->DrawTextureAlphaNew(172 / 640.0f, 459 / 480.0f, progressbar_loading);
118  render->ResetUIClipRect();
119  }
120 
121  render->EndScene();
122  render->Present();
123 }
GUIProgressBar::progressbar_dungeon
Image * progressbar_dungeon
Definition: GUIProgressBar.h:34
IconFrameTable.h
PartyAlignment::PartyAlignment_Good
@ PartyAlignment_Good
PartyAlignment::PartyAlignment_Neutral
@ PartyAlignment_Neutral
LOD.h
GUIProgressBar::TYPE_Fullscreen
@ TYPE_Fullscreen
Definition: GUIProgressBar.h:11
pIconsFrameTable
struct IconFrameTable * pIconsFrameTable
Definition: mm7_data.cpp:168
PartyAlignment::PartyAlignment_Evil
@ PartyAlignment_Evil
GUIProgressBar::Type
Type
Definition: GUIProgressBar.h:9
GUIProgressBar::uType
Type uType
Definition: GUIProgressBar.h:32
AssetsManager::GetImage_PCXFromIconsLOD
Texture * GetImage_PCXFromIconsLOD(const String &name)
Definition: AssetsManager.cpp:81
GUIProgressBar::uHeight
int uHeight
Definition: GUIProgressBar.h:28
Icon::GetTexture
Texture * GetTexture()
Definition: IconFrameTable.cpp:9
AssetsManager.h
Engine.h
GUIProgressBar::Initialize
bool Initialize(Type type)
Definition: GUIProgressBar.cpp:22
pParty
Party * pParty
Definition: Party.cpp:30
IRender.h
pGameLoadingUI_ProgressBar
GUIProgressBar * pGameLoadingUI_ProgressBar
Definition: GUIProgressBar.cpp:14
GUIProgressBar::TYPE_Box
@ TYPE_Box
Definition: GUIProgressBar.h:12
AssetsManager::GetImage_ColorKey
Texture * GetImage_ColorKey(const String &name, uint16_t colorkey)
Definition: AssetsManager.cpp:34
Party.h
GUIProgressBar::Reset
void Reset(uint8_t uMaxProgress)
Definition: GUIProgressBar.cpp:78
GUIProgressBar::uY
int uY
Definition: GUIProgressBar.h:26
f
GLfloat f
Definition: SDL_opengl_glext.h:1873
GUIProgressBar::uX
int uX
Definition: GUIProgressBar.h:25
type
EGLenum type
Definition: SDL_egl.h:850
GUIProgressBar::Draw
void Draw()
Definition: GUIProgressBar.cpp:105
GUIProgressBar::uProgressCurrent
uint8_t uProgressCurrent
Definition: GUIProgressBar.h:31
GUIProgressBar::TYPE_None
@ TYPE_None
Definition: GUIProgressBar.h:10
uIconID_TurnHour
unsigned int uIconID_TurnHour
Definition: mm7_data.cpp:572
IconFrameTable::GetFrame
Icon * GetFrame(unsigned int uIconID, unsigned int frame_time)
Definition: IconFrameTable.cpp:39
GUIProgressBar::uProgressMax
uint8_t uProgressMax
Definition: GUIProgressBar.h:30
uint8_t
unsigned __int8 uint8_t
Definition: SDL_config.h:35
GUIProgressBar::Release
void Release()
Definition: GUIProgressBar.cpp:88
assets
AssetsManager * assets
Definition: AssetsManager.cpp:12
GUIProgressBar::GUIProgressBar
GUIProgressBar()
Definition: GUIProgressBar.cpp:16
AssetsManager::GetImage_Alpha
Texture * GetImage_Alpha(const String &name)
Definition: AssetsManager.cpp:66
GUIProgressBar
Definition: GUIProgressBar.h:7
GUIProgressBar::uWidth
int uWidth
Definition: GUIProgressBar.h:27
GUIProgressBar::Progress
void Progress()
Definition: GUIProgressBar.cpp:83
StringPrintf
String StringPrintf(const char *fmt,...)
Definition: Strings.cpp:9
GUIProgressBar.h
GUIProgressBar::progressbar_loading
Image * progressbar_loading
Definition: GUIProgressBar.h:35
GUIProgressBar::loading_bg
Image * loading_bg
Definition: GUIProgressBar.h:37
Image::Release
bool Release()
Definition: Image.cpp:335
Party::alignment
PartyAlignment alignment
Definition: Party.h:308
render
std::shared_ptr< IRender > render
Definition: RenderOpenGL.cpp:52