Refactor OverworldEditor copy functionality to use selected points
- Updated the `Copy` method in `OverworldEditor` to utilize selected points instead of tiles for copying tile16 IDs to the clipboard, enhancing the selection mechanism. - Improved the logic for determining the width and height of the selection based on the selected points, ensuring accurate tile copying. - Adjusted the `DrawSelectRect` method in `Canvas` to correctly calculate local map indices, refining the tile selection process. - Added a new configuration option in `Canvas` to control clamping behavior for local maps, providing more flexibility in canvas settings.
This commit is contained in:
@@ -1051,15 +1051,8 @@ absl::Status OverworldEditor::Copy() {
|
|||||||
return absl::FailedPreconditionError("No editor context");
|
return absl::FailedPreconditionError("No editor context");
|
||||||
// If a rectangle selection exists, copy its tile16 IDs into shared clipboard
|
// If a rectangle selection exists, copy its tile16 IDs into shared clipboard
|
||||||
if (ow_map_canvas_.select_rect_active() &&
|
if (ow_map_canvas_.select_rect_active() &&
|
||||||
!ow_map_canvas_.selected_tiles().empty()) {
|
!ow_map_canvas_.selected_points().empty()) {
|
||||||
std::vector<int> ids;
|
std::vector<int> ids;
|
||||||
ids.reserve(ow_map_canvas_.selected_tiles().size());
|
|
||||||
overworld_.set_current_world(current_world_);
|
|
||||||
overworld_.set_current_map(current_map_);
|
|
||||||
for (const auto& pos : ow_map_canvas_.selected_tiles()) {
|
|
||||||
ids.push_back(overworld_.GetTileFromPosition(pos));
|
|
||||||
}
|
|
||||||
// Determine width/height in tile16 based on selection bounds
|
|
||||||
const auto start = ow_map_canvas_.selected_points()[0];
|
const auto start = ow_map_canvas_.selected_points()[0];
|
||||||
const auto end = ow_map_canvas_.selected_points()[1];
|
const auto end = ow_map_canvas_.selected_points()[1];
|
||||||
const int start_x =
|
const int start_x =
|
||||||
@@ -1072,6 +1065,14 @@ absl::Status OverworldEditor::Copy() {
|
|||||||
static_cast<int>(std::floor(std::max(start.y, end.y) / 16.0f));
|
static_cast<int>(std::floor(std::max(start.y, end.y) / 16.0f));
|
||||||
const int width = end_x - start_x + 1;
|
const int width = end_x - start_x + 1;
|
||||||
const int height = end_y - start_y + 1;
|
const int height = end_y - start_y + 1;
|
||||||
|
ids.reserve(width * height);
|
||||||
|
overworld_.set_current_world(current_world_);
|
||||||
|
overworld_.set_current_map(current_map_);
|
||||||
|
for (int y = start_y; y <= end_y; ++y) {
|
||||||
|
for (int x = start_x; x <= end_x; ++x) {
|
||||||
|
ids.push_back(overworld_.GetTile(x, y));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
context_->shared_clipboard.overworld_tile16_ids = std::move(ids);
|
context_->shared_clipboard.overworld_tile16_ids = std::move(ids);
|
||||||
context_->shared_clipboard.overworld_width = width;
|
context_->shared_clipboard.overworld_width = width;
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ void Canvas::InitializeDefaults() {
|
|||||||
config_.global_scale = 1.0f;
|
config_.global_scale = 1.0f;
|
||||||
config_.canvas_size = ImVec2(0, 0);
|
config_.canvas_size = ImVec2(0, 0);
|
||||||
config_.custom_canvas_size = false;
|
config_.custom_canvas_size = false;
|
||||||
|
config_.clamp_rect_to_local_maps = false;
|
||||||
|
|
||||||
// Initialize selection state
|
// Initialize selection state
|
||||||
selection_.Clear();
|
selection_.Clear();
|
||||||
@@ -1040,8 +1041,8 @@ void Canvas::DrawSelectRect(int current_map, int tile_size, float scale) {
|
|||||||
for (int y = start_y; y <= end_y; y += tile16_size) {
|
for (int y = start_y; y <= end_y; y += tile16_size) {
|
||||||
for (int x = start_x; x <= end_x; x += tile16_size) {
|
for (int x = start_x; x <= end_x; x += tile16_size) {
|
||||||
// Determine which local map (512x512) the tile is in
|
// Determine which local map (512x512) the tile is in
|
||||||
int local_map_x = x / small_map_size;
|
int local_map_x = (x / small_map_size) % 8;
|
||||||
int local_map_y = y / small_map_size;
|
int local_map_y = (y / small_map_size) % 8;
|
||||||
|
|
||||||
// Calculate the tile's position within its local map
|
// Calculate the tile's position within its local map
|
||||||
int tile16_x = (x % small_map_size) / tile16_size;
|
int tile16_x = (x % small_map_size) / tile16_size;
|
||||||
|
|||||||
@@ -252,6 +252,8 @@ endif()
|
|||||||
target_link_options(yaze_test PRIVATE /STACK:8388608) # 8MB stack
|
target_link_options(yaze_test PRIVATE /STACK:8388608) # 8MB stack
|
||||||
elseif(MINGW)
|
elseif(MINGW)
|
||||||
target_link_options(yaze_test PRIVATE -Wl,--stack,8388608)
|
target_link_options(yaze_test PRIVATE -Wl,--stack,8388608)
|
||||||
|
else()
|
||||||
|
target_link_options(yaze_test PRIVATE -Wl,-w)
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
Reference in New Issue
Block a user