Skip to content

Commit

Permalink
Merge pull request #3052 from EasyRPG-NewFeatures/Primekick-Battle2k3
Browse files Browse the repository at this point in the history
Battle 2k3: fixed battler facing direction + horizontal ally/enemy select
  • Loading branch information
fdelapena authored Sep 21, 2023
2 parents c35380f + 16217f0 commit 42a5683
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 8 deletions.
9 changes: 9 additions & 0 deletions src/feature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,12 @@ bool Feature::HasPlaceholders() {

return Player::IsRPG2k3() && HasRpg2kBattleSystem() && lcf::Data::system.easyrpg_battle_use_rpg2ke_strings;
}

bool Feature::HasFixedActorFacingDirection() {
return HasRpg2k3BattleSystem() && lcf::Data::battlecommands.easyrpg_fixed_actor_facing_direction > 0;
}

bool Feature::HasFixedEnemyFacingDirection() {
return HasRpg2k3BattleSystem() && lcf::Data::battlecommands.easyrpg_fixed_enemy_facing_direction > 0;
}

10 changes: 10 additions & 0 deletions src/feature.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ namespace Feature {
* @return true if text placeholders are used
*/
bool HasPlaceholders();

/**
* @return true if fixed actor facing direction is used
*/
bool HasFixedActorFacingDirection();

/**
* @return true if fixed enemy facing direction is used
*/
bool HasFixedEnemyFacingDirection();
}

#endif
17 changes: 15 additions & 2 deletions src/game_battler.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,15 @@ class Game_Battler {

/**
* Gets the base attribute rate when actor is damaged, without battle attribute shifts.
*
*
* @param attribute_id Attribute to query
* @return Attribute rate
*/
virtual int GetBaseAttributeRate(int attribute_id) const = 0;

/**
* Gets the attribute rate when actor is damaged.
*
*
* @param attribute_id Attribute to query
* @return Attribute rate
*/
Expand Down Expand Up @@ -431,6 +431,9 @@ class Game_Battler {
/** @return whether the battler is facing the opposite it's normal direction */
bool IsDirectionFlipped() const;

/** @return whether the battler's sprite should be facing the opposite it's normal direction */
bool IsSpriteDirectionFlipped() const;

/**
* Set whether the battler is facing the opposite it's normal direction
*
Expand Down Expand Up @@ -1155,4 +1158,14 @@ inline int Game_Battler::CalculateWeaponSpCost(Weapon) const {
return 0;
}

inline bool Game_Battler::IsSpriteDirectionFlipped() const {
switch (GetBattleSprite()->GetFixedFacing()) {
case Sprite_Battler::AlwaysFlipped:
return true;
case Sprite_Battler::NeverFlipped:
return false;
default:
return IsDirectionFlipped();
}
}
#endif
3 changes: 3 additions & 0 deletions src/scene_battle_rpg2k3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,8 @@ void Scene_Battle_Rpg2k3::CreateBattleTargetWindow() {
int transp = IsTransparent() ? 160 : 255;
target_window->SetBackOpacity(transp);
}

target_window->SetSingleColumnWrapping(true);
}

void Scene_Battle_Rpg2k3::RefreshTargetWindow() {
Expand Down Expand Up @@ -1744,6 +1746,7 @@ Scene_Battle_Rpg2k3::SceneActionReturn Scene_Battle_Rpg2k3::ProcessSceneActionVi
auto* sprite = actor->GetActorBattleSprite();
if (actor->Exists() && sprite) {
sprite->SetNormalAttacking(false);
sprite->ResetFixedFacingDirection();
auto* weapon = actor->GetWeaponSprite();
if (weapon) {
weapon->StopAttack();
Expand Down
9 changes: 8 additions & 1 deletion src/sprite_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,17 @@
#include "player.h"
#include <lcf/reader_util.h>
#include "output.h"
#include "feature.h"
#include "game_battle.h"

Sprite_Actor::Sprite_Actor(Game_Actor* actor)
: Sprite_Battler(actor, actor->GetId())
{
CreateSprite();
auto condition = Game_Battle::GetBattleCondition();
if ((condition == lcf::rpg::System::BattleCondition_none || condition == lcf::rpg::System::BattleCondition_initiative) && Feature::HasFixedActorFacingDirection()) {
fixed_facing = static_cast<FixedFacing>(lcf::Data::battlecommands.easyrpg_fixed_actor_facing_direction);
}
}

Sprite_Actor::~Sprite_Actor() {
Expand Down Expand Up @@ -60,7 +66,7 @@ void Sprite_Actor::Update() {

if (animation) {
// Is a battle animation
animation->SetInvert(battler->IsDirectionFlipped());
animation->SetInvert(battler->IsSpriteDirectionFlipped());
animation->Update();

if (animation->IsDone()) {
Expand Down Expand Up @@ -284,6 +290,7 @@ void Sprite_Actor::Draw(Bitmap& dst) {
int steps = static_cast<int>(256 / images.size());
int opacity = steps;
for (auto it = images.crbegin(); it != images.crend(); ++it) {
Sprite_Battler::SetFixedFlipX();
Sprite_Battler::SetX(it->x);
Sprite_Battler::SetY(it->y);
Sprite_Battler::SetOpacity(std::min(opacity, 255));
Expand Down
35 changes: 35 additions & 0 deletions src/sprite_battler.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ class Game_Battler;
*/
class Sprite_Battler : public Sprite {
public:
enum FixedFacing {
Disabled = 0,
AlwaysFlipped = 1,
NeverFlipped = 2,
};
/**
* Constructor.
*
Expand All @@ -44,6 +49,15 @@ class Sprite_Battler : public Sprite {

void SetBattler(Game_Battler* new_battler);

void ResetFixedFacingDirection();

FixedFacing GetFixedFacing() const;

/**
* Sets the sprite flip when fixed facing direction is enabled. Otherwise does nothing..
*/
void SetFixedFlipX();

/**
* Recompute the Z value for the sprite from it's Y coordinate.
*/
Expand All @@ -52,6 +66,7 @@ class Sprite_Battler : public Sprite {
protected:
Game_Battler* battler = nullptr;
int battle_index = 0;
FixedFacing fixed_facing = Disabled;
};

inline Game_Battler* Sprite_Battler::GetBattler() const {
Expand All @@ -62,5 +77,25 @@ inline void Sprite_Battler::SetBattler(Game_Battler* new_battler) {
battler = new_battler;
}

inline void Sprite_Battler::ResetFixedFacingDirection() {
fixed_facing = Disabled;
}

inline void Sprite_Battler::SetFixedFlipX() {
switch (fixed_facing) {
case AlwaysFlipped:
SetFlipX(true);
break;
case NeverFlipped:
SetFlipX(false);
break;
default:
break;
}
}

inline Sprite_Battler::FixedFacing Sprite_Battler::GetFixedFacing() const {
return fixed_facing;
}

#endif
12 changes: 11 additions & 1 deletion src/sprite_enemy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,17 @@
#include "player.h"
#include <lcf/reader_util.h>
#include "output.h"
#include "feature.h"
#include "game_battle.h"

Sprite_Enemy::Sprite_Enemy(Game_Enemy* enemy)
: Sprite_Battler(enemy, enemy->GetTroopMemberId())
{
CreateSprite();
auto condition = Game_Battle::GetBattleCondition();
if ((condition == lcf::rpg::System::BattleCondition_none || condition == lcf::rpg::System::BattleCondition_initiative) && Feature::HasFixedEnemyFacingDirection()) {
fixed_facing = static_cast<FixedFacing>(lcf::Data::battlecommands.easyrpg_fixed_enemy_facing_direction);
}
}

Sprite_Enemy::~Sprite_Enemy() {
Expand Down Expand Up @@ -119,7 +125,11 @@ void Sprite_Enemy::Draw(Bitmap& dst) {
SetX(enemy->GetDisplayX());
SetY(enemy->GetDisplayY());
SetFlashEffect(enemy->GetFlashColor());
SetFlipX(enemy->IsDirectionFlipped());
if (fixed_facing != Disabled) {
SetFixedFlipX();
} else {
SetFlipX(enemy->IsDirectionFlipped());
}

Sprite_Battler::Draw(dst);
}
Expand Down
4 changes: 2 additions & 2 deletions src/window_battlestatus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ void Window_BattleStatus::Update() {
}

if (active && index >= 0) {
if (Input::IsRepeated(Input::DOWN) || Input::IsTriggered(Input::SCROLL_DOWN)) {
if (Input::IsRepeated(Input::DOWN) || Input::IsRepeated(Input::RIGHT) || Input::IsTriggered(Input::SCROLL_DOWN)) {
Main_Data::game_system->SePlay(Main_Data::game_system->GetSystemSE(Main_Data::game_system->SFX_Cursor));
for (int i = 1; i < item_max; i++) {
int new_index = (index + i) % item_max;
Expand All @@ -293,7 +293,7 @@ void Window_BattleStatus::Update() {
}
}
}
if (Input::IsRepeated(Input::UP) || Input::IsTriggered(Input::SCROLL_UP)) {
if (Input::IsRepeated(Input::UP) || Input::IsRepeated(Input::LEFT) || Input::IsTriggered(Input::SCROLL_UP)) {
Main_Data::game_system->SePlay(Main_Data::game_system->GetSystemSE(Main_Data::game_system->SFX_Cursor));
for (int i = item_max - 1; i > 0; i--) {
int new_index = (index + i) % item_max;
Expand Down
8 changes: 6 additions & 2 deletions src/window_selectable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,13 @@ void Window_Selectable::Update() {
}
}
if (Input::IsRepeated(Input::RIGHT)) {
if (column_max >= 2 && index < item_max - 1) {
if (column_max >= wrap_limit && index < item_max - 1) {
Main_Data::game_system->SePlay(Main_Data::game_system->GetSystemSE(Main_Data::game_system->SFX_Cursor));
index += 1;
}
}
if (Input::IsRepeated(Input::LEFT)) {
if (column_max >= 2 && index > 0) {
if (column_max >= wrap_limit && index > 0) {
Main_Data::game_system->SePlay(Main_Data::game_system->GetSystemSE(Main_Data::game_system->SFX_Cursor));
index -= 1;
}
Expand Down Expand Up @@ -234,3 +234,7 @@ void Window_Selectable::SetEndlessScrolling(bool state) {
void Window_Selectable::SetMenuItemHeight(int height) {
menu_item_height = height;
}

void Window_Selectable::SetSingleColumnWrapping(bool wrap) {
wrap_limit = wrap ? 1 : 2;
}
10 changes: 10 additions & 0 deletions src/window_selectable.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ class Window_Selectable: public Window_Base {
*/
void SetMenuItemHeight(int height);

/**
* Allow left/right input to move cursor up/down when the selectable has only one column.
* By default this behaviour is only enabled for two and more columns.
*
* @param wrap enable/disable single column wrap
*/
void SetSingleColumnWrapping(bool wrap);

protected:
void UpdateArrows();

Expand All @@ -107,6 +115,8 @@ class Window_Selectable: public Window_Base {

int scroll_dir = 0;
int scroll_progress = 0;

int wrap_limit = 2;
};

inline void Window_Selectable::SetItemMax(int value) {
Expand Down

0 comments on commit 42a5683

Please sign in to comment.