Skip to content

Commit c016ff1

Browse files
authored
Merge pull request #3434 from florianessl/fix/VisualFixes
Visual Fixes
2 parents fcef8db + 814489c commit c016ff1

File tree

10 files changed

+82
-53
lines changed

10 files changed

+82
-53
lines changed

src/audio_generic.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,9 @@ bool GenericAudio::PlayOnChannel(BgmChannel& chan, Filesystem_Stream::InputStrea
229229
chan.paused = true; // Pause channel so the audio thread doesn't work on it
230230
chan.stopped = false; // Unstop channel so the audio thread doesn't delete it
231231

232+
std::string_view name = filestream.GetName();
232233
if (!filestream) {
233-
Output::Warning("BGM file not readable: {}", filestream.GetName());
234+
Output::Warning("BGM file not readable: {}", name);
234235
return false;
235236
}
236237

@@ -282,7 +283,7 @@ bool GenericAudio::PlayOnChannel(BgmChannel& chan, Filesystem_Stream::InputStrea
282283

283284
return true;
284285
} else {
285-
Output::Warning("Couldn't play BGM {}. Format not supported", filestream.GetName());
286+
Output::Warning("Couldn't play BGM {}. Format not supported", name);
286287
}
287288

288289
return false;

src/game_character.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1054,7 +1054,7 @@ bool Game_Character::CalculateMoveRoute(const CalculateMoveRouteArgs& args) {
10541054
route.skippable = args.skip_when_failed;
10551055
route.repeat = false;
10561056

1057-
for (SearchNode node2 : list_move) {
1057+
for (SearchNode const& node2 : list_move) {
10581058
if (node2.direction >= 0) {
10591059
lcf::rpg::MoveCommand cmd;
10601060
cmd.command_id = node2.direction;

src/plane.cpp

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,13 @@ void Plane::Draw(Bitmap& dst) {
5050
int src_x = -ox - GetRenderOx();
5151
int src_y = -oy - GetRenderOy();
5252

53+
int offset_x = 0;
54+
5355
// Apply screen shaking
5456
const int shake_x = Main_Data::game_screen->GetShakeOffsetX();
5557
const int shake_y = Main_Data::game_screen->GetShakeOffsetY();
5658
if (Game_Map::LoopHorizontal()) {
57-
src_x += shake_x;
59+
offset_x = shake_x;
5860
} else {
5961
// The panorama occupies the same rectangle as the whole map.
6062
// Using coordinates where the top-left of the screen is the origin...
@@ -82,11 +84,26 @@ void Plane::Draw(Bitmap& dst) {
8284
dst_rect.x = bg_x;
8385
dst_rect.width = bg_width;
8486

87+
if (Game_Map::GetDisplayX() / 16 + Player::screen_width > Game_Map::GetTilesX() * TILE_SIZE) {
88+
// Do not draw out of bounds to the right
89+
dst_rect.width -= (Game_Map::GetDisplayX() / 16 + Player::screen_width) - (Game_Map::GetTilesX() * TILE_SIZE);
90+
}
91+
8592
// Correct the offset if the top-left corner moved.
86-
src_x += shake_x + bg_x;
93+
offset_x = shake_x + bg_x;
8794
}
8895
src_y += shake_y;
8996

90-
dst.TiledBlit(src_x, src_y, source->GetRect(), *source, dst_rect, 255);
91-
}
97+
dst.TiledBlit(src_x + offset_x, src_y, source->GetRect(), *source, dst_rect, 255);
9298

99+
if (!Game_Map::LoopHorizontal()) {
100+
// Clear out of bounds map area visible during shake
101+
if (offset_x < 0 && src_x + offset_x < 0) {
102+
auto clear_rect = Rect(dst.GetRect().x, dst.GetRect().y, -offset_x, dst.GetRect().height);
103+
dst.ClearRect(clear_rect);
104+
} else if (dst_rect.width < Player::screen_width) {
105+
auto clear_rect = Rect(dst_rect.width, dst.GetRect().y, Player::screen_width - dst_rect.width, dst.GetRect().height);
106+
dst.ClearRect(clear_rect);
107+
}
108+
}
109+
}

src/sprite_timer.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "game_party.h"
2424
#include "game_system.h"
2525
#include "game_battle.h"
26+
#include "window_message.h"
2627
#include <player.h>
2728

2829
Sprite_Timer::Sprite_Timer(int which) :
@@ -90,7 +91,10 @@ void Sprite_Timer::Draw(Bitmap& dst) {
9091
if (Game_Battle::IsBattleRunning()) {
9192
SetY((Player::screen_height / 3 * 2) - 20);
9293
}
93-
else if (Game_Message::IsMessageActive() && Game_Message::GetRealPosition() == 0) {
94+
// RPG_RT doesn't check for the global setting for window positioning (Top/Middle/Bottom)
95+
// here. It actually just checks for the Y position of the message window, regardless if
96+
// it is active or visible.
97+
else if (Game_Message::GetWindow()->GetY() < 20) {
9498
SetY(Player::screen_height - 20 - Player::menu_offset_y);
9599
}
96100
else {

src/spriteset_battle.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#include "sprite_actor.h"
3232
#include "sprite_enemy.h"
3333

34-
Spriteset_Battle::Spriteset_Battle(const std::string bg_name, int terrain_id)
34+
Spriteset_Battle::Spriteset_Battle(std::string bg_name, int terrain_id)
3535
{
3636
background_name = std::move(bg_name);
3737

src/window_item.cpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -108,26 +108,27 @@ void Window_Item::DrawItem(int index) {
108108
contents->ClearRect(rect);
109109

110110
int item_id = data[index];
111+
if (item_id <= 0)
112+
return;
111113

112-
if (item_id > 0) {
113-
int number = Main_Data::game_party->GetItemCount(item_id);
114+
int number = Main_Data::game_party->GetItemCount(item_id);
114115

115-
// Items are guaranteed to be valid
116-
const lcf::rpg::Item* item = lcf::ReaderUtil::GetElement(lcf::Data::items, item_id);
117-
if (actor) {
118-
if (item->use_skill) {
119-
number += actor->GetItemCount(item_id);
120-
}
116+
// Items are guaranteed to be valid
117+
const lcf::rpg::Item* item = lcf::ReaderUtil::GetElement(lcf::Data::items, item_id);
118+
if (actor) {
119+
if (item->use_skill) {
120+
number += actor->GetItemCount(item_id);
121121
}
122+
}
122123

123-
bool enabled = CheckEnable(item_id);
124-
DrawItemName(*item, rect.x, rect.y, enabled);
124+
bool enabled = CheckEnable(item_id);
125+
DrawItemName(*item, rect.x, rect.y, enabled);
125126

126-
Font::SystemColor color = enabled ? Font::ColorDefault : Font::ColorDisabled;
127-
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));
128-
}
127+
Font::SystemColor color = enabled ? Font::ColorDefault : Font::ColorDisabled;
128+
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));
129129
}
130130

131+
131132
void Window_Item::UpdateHelp() {
132133
help_window->SetText(GetItem() == nullptr ? "" : ToString(GetItem()->description));
133134
}

src/window_message.cpp

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,8 @@ void Window_Message::StartMessageProcessing(PendingMessage pm) {
190190

191191
DebugLog("{}: MSG TEXT \n{}", text);
192192

193-
auto open_frames = (!IsVisible() && !Game_Battle::IsBattleRunning()) ? message_animation_frames : 0;
194-
SetOpenAnimation(open_frames);
195-
DebugLog("{}: MSG START OPEN {}", open_frames);
196-
197-
InsertNewPage();
193+
disallow_next_message = true;
194+
msg_was_pushed_this_frame = true;
198195
}
199196

200197
void Window_Message::OnFinishPage() {
@@ -419,7 +416,7 @@ void Window_Message::Update() {
419416
if (IsClosing()) { DebugLog("{}: MSG CLOSING"); }
420417

421418
close_started_this_frame = false;
422-
close_finished_this_frame = false;
419+
disallow_next_message = false;
423420

424421
const bool was_closing = IsClosing();
425422

@@ -428,10 +425,22 @@ void Window_Message::Update() {
428425
gold_window->Update();
429426

430427
if (was_closing && !IsClosing()) {
431-
close_finished_this_frame = true;
428+
disallow_next_message = true;
432429
}
433430

434431
if (!IsVisible()) {
432+
if (msg_was_pushed_this_frame) {
433+
msg_was_pushed_this_frame = false;
434+
disallow_next_message = true;
435+
return;
436+
}
437+
if (!text.empty() && text_index == text.data()) {
438+
auto open_frames = (!IsVisible() && !Game_Battle::IsBattleRunning()) ? message_animation_frames : 0;
439+
SetOpenAnimation(open_frames);
440+
DebugLog("{}: MSG START OPEN {}", open_frames);
441+
442+
InsertNewPage();
443+
}
435444
return;
436445
}
437446

src/window_message.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,9 @@ class Window_Message: public Window_Selectable {
165165
// FIXME: This hacky flags exist because RPG_RT likely animates the message window
166166
// after the game loop finishes. Our code isn't structured that way, so we must hack
167167
// around it.
168+
bool msg_was_pushed_this_frame = false;
168169
bool close_started_this_frame = false;
169-
bool close_finished_this_frame = false;
170+
bool disallow_next_message = false;
170171

171172
/** Frames to wait when a message wait command was used */
172173
int wait_count = 0;
@@ -214,8 +215,8 @@ inline AsyncOp Window_Message::GetAsyncOp() const {
214215
}
215216

216217
inline bool Window_Message::GetAllowNextMessage(bool foreground) const {
217-
bool is_active = (IsVisible() || close_finished_this_frame);
218-
return foreground ? !is_active || close_started_this_frame : !is_active;
218+
bool is_active = (IsVisible() || disallow_next_message);
219+
return foreground ? !is_active || (close_started_this_frame && !disallow_next_message): !is_active;
219220
}
220221

221222
inline int Window_Message::GetMaxLinesPerPage() const {

src/window_shopbuy.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,27 +57,25 @@ void Window_ShopBuy::Refresh() {
5757
}
5858

5959
void Window_ShopBuy::DrawItem(int index) {
60+
Rect rect = GetItemRect(index);
61+
contents->ClearRect(rect);
62+
6063
int item_id = data[index];
64+
if (item_id <= 0)
65+
return;
6166

6267
// (Shop) items are guaranteed to be valid
6368
const lcf::rpg::Item* item = lcf::ReaderUtil::GetElement(lcf::Data::items, item_id);
64-
65-
int price = 0;
66-
bool enabled = false;
67-
6869
if (!item) {
6970
Output::Warning("Window ShopBuy: Invalid item ID {}", item_id);
70-
} else {
71-
enabled = item->price <= Main_Data::game_party->GetGold() && Main_Data::game_party->GetItemCount(item_id) < Main_Data::game_party->GetMaxItemCount(item_id);
72-
price = item->price;
71+
return;
7372
}
7473

75-
Rect rect = GetItemRect(index);
76-
contents->ClearRect(rect);
74+
bool enabled = CheckEnable(item_id);
7775
DrawItemName(*item, rect.x, rect.y, enabled);
7876

79-
std::string str = std::to_string(price);
80-
contents->TextDraw(rect.width, rect.y, enabled ? Font::ColorDefault : Font::ColorDisabled, str, Text::AlignRight);
77+
Font::SystemColor color = enabled ? Font::ColorDefault : Font::ColorDisabled;
78+
contents->TextDraw(rect.width, rect.y, color, std::to_string(item->price), Text::AlignRight);
8179
}
8280

8381
void Window_ShopBuy::UpdateHelp() {

src/window_skill.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,16 @@ void Window_Skill::DrawItem(int index) {
7676
contents->ClearRect(rect);
7777

7878
int skill_id = data[index];
79+
if (skill_id <= 0)
80+
return;
7981

80-
if (skill_id > 0) {
81-
int costs = actor->CalculateSkillCost(skill_id);
82+
bool enabled = CheckEnable(skill_id);
83+
Font::SystemColor color = enabled ? Font::ColorDefault : Font::ColorDisabled;
84+
int costs = actor->CalculateSkillCost(skill_id);
85+
contents->TextDraw(rect.x + rect.width - 24, rect.y, color, fmt::format("{}{:3d}", lcf::rpg::Terms::TermOrDefault(lcf::Data::terms.easyrpg_skill_cost_separator, "-"), costs));
8286

83-
bool enabled = CheckEnable(skill_id);
84-
int color = !enabled ? Font::ColorDisabled : Font::ColorDefault;
85-
86-
contents->TextDraw(rect.x + rect.width - 24, rect.y, color, fmt::format("{}{:3d}", lcf::rpg::Terms::TermOrDefault(lcf::Data::terms.easyrpg_skill_cost_separator, "-"), costs));
87-
88-
// Skills are guaranteed to be valid
89-
DrawSkillName(*lcf::ReaderUtil::GetElement(lcf::Data::skills, skill_id), rect.x, rect.y, enabled);
90-
}
87+
// Skills are guaranteed to be valid
88+
DrawSkillName(*lcf::ReaderUtil::GetElement(lcf::Data::skills, skill_id), rect.x, rect.y, enabled);
9189
}
9290

9391
void Window_Skill::UpdateHelp() {

0 commit comments

Comments
 (0)