Skip to content

Tool mode state and tool palette - #80

Closed
deanblackborough wants to merge 5 commits into
mainfrom
tool-mode-state
Closed

Tool mode state and tool palette#80
deanblackborough wants to merge 5 commits into
mainfrom
tool-mode-state

Conversation

@deanblackborough

@deanblackborough deanblackborough commented Jun 16, 2026

Copy link
Copy Markdown
Owner
  • Added tool mode
  • Added a tool palette top right of viewport
  • TODO: Add a game tool palette

Summary by CodeRabbit

  • New Features

    • Explicit editor tool modes (Select and Move) now available for direct selection.
    • Tool palette integrated into the viewport interface for quick access.
    • Refined object dragging behaviour that responds to the currently active tool mode.
  • Documentation

    • Updated on-screen controls information to reflect new tool interactions.

@deanblackborough deanblackborough self-assigned this Jun 16, 2026
@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR introduces an explicit EditorTool enum (Select, Move) with label and body-move helper functions. The active tool is stored as editor_tool in SceneState, defaulting to EditorTool::Select. The Scene base class gains default virtual implementations for current_editor_tool, set_current_editor_tool, and execute_scene_creation_action; WorldScene provides final overrides, replacing the ImGui-driven draw_creation_tools() loop with a non-UI execute_scene_creation_action function. All three concrete scenes (Artillery, Platformer, Simple Shooter) reset the tool on runtime reset and drop their draw_creation_tools() calls. SceneInteraction gains tool-aware drag-target selection that gates body-move behaviour on the active tool. A new viewport tool palette overlay renders Select/Move buttons and scene-creation actions in ui.cpp, with hover suppression applied when the mouse is over the palette.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • deanblackborough/Prune#65: Directly overlaps in WorldScene — that PR added draw_creation_tools() and debug overlay controls, which this PR replaces with execute_scene_creation_action.
  • deanblackborough/Prune#78: Both PRs modify SceneInteraction's drag/move target selection; PR #78 added multi-select move handling that this PR now gates behind editor_tool_allows_body_move.
  • deanblackborough/Prune#27: Both PRs modify the scene viewport rendering and hover/input handling code path in src/prune/tooling/ui.cpp.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarises the primary changes: introducing tool mode state management and displaying a tool palette interface for scene manipulation.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch tool-mode-state

Comment @coderabbitai help to get the list of available commands and usage tips.

@deanblackborough deanblackborough added the enhancement New feature or request label Jun 18, 2026
@deanblackborough
deanblackborough marked this pull request as ready for review June 18, 2026 22:46

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/prune/scene/simple_shooter/simple_shooter_scene.cpp (1)

83-89: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Normalise player_id before mutating the loaded player object

Line 83 currently patches runtime.behaviour and editor.movable before player_id is validated. If player_id points at a non-player object, the wrong object is mutated and the resolved player may never get editor.movable = true.

🔧 Suggested fix
-            if (GameObject* player = state.objects.get_by_id(shooter_state.player_id)) {
-                if (player->runtime.behaviour.empty()) {
-                    player->runtime.behaviour = simple_shooter_ids::player_behaviour;
-                }
-
-                player->editor.movable = true;
-            }
-
             restore_legacy_wall_concepts(state);
 
             if (!object_has_kind(state, shooter_state.player_id, simple_shooter_concepts::ObjectKind::Player)) {
                 shooter_state.player_id = first_object_id_for_kind(state, simple_shooter_concepts::ObjectKind::Player);
             }
 
             if (shooter_state.player_id == k_invalid_game_object_id) {
                 shooter_state.player_id = state.objects.create_object(simple_shooter_factory::create_player());
             }
+
+            if (GameObject* player = state.objects.get_by_id(shooter_state.player_id)) {
+                if (player->runtime.behaviour.empty()) {
+                    player->runtime.behaviour = simple_shooter_ids::player_behaviour;
+                }
+
+                player->editor.movable = true;
+            }

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 97ac6068-b317-47d7-8666-de65844ba3b8

📥 Commits

Reviewing files that changed from the base of the PR and between b9f7086 and 276d853.

⛔ Files ignored due to path filters (3)
  • assets/repo/artillery.png is excluded by !**/*.png
  • assets/repo/platformer.png is excluded by !**/*.png
  • assets/repo/simple-shooter.png is excluded by !**/*.png
📒 Files selected for processing (15)
  • DECISIONS.md
  • NOTES.md
  • src/prune/editor/editor_tool.hpp
  • src/prune/scene/artillery/artillery_scene.cpp
  • src/prune/scene/platformer/platformer_scene.cpp
  • src/prune/scene/scene.hpp
  • src/prune/scene/scene_interaction.cpp
  • src/prune/scene/scene_interaction.hpp
  • src/prune/scene/scene_state.hpp
  • src/prune/scene/simple_shooter/simple_shooter_scene.cpp
  • src/prune/scene/world_scene.cpp
  • src/prune/scene/world_scene.hpp
  • src/prune/tooling/controls.cpp
  • src/prune/tooling/editor_layout.cpp
  • src/prune/tooling/ui.cpp

tooling::imgui::layout::text_wrapped("Shift+Left click toggles objects in the selection set");
tooling::imgui::layout::text_wrapped("Empty viewport click clears the selection set");
tooling::imgui::layout::text_wrapped("Mouse button left on a selection handle moves the selected object or selected objects");
tooling::imgui::layout::text_wrapped("Use the Select/Move tool buttons in the main menu bar to change viewport tool mode");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Update the tool location text to match the actual UI.

The tools are rendered in the viewport palette, not in the main menu bar, so this instruction is currently misleading.

Comment thread src/prune/tooling/ui.cpp
Comment on lines +127 to +130
ImGui::PushID(action.id.data());

if (ImGui::Button(action.label.data(), ImVec2(button_width, 0.0f))) {
scene.execute_scene_creation_action(action.id);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify SceneCreationAction string field types and call sites that pass .data() to ImGui APIs.

rg -n -C3 'struct\s+SceneCreationAction|SceneCreationAction' src
rg -n -C3 'ImGui::(Button|PushID)\(' src/prune/tooling/ui.cpp
rg -n -C3 '\.id\.data\(\)|\.label\.data\(\)' src

Repository: deanblackborough/Prune

Length of output: 11326


Ensure string_view::data() is NUL-terminated before passing to ImGui APIs.

action.id.data() and action.label.data() assume NUL-termination, but std::string_view doesn't guarantee it in its contract. Right now you're safe because all the static action arrays use string literals, but if those views ever come from slicing a longer string or a non-literal source, you'll get undefined behaviour. Think of it as a defensive bet—protect the API boundary now, before someone else inherits this code and accidentally breaks it.

The fix is straightforward: use the range overload for ImGui::PushID() and convert the label to a temporary std::string to guarantee NUL-termination.

Suggested fix
 void draw_scene_creation_action_button(
     Scene& scene,
     const SceneCreationAction& action,
     float button_width
 )
 {
-    ImGui::PushID(action.id.data());
-
-    if (ImGui::Button(action.label.data(), ImVec2(button_width, 0.0f))) {
+    const std::string button_text(action.label);
+    ImGui::PushID(action.id.data(), action.id.data() + action.id.size());
+    if (ImGui::Button(button_text.c_str(), ImVec2(button_width, 0.0f))) {
         scene.execute_scene_creation_action(action.id);
     }
 
     ImGui::PopID();
 }
🧰 Tools
🪛 Clang (14.0.6)

[warning] 129-129: floating point literal has suffix 'f', which is not uppercase

(readability-uppercase-literal-suffix)

@hoanbin631-debug hoanbin631-debug left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hoanbin631-debug hoanbin631-debug left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requested changes in CodeRabbit Change Stack

@deanblackborough
deanblackborough marked this pull request as draft June 21, 2026 20:29
@deanblackborough
deanblackborough dismissed stale reviews from hoanbin631-debug June 21, 2026 20:30

AI slop

@deanblackborough
deanblackborough marked this pull request as ready for review June 21, 2026 20:45
@deanblackborough
deanblackborough deleted the tool-mode-state branch June 21, 2026 22:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants