Skip to content

Commit

Permalink
Fixed holding ctrl for autotile
Browse files Browse the repository at this point in the history
  • Loading branch information
MatusGuy committed Dec 29, 2024
1 parent 9e9b47b commit ace1051
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 35 deletions.
2 changes: 0 additions & 2 deletions src/editor/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,6 @@ Editor::get_level_directory() const
void
Editor::test_level(const std::optional<std::pair<std::string, Vector>>& test_pos)
{
m_overlay_widget->reset_action_press();

Tile::draw_editor_images = false;
Compositor::s_render_lighting = true;
std::string backup_filename = get_autosave_from_levelname(m_levelfile);
Expand Down
3 changes: 2 additions & 1 deletion src/editor/editor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ class Editor final : public Screen,

std::string* m_particle_editor_filename;

bool m_ctrl_pressed;

private:
Sector* m_sector;

Expand All @@ -232,7 +234,6 @@ class Editor final : public Screen,
float m_scroll_speed;
float m_new_scale;

bool m_ctrl_pressed;
Vector m_mouse_pos;

private:
Expand Down
55 changes: 24 additions & 31 deletions src/editor/overlay_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ EditorOverlayWidget::put_tiles(const Vector& target_tile, TileSelection* tiles)
{
const uint32_t tile = tiles->pos(static_cast<int>(add_tile.x), static_cast<int>(add_tile.y));

if (g_config->editor_autotile_mode)
if (m_autotile_mode)
{
AutotileSet* autotileset = get_current_autotileset();
if (autotileset)
Expand Down Expand Up @@ -356,7 +356,7 @@ EditorOverlayWidget::check_tiles_for_fill(uint32_t replace_tile,
uint32_t target_tile,
uint32_t third_tile) const
{
if (g_config->editor_autotile_mode)
if (m_autotile_mode)
{
return m_editor.get_tileset()->has_mutual_autotileset(replace_tile, target_tile) &&
!m_editor.get_tileset()->has_mutual_autotileset(replace_tile, third_tile);
Expand Down Expand Up @@ -465,7 +465,7 @@ EditorOverlayWidget::fill()
}

// Autotile happens after directional detection (because of borders; see snow tileset)
if (g_config->editor_autotile_mode)
if (m_autotile_mode)
input_autotile(pos, tiles->pos(static_cast<int>(tpos.x), static_cast<int>(tpos.y)));

// When tiles on each side are already filled or occupied by another tiles, it ends.
Expand Down Expand Up @@ -521,7 +521,7 @@ EditorOverlayWidget::hover_object()
auto* bezier_marker = dynamic_cast<BezierMarker*>(&moving_object);
if (bezier_marker)
{
if (!action_pressed)
if (!m_editor.m_ctrl_pressed)
{
marker_hovered_without_ctrl = bezier_marker;
continue;
Expand Down Expand Up @@ -584,16 +584,6 @@ EditorOverlayWidget::edit_path(PathGameObject* path, GameObject* new_marked_obje
}
}

void
EditorOverlayWidget::reset_action_press()
{
if (action_pressed)
{
g_config->editor_autotile_mode = !g_config->editor_autotile_mode;
action_pressed = false;
}
}

void
EditorOverlayWidget::select_object()
{
Expand Down Expand Up @@ -1139,22 +1129,20 @@ EditorOverlayWidget::on_mouse_motion(const SDL_MouseMotionEvent& motion)
bool
EditorOverlayWidget::on_key_up(const SDL_KeyboardEvent& key)
{
auto sym = key.keysym.sym;
if (sym == SDLK_LSHIFT)
std::uint16_t mod = key.keysym.mod;

if (mod & KMOD_SHIFT)
{
g_config->editor_snap_to_grid = !g_config->editor_snap_to_grid;
}
else if (sym == SDLK_LCTRL || sym == SDLK_RCTRL)
else if (!m_editor.m_ctrl_pressed)
{
if (action_pressed)
{
g_config->editor_autotile_mode = !g_config->editor_autotile_mode;
action_pressed = false;
}
// Hovered objects depend on which keys are pressed
m_autotile_mode = g_config->editor_autotile_mode;

// Hovered objects depend on if ctrl is pressed
hover_object();
}
else if (sym == SDLK_LALT || sym == SDLK_RALT)
else if (mod & KMOD_ALT)
{
alt_pressed = false;
}
Expand All @@ -1164,24 +1152,29 @@ EditorOverlayWidget::on_key_up(const SDL_KeyboardEvent& key)
bool
EditorOverlayWidget::on_key_down(const SDL_KeyboardEvent& key)
{
auto sym = key.keysym.sym;
SDL_Keycode sym = key.keysym.sym;
std::uint16_t mod = key.keysym.mod;

if (sym == SDLK_F8)
{
g_config->editor_render_grid = !g_config->editor_render_grid;
}
else if (sym == SDLK_F7 || sym == SDLK_LSHIFT)
else if (sym == SDLK_F7 || mod & KMOD_SHIFT)
{
g_config->editor_snap_to_grid = !g_config->editor_snap_to_grid;
}
else if (sym == SDLK_F5 || ((sym == SDLK_LCTRL || sym == SDLK_RCTRL) && !action_pressed))
else if (sym == SDLK_F5)
{
g_config->editor_autotile_mode = !g_config->editor_autotile_mode;
action_pressed = true;
// Hovered objects depend on which keys are pressed
m_autotile_mode = g_config->editor_autotile_mode;
}
else if (m_editor.m_ctrl_pressed)
{
m_autotile_mode = !g_config->editor_autotile_mode;
// Hovered objects depend on if ctrl is pressed.
hover_object();
}
else if (sym == SDLK_LALT || sym == SDLK_RALT)
else if (mod & KMOD_ALT)
{
alt_pressed = true;
}
Expand Down Expand Up @@ -1582,7 +1575,7 @@ EditorOverlayWidget::draw(DrawingContext& context)

if (g_config->editor_autotile_help)
{
if (g_config->editor_autotile_mode)
if (m_autotile_mode)
{
AutotileSet* autotileset = get_current_autotileset();
if (m_editor.get_tiles()->pos(0, 0) == 0)
Expand Down
7 changes: 6 additions & 1 deletion src/editor/overlay_widget.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class EditorOverlayWidget final : public Widget
void on_level_change();

void edit_path(PathGameObject* path, GameObject* new_marked_object = nullptr);
void reset_action_press();
//void reset_action_press();

private:
static bool action_pressed;
Expand Down Expand Up @@ -168,6 +168,11 @@ class EditorOverlayWidget final : public Widget

bool m_selection_warning;

/// Not to be confused with g_config.editor_autotile_mode,
/// this variable is the one that *also* changes when holding CTRL.
/// The other one only changes hitting F5
bool m_autotile_mode;

private:
EditorOverlayWidget(const EditorOverlayWidget&) = delete;
EditorOverlayWidget& operator=(const EditorOverlayWidget&) = delete;
Expand Down

0 comments on commit ace1051

Please sign in to comment.