1 /*
2 * This file is part of EasyRPG Player.
3 *
4 * EasyRPG Player is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * EasyRPG Player is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with EasyRPG Player. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 // Headers
19 #include "sprite_timer.h"
20 #include "cache.h"
21 #include "bitmap.h"
22 #include "game_message.h"
23 #include "game_party.h"
24 #include "game_system.h"
25 #include "game_battle.h"
26
Sprite_Timer(int which)27 Sprite_Timer::Sprite_Timer(int which) :
28 which(which)
29 {
30 if (which != Game_Party::Timer1 &&
31 which != Game_Party::Timer2) {
32 assert(false && "Invalid timer");
33 }
34
35 for (auto& d: digits) {
36 d = Rect(0, 32, 8, 16);
37 }
38 digits[2].x = 32 + 8 * 10; // :
39
40 SetBitmap(Bitmap::Create(40, 16));
41
42 SetVisible(false);
43
44 switch (which) {
45 case Game_Party::Timer1:
46 SetX(4);
47 break;
48 case Game_Party::Timer2:
49 SetX(SCREEN_TARGET_WIDTH - 8 * 5 - 4);
50 break;
51 default:
52 break;
53 }
54
55 SetZ(Priority_Timer);
56 SetVisible(true);
57 }
58
~Sprite_Timer()59 Sprite_Timer::~Sprite_Timer() {
60 }
61
Draw(Bitmap & dst)62 void Sprite_Timer::Draw(Bitmap& dst) {
63 if (!Main_Data::game_party->GetTimerVisible(which, Game_Battle::IsBattleRunning())) {
64 return;
65 }
66
67 // RPG_RT never displays timers if there is no system graphic.
68 BitmapRef system = Cache::System();
69 if (!system) {
70 return;
71 }
72
73 const int all_secs = Main_Data::game_party->GetTimerSeconds(which);
74
75 int mins = all_secs / 60;
76 int secs = all_secs % 60;
77
78 int mins_1 = mins % 10;
79 int mins_10 = mins / 10;
80
81 int secs_1 = secs % 10;
82 int secs_10 = secs / 10;
83
84 digits[0].x = 32 + 8 * mins_10;
85 digits[1].x = 32 + 8 * mins_1;
86 digits[3].x = 32 + 8 * secs_10;
87 digits[4].x = 32 + 8 * secs_1;
88
89 if (Game_Battle::IsBattleRunning()) {
90 SetY(SCREEN_TARGET_HEIGHT / 3 * 2 - 20);
91 }
92 else if (Game_Message::IsMessageActive() && Game_Message::GetRealPosition() == 0) {
93 SetY(SCREEN_TARGET_HEIGHT - 20);
94 }
95 else {
96 SetY(4);
97 }
98
99 GetBitmap()->Clear();
100 for (int i = 0; i < 5; ++i) {
101 if (i == 2) { // :
102 int frames = Main_Data::game_party->GetTimerFrames(which);
103 if (frames % DEFAULT_FPS < DEFAULT_FPS / 2) {
104 continue;
105 }
106 }
107 GetBitmap()->Blit(i * 8, 0, *system, digits[i], Opacity());
108 }
109
110 Sprite::Draw(dst);
111 }
112
113