Add hex utility functions and refactor usage in editors
This commit is contained in:
@@ -9,9 +9,10 @@
|
||||
#include "app/gui/input.h"
|
||||
#include "app/rom.h"
|
||||
#include "app/zelda3/dungeon/object_names.h"
|
||||
#include "app/zelda3/dungeon/room.h"
|
||||
#include "imgui/imgui.h"
|
||||
#include "imgui_memory_editor.h"
|
||||
#include "zelda3/dungeon/room.h"
|
||||
#include "util/hex.h"
|
||||
|
||||
namespace yaze {
|
||||
namespace editor {
|
||||
@@ -109,7 +110,7 @@ absl::Status DungeonEditor::Initialize() {
|
||||
ASSIGN_OR_RETURN(current_palette_group_,
|
||||
gfx::CreatePaletteGroupFromLargePalette(full_palette_));
|
||||
|
||||
graphics_bin_ = GraphicsSheetManager::GetInstance().gfx_sheets();
|
||||
graphics_bin_ = GraphicsSheetManager::GetInstance().gfx_sheets();
|
||||
// Create a vector of pointers to the current block bitmaps
|
||||
for (int block : rooms_[current_room_id_].blocks()) {
|
||||
room_gfx_sheets_.emplace_back(&graphics_bin_[block]);
|
||||
@@ -327,7 +328,7 @@ void DungeonEditor::DrawRoomSelector() {
|
||||
int i = 0;
|
||||
for (const auto each_room_name : zelda3::kRoomNames) {
|
||||
rom()->resource_label()->SelectableLabelWithNameEdit(
|
||||
current_room_id_ == i, "Dungeon Room Names", core::HexByte(i),
|
||||
current_room_id_ == i, "Dungeon Room Names", util::HexByte(i),
|
||||
each_room_name.data());
|
||||
if (ImGui::IsItemClicked()) {
|
||||
// TODO: Jump to tab if room is already open
|
||||
@@ -402,7 +403,7 @@ void DungeonEditor::DrawEntranceSelector() {
|
||||
for (int i = 0; i < 0x85 + 7; i++) {
|
||||
rom()->resource_label()->SelectableLabelWithNameEdit(
|
||||
current_entrance_id_ == i, "Dungeon Entrance Names",
|
||||
core::HexByte(i), zelda3::kEntranceNames[i].data());
|
||||
util::HexByte(i), zelda3::kEntranceNames[i].data());
|
||||
|
||||
if (ImGui::IsItemClicked()) {
|
||||
current_entrance_id_ = i;
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "editor/editor.h"
|
||||
#include "imgui/imgui.h"
|
||||
#include "imgui/misc/cpp/imgui_stdlib.h"
|
||||
#include "util/hex.h"
|
||||
#include "util/macro.h"
|
||||
|
||||
namespace yaze {
|
||||
@@ -345,7 +346,7 @@ void EditorManager::DrawPopups() {
|
||||
if (BeginPopupModal("ROM Information", nullptr,
|
||||
ImGuiWindowFlags_AlwaysAutoResize)) {
|
||||
Text("Title: %s", rom()->title().c_str());
|
||||
Text("ROM Size: %s", core::HexLongLong(rom()->size()).c_str());
|
||||
Text("ROM Size: %s", util::HexLongLong(rom()->size()).c_str());
|
||||
|
||||
if (Button("Close", gui::kDefaultModalSize) ||
|
||||
IsKeyPressed(ImGuiKey_Escape)) {
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "app/gui/icons.h"
|
||||
#include "app/gui/input.h"
|
||||
#include "imgui/imgui.h"
|
||||
#include "util/hex.h"
|
||||
#include "util/macro.h"
|
||||
|
||||
namespace yaze {
|
||||
@@ -162,7 +163,7 @@ absl::Status ScreenEditor::LoadDungeonMaps() {
|
||||
gdata[j] = rom()->data()[pc_ptr_gfx++];
|
||||
}
|
||||
|
||||
std::string label = core::HexByte(rdata[j]);
|
||||
std::string label = util::HexByte(rdata[j]);
|
||||
dungeon_map_labels_[d][i][j] = label;
|
||||
}
|
||||
|
||||
@@ -313,7 +314,7 @@ void ScreenEditor::DrawDungeonMapsTabs() {
|
||||
std::string label =
|
||||
dungeon_map_labels_[selected_dungeon][floor_number][j];
|
||||
screen_canvas_.DrawText(label, (posX * 2), (posY * 2));
|
||||
std::string gfx_id = core::HexByte(tile16_id);
|
||||
std::string gfx_id = util::HexByte(tile16_id);
|
||||
screen_canvas_.DrawText(gfx_id, (posX * 2), (posY * 2) + 16);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "app/rom.h"
|
||||
#include "app/zelda3/overworld/overworld.h"
|
||||
#include "imgui/imgui.h"
|
||||
#include "util/hex.h"
|
||||
|
||||
namespace yaze {
|
||||
namespace editor {
|
||||
@@ -58,7 +59,7 @@ absl::Status Tile16Editor::InitBlockset(
|
||||
RETURN_IF_ERROR(LoadTile8());
|
||||
ImVector<std::string> tile16_names;
|
||||
for (int i = 0; i < 0x200; ++i) {
|
||||
std::string str = core::HexByte(all_tiles_types_[i]);
|
||||
std::string str = util::HexByte(all_tiles_types_[i]);
|
||||
tile16_names.push_back(str);
|
||||
}
|
||||
*tile8_source_canvas_.mutable_labels(0) = tile16_names;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <string>
|
||||
|
||||
#include "app/core/common.h"
|
||||
#include "util/hex.h"
|
||||
|
||||
namespace yaze {
|
||||
namespace editor {
|
||||
@@ -227,7 +228,7 @@ absl::StatusOr<MessageData> ParseSingleMessage(
|
||||
current_message_raw.append("[");
|
||||
current_message_raw.append(DICTIONARYTOKEN);
|
||||
current_message_raw.append(":");
|
||||
current_message_raw.append(core::HexWord(dictionary));
|
||||
current_message_raw.append(util::HexWord(dictionary));
|
||||
current_message_raw.append("]");
|
||||
|
||||
auto mutable_rom_data = const_cast<uint8_t *>(rom_data.data());
|
||||
@@ -265,7 +266,7 @@ std::vector<std::string> ParseMessageData(
|
||||
|
||||
for (auto &message : message_data) {
|
||||
std::cout << "Message #" << message.ID << " at address "
|
||||
<< core::HexLong(message.Address) << std::endl;
|
||||
<< util::HexLong(message.Address) << std::endl;
|
||||
std::cout << " " << message.RawString << std::endl;
|
||||
|
||||
std::string parsed_message = "";
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "app/rom.h"
|
||||
#include "imgui.h"
|
||||
#include "imgui/misc/cpp/imgui_stdlib.h"
|
||||
#include "util/hex.h"
|
||||
|
||||
namespace yaze {
|
||||
namespace editor {
|
||||
@@ -131,7 +132,7 @@ void MessageEditor::DrawMessageList() {
|
||||
|
||||
for (const auto &message : list_of_texts_) {
|
||||
TableNextColumn();
|
||||
if (Button(core::HexWord(message.ID).c_str())) {
|
||||
if (Button(util::HexWord(message.ID).c_str())) {
|
||||
current_message_ = message;
|
||||
DrawMessagePreview();
|
||||
}
|
||||
@@ -139,7 +140,7 @@ void MessageEditor::DrawMessageList() {
|
||||
TextWrapped("%s", parsed_messages_[message.ID].c_str());
|
||||
TableNextColumn();
|
||||
TextWrapped("%s",
|
||||
core::HexLong(list_of_texts_[message.ID].Address).c_str());
|
||||
util::HexLong(list_of_texts_[message.ID].Address).c_str());
|
||||
}
|
||||
|
||||
EndTable();
|
||||
@@ -209,7 +210,7 @@ void MessageEditor::DrawDictionary() {
|
||||
|
||||
for (const auto &dictionary : all_dictionaries_) {
|
||||
TableNextColumn();
|
||||
Text("%s", core::HexWord(dictionary.ID).c_str());
|
||||
Text("%s", util::HexWord(dictionary.ID).c_str());
|
||||
TableNextColumn();
|
||||
Text("%s", dictionary.Contents.c_str());
|
||||
}
|
||||
@@ -244,12 +245,12 @@ void MessageEditor::ReadAllTextDataV2() {
|
||||
std::cout << "Parsed: " << current_parsed_message << std::endl;
|
||||
std::cout << "Raw Bytes: ";
|
||||
for (const auto &byte : raw_message) {
|
||||
std::cout << core::HexByte(byte) << " ";
|
||||
std::cout << util::HexByte(byte) << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
std::cout << "Parsed Bytes: ";
|
||||
for (const auto &byte : parsed_message) {
|
||||
std::cout << core::HexByte(byte) << " ";
|
||||
std::cout << util::HexByte(byte) << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
raw_message.clear();
|
||||
@@ -295,7 +296,7 @@ void MessageEditor::ReadAllTextDataV2() {
|
||||
current_raw_message.append("[");
|
||||
current_raw_message.append(DICTIONARYTOKEN);
|
||||
current_raw_message.append(":");
|
||||
current_raw_message.append(core::HexWord(dictionary));
|
||||
current_raw_message.append(util::HexWord(dictionary));
|
||||
current_raw_message.append("]");
|
||||
|
||||
uint32_t address = core::Get24LocalFromPC(
|
||||
@@ -393,7 +394,7 @@ void MessageEditor::ReadAllTextData() {
|
||||
current_message_raw.append("[");
|
||||
current_message_raw.append(DICTIONARYTOKEN);
|
||||
current_message_raw.append(":");
|
||||
current_message_raw.append(core::HexWord(dictionary));
|
||||
current_message_raw.append(util::HexWord(dictionary));
|
||||
current_message_raw.append("]");
|
||||
|
||||
uint32_t address = core::Get24LocalFromPC(
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "app/gui/icons.h"
|
||||
#include "app/gui/input.h"
|
||||
#include "app/gui/style.h"
|
||||
#include "util/hex.h"
|
||||
|
||||
namespace yaze {
|
||||
namespace editor {
|
||||
@@ -91,7 +92,7 @@ void HandleEntityDragging(zelda3::GameEntity *entity, ImVec2 canvas_p0,
|
||||
ImGui::SetDragDropPayload("ENTITY_PAYLOAD", &entity,
|
||||
sizeof(zelda3::GameEntity));
|
||||
Text("Moving %s ID: %s", entity_type.c_str(),
|
||||
core::HexByte(entity->entity_id_).c_str());
|
||||
util::HexByte(entity->entity_id_).c_str());
|
||||
ImGui::EndDragDropSource();
|
||||
}
|
||||
MoveEntityOnGrid(dragged_entity, canvas_p0, scrolling, free_movement);
|
||||
@@ -126,8 +127,7 @@ bool DrawEntranceInserterPopup() {
|
||||
}
|
||||
|
||||
// TODO: Implement deleting OverworldEntrance objects, currently only hides them
|
||||
bool DrawOverworldEntrancePopup(
|
||||
zelda3::OverworldEntrance &entrance) {
|
||||
bool DrawOverworldEntrancePopup(zelda3::OverworldEntrance &entrance) {
|
||||
static bool set_done = false;
|
||||
if (set_done) {
|
||||
set_done = false;
|
||||
@@ -317,8 +317,7 @@ void DrawItemInsertPopup() {
|
||||
BeginChild("ScrollRegion", ImVec2(150, 150), true,
|
||||
ImGuiWindowFlags_AlwaysVerticalScrollbar);
|
||||
for (size_t i = 0; i < zelda3::kSecretItemNames.size(); i++) {
|
||||
if (Selectable(zelda3::kSecretItemNames[i].c_str(),
|
||||
i == new_item_id)) {
|
||||
if (Selectable(zelda3::kSecretItemNames[i].c_str(), i == new_item_id)) {
|
||||
new_item_id = i;
|
||||
}
|
||||
}
|
||||
@@ -351,8 +350,7 @@ bool DrawItemEditorPopup(zelda3::OverworldItem &item) {
|
||||
ImGuiWindowFlags_AlwaysVerticalScrollbar);
|
||||
ImGui::BeginGroup();
|
||||
for (size_t i = 0; i < zelda3::kSecretItemNames.size(); i++) {
|
||||
if (Selectable(zelda3::kSecretItemNames[i].c_str(),
|
||||
item.id_ == i)) {
|
||||
if (Selectable(zelda3::kSecretItemNames[i].c_str(), item.id_ == i)) {
|
||||
item.id_ = i;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,8 +23,10 @@
|
||||
#include "app/zelda3/overworld/overworld.h"
|
||||
#include "imgui/imgui.h"
|
||||
#include "imgui_memory_editor.h"
|
||||
#include "util/hex.h"
|
||||
#include "util/macro.h"
|
||||
|
||||
|
||||
namespace yaze {
|
||||
namespace editor {
|
||||
|
||||
@@ -789,7 +791,7 @@ void OverworldEditor::DrawOverworldEntrances(ImVec2 canvas_p0, ImVec2 scrolling,
|
||||
color = ImVec4(255, 255, 255, 200);
|
||||
}
|
||||
ow_map_canvas_.DrawRect(each.x_, each.y_, 16, 16, color);
|
||||
std::string str = core::HexByte(each.entrance_id_);
|
||||
std::string str = util::HexByte(each.entrance_id_);
|
||||
|
||||
if (current_mode == EditingMode::ENTRANCES) {
|
||||
HandleEntityDragging(&each, canvas_p0, scrolling, is_dragging_entity_,
|
||||
@@ -872,7 +874,7 @@ void OverworldEditor::DrawOverworldExits(ImVec2 canvas_p0, ImVec2 scrolling) {
|
||||
}
|
||||
}
|
||||
|
||||
std::string str = core::HexByte(i);
|
||||
std::string str = util::HexByte(i);
|
||||
ow_map_canvas_.DrawText(str, each.x_, each.y_);
|
||||
}
|
||||
i++;
|
||||
@@ -1367,7 +1369,7 @@ absl::Status OverworldEditor::UpdateUsageStats() {
|
||||
ImGuiWindowFlags_HorizontalScrollbar)) {
|
||||
for (int i = 0; i < 0x81; i++) {
|
||||
auto entrance_name = rom_.resource_label()->CreateOrGetLabel(
|
||||
"Dungeon Entrance Names", core::HexByte(i),
|
||||
"Dungeon Entrance Names", util::HexByte(i),
|
||||
zelda3::kEntranceNames[i].data());
|
||||
std::string str = absl::StrFormat("%#x - %s", i, entrance_name);
|
||||
if (Selectable(str.c_str(), selected_entrance_ == i,
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "app/gui/icons.h"
|
||||
#include "app/gui/input.h"
|
||||
#include "app/zelda3/sprite/sprite.h"
|
||||
#include "util/hex.h"
|
||||
|
||||
namespace yaze {
|
||||
namespace editor {
|
||||
@@ -175,7 +176,9 @@ void SpriteEditor::DrawCurrentSheets() {
|
||||
graphics_sheet_canvas_.DrawTileSelector(32);
|
||||
for (int i = 0; i < 8; i++) {
|
||||
graphics_sheet_canvas_.DrawBitmap(
|
||||
GraphicsSheetManager::GetInstance().gfx_sheets().at(current_sheets_[i]), 1, (i * 0x40) + 1, 2);
|
||||
GraphicsSheetManager::GetInstance().gfx_sheets().at(
|
||||
current_sheets_[i]),
|
||||
1, (i * 0x40) + 1, 2);
|
||||
}
|
||||
graphics_sheet_canvas_.DrawGrid();
|
||||
graphics_sheet_canvas_.DrawOverlay();
|
||||
@@ -190,7 +193,7 @@ void SpriteEditor::DrawSpritesList() {
|
||||
int i = 0;
|
||||
for (const auto each_sprite_name : zelda3::kSpriteDefaultNames) {
|
||||
rom()->resource_label()->SelectableLabelWithNameEdit(
|
||||
current_sprite_id_ == i, "Sprite Names", core::HexByte(i),
|
||||
current_sprite_id_ == i, "Sprite Names", util::HexByte(i),
|
||||
zelda3::kSpriteDefaultNames[i].data());
|
||||
if (ImGui::IsItemClicked()) {
|
||||
current_sprite_id_ = i;
|
||||
|
||||
Reference in New Issue
Block a user