yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
yaze::zelda3::DungeonObjectEditor Class Reference

Interactive dungeon object editor with scroll wheel support. More...

#include <dungeon_object_editor.h>

Collaboration diagram for yaze::zelda3::DungeonObjectEditor:

Classes

struct  EditingState
 
struct  EditorConfig
 
struct  SelectionState
 
struct  UndoPoint
 

Public Types

enum class  Mode {
  kSelect , kInsert , kDelete , kEdit ,
  kLayer , kPreview
}
 
using ObjectChangedCallback = std::function< void(size_t object_index, const RoomObject &object)>
 
using RoomChangedCallback = std::function< void()>
 
using SelectionChangedCallback = std::function< void(const SelectionState &)>
 

Public Member Functions

 DungeonObjectEditor (Rom *rom)
 
 ~DungeonObjectEditor ()=default
 
absl::Status LoadRoom (int room_id)
 
absl::Status SaveRoom ()
 
absl::Status ClearRoom ()
 
absl::Status InsertObject (int x, int y, int object_type, int size=0x12, int layer=0)
 
absl::Status DeleteObject (size_t object_index)
 
absl::Status DeleteSelectedObjects ()
 
absl::Status MoveObject (size_t object_index, int new_x, int new_y)
 
absl::Status ResizeObject (size_t object_index, int new_size)
 
absl::Status ChangeObjectType (size_t object_index, int new_type)
 
absl::Status ChangeObjectLayer (size_t object_index, int new_layer)
 
absl::Status SelectObject (int screen_x, int screen_y)
 
absl::Status SelectObjects (int start_x, int start_y, int end_x, int end_y)
 
absl::Status ClearSelection ()
 
absl::Status AddToSelection (size_t object_index)
 
absl::Status RemoveFromSelection (size_t object_index)
 
absl::Status HandleMouseClick (int x, int y, bool left_button, bool right_button, bool shift_pressed)
 
absl::Status HandleMouseDrag (int start_x, int start_y, int current_x, int current_y)
 
absl::Status HandleMouseRelease (int x, int y)
 
absl::Status HandleScrollWheel (int delta, int x, int y, bool ctrl_pressed)
 
absl::Status HandleKeyPress (int key_code, bool ctrl_pressed, bool shift_pressed)
 
void SetMode (Mode mode)
 
Mode GetMode () const
 
void SetCurrentLayer (int layer)
 
int GetCurrentLayer () const
 
absl::StatusOr< std::vector< RoomObject > > GetObjectsByLayer (int layer)
 
absl::Status MoveObjectToLayer (size_t object_index, int layer)
 
void SetCurrentObjectType (int object_type)
 
int GetCurrentObjectType () const
 
absl::StatusOr< std::vector< int > > GetAvailableObjectTypes ()
 
absl::Status ValidateObjectType (int object_type)
 
absl::StatusOr< gfx::BitmapRenderPreview (int x, int y)
 
void SetPreviewPosition (int x, int y)
 
void UpdatePreview ()
 
void RenderSelectionHighlight (gfx::Bitmap &canvas)
 
void RenderLayerVisualization (gfx::Bitmap &canvas)
 
void RenderObjectPropertyPanel ()
 
void RenderLayerControls ()
 
absl::Status HandleDragOperation (int current_x, int current_y)
 
absl::Status Undo ()
 
absl::Status Redo ()
 
bool CanUndo () const
 
bool CanRedo () const
 
void ClearHistory ()
 
void SetROM (Rom *rom)
 
void SetConfig (const EditorConfig &config)
 
EditorConfig GetConfig () const
 
void SetSnapToGrid (bool enabled)
 
void SetGridSize (int size)
 
void SetShowGrid (bool enabled)
 
absl::Status ValidateRoom ()
 
absl::Status ValidateObject (const RoomObject &object)
 
std::vector< std::string > GetValidationErrors ()
 
void SetObjectChangedCallback (ObjectChangedCallback callback)
 
void SetRoomChangedCallback (RoomChangedCallback callback)
 
void SetSelectionChangedCallback (SelectionChangedCallback callback)
 
const RoomGetRoom () const
 
RoomGetMutableRoom ()
 
const SelectionStateGetSelection () const
 
const EditingStateGetEditingState () const
 
size_t GetObjectCount () const
 
const std::vector< RoomObject > & GetObjects () const
 

Private Member Functions

absl::Status InitializeEditor ()
 
absl::Status CreateUndoPoint ()
 
absl::Status ApplyUndoPoint (const UndoPoint &undo_point)
 
std::pair< int, int > ScreenToRoomCoordinates (int screen_x, int screen_y)
 
std::pair< int, int > RoomToScreenCoordinates (int room_x, int room_y)
 
int SnapToGrid (int coordinate)
 
std::optional< size_t > FindObjectAt (int room_x, int room_y)
 
std::vector< size_t > FindObjectsInArea (int start_x, int start_y, int end_x, int end_y)
 
bool IsObjectAtPosition (const RoomObject &object, int x, int y)
 
bool ObjectsCollide (const RoomObject &obj1, const RoomObject &obj2)
 
absl::StatusOr< gfx::BitmapRenderObjectPreview (int object_type, int x, int y, int size)
 
void UpdatePreviewObject ()
 
absl::Status ValidatePreviewPosition (int x, int y)
 
absl::Status HandleSizeEdit (int delta, int x, int y)
 
int GetNextSize (int current_size, int delta)
 
int GetPreviousSize (int current_size, int delta)
 
bool IsValidSize (int size)
 

Private Attributes

Romrom_
 
std::unique_ptr< Roomcurrent_room_
 
SelectionState selection_state_
 
EditingState editing_state_
 
EditorConfig config_
 
std::vector< UndoPointundo_history_
 
std::vector< UndoPointredo_history_
 
std::optional< RoomObjectpreview_object_
 
bool preview_visible_ = false
 
ObjectChangedCallback object_changed_callback_
 
RoomChangedCallback room_changed_callback_
 
SelectionChangedCallback selection_changed_callback_
 
std::vector< RoomObjectempty_objects_
 

Static Private Attributes

static constexpr size_t kMaxUndoHistory = 50
 
static constexpr int kMinObjectSize = 0x00
 
static constexpr int kMaxObjectSize = 0xFF
 
static constexpr int kDefaultObjectSize = 0x12
 
static constexpr int kMinLayer = 0
 
static constexpr int kMaxLayer = 2
 

Detailed Description

Interactive dungeon object editor with scroll wheel support.

This class provides a comprehensive object editing system for dungeon rooms, including:

  • Object insertion and deletion
  • Object size editing with scroll wheel
  • Object position editing with mouse
  • Layer management
  • Real-time preview and validation
  • Undo/redo functionality
  • Object property editing

Definition at line 35 of file dungeon_object_editor.h.

Member Typedef Documentation

◆ ObjectChangedCallback

using yaze::zelda3::DungeonObjectEditor::ObjectChangedCallback = std::function<void(size_t object_index, const RoomObject& object)>

Definition at line 184 of file dungeon_object_editor.h.

◆ RoomChangedCallback

Definition at line 186 of file dungeon_object_editor.h.

◆ SelectionChangedCallback

Definition at line 187 of file dungeon_object_editor.h.

Member Enumeration Documentation

◆ Mode

Enumerator
kSelect 
kInsert 
kDelete 
kEdit 
kLayer 
kPreview 

Definition at line 38 of file dungeon_object_editor.h.

Constructor & Destructor Documentation

◆ DungeonObjectEditor()

yaze::zelda3::DungeonObjectEditor::DungeonObjectEditor ( Rom rom)
explicit

Definition at line 16 of file dungeon_object_editor.cc.

◆ ~DungeonObjectEditor()

yaze::zelda3::DungeonObjectEditor::~DungeonObjectEditor ( )
default

Member Function Documentation

◆ LoadRoom()

◆ SaveRoom()

absl::Status yaze::zelda3::DungeonObjectEditor::SaveRoom ( )

Definition at line 80 of file dungeon_object_editor.cc.

References config_, current_room_, yaze::zelda3::DungeonObjectEditor::EditorConfig::validate_objects, and ValidateRoom().

Here is the call graph for this function:

◆ ClearRoom()

absl::Status yaze::zelda3::DungeonObjectEditor::ClearRoom ( )

Definition at line 97 of file dungeon_object_editor.cc.

References ClearSelection(), CreateUndoPoint(), current_room_, and room_changed_callback_.

Here is the call graph for this function:

◆ InsertObject()

◆ DeleteObject()

absl::Status yaze::zelda3::DungeonObjectEditor::DeleteObject ( size_t  object_index)

◆ DeleteSelectedObjects()

absl::Status yaze::zelda3::DungeonObjectEditor::DeleteSelectedObjects ( )

◆ MoveObject()

◆ ResizeObject()

absl::Status yaze::zelda3::DungeonObjectEditor::ResizeObject ( size_t  object_index,
int  new_size 
)

Definition at line 328 of file dungeon_object_editor.cc.

References CreateUndoPoint(), current_room_, kMaxObjectSize, object_changed_callback_, and room_changed_callback_.

Referenced by HandleSizeEdit().

Here is the call graph for this function:

◆ ChangeObjectType()

absl::Status yaze::zelda3::DungeonObjectEditor::ChangeObjectType ( size_t  object_index,
int  new_type 
)

◆ ChangeObjectLayer()

absl::Status yaze::zelda3::DungeonObjectEditor::ChangeObjectLayer ( size_t  object_index,
int  new_layer 
)

◆ SelectObject()

absl::Status yaze::zelda3::DungeonObjectEditor::SelectObject ( int  screen_x,
int  screen_y 
)

◆ SelectObjects()

absl::Status yaze::zelda3::DungeonObjectEditor::SelectObjects ( int  start_x,
int  start_y,
int  end_x,
int  end_y 
)

◆ ClearSelection()

◆ AddToSelection()

absl::Status yaze::zelda3::DungeonObjectEditor::AddToSelection ( size_t  object_index)

◆ RemoveFromSelection()

absl::Status yaze::zelda3::DungeonObjectEditor::RemoveFromSelection ( size_t  object_index)

◆ HandleMouseClick()

◆ HandleMouseDrag()

absl::Status yaze::zelda3::DungeonObjectEditor::HandleMouseDrag ( int  start_x,
int  start_y,
int  current_x,
int  current_y 
)

◆ HandleMouseRelease()

absl::Status yaze::zelda3::DungeonObjectEditor::HandleMouseRelease ( int  x,
int  y 
)

◆ HandleScrollWheel()

absl::Status yaze::zelda3::DungeonObjectEditor::HandleScrollWheel ( int  delta,
int  x,
int  y,
bool  ctrl_pressed 
)

◆ HandleKeyPress()

absl::Status yaze::zelda3::DungeonObjectEditor::HandleKeyPress ( int  key_code,
bool  ctrl_pressed,
bool  shift_pressed 
)

◆ SetMode()

void yaze::zelda3::DungeonObjectEditor::SetMode ( Mode  mode)

Definition at line 630 of file dungeon_object_editor.cc.

References yaze::zelda3::DungeonObjectEditor::EditingState::current_mode, editing_state_, and UpdatePreviewObject().

Here is the call graph for this function:

◆ GetMode()

Mode yaze::zelda3::DungeonObjectEditor::GetMode ( ) const
inline

◆ SetCurrentLayer()

void yaze::zelda3::DungeonObjectEditor::SetCurrentLayer ( int  layer)

Definition at line 637 of file dungeon_object_editor.cc.

References yaze::zelda3::DungeonObjectEditor::EditingState::current_layer, editing_state_, kMaxLayer, kMinLayer, and UpdatePreviewObject().

Referenced by HandleScrollWheel().

Here is the call graph for this function:

◆ GetCurrentLayer()

int yaze::zelda3::DungeonObjectEditor::GetCurrentLayer ( ) const
inline

◆ GetObjectsByLayer()

absl::StatusOr< std::vector< RoomObject > > yaze::zelda3::DungeonObjectEditor::GetObjectsByLayer ( int  layer)

◆ MoveObjectToLayer()

absl::Status yaze::zelda3::DungeonObjectEditor::MoveObjectToLayer ( size_t  object_index,
int  layer 
)

◆ SetCurrentObjectType()

void yaze::zelda3::DungeonObjectEditor::SetCurrentObjectType ( int  object_type)

Definition at line 644 of file dungeon_object_editor.cc.

References yaze::zelda3::DungeonObjectEditor::EditingState::current_object_type, editing_state_, and UpdatePreviewObject().

Here is the call graph for this function:

◆ GetCurrentObjectType()

int yaze::zelda3::DungeonObjectEditor::GetCurrentObjectType ( ) const
inline

◆ GetAvailableObjectTypes()

absl::StatusOr< std::vector< int > > yaze::zelda3::DungeonObjectEditor::GetAvailableObjectTypes ( )

◆ ValidateObjectType()

absl::Status yaze::zelda3::DungeonObjectEditor::ValidateObjectType ( int  object_type)

◆ RenderPreview()

absl::StatusOr< gfx::Bitmap > yaze::zelda3::DungeonObjectEditor::RenderPreview ( int  x,
int  y 
)

◆ SetPreviewPosition()

void yaze::zelda3::DungeonObjectEditor::SetPreviewPosition ( int  x,
int  y 
)

◆ UpdatePreview()

void yaze::zelda3::DungeonObjectEditor::UpdatePreview ( )

◆ RenderSelectionHighlight()

◆ RenderLayerVisualization()

◆ RenderObjectPropertyPanel()

◆ RenderLayerControls()

◆ HandleDragOperation()

◆ Undo()

◆ Redo()

◆ CanUndo()

bool yaze::zelda3::DungeonObjectEditor::CanUndo ( ) const

Definition at line 856 of file dungeon_object_editor.cc.

References undo_history_.

Referenced by Undo().

◆ CanRedo()

bool yaze::zelda3::DungeonObjectEditor::CanRedo ( ) const

Definition at line 860 of file dungeon_object_editor.cc.

References redo_history_.

Referenced by Redo().

◆ ClearHistory()

void yaze::zelda3::DungeonObjectEditor::ClearHistory ( )

Definition at line 864 of file dungeon_object_editor.cc.

References redo_history_, and undo_history_.

◆ SetROM()

void yaze::zelda3::DungeonObjectEditor::SetROM ( Rom rom)

Definition at line 1192 of file dungeon_object_editor.cc.

References InitializeEditor(), and rom_.

Here is the call graph for this function:

◆ SetConfig()

void yaze::zelda3::DungeonObjectEditor::SetConfig ( const EditorConfig config)

Definition at line 1188 of file dungeon_object_editor.cc.

References config_.

◆ GetConfig()

EditorConfig yaze::zelda3::DungeonObjectEditor::GetConfig ( ) const
inline

Definition at line 173 of file dungeon_object_editor.h.

References config_.

◆ SetSnapToGrid()

void yaze::zelda3::DungeonObjectEditor::SetSnapToGrid ( bool  enabled)

◆ SetGridSize()

void yaze::zelda3::DungeonObjectEditor::SetGridSize ( int  size)

◆ SetShowGrid()

void yaze::zelda3::DungeonObjectEditor::SetShowGrid ( bool  enabled)

◆ ValidateRoom()

absl::Status yaze::zelda3::DungeonObjectEditor::ValidateRoom ( )

Definition at line 1155 of file dungeon_object_editor.cc.

References config_, current_room_, ObjectsCollide(), and yaze::zelda3::DungeonObjectEditor::EditorConfig::validate_objects.

Referenced by SaveRoom().

Here is the call graph for this function:

◆ ValidateObject()

absl::Status yaze::zelda3::DungeonObjectEditor::ValidateObject ( const RoomObject object)

◆ GetValidationErrors()

std::vector< std::string > yaze::zelda3::DungeonObjectEditor::GetValidationErrors ( )

◆ SetObjectChangedCallback()

void yaze::zelda3::DungeonObjectEditor::SetObjectChangedCallback ( ObjectChangedCallback  callback)

Definition at line 1176 of file dungeon_object_editor.cc.

References object_changed_callback_.

◆ SetRoomChangedCallback()

void yaze::zelda3::DungeonObjectEditor::SetRoomChangedCallback ( RoomChangedCallback  callback)

Definition at line 1180 of file dungeon_object_editor.cc.

References room_changed_callback_.

◆ SetSelectionChangedCallback()

void yaze::zelda3::DungeonObjectEditor::SetSelectionChangedCallback ( SelectionChangedCallback  callback)

Definition at line 1184 of file dungeon_object_editor.cc.

References selection_changed_callback_.

◆ GetRoom()

const Room & yaze::zelda3::DungeonObjectEditor::GetRoom ( ) const
inline

Definition at line 194 of file dungeon_object_editor.h.

References current_room_.

◆ GetMutableRoom()

Room * yaze::zelda3::DungeonObjectEditor::GetMutableRoom ( )
inline

Definition at line 195 of file dungeon_object_editor.h.

References current_room_.

◆ GetSelection()

const SelectionState & yaze::zelda3::DungeonObjectEditor::GetSelection ( ) const
inline

Definition at line 196 of file dungeon_object_editor.h.

References selection_state_.

◆ GetEditingState()

const EditingState & yaze::zelda3::DungeonObjectEditor::GetEditingState ( ) const
inline

Definition at line 197 of file dungeon_object_editor.h.

References editing_state_.

◆ GetObjectCount()

size_t yaze::zelda3::DungeonObjectEditor::GetObjectCount ( ) const
inline

Definition at line 198 of file dungeon_object_editor.h.

References current_room_.

◆ GetObjects()

const std::vector< RoomObject > & yaze::zelda3::DungeonObjectEditor::GetObjects ( ) const
inline

Definition at line 201 of file dungeon_object_editor.h.

References current_room_, and empty_objects_.

◆ InitializeEditor()

◆ CreateUndoPoint()

◆ ApplyUndoPoint()

absl::Status yaze::zelda3::DungeonObjectEditor::ApplyUndoPoint ( const UndoPoint undo_point)
private

◆ ScreenToRoomCoordinates()

std::pair< int, int > yaze::zelda3::DungeonObjectEditor::ScreenToRoomCoordinates ( int  screen_x,
int  screen_y 
)
private

Definition at line 719 of file dungeon_object_editor.cc.

Referenced by HandleMouseClick(), HandleScrollWheel(), and SelectObject().

◆ RoomToScreenCoordinates()

std::pair< int, int > yaze::zelda3::DungeonObjectEditor::RoomToScreenCoordinates ( int  room_x,
int  room_y 
)
private

Definition at line 730 of file dungeon_object_editor.cc.

◆ SnapToGrid()

int yaze::zelda3::DungeonObjectEditor::SnapToGrid ( int  coordinate)
private

◆ FindObjectAt()

std::optional< size_t > yaze::zelda3::DungeonObjectEditor::FindObjectAt ( int  room_x,
int  room_y 
)
private

Definition at line 651 of file dungeon_object_editor.cc.

References current_room_, and IsObjectAtPosition().

Referenced by HandleMouseClick(), and SelectObject().

Here is the call graph for this function:

◆ FindObjectsInArea()

std::vector< size_t > yaze::zelda3::DungeonObjectEditor::FindObjectsInArea ( int  start_x,
int  start_y,
int  end_x,
int  end_y 
)
private

◆ IsObjectAtPosition()

bool yaze::zelda3::DungeonObjectEditor::IsObjectAtPosition ( const RoomObject object,
int  x,
int  y 
)
private

Definition at line 666 of file dungeon_object_editor.cc.

Referenced by FindObjectAt().

◆ ObjectsCollide()

bool yaze::zelda3::DungeonObjectEditor::ObjectsCollide ( const RoomObject obj1,
const RoomObject obj2 
)
private

◆ RenderObjectPreview()

absl::StatusOr< gfx::Bitmap > yaze::zelda3::DungeonObjectEditor::RenderObjectPreview ( int  object_type,
int  x,
int  y,
int  size 
)
private

◆ UpdatePreviewObject()

◆ ValidatePreviewPosition()

absl::Status yaze::zelda3::DungeonObjectEditor::ValidatePreviewPosition ( int  x,
int  y 
)
private

◆ HandleSizeEdit()

absl::Status yaze::zelda3::DungeonObjectEditor::HandleSizeEdit ( int  delta,
int  x,
int  y 
)
private

◆ GetNextSize()

int yaze::zelda3::DungeonObjectEditor::GetNextSize ( int  current_size,
int  delta 
)
private

Definition at line 425 of file dungeon_object_editor.cc.

Referenced by HandleSizeEdit().

◆ GetPreviousSize()

int yaze::zelda3::DungeonObjectEditor::GetPreviousSize ( int  current_size,
int  delta 
)
private

◆ IsValidSize()

bool yaze::zelda3::DungeonObjectEditor::IsValidSize ( int  size)
private

Definition at line 451 of file dungeon_object_editor.cc.

References kMaxObjectSize, and kMinObjectSize.

Referenced by HandleSizeEdit().

Member Data Documentation

◆ rom_

Rom* yaze::zelda3::DungeonObjectEditor::rom_
private

◆ current_room_

◆ selection_state_

◆ editing_state_

◆ config_

◆ undo_history_

std::vector<UndoPoint> yaze::zelda3::DungeonObjectEditor::undo_history_
private

Definition at line 243 of file dungeon_object_editor.h.

Referenced by CanUndo(), ClearHistory(), CreateUndoPoint(), Redo(), and Undo().

◆ redo_history_

std::vector<UndoPoint> yaze::zelda3::DungeonObjectEditor::redo_history_
private

Definition at line 244 of file dungeon_object_editor.h.

Referenced by CanRedo(), ClearHistory(), CreateUndoPoint(), Redo(), and Undo().

◆ kMaxUndoHistory

constexpr size_t yaze::zelda3::DungeonObjectEditor::kMaxUndoHistory = 50
staticconstexprprivate

Definition at line 245 of file dungeon_object_editor.h.

Referenced by CreateUndoPoint().

◆ preview_object_

std::optional<RoomObject> yaze::zelda3::DungeonObjectEditor::preview_object_
private

Definition at line 248 of file dungeon_object_editor.h.

Referenced by UpdatePreviewObject().

◆ preview_visible_

bool yaze::zelda3::DungeonObjectEditor::preview_visible_ = false
private

Definition at line 249 of file dungeon_object_editor.h.

Referenced by UpdatePreviewObject().

◆ object_changed_callback_

ObjectChangedCallback yaze::zelda3::DungeonObjectEditor::object_changed_callback_
private

◆ room_changed_callback_

RoomChangedCallback yaze::zelda3::DungeonObjectEditor::room_changed_callback_
private

◆ selection_changed_callback_

SelectionChangedCallback yaze::zelda3::DungeonObjectEditor::selection_changed_callback_
private

◆ kMinObjectSize

constexpr int yaze::zelda3::DungeonObjectEditor::kMinObjectSize = 0x00
staticconstexprprivate

Definition at line 257 of file dungeon_object_editor.h.

Referenced by IsValidSize().

◆ kMaxObjectSize

constexpr int yaze::zelda3::DungeonObjectEditor::kMaxObjectSize = 0xFF
staticconstexprprivate

Definition at line 258 of file dungeon_object_editor.h.

Referenced by InsertObject(), IsValidSize(), and ResizeObject().

◆ kDefaultObjectSize

constexpr int yaze::zelda3::DungeonObjectEditor::kDefaultObjectSize = 0x12
staticconstexprprivate

Definition at line 259 of file dungeon_object_editor.h.

Referenced by InitializeEditor().

◆ kMinLayer

constexpr int yaze::zelda3::DungeonObjectEditor::kMinLayer = 0
staticconstexprprivate

Definition at line 260 of file dungeon_object_editor.h.

Referenced by HandleScrollWheel(), and SetCurrentLayer().

◆ kMaxLayer

constexpr int yaze::zelda3::DungeonObjectEditor::kMaxLayer = 2
staticconstexprprivate

Definition at line 261 of file dungeon_object_editor.h.

Referenced by HandleScrollWheel(), InsertObject(), and SetCurrentLayer().

◆ empty_objects_

std::vector<RoomObject> yaze::zelda3::DungeonObjectEditor::empty_objects_
private

Definition at line 264 of file dungeon_object_editor.h.

Referenced by GetObjects().


The documentation for this class was generated from the following files: