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.
 
DoorInteractionHandlerdoor_handler ()
 
const DoorInteractionHandlerdoor_handler () const
 
SpriteInteractionHandlersprite_handler ()
 
const SpriteInteractionHandlersprite_handler () const
 
ItemInteractionHandleritem_handler ()
 
const ItemInteractionHandleritem_handler () const
 
TileObjectHandlertile_handler ()
 
const TileObjectHandlertile_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)
 
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< SelectedEntityGetEntityAtPosition (int canvas_x, int canvas_y) const
 
std::vector< SelectedEntityGetEntitiesAtPosition (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.
 
void DeleteSelectedEntity ()
 Delete currently selected entity.
 
Mode GetSelectedEntityType () const
 Get the type of currently selected entity.
 

Private Member Functions

BaseEntityHandlerGetActiveHandler ()
 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
 
bool NudgeSelectedEntities (int delta_x, int delta_y, bool defer_drag_notifications)
 
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

Mode current_mode_ = Mode::Select
 
InteractionContextctx_ = nullptr
 
DoorInteractionHandler door_handler_
 
SpriteInteractionHandler sprite_handler_
 
ItemInteractionHandler item_handler_
 
TileObjectHandler tile_handler_
 
std::vector< SelectedEntityselected_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< SelectedEntitycycle_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
 
bool entity_group_drag_doors_mutation_started_ = false
 
bool entity_group_drag_sprites_mutation_started_ = false
 
bool entity_group_drag_items_mutation_started_ = false
 
bool entity_group_drag_doors_changed_ = false
 
bool entity_group_drag_sprites_changed_ = false
 
bool entity_group_drag_items_changed_ = false
 

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 24 of file interaction_coordinator.h.

Member Enumeration Documentation

◆ Mode

Available interaction modes.

Enumerator
Select 
PlaceDoor 
PlaceSprite 
PlaceItem 

Definition at line 29 of file interaction_coordinator.h.

Constructor & Destructor Documentation

◆ InteractionCoordinator()

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

Definition at line 36 of file interaction_coordinator.h.

Member Function Documentation

◆ SetContext()

◆ GetCurrentMode()

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

Get current interaction mode.

Definition at line 48 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]

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

◆ door_handler() [2/2]

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

Definition at line 72 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 75 of file interaction_coordinator.h.

References sprite_handler_.

◆ item_handler() [1/2]

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

◆ item_handler() [2/2]

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

Definition at line 80 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 83 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 147 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_, yaze::editor::Door, 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(), yaze::editor::Item, item_handler_, yaze::editor::InteractionContext::NotifyEntityChanged(), yaze::editor::Object, SameCycleTarget(), selected_entities_, yaze::editor::InteractionContext::selection, yaze::editor::Sprite, sprite_handler_, tile_handler_, and UpdateEntitySelection().

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

◆ HandleMouseWheel()

◆ SelectEntity()

◆ SetSelectedEntities()

◆ ClearEntitySelection()

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

◆ HasEntitySelection()

◆ NudgeSelected()

◆ CancelPlacement()

◆ GetSelectedEntities()

const std::vector< SelectedEntity > & yaze::editor::InteractionCoordinator::GetSelectedEntities ( ) const
inline

◆ SelectEntitiesInRect()

◆ BeginSelectionDrag()

◆ GetEntityAtPosition()

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

Definition at line 368 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 514 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()

◆ ClearAllEntitySelections()

◆ DeleteSelectedEntity()

◆ GetSelectedEntityType()

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

◆ 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 866 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 978 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:

◆ NudgeSelectedEntities()

◆ ResetEntityGroupDragState()

◆ FinishEntityGroupDrag()

◆ HandleEntityGroupDrag()

void yaze::editor::InteractionCoordinator::HandleEntityGroupDrag ( ImVec2 current_pos)
private

◆ 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 1336 of file interaction_coordinator.cc.

References DescribeEntity().

Referenced by DrawSelectionCycleHud().

Here is the call graph for this function:

Member Data Documentation

◆ 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 187 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 193 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 194 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

◆ entity_group_drag_doors_mutation_started_

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

◆ entity_group_drag_sprites_mutation_started_

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

◆ entity_group_drag_items_mutation_started_

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

◆ entity_group_drag_doors_changed_

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

◆ entity_group_drag_sprites_changed_

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

◆ entity_group_drag_items_changed_

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

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