forked from EasyRPG/Player
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwindow_item.cpp
137 lines (113 loc) · 3.51 KB
/
window_item.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
/*
* 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 "window_item.h"
#include "game_party.h"
#include "bitmap.h"
#include "font.h"
#include <lcf/reader_util.h>
#include "game_battle.h"
#include "output.h"
Window_Item::Window_Item(int ix, int iy, int iwidth, int iheight) :
Window_Selectable(ix, iy, iwidth, iheight) {
column_max = 2;
}
const lcf::rpg::Item* Window_Item::GetItem() const {
if (index < 0) {
return nullptr;
}
return lcf::ReaderUtil::GetElement(lcf::Data::items, data[index]);
}
bool Window_Item::CheckInclude(int item_id) {
if (data.size() == 0 && item_id == 0) {
return true;
} else {
return (item_id > 0);
}
}
bool Window_Item::CheckEnable(int item_id) {
auto* item = lcf::ReaderUtil::GetElement(lcf::Data::items, item_id);
if (!item) {
return false;
}
if (item->type == lcf::rpg::Item::Type_medicine
&& (!Game_Battle::IsBattleRunning() || !item->occasion_field1)) {
return true;
}
return Main_Data::game_party->IsItemUsable(item_id, actor);
}
void Window_Item::Refresh() {
std::vector<int> party_items;
data.clear();
Main_Data::game_party->GetItems(party_items);
for (size_t i = 0; i < party_items.size(); ++i) {
if (this->CheckInclude(party_items[i])) {
data.push_back(party_items[i]);
}
}
if (Game_Battle::IsBattleRunning()) {
// Include equipped accessories that invoke skills in sorted order.
if (actor) {
for (int i = 1; i <= 5; ++i) {
const lcf::rpg::Item* item = actor->GetEquipment(i);
if (item && item->use_skill && item->skill_id > 0) {
auto iter = std::lower_bound(data.begin(), data.end(), item->ID);
if (iter == data.end() || *iter != item->ID) {
data.insert(iter, item->ID);
}
}
}
}
}
if (CheckInclude(0)) {
data.push_back(0);
}
item_max = data.size();
CreateContents();
SetIndex(index);
contents->Clear();
for (int i = 0; i < item_max; ++i) {
DrawItem(i);
}
}
void Window_Item::DrawItem(int index) {
Rect rect = GetItemRect(index);
contents->ClearRect(rect);
int item_id = data[index];
if (item_id > 0) {
int number = Main_Data::game_party->GetItemCount(item_id);
// Items are guaranteed to be valid
const lcf::rpg::Item* item = lcf::ReaderUtil::GetElement(lcf::Data::items, item_id);
if (actor) {
if (item->use_skill) {
number += actor->GetItemCount(item_id);
}
}
bool enabled = CheckEnable(item_id);
DrawItemName(*item, rect.x, rect.y, enabled);
Font::SystemColor color = enabled ? Font::ColorDefault : Font::ColorDisabled;
contents->TextDraw(rect.x + rect.width - 24, rect.y, color, fmt::format("{}{:3d}", lcf::rpg::Terms::TermOrDefault(lcf::Data::terms.easyrpg_item_number_separator, ":"), number));
}
}
void Window_Item::UpdateHelp() {
help_window->SetText(GetItem() == nullptr ? "" : ToString(GetItem()->description));
}
void Window_Item::SetActor(Game_Actor * actor) {
this->actor = actor;
}