Add "Advanced Options" checkbox in Tileset selector

To hide "Base Index" & "Allowed Flips" options by default.
This commit is contained in:
David Capello 2023-11-10 17:19:41 -03:00
parent dd5fb871b5
commit 62bdd8af9f
8 changed files with 89 additions and 28 deletions

View File

@ -435,6 +435,7 @@
<section id="tileset">
<option id="base_index" type="int" default="1" />
<option id="cache_compressed_tilesets" type="bool" default="true" />
<option id="advanced" type="bool" default="false" />
</section>
<section id="tilemap">
<option id="show_delete_unused_tileset_alert" type="bool" default="true" />

View File

@ -1425,8 +1425,8 @@ Visible aid to see the first tile with content from the tileset
as index 1 (by default, one-based index) or other value.
E.g. you can use 0 here for zero-based indexing.
END
allow_flipped_tiles = Allow Flipped Tiles:
allow_flipped_tiles_tooltip = <<<END
allowed_flips = Allowed Flips:
allowed_flips_tooltip = <<<END
Aseprite can reuse tiles matching automatically with their flipped
versions (in X, Y, or Diagonal axes) in Auto/Stack modes.
END

View File

@ -1,6 +1,6 @@
<!-- Aseprite -->
<!-- Copyright (C) 2019-2020 Igara Studio S.A. -->
<gui>
<!-- Copyright (C) 2019-2023 Igara Studio S.A. -->
<gui i18nwarnings="false">
<vbox id="tileset_selector">
<combobox id="tilesets">
<listitem text="@.new_tileset" value="-1" />
@ -15,18 +15,19 @@
<label text="@.grid_height" />
<expr id="grid_height" text="" />
<label text="@.base_index" />
<label id="base_index_label" text="@.base_index" />
<expr id="base_index" text="1" tooltip="@.base_tooltip" />
<boxfiller cell_hspan="2" />
</grid>
<boxfiller id="base_index_filler" cell_hspan="2" />
<hbox>
<label text="@.allow_flipped_tiles" />
<buttonset id="flipped_tiles" columns="3" multiple="true">
<item id="xflip" text="X" minwidth="20" tooltip="@.allow_flipped_tiles_tooltip" tooltip_dir="bottom" />
<item id="yflip" text="Y" minwidth="20" tooltip="@.allow_flipped_tiles_tooltip" tooltip_dir="bottom" />
<item id="dflip" text="D" minwidth="20" tooltip="@.allow_flipped_tiles_tooltip" tooltip_dir="bottom" />
<label id="flips_label" text="@.allowed_flips" />
<buttonset id="flips" columns="3" multiple="true">
<item id="xflip" text="X" minwidth="20" tooltip="@.allowed_flips_tooltip" tooltip_dir="bottom" />
<item id="yflip" text="Y" minwidth="20" tooltip="@.allowed_flips_tooltip" tooltip_dir="bottom" />
<item id="dflip" text="D" minwidth="20" tooltip="@.allowed_flips_tooltip" tooltip_dir="bottom" />
</buttonset>
</hbox>
<boxfiller id="flips_filler" cell_hspan="2" />
<check id="advanced" text="@general.advanced_options" cell_hspan="4" />
</grid>
</vbox>
</gui>

View File

@ -374,6 +374,9 @@ private:
if (window.closer() != window.ok())
return;
// Save "advanced" options
tilesetSel.saveAdvancedPreferences();
tilesetInfo = tilesetSel.getInfo();
if (tileset->name() != tilesetInfo.name ||

View File

@ -238,7 +238,10 @@ void NewLayerCommand::onExecute(Context* context)
name = window.name()->text();
if (tilesetSelector) {
tilesetInfo = tilesetSelector->getInfo();
// Save information for next new tilemap layers
pref.tileset.baseIndex(tilesetInfo.baseIndex);
tilesetSelector->saveAdvancedPreferences();
}
}
#endif

View File

@ -11,6 +11,7 @@
#include "app/ui/tileset_selector.h"
#include "app/i18n/strings.h"
#include "app/pref/preferences.h"
#include "doc/sprite.h"
#include "doc/tilesets.h"
#include "fmt/format.h"
@ -22,7 +23,9 @@ namespace app {
using namespace ui;
TilesetSelector::TilesetSelector(const doc::Sprite* sprite,
const TilesetSelector::Info& info) : m_info(info)
const TilesetSelector::Info& info)
: m_sprite(sprite)
, m_info(info)
{
initTheme();
@ -55,12 +58,22 @@ TilesetSelector::TilesetSelector(const doc::Sprite* sprite,
}
if (m_info.enabled) {
tilesets()->Change.connect(
[this, sprite]() {
updateControlsState(sprite->tilesets());
});
tilesets()->Change.connect([this]() {
updateControlsState();
});
}
updateControlsState(sprite->tilesets());
// Advanced controls
const Preferences& pref = Preferences::instance();
advanced()->setSelected(pref.tileset.advanced());
advanced()->Click.connect([this]() {
updateControlsVisibility();
if (auto win = window())
win->expandWindow(win->sizeHint());
});
updateControlsState();
updateControlsVisibility();
}
void TilesetSelector::fillControls(const std::string& nameValue,
@ -77,8 +90,10 @@ void TilesetSelector::fillControls(const std::string& nameValue,
dflip()->setSelected((matchFlags & doc::tile_f_dflip) ? true: false);
}
void TilesetSelector::updateControlsState(const doc::Tilesets* spriteTilesets)
void TilesetSelector::updateControlsState()
{
const doc::Tilesets* spriteTilesets = m_sprite->tilesets();
if (m_info.enabled) {
const int index = getSelectedItemIndex();
const bool isNewTileset = (index == 0);
@ -110,6 +125,17 @@ void TilesetSelector::updateControlsState(const doc::Tilesets* spriteTilesets)
}
}
void TilesetSelector::updateControlsVisibility()
{
const bool v = advanced()->isSelected();
baseIndexLabel()->setVisible(v);
baseIndex()->setVisible(v);
baseIndexFiller()->setVisible(v);
flipsLabel()->setVisible(v);
flips()->setVisible(v);
flipsFiller()->setVisible(v);
}
TilesetSelector::Info TilesetSelector::getInfo()
{
int itemIndex = getSelectedItemIndex();
@ -126,15 +152,34 @@ TilesetSelector::Info TilesetSelector::getInfo()
info.tsi = itemIndex-1;
}
info.name = name()->text();
info.baseIndex = baseIndex()->textInt();
info.matchFlags =
(xflip()->isSelected() ? doc::tile_f_xflip: 0) |
(yflip()->isSelected() ? doc::tile_f_yflip: 0) |
(dflip()->isSelected() ? doc::tile_f_dflip: 0);
// If we are creating a new tilemap/tileset, and the advanced
// options are hidden, we use the default values (only in that
// case). In other case we use the edited options (even if the
// advanced options are hidden).
if (m_info.allowNewTileset &&
m_info.newTileset &&
!advanced()->isSelected()) {
info.baseIndex = 1;
info.matchFlags = 0;
}
else {
info.baseIndex = baseIndex()->textInt();
info.matchFlags =
(xflip()->isSelected() ? doc::tile_f_xflip: 0) |
(yflip()->isSelected() ? doc::tile_f_yflip: 0) |
(dflip()->isSelected() ? doc::tile_f_dflip: 0);
}
return info;
}
void TilesetSelector::saveAdvancedPreferences()
{
Preferences& pref = Preferences::instance();
pref.tileset.advanced(advanced()->isSelected());
}
int TilesetSelector::getSelectedItemIndex()
{
int index = tilesets()->getSelectedItemIndex();

View File

@ -47,17 +47,22 @@ namespace app {
// Returns the data of this widget according to the user input
Info getInfo();
void saveAdvancedPreferences();
private:
void fillControls(const std::string& name,
const gfx::Size& gridSize,
const int baseIndex,
const doc::tile_flags matchFlags);
void updateControlsState(const doc::Tilesets* spriteTilesets);
void updateControlsState();
void updateControlsVisibility();
// Returns the selected item index as if the combobox always has the "New Tileset"
// as its first item.
int getSelectedItemIndex();
const doc::Sprite* m_sprite;
// Holds the information used to create this widget
const TilesetSelector::Info m_info;
};

View File

@ -1,5 +1,5 @@
// Aseprite Code Generator
// Copyright (c) 2021 Igara Studio S.A.
// Copyright (c) 2021-2023 Igara Studio S.A.
// Copyright (c) 2014-2018 David Capello
//
// This file is released under the terms of the MIT license.
@ -82,6 +82,9 @@ static Item convert_to_item(TiXmlElement* elem)
if (name == "box")
return item.typeIncl("ui::Box",
"ui/box.h");
if (name == "boxfiller")
return item.typeIncl("ui::Box",
"ui/box.h");
if (name == "button")
return item.typeIncl("ui::Button",
"ui/button.h");