Refactor OverworldEditor to use zelda3::GameEntity
This commit is contained in:
@@ -16,7 +16,7 @@ using ImGui::SameLine;
|
|||||||
using ImGui::Selectable;
|
using ImGui::Selectable;
|
||||||
using ImGui::Text;
|
using ImGui::Text;
|
||||||
|
|
||||||
bool IsMouseHoveringOverEntity(const zelda3::OverworldEntity &entity,
|
bool IsMouseHoveringOverEntity(const zelda3::GameEntity &entity,
|
||||||
ImVec2 canvas_p0, ImVec2 scrolling) {
|
ImVec2 canvas_p0, ImVec2 scrolling) {
|
||||||
// Get the mouse position relative to the canvas
|
// Get the mouse position relative to the canvas
|
||||||
const ImGuiIO &io = ImGui::GetIO();
|
const ImGuiIO &io = ImGui::GetIO();
|
||||||
@@ -31,7 +31,7 @@ bool IsMouseHoveringOverEntity(const zelda3::OverworldEntity &entity,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MoveEntityOnGrid(zelda3::OverworldEntity *entity, ImVec2 canvas_p0,
|
void MoveEntityOnGrid(zelda3::GameEntity *entity, ImVec2 canvas_p0,
|
||||||
ImVec2 scrolling, bool free_movement) {
|
ImVec2 scrolling, bool free_movement) {
|
||||||
// Get the mouse position relative to the canvas
|
// Get the mouse position relative to the canvas
|
||||||
const ImGuiIO &io = ImGui::GetIO();
|
const ImGuiIO &io = ImGui::GetIO();
|
||||||
@@ -51,19 +51,19 @@ void MoveEntityOnGrid(zelda3::OverworldEntity *entity, ImVec2 canvas_p0,
|
|||||||
entity->set_y(new_y);
|
entity->set_y(new_y);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HandleEntityDragging(zelda3::OverworldEntity *entity, ImVec2 canvas_p0,
|
void HandleEntityDragging(zelda3::GameEntity *entity, ImVec2 canvas_p0,
|
||||||
ImVec2 scrolling, bool &is_dragging_entity,
|
ImVec2 scrolling, bool &is_dragging_entity,
|
||||||
zelda3::OverworldEntity *&dragged_entity,
|
zelda3::GameEntity *&dragged_entity,
|
||||||
zelda3::OverworldEntity *¤t_entity,
|
zelda3::GameEntity *¤t_entity,
|
||||||
bool free_movement) {
|
bool free_movement) {
|
||||||
std::string entity_type = "Entity";
|
std::string entity_type = "Entity";
|
||||||
if (entity->type_ == zelda3::OverworldEntity::EntityType::kExit) {
|
if (entity->entity_type_ == zelda3::GameEntity::EntityType::kExit) {
|
||||||
entity_type = "Exit";
|
entity_type = "Exit";
|
||||||
} else if (entity->type_ == zelda3::OverworldEntity::EntityType::kEntrance) {
|
} else if (entity->entity_type_ == zelda3::GameEntity::EntityType::kEntrance) {
|
||||||
entity_type = "Entrance";
|
entity_type = "Entrance";
|
||||||
} else if (entity->type_ == zelda3::OverworldEntity::EntityType::kSprite) {
|
} else if (entity->entity_type_ == zelda3::GameEntity::EntityType::kSprite) {
|
||||||
entity_type = "Sprite";
|
entity_type = "Sprite";
|
||||||
} else if (entity->type_ == zelda3::OverworldEntity::EntityType::kItem) {
|
} else if (entity->entity_type_ == zelda3::GameEntity::EntityType::kItem) {
|
||||||
entity_type = "Item";
|
entity_type = "Item";
|
||||||
}
|
}
|
||||||
const auto is_hovering =
|
const auto is_hovering =
|
||||||
@@ -87,7 +87,7 @@ void HandleEntityDragging(zelda3::OverworldEntity *entity, ImVec2 canvas_p0,
|
|||||||
} else if (is_dragging_entity && dragged_entity == entity) {
|
} else if (is_dragging_entity && dragged_entity == entity) {
|
||||||
if (ImGui::BeginDragDropSource()) {
|
if (ImGui::BeginDragDropSource()) {
|
||||||
ImGui::SetDragDropPayload("ENTITY_PAYLOAD", &entity,
|
ImGui::SetDragDropPayload("ENTITY_PAYLOAD", &entity,
|
||||||
sizeof(zelda3::OverworldEntity));
|
sizeof(zelda3::GameEntity));
|
||||||
Text("Moving %s ID: %s", entity_type.c_str(),
|
Text("Moving %s ID: %s", entity_type.c_str(),
|
||||||
core::UppercaseHexByte(entity->entity_id_).c_str());
|
core::UppercaseHexByte(entity->entity_id_).c_str());
|
||||||
ImGui::EndDragDropSource();
|
ImGui::EndDragDropSource();
|
||||||
|
|||||||
@@ -11,16 +11,16 @@ namespace yaze {
|
|||||||
namespace app {
|
namespace app {
|
||||||
namespace editor {
|
namespace editor {
|
||||||
|
|
||||||
bool IsMouseHoveringOverEntity(const zelda3::OverworldEntity &entity,
|
bool IsMouseHoveringOverEntity(const zelda3::GameEntity &entity,
|
||||||
ImVec2 canvas_p0, ImVec2 scrolling);
|
ImVec2 canvas_p0, ImVec2 scrolling);
|
||||||
|
|
||||||
void MoveEntityOnGrid(zelda3::OverworldEntity *entity, ImVec2 canvas_p0,
|
void MoveEntityOnGrid(zelda3::GameEntity *entity, ImVec2 canvas_p0,
|
||||||
ImVec2 scrolling, bool free_movement = false);
|
ImVec2 scrolling, bool free_movement = false);
|
||||||
|
|
||||||
void HandleEntityDragging(zelda3::OverworldEntity *entity, ImVec2 canvas_p0,
|
void HandleEntityDragging(zelda3::GameEntity *entity, ImVec2 canvas_p0,
|
||||||
ImVec2 scrolling, bool &is_dragging_entity,
|
ImVec2 scrolling, bool &is_dragging_entity,
|
||||||
zelda3::OverworldEntity *&dragged_entity,
|
zelda3::GameEntity *&dragged_entity,
|
||||||
zelda3::OverworldEntity *¤t_entity,
|
zelda3::GameEntity *¤t_entity,
|
||||||
bool free_movement = false);
|
bool free_movement = false);
|
||||||
|
|
||||||
bool DrawEntranceInserterPopup();
|
bool DrawEntranceInserterPopup();
|
||||||
|
|||||||
@@ -898,8 +898,8 @@ void OverworldEditor::DrawOverworldSprites() {
|
|||||||
// So we need to check if the map is large or small then add the offset
|
// So we need to check if the map is large or small then add the offset
|
||||||
|
|
||||||
// Calculate the superX and superY values
|
// Calculate the superX and superY values
|
||||||
int superY = map_id / 8;
|
// int superY = map_id / 8;
|
||||||
int superX = map_id % 8;
|
// int superX = map_id % 8;
|
||||||
|
|
||||||
// Calculate the map_x and map_y values
|
// Calculate the map_x and map_y values
|
||||||
int map_x = sprite.map_x();
|
int map_x = sprite.map_x();
|
||||||
|
|||||||
@@ -282,8 +282,8 @@ class OverworldEditor : public Editor,
|
|||||||
zelda3::overworld::OverworldExit current_exit_;
|
zelda3::overworld::OverworldExit current_exit_;
|
||||||
zelda3::overworld::OverworldItem current_item_;
|
zelda3::overworld::OverworldItem current_item_;
|
||||||
|
|
||||||
zelda3::OverworldEntity* current_entity_;
|
zelda3::GameEntity* current_entity_;
|
||||||
zelda3::OverworldEntity* dragged_entity_;
|
zelda3::GameEntity* dragged_entity_;
|
||||||
|
|
||||||
gui::Canvas ow_map_canvas_{"OwMap", kOverworldCanvasSize,
|
gui::Canvas ow_map_canvas_{"OwMap", kOverworldCanvasSize,
|
||||||
gui::CanvasGridSize::k64x64};
|
gui::CanvasGridSize::k64x64};
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ constexpr int kOverworldItemsAddress = 0xDC8B9; // 1BC2F9
|
|||||||
constexpr int overworldItemsBank = 0xDC8BF;
|
constexpr int overworldItemsBank = 0xDC8BF;
|
||||||
constexpr int overworldItemsEndData = 0xDC89C; // 0DC89E
|
constexpr int overworldItemsEndData = 0xDC89C; // 0DC89E
|
||||||
|
|
||||||
class OverworldItem : public OverworldEntity {
|
class OverworldItem : public GameEntity {
|
||||||
public:
|
public:
|
||||||
bool bg2_ = false;
|
bool bg2_ = false;
|
||||||
uint8_t id_;
|
uint8_t id_;
|
||||||
@@ -96,7 +96,7 @@ class OverworldItem : public OverworldEntity {
|
|||||||
this->room_map_id_ = room_map_id;
|
this->room_map_id_ = room_map_id;
|
||||||
this->map_id_ = room_map_id;
|
this->map_id_ = room_map_id;
|
||||||
this->entity_id_ = id;
|
this->entity_id_ = id;
|
||||||
this->type_ = kItem;
|
this->entity_type_ = kItem;
|
||||||
|
|
||||||
int map_x = room_map_id - ((room_map_id / 8) * 8);
|
int map_x = room_map_id - ((room_map_id / 8) * 8);
|
||||||
int map_y = room_map_id / 8;
|
int map_y = room_map_id / 8;
|
||||||
@@ -155,7 +155,7 @@ constexpr int OWExitUnk1Whirlpool = 0x16BF5; // JP = ;016E91
|
|||||||
constexpr int OWExitUnk2Whirlpool = 0x16C17; // JP = ;016EB3
|
constexpr int OWExitUnk2Whirlpool = 0x16C17; // JP = ;016EB3
|
||||||
constexpr int OWWhirlpoolPosition = 0x16CF8; // JP = ;016F94
|
constexpr int OWWhirlpoolPosition = 0x16CF8; // JP = ;016F94
|
||||||
|
|
||||||
class OverworldExit : public OverworldEntity {
|
class OverworldExit : public GameEntity {
|
||||||
public:
|
public:
|
||||||
uint16_t y_scroll_;
|
uint16_t y_scroll_;
|
||||||
uint16_t x_scroll_;
|
uint16_t x_scroll_;
|
||||||
@@ -204,7 +204,7 @@ class OverworldExit : public OverworldEntity {
|
|||||||
x_ = player_x;
|
x_ = player_x;
|
||||||
y_ = player_y;
|
y_ = player_y;
|
||||||
map_id_ = map_id;
|
map_id_ = map_id;
|
||||||
type_ = kExit;
|
entity_type_ = kExit;
|
||||||
|
|
||||||
int mapX = (map_id_ - ((map_id_ / 8) * 8));
|
int mapX = (map_id_ - ((map_id_ / 8) * 8));
|
||||||
int mapY = (map_id_ / 8);
|
int mapY = (map_id_ / 8);
|
||||||
@@ -331,7 +331,7 @@ constexpr int OWHoleArea = 0xDB826;
|
|||||||
//(0x13 entries, 1 byte each) corresponding entrance numbers
|
//(0x13 entries, 1 byte each) corresponding entrance numbers
|
||||||
constexpr int OWHoleEntrance = 0xDB84C;
|
constexpr int OWHoleEntrance = 0xDB84C;
|
||||||
|
|
||||||
class OverworldEntrance : public OverworldEntity {
|
class OverworldEntrance : public GameEntity {
|
||||||
public:
|
public:
|
||||||
uint16_t map_pos_;
|
uint16_t map_pos_;
|
||||||
uchar entrance_id_;
|
uchar entrance_id_;
|
||||||
@@ -348,7 +348,7 @@ class OverworldEntrance : public OverworldEntity {
|
|||||||
y_ = y;
|
y_ = y;
|
||||||
map_id_ = map_id;
|
map_id_ = map_id;
|
||||||
entity_id_ = entrance_id;
|
entity_id_ = entrance_id;
|
||||||
type_ = kEntrance;
|
entity_type_ = kEntrance;
|
||||||
|
|
||||||
int mapX = (map_id_ - ((map_id_ / 8) * 8));
|
int mapX = (map_id_ - ((map_id_ / 8) * 8));
|
||||||
int mapY = (map_id_ / 8);
|
int mapY = (map_id_ / 8);
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ void Sprite::UpdateCoordinates(int map_x, int map_y) {
|
|||||||
map_y_ = map_y;
|
map_y_ = map_y;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sprite::updateBBox() {
|
void Sprite::UpdateBoundaryBox() {
|
||||||
lowerX_ = 1;
|
lowerX_ = 1;
|
||||||
lowerY_ = 1;
|
lowerY_ = 1;
|
||||||
higherX_ = 15;
|
higherX_ = 15;
|
||||||
|
|||||||
@@ -282,35 +282,34 @@ static const std::string kSpriteDefaultNames[]{
|
|||||||
* @class Sprite
|
* @class Sprite
|
||||||
* @brief A class for managing sprites in the overworld and underworld.
|
* @brief A class for managing sprites in the overworld and underworld.
|
||||||
*/
|
*/
|
||||||
class Sprite : public OverworldEntity {
|
class Sprite : public GameEntity {
|
||||||
public:
|
public:
|
||||||
Sprite() = default;
|
Sprite() = default;
|
||||||
Sprite(std::vector<uint8_t> src, uint8_t mapid, uint8_t id, uint8_t x,
|
Sprite(std::vector<uint8_t> src, uint8_t overworld_map_id, uint8_t id,
|
||||||
uint8_t y, int map_x, int map_y)
|
uint8_t x, uint8_t y, int map_x, int map_y)
|
||||||
: current_gfx_(src),
|
: map_id_(static_cast<int>(overworld_map_id)),
|
||||||
map_id_(static_cast<int>(mapid)),
|
|
||||||
id_(id),
|
id_(id),
|
||||||
nx_(x),
|
nx_(x),
|
||||||
ny_(y),
|
ny_(y),
|
||||||
map_x_(map_x),
|
map_x_(map_x),
|
||||||
map_y_(map_y) {
|
map_y_(map_y),
|
||||||
type_ = zelda3::OverworldEntity::EntityType::kSprite;
|
current_gfx_(src) {
|
||||||
|
entity_type_ = zelda3::GameEntity::EntityType::kSprite;
|
||||||
entity_id_ = id;
|
entity_id_ = id;
|
||||||
x_ = map_x_;
|
x_ = map_x_;
|
||||||
y_ = map_y_;
|
y_ = map_y_;
|
||||||
current_gfx_ = src;
|
|
||||||
overworld_ = true;
|
overworld_ = true;
|
||||||
name_ = kSpriteDefaultNames[id];
|
name_ = kSpriteDefaultNames[id];
|
||||||
preview_gfx_.resize(64 * 64, 0xFF);
|
preview_gfx_.resize(64 * 64, 0xFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InitSprite(const std::vector<uint8_t>& src, uint8_t mapid, uint8_t id,
|
void InitSprite(const std::vector<uint8_t>& src, uint8_t overworld_map_id,
|
||||||
uint8_t x, uint8_t y, int map_x, int map_y) {
|
uint8_t id, uint8_t x, uint8_t y, int map_x, int map_y) {
|
||||||
current_gfx_ = src;
|
current_gfx_ = src;
|
||||||
overworld_ = true;
|
overworld_ = true;
|
||||||
map_id_ = static_cast<int>(mapid);
|
map_id_ = static_cast<int>(overworld_map_id);
|
||||||
id_ = id;
|
id_ = id;
|
||||||
type_ = zelda3::OverworldEntity::EntityType::kSprite;
|
entity_type_ = zelda3::GameEntity::EntityType::kSprite;
|
||||||
entity_id_ = id;
|
entity_id_ = id;
|
||||||
x_ = map_x_;
|
x_ = map_x_;
|
||||||
y_ = map_y_;
|
y_ = map_y_;
|
||||||
@@ -321,7 +320,7 @@ class Sprite : public OverworldEntity {
|
|||||||
map_y_ = map_y;
|
map_y_ = map_y;
|
||||||
preview_gfx_.resize(64 * 64, 0xFF);
|
preview_gfx_.resize(64 * 64, 0xFF);
|
||||||
}
|
}
|
||||||
void updateBBox();
|
void UpdateBoundaryBox();
|
||||||
|
|
||||||
void Draw();
|
void Draw();
|
||||||
void DrawSpriteTile(int x, int y, int srcx, int srcy, int pal,
|
void DrawSpriteTile(int x, int y, int srcx, int srcy, int pal,
|
||||||
@@ -347,7 +346,6 @@ class Sprite : public OverworldEntity {
|
|||||||
|
|
||||||
auto layer() const { return layer_; }
|
auto layer() const { return layer_; }
|
||||||
auto subtype() const { return subtype_; }
|
auto subtype() const { return subtype_; }
|
||||||
auto& keyDrop() const { return key_drop_; }
|
|
||||||
|
|
||||||
auto Width() const { return bounding_box_.w; }
|
auto Width() const { return bounding_box_.w; }
|
||||||
auto Height() const { return bounding_box_.h; }
|
auto Height() const { return bounding_box_.h; }
|
||||||
|
|||||||
Reference in New Issue
Block a user