forked from EasyRPG/Player
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwindow_equipstatus.cpp
147 lines (126 loc) · 3.57 KB
/
window_equipstatus.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/*
* This file is part of EasyRPG Player.
*
* EasyRPG Player is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* EasyRPG Player is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with EasyRPG Player. If not, see <http://www.gnu.org/licenses/>.
*/
// Headers
#include <iomanip>
#include <sstream>
#include "game_actors.h"
#include "window_equipstatus.h"
#include "bitmap.h"
#include "font.h"
#include "player.h"
Window_EquipStatus::Window_EquipStatus(int ix, int iy, int iwidth, int iheight, const Game_Actor& actor) :
Window_Base(ix, iy, iwidth, iheight),
actor(actor),
draw_params(false),
dirty(true) {
SetContents(Bitmap::Create(width - 16, height - 16));
Refresh();
}
void Window_EquipStatus::Refresh() {
if (dirty) {
contents->Clear();
int y_offset;
y_offset = 18;
// Actor data is guaranteed to be valid
DrawActorName(actor, 0, 2);
for (int i = 0; i < 4; ++i) {
DrawParameter(0, y_offset + ((12 + 4) * i), i);
}
dirty = false;
}
}
void Window_EquipStatus::SetNewParameters(
int new_atk, int new_def, int new_spi, int new_agi) {
draw_params = true;
dirty = true;
atk = new_atk;
def = new_def;
spi = new_spi;
agi = new_agi;
}
void Window_EquipStatus::ClearParameters() {
if (draw_params != false) {
draw_params = false;
dirty = true;
Refresh();
}
}
int Window_EquipStatus::GetNewParameterColor(int old_value, int new_value) {
if (old_value == new_value) {
return 0;
} else if (old_value < new_value) {
return 2;
} else {
return 3;
}
}
void Window_EquipStatus::DrawParameter(int cx, int cy, int type) {
StringView name;
int value;
int new_value;
switch (type) {
case 0:
name = lcf::Data::terms.attack;
value = actor.GetAtk();
new_value = atk;
break;
case 1:
name = lcf::Data::terms.defense;
value = actor.GetDef();
new_value = def;
break;
case 2:
name = lcf::Data::terms.spirit;
value = actor.GetSpi();
new_value = spi;
break;
case 3:
name = lcf::Data::terms.agility;
value = actor.GetAgi();
new_value = agi;
break;
default:
return;
}
// Check if 4 digits are needed instead of 3
int limit = actor.MaxStatBaseValue();
bool more_space_needed = (Player::IsRPG2k3() && limit >= 500) || limit >= 1000;
// Draw Term
contents->TextDraw(cx, cy, 1, name);
// Draw Value
cx += (more_space_needed ? (8 * 6 + 6 * 4) : (10 * 6 + 6 * 3));
contents->TextDraw(cx, cy, Font::ColorDefault, std::to_string(value), Text::AlignRight);
if (draw_params) {
if (lcf::Data::terms.easyrpg_equipment_arrow == lcf::Data::terms.kDefaultTerm) {
if (Player::IsCP932()) {
// Draw fullwidth arrow
contents->TextDraw(cx, cy, 1, "→");
} else {
// Draw arrow (+3 for center between the two numbers)
contents->TextDraw(cx + 3, cy, 1, ">");
}
} else {
// Draw arrow
int offset = (12 - Text::GetSize(*Font::Default(), lcf::Data::terms.easyrpg_equipment_arrow).width) / 2;
contents->TextDraw(cx + offset, cy, 1, lcf::Data::terms.easyrpg_equipment_arrow);
}
// Draw New Value
cx += 6 * 2 + (more_space_needed ? (6 * 4) : (6 * 3));
int color = GetNewParameterColor(value, new_value);
contents->TextDraw(cx, cy, color, std::to_string(new_value), Text::AlignRight);
}
}