Skip to content

Commit

Permalink
Added separate Width/Height Values for pictures
Browse files Browse the repository at this point in the history
Added:
- Separate Width and Height value as per .scale2 parameter in ManiacPatch 211010
- Set Height to Width when using picture effects (as per ManiacPatch)
- Set both Width and Height to Magnify when using .scale parameter
- When scaling, set Width and Height to 0.0 if either one is set to 0.0

Bugfix:
- Fix crash when getting width/height on invalid bitmap
- Fix ManiacPatch picture rotation not fully working

Revert big brain gamer move

What could possibly go wrong?
Re-added the assert tags

Final thing

Bad Window.h file

Wrong files

Redone a few things

ShowStringPicture should now work with scaling enabled
  • Loading branch information
ToolMan2k committed Jan 7, 2024
1 parent 92a0dc4 commit 7b7cb51
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 10 deletions.
63 changes: 55 additions & 8 deletions src/game_interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2804,6 +2804,9 @@ bool Game_Interpreter::CommandShowPicture(lcf::rpg::EventCommand const& com) { /
params.saturation = com.parameters[11];
params.effect_mode = com.parameters[12];
params.effect_power = com.parameters[13];
// Set width and height to current magnify value
params.scale_width = params.magnify;
params.scale_height = params.magnify;

size_t param_size = com.parameters.size();

Expand All @@ -2828,7 +2831,18 @@ bool Game_Interpreter::CommandShowPicture(lcf::rpg::EventCommand const& com) { /
}
params.name = PicPointerPatch::ReplaceName(params.name, var, com.parameters[18]);
}
params.magnify = ValueOrVariable(com.parameters[20], params.magnify);
// When using special effects on Maniacs, Height is set to Width
// However by removing the effect_mode check, we can use separate Width and Height on EasyRPG by default
if (Player::IsPatchManiac() && com.parameters[20] >= 16 && params.effect_mode == 0) {
params.scale_width = ValueOrVariableBitfield((com.parameters[20]), 0, com.parameters[5]);
params.scale_height = ValueOrVariableBitfield((com.parameters[20] >> 1), 1, com.parameters[31]);
params.magnify = params.scale_width;
} else {
params.magnify = ValueOrVariableBitfield(com.parameters[20] & 0x0F, 0, com.parameters[5]);
params.scale_width = params.magnify;
params.scale_height = params.magnify;
}

params.top_trans = ValueOrVariable(com.parameters[21], params.top_trans);
if (com.parameters[22] > 0) {
// If spritesheet is enabled
Expand Down Expand Up @@ -2880,6 +2894,8 @@ bool Game_Interpreter::CommandShowPicture(lcf::rpg::EventCommand const& com) { /
params.magnify = std::max(0, std::min(params.magnify, 2000));
params.top_trans = std::max(0, std::min(params.top_trans, 100));
params.bottom_trans = std::max(0, std::min(params.bottom_trans, 100));
params.scale_width = std::max(0, std::min(params.scale_width, 2000));
params.scale_height = std::max(0, std::min(params.scale_height, 2000));

if (pic_id <= 0) {
Output::Error("ShowPicture: Requested invalid picture id ({})", pic_id);
Expand Down Expand Up @@ -2923,6 +2939,9 @@ bool Game_Interpreter::CommandMovePicture(lcf::rpg::EventCommand const& com) { /
params.effect_mode = com.parameters[12];
params.effect_power = com.parameters[13];
params.duration = com.parameters[14];
// Set width and height to current magnify value
params.scale_width = params.magnify;
params.scale_height = params.magnify;

bool wait = com.parameters[15] != 0;

Expand All @@ -2936,7 +2955,18 @@ bool Game_Interpreter::CommandMovePicture(lcf::rpg::EventCommand const& com) { /
// Currently unused by RPG Maker
//int chars_to_replace = com.parameters[18];
//int replace_with = com.parameters[19];
params.magnify = ValueOrVariable(com.parameters[20], params.magnify);

// When using special effects on Maniacs, Height is set to Width
// However by removing the effect_mode check, we can use separate Width and Height on EasyRPG by default
if (Player::IsPatchManiac() && com.parameters[20] >= 16 && params.effect_mode == 0) {
params.scale_width = ValueOrVariableBitfield((com.parameters[20] ), 0, com.parameters[5]);
params.scale_height = ValueOrVariableBitfield((com.parameters[20] >> 1), 1, com.parameters[18]);
params.magnify = params.scale_width;
} else {
params.magnify = ValueOrVariableBitfield(com.parameters[20], 0, com.parameters[5]);
params.scale_width = params.magnify;
params.scale_height = params.magnify;
}
params.top_trans = ValueOrVariable(com.parameters[21], params.top_trans);
}

Expand All @@ -2962,8 +2992,8 @@ bool Game_Interpreter::CommandMovePicture(lcf::rpg::EventCommand const& com) { /
params.origin = com.parameters[1] >> 8;

if (params.effect_mode == lcf::rpg::SavePicture::Effect_maniac_fixed_angle) {
params.effect_power = ValueOrVariableBitfield(com.parameters[16], 0, params.effect_power);
int divisor = ValueOrVariableBitfield(com.parameters[16], 1, com.parameters[15]);
params.effect_power = ValueOrVariableBitfield(com.parameters[4], 0, params.effect_power);
int divisor = ValueOrVariableBitfield(com.parameters[4], 1, com.parameters[7]);
if (divisor == 0) {
divisor = 1;
}
Expand All @@ -2981,6 +3011,8 @@ bool Game_Interpreter::CommandMovePicture(lcf::rpg::EventCommand const& com) { /
params.magnify = std::max(0, std::min(params.magnify, 2000));
params.top_trans = std::max(0, std::min(params.top_trans, 100));
params.bottom_trans = std::max(0, std::min(params.bottom_trans, 100));
params.scale_width = std::max(0, std::min(params.scale_width, 2000));
params.scale_height = std::max(0, std::min(params.scale_height, 2000));
params.duration = std::max(Player::IsPatchManiac() ? -10000 : 0, std::min(params.duration, 10000));

if (pic_id <= 0) {
Expand Down Expand Up @@ -4271,6 +4303,21 @@ bool Game_Interpreter::CommandManiacShowStringPicture(lcf::rpg::EventCommand con
params.battle_layer = com.parameters[16];
params.flags = com.parameters[17];

params.scale_width = params.magnify;
params.scale_height = params.magnify;

// When using special effects on Maniacs, Height is set to Width
// However by removing the effect_mode check, we can use separate Width and Height on EasyRPG by default
if (Player::IsPatchManiac() && com.parameters[0] >= 0x10000000 && ( params.effect_mode == 0)) {
params.scale_width = ValueOrVariableBitfield((com.parameters[0] ), 2, com.parameters[4]);
params.scale_height = ValueOrVariableBitfield((com.parameters[0] >> 1), 7, com.parameters[23]);
params.magnify = params.scale_width;
} else {
params.magnify = ValueOrVariableBitfield(com.parameters[0], 2, com.parameters[4]);
params.scale_width = params.magnify;
params.scale_height = params.magnify;
}

int flags = com.parameters[12];
int blend_mode = flags & 0xF;
if (blend_mode == 1) {
Expand Down Expand Up @@ -4410,14 +4457,14 @@ bool Game_Interpreter::CommandManiacGetPictureInfo(lcf::rpg::EventCommand const&
case 1:
x = Utils::RoundTo<int>(data.current_x);
y = Utils::RoundTo<int>(data.current_y);
width = Utils::RoundTo<int>(width * data.current_magnify / 100.0);
height = Utils::RoundTo<int>(height * data.current_magnify / 100.0);
width = Utils::RoundTo<int>(width * data.current_scale_width / 100.0);
height = Utils::RoundTo<int>(height * data.current_scale_height / 100.0);
break;
case 2:
x = Utils::RoundTo<int>(data.finish_x);
y = Utils::RoundTo<int>(data.finish_y);
width = Utils::RoundTo<int>(width * data.finish_magnify / 100.0);
height = Utils::RoundTo<int>(height * data.finish_magnify / 100.0);
width = Utils::RoundTo<int>(width * data.finish_scale_width / 100.0);
height = Utils::RoundTo<int>(height * data.finish_scale_height / 100.0);
break;
}

Expand Down
8 changes: 8 additions & 0 deletions src/game_pictures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ void SyncCurrentToFinish(lcf::rpg::SavePicture& data) {
data.current_blue = data.finish_blue;
data.current_sat = data.finish_sat;
data.current_magnify = data.finish_magnify;
data.current_scale_width = data.finish_scale_width;
data.current_scale_height = data.finish_scale_height;
data.current_top_trans = data.finish_top_trans;
data.current_bot_trans = data.finish_bot_trans;
if (do_effect) {
Expand Down Expand Up @@ -534,6 +536,8 @@ void Game_Pictures::Picture::Update(bool is_battle) {
data.current_blue = interpolate(data.current_blue, data.finish_blue);
data.current_sat = interpolate(data.current_sat, data.finish_sat);
data.current_magnify = interpolate(data.current_magnify, data.finish_magnify);
data.current_scale_width = interpolate(data.current_scale_width, data.finish_scale_width);
data.current_scale_height = interpolate(data.current_scale_height, data.finish_scale_height);
data.current_top_trans = interpolate(data.current_top_trans, data.finish_top_trans);
data.current_bot_trans = interpolate(data.current_bot_trans, data.finish_bot_trans);
}
Expand Down Expand Up @@ -602,6 +606,8 @@ Game_Pictures::ShowParams Game_Pictures::Picture::GetShowParams() const {
params.position_x = static_cast<int>(data.finish_x);
params.position_y = static_cast<int>(data.finish_y);
params.magnify = data.finish_magnify;
params.scale_width = data.finish_scale_width;
params.scale_height = data.finish_scale_height;
params.top_trans = data.finish_top_trans;
params.bottom_trans = data.finish_bot_trans;
params.red = data.finish_red;
Expand Down Expand Up @@ -632,6 +638,8 @@ void Game_Pictures::Picture::SetNonEffectParams(const Params& params, bool set_p
data.finish_y = params.position_y;
}
data.finish_magnify = params.magnify;
data.finish_scale_width = params.scale_width;
data.finish_scale_height = params.scale_height;
data.finish_top_trans = params.top_trans;
data.finish_bot_trans = params.bottom_trans;
data.finish_red = params.red;
Expand Down
2 changes: 2 additions & 0 deletions src/game_pictures.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ class Game_Pictures {
bool flip_y = false;
int blend_mode = 0;
int origin = 0;
int scale_width = 100;
int scale_height = 100;
};
struct ShowParams : Params {
std::string name;
Expand Down
16 changes: 14 additions & 2 deletions src/sprite_picture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,20 @@ void Sprite_Picture::Draw(Bitmap& dst) {
SetX(x);
SetY(y);
}
SetZoomX(data.current_magnify / 100.0);
SetZoomY(data.current_magnify / 100.0);

if (Player::IsPatchManiac()) {
// Sanitanize zoom value to zero, otherwise we'll see a ghost square up left
if (data.current_scale_width == 0.0 || data.current_scale_height == 0.0) {
SetZoomX(0.0);
SetZoomY(0.0);
} else {
SetZoomX(data.current_scale_width / 100.0);
SetZoomY(data.current_scale_height / 100.0);
}
} else {
SetZoomX(data.current_magnify / 100.0);
SetZoomY(data.current_magnify / 100.0);
}

auto sr = GetSrcRect();
SetOx(sr.width / 2);
Expand Down

0 comments on commit 7b7cb51

Please sign in to comment.