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

Coordinates interaction mode switching and dispatches to handlers. More...

#include <interaction_coordinator.h>

Public Types

enum class  Mode { Select , PlaceDoor , PlaceSprite , PlaceItem }
 Available interaction modes. More...
 

Public Member Functions

 InteractionCoordinator ()
 
void SetContext (InteractionContext *ctx)
 Set the shared interaction context.
 
Mode GetCurrentMode () const
 Get current interaction mode.
 
void SetMode (Mode mode)
 Set interaction mode.
 
void CancelCurrentMode ()
 Cancel current mode and return to select mode.
 
bool IsPlacementActive () const
 Check if any placement mode is active.
 
DoorInteractionHandler & door_handler ()
 
const DoorInteractionHandler & door_handler () const
 
SpriteInteractionHandler & sprite_handler ()
 
const SpriteInteractionHandler & sprite_handler () const
 
ItemInteractionHandler & item_handler ()
 
const ItemInteractionHandler & item_handler () const
 
TileObjectHandler & tile_handler ()
 
const TileObjectHandler & tile_handler () const
 
bool HandleClick (int canvas_x, int canvas_y)
 Handle click at canvas position.
 
bool HandleMouseWheel (float delta)
 
void SelectEntity (EntityType type, size_t index)
 
void SetSelectedEntities (std::vector< SelectedEntity > entities)
 
void ClearEntitySelection ()
 
bool HasEntitySelection () const
 
bool NudgeSelected (int delta_x, int delta_y)
 
absl::Status CommitSelectionEdit (const DungeonSelectionEditRequest &request, bool continuous=false)
 
std::vector< SelectedEntity > SelectedEntitiesForEdit () const
 
int SelectionMoveStepPixels () const
 
void FinishSelectionGesture ()
 
const absl::Status & selection_edit_status () const
 
absl::Status ReportSelectionEditStatus (absl::Status status)
 
void CancelPlacement ()
 
const std::vector< SelectedEntity > & GetSelectedEntities () const
 
void SelectEntitiesInRect (const std::tuple< int, int, int, int > &bounds, bool additive, bool toggle)
 
void BeginSelectionDrag (ImVec2 start_pos)
 
std::optional< SelectedEntity > GetEntityAtPosition (int canvas_x, int canvas_y) const
 
std::vector< SelectedEntity > GetEntitiesAtPosition (int canvas_x, int canvas_y) const
 
SelectedEntity GetSelectedEntity () const
 
void HandleDrag (ImVec2 current_pos, ImVec2 delta)
 Handle drag operation.
 
void HandleRelease ()
 Handle mouse release.
 
void DrawGhostPreviews ()
 Draw ghost previews for active placement mode.
 
void DrawSelectionHighlights ()
 Draw selection highlights for all entity types.
 
void DrawPostPlacementOverlays ()
 Draw post-placement success toasts for all handlers (unconditional)
 
bool TrySelectEntityAtCursor (int canvas_x, int canvas_y)
 Try to select entity at cursor position.
 
void ClearAllEntitySelections ()
 Clear all entity selections.
 
absl::Status DeleteSelectedEntity ()
 Delete currently selected entity.
 
Mode GetSelectedEntityType () const
 Get the type of currently selected entity.
 

Private Member Functions

BaseEntityHandler * GetActiveHandler ()
 Get active handler based on current mode.
 
bool ApplySelection (SelectedEntity entity)
 
bool UpdateEntitySelection (SelectedEntity entity, bool additive, bool toggle)
 
bool IsSelectionHitSelected (SelectedEntity entity) const
 
bool HasGroupDragSelection () const
 
void ResetEntityGroupDragState ()
 
void FinishEntityGroupDrag ()
 
void HandleEntityGroupDrag (ImVec2 current_pos)
 
bool SameCycleTarget (int canvas_x, int canvas_y, const std::vector< SelectedEntity > &hits) const
 
void UpdateSelectionCycleHudPreview ()
 
std::optional< size_t > FindSelectedCycleIndex (const std::vector< SelectedEntity > &hits) const
 
void DrawSelectionCycleHud ()
 
void DrawMultiEntitySelectionHighlights ()
 
std::string DescribeEntity (SelectedEntity entity) const
 
std::string DescribeCycleHudEntity (SelectedEntity entity) const
 

Private Attributes

absl::Status selection_edit_status_
 
Mode current_mode_ = Mode::Select
 
InteractionContext * ctx_ = nullptr
 
DoorInteractionHandler door_handler_
 
SpriteInteractionHandler sprite_handler_
 
ItemInteractionHandler item_handler_
 
TileObjectHandler tile_handler_
 
std::vector< SelectedEntity > selected_entities_
 
int cycle_last_x_ = -1
 
int cycle_last_y_ = -1
 
size_t cycle_next_index_ = 0
 
size_t cycle_active_index_ = 0
 
ImVec2 cycle_hud_screen_pos_ {0.0f, 0.0f}
 
double cycle_hud_start_time_ = -1.0
 
std::vector< SelectedEntity > cycle_last_hits_
 
bool entity_group_drag_active_ = false
 
ImVec2 entity_group_drag_start_ {0.0f, 0.0f}
 
ImVec2 entity_group_drag_current_ {0.0f, 0.0f}
 
int entity_group_drag_last_dx_ = 0
 
int entity_group_drag_last_dy_ = 0
 

Detailed Description

Coordinates interaction mode switching and dispatches to handlers.

The coordinator manages the current interaction mode and ensures only one handler is active at a time. It provides a unified interface for the DungeonObjectInteraction facade to delegate to.

Definition at line 26 of file interaction_coordinator.h.

Member Enumeration Documentation

◆ Mode

Available interaction modes.

Enumerator
Select 
PlaceDoor 
PlaceSprite 
PlaceItem 

Definition at line 31 of file interaction_coordinator.h.

Constructor & Destructor Documentation

◆ InteractionCoordinator()

yaze::editor::InteractionCoordinator::InteractionCoordinator ( )
inline

Definition at line 38 of file interaction_coordinator.h.

Member Function Documentation

◆ SetContext()

◆ GetCurrentMode()

Mode yaze::editor::InteractionCoordinator::GetCurrentMode ( ) const
inline

Get current interaction mode.

Definition at line 50 of file interaction_coordinator.h.

References current_mode_.

◆ SetMode()

void yaze::editor::InteractionCoordinator::SetMode ( Mode mode)

◆ CancelCurrentMode()

void yaze::editor::InteractionCoordinator::CancelCurrentMode ( )

◆ IsPlacementActive()

◆ door_handler() [1/2]

◆ door_handler() [2/2]

const DoorInteractionHandler & yaze::editor::InteractionCoordinator::door_handler ( ) const
inline

Definition at line 74 of file interaction_coordinator.h.

References door_handler_.

◆ sprite_handler() [1/2]

◆ sprite_handler() [2/2]

const SpriteInteractionHandler & yaze::editor::InteractionCoordinator::sprite_handler ( ) const
inline

Definition at line 77 of file interaction_coordinator.h.

References sprite_handler_.

◆ item_handler() [1/2]

◆ item_handler() [2/2]

const ItemInteractionHandler & yaze::editor::InteractionCoordinator::item_handler ( ) const
inline

Definition at line 82 of file interaction_coordinator.h.

References item_handler_.

◆ tile_handler() [1/2]

◆ tile_handler() [2/2]

const TileObjectHandler & yaze::editor::InteractionCoordinator::tile_handler ( ) const
inline

Definition at line 85 of file interaction_coordinator.h.

References tile_handler_.

◆ HandleClick()

bool yaze::editor::InteractionCoordinator::HandleClick ( int canvas_x,
int canvas_y )

Handle click at canvas position.

Dispatches to appropriate handler based on current mode.

Returns
true if click was handled

Definition at line 149 of file interaction_coordinator.cc.

References ApplySelection(), ClearAllEntitySelections(), yaze::editor::DoorInteractionHandler::ClearSelection(), yaze::editor::ItemInteractionHandler::ClearSelection(), yaze::editor::SpriteInteractionHandler::ClearSelection(), yaze::editor::ObjectSelection::ClearSelection(), ctx_, cycle_active_index_, cycle_hud_screen_pos_, cycle_hud_start_time_, cycle_last_hits_, cycle_last_x_, cycle_last_y_, cycle_next_index_, door_handler_, GetEntitiesAtPosition(), yaze::editor::ObjectSelection::GetSelectionCount(), yaze::editor::DoorInteractionHandler::HandleClick(), yaze::editor::ItemInteractionHandler::HandleClick(), yaze::editor::SpriteInteractionHandler::HandleClick(), yaze::editor::TileObjectHandler::HandleClick(), yaze::editor::DoorInteractionHandler::HandleOverlayClick(), HasEntitySelection(), HasGroupDragSelection(), yaze::editor::ObjectSelection::HasSelection(), yaze::editor::DoorInteractionHandler::IsPlacementActive(), yaze::editor::ItemInteractionHandler::IsPlacementActive(), yaze::editor::SpriteInteractionHandler::IsPlacementActive(), yaze::editor::TileObjectHandler::IsPlacementActive(), IsSelectionHitSelected(), yaze::editor::dungeon_coords::IsWithinBounds(), item_handler_, yaze::editor::InteractionContext::NotifyEntityChanged(), SameCycleTarget(), selected_entities_, yaze::editor::InteractionContext::selection, sprite_handler_, tile_handler_, and UpdateEntitySelection().

Referenced by yaze::editor::DungeonObjectInteraction::HandleLeftClick().

◆ HandleMouseWheel()

◆ SelectEntity()

◆ SetSelectedEntities()

◆ ClearEntitySelection()

void yaze::editor::InteractionCoordinator::ClearEntitySelection ( )

◆ HasEntitySelection()

◆ NudgeSelected()

◆ CommitSelectionEdit()

◆ SelectedEntitiesForEdit()

std::vector< SelectedEntity > yaze::editor::InteractionCoordinator::SelectedEntitiesForEdit ( ) const

Definition at line 542 of file interaction_coordinator.cc.

References GetSelectedEntity(), and selected_entities_.

Referenced by DeleteSelectedEntity(), HandleEntityGroupDrag(), NudgeSelected(), and SelectionMoveStepPixels().

Here is the call graph for this function:

◆ SelectionMoveStepPixels()

int yaze::editor::InteractionCoordinator::SelectionMoveStepPixels ( ) const

◆ FinishSelectionGesture()

void yaze::editor::InteractionCoordinator::FinishSelectionGesture ( )

Definition at line 461 of file interaction_coordinator.cc.

References FinishEntityGroupDrag().

Referenced by CommitSelectionEdit(), and yaze::editor::DungeonObjectInteraction::FinishSelectionGesture().

Here is the call graph for this function:

◆ selection_edit_status()

const absl::Status & yaze::editor::InteractionCoordinator::selection_edit_status ( ) const
inline

◆ ReportSelectionEditStatus()

absl::Status yaze::editor::InteractionCoordinator::ReportSelectionEditStatus ( absl::Status status)

◆ CancelPlacement()

◆ GetSelectedEntities()

◆ SelectEntitiesInRect()

◆ BeginSelectionDrag()

void yaze::editor::InteractionCoordinator::BeginSelectionDrag ( ImVec2 start_pos)

◆ GetEntityAtPosition()

std::optional< SelectedEntity > yaze::editor::InteractionCoordinator::GetEntityAtPosition ( int canvas_x,
int canvas_y ) const

Definition at line 370 of file interaction_coordinator.cc.

References GetEntitiesAtPosition().

Here is the call graph for this function:

◆ GetEntitiesAtPosition()

◆ GetSelectedEntity()

◆ HandleDrag()

◆ HandleRelease()

◆ DrawGhostPreviews()

◆ DrawSelectionHighlights()

◆ DrawPostPlacementOverlays()

void yaze::editor::InteractionCoordinator::DrawPostPlacementOverlays ( )

Draw post-placement success toasts for all handlers (unconditional)

Called every frame so toasts remain visible even after the user exits placement mode immediately after a successful placement.

Definition at line 499 of file interaction_coordinator.cc.

References door_handler_, yaze::editor::BaseEntityHandler::DrawPostPlacementToast(), item_handler_, sprite_handler_, and tile_handler_.

Here is the call graph for this function:

◆ TrySelectEntityAtCursor()

bool yaze::editor::InteractionCoordinator::TrySelectEntityAtCursor ( int canvas_x,
int canvas_y )

◆ ClearAllEntitySelections()

◆ DeleteSelectedEntity()

absl::Status yaze::editor::InteractionCoordinator::DeleteSelectedEntity ( )

Delete currently selected entity.

Definition at line 699 of file interaction_coordinator.cc.

References CommitSelectionEdit(), yaze::editor::DungeonSelectionEditRequest::entities, yaze::editor::kDelete, yaze::editor::DungeonSelectionEditRequest::kind, and SelectedEntitiesForEdit().

Here is the call graph for this function:

◆ GetSelectedEntityType()

InteractionCoordinator::Mode yaze::editor::InteractionCoordinator::GetSelectedEntityType ( ) const

Get the type of currently selected entity.

Returns
Selected entity type, or Mode::Select if no entity selected

Definition at line 706 of file interaction_coordinator.cc.

References door_handler_, yaze::editor::DoorInteractionHandler::HasSelection(), yaze::editor::ItemInteractionHandler::HasSelection(), yaze::editor::SpriteInteractionHandler::HasSelection(), item_handler_, PlaceDoor, PlaceItem, PlaceSprite, Select, selected_entities_, and sprite_handler_.

Here is the call graph for this function:

◆ GetActiveHandler()

BaseEntityHandler * yaze::editor::InteractionCoordinator::GetActiveHandler ( )
private

Get active handler based on current mode.

Returns
Pointer to active handler, or nullptr if in Select mode

Definition at line 734 of file interaction_coordinator.cc.

References current_mode_, door_handler_, item_handler_, PlaceDoor, PlaceItem, PlaceSprite, Select, and sprite_handler_.

◆ ApplySelection()

◆ UpdateEntitySelection()

◆ IsSelectionHitSelected()

bool yaze::editor::InteractionCoordinator::IsSelectionHitSelected ( SelectedEntity entity) const
private

◆ HasGroupDragSelection()

bool yaze::editor::InteractionCoordinator::HasGroupDragSelection ( ) const
private

Definition at line 846 of file interaction_coordinator.cc.

References ctx_, yaze::editor::ObjectSelection::HasSelection(), selected_entities_, and yaze::editor::InteractionContext::selection.

Referenced by BeginSelectionDrag(), and HandleClick().

Here is the call graph for this function:

◆ ResetEntityGroupDragState()

void yaze::editor::InteractionCoordinator::ResetEntityGroupDragState ( )
private

◆ FinishEntityGroupDrag()

void yaze::editor::InteractionCoordinator::FinishEntityGroupDrag ( )
private

◆ HandleEntityGroupDrag()

◆ SameCycleTarget()

bool yaze::editor::InteractionCoordinator::SameCycleTarget ( int canvas_x,
int canvas_y,
const std::vector< SelectedEntity > & hits ) const
private

◆ UpdateSelectionCycleHudPreview()

◆ FindSelectedCycleIndex()

std::optional< size_t > yaze::editor::InteractionCoordinator::FindSelectedCycleIndex ( const std::vector< SelectedEntity > & hits) const
private

◆ DrawSelectionCycleHud()

void yaze::editor::InteractionCoordinator::DrawSelectionCycleHud ( )
private

◆ DrawMultiEntitySelectionHighlights()

◆ DescribeEntity()

◆ DescribeCycleHudEntity()

std::string yaze::editor::InteractionCoordinator::DescribeCycleHudEntity ( SelectedEntity entity) const
private

Definition at line 1202 of file interaction_coordinator.cc.

References DescribeEntity().

Referenced by DrawSelectionCycleHud().

Here is the call graph for this function:

Member Data Documentation

◆ selection_edit_status_

absl::Status yaze::editor::InteractionCoordinator::selection_edit_status_
private

Definition at line 188 of file interaction_coordinator.h.

Referenced by ReportSelectionEditStatus(), and selection_edit_status().

◆ current_mode_

Mode yaze::editor::InteractionCoordinator::current_mode_ = Mode::Select
private

◆ ctx_

◆ door_handler_

◆ sprite_handler_

◆ item_handler_

◆ tile_handler_

◆ selected_entities_

◆ cycle_last_x_

int yaze::editor::InteractionCoordinator::cycle_last_x_ = -1
private

◆ cycle_last_y_

int yaze::editor::InteractionCoordinator::cycle_last_y_ = -1
private

◆ cycle_next_index_

size_t yaze::editor::InteractionCoordinator::cycle_next_index_ = 0
private

Definition at line 199 of file interaction_coordinator.h.

Referenced by HandleClick(), and UpdateSelectionCycleHudPreview().

◆ cycle_active_index_

size_t yaze::editor::InteractionCoordinator::cycle_active_index_ = 0
private

◆ cycle_hud_screen_pos_

ImVec2 yaze::editor::InteractionCoordinator::cycle_hud_screen_pos_ {0.0f, 0.0f}
private

◆ cycle_hud_start_time_

double yaze::editor::InteractionCoordinator::cycle_hud_start_time_ = -1.0
private

◆ cycle_last_hits_

std::vector<SelectedEntity> yaze::editor::InteractionCoordinator::cycle_last_hits_
private

◆ entity_group_drag_active_

bool yaze::editor::InteractionCoordinator::entity_group_drag_active_ = false
private

◆ entity_group_drag_start_

ImVec2 yaze::editor::InteractionCoordinator::entity_group_drag_start_ {0.0f, 0.0f}
private

Definition at line 205 of file interaction_coordinator.h.

Referenced by BeginSelectionDrag(), and HandleEntityGroupDrag().

◆ entity_group_drag_current_

ImVec2 yaze::editor::InteractionCoordinator::entity_group_drag_current_ {0.0f, 0.0f}
private

Definition at line 206 of file interaction_coordinator.h.

Referenced by BeginSelectionDrag(), and HandleEntityGroupDrag().

◆ entity_group_drag_last_dx_

int yaze::editor::InteractionCoordinator::entity_group_drag_last_dx_ = 0
private

◆ entity_group_drag_last_dy_

int yaze::editor::InteractionCoordinator::entity_group_drag_last_dy_ = 0
private

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