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"> <section id="tileset">
<option id="base_index" type="int" default="1" /> <option id="base_index" type="int" default="1" />
<option id="cache_compressed_tilesets" type="bool" default="true" /> <option id="cache_compressed_tilesets" type="bool" default="true" />
<option id="advanced" type="bool" default="false" />
</section> </section>
<section id="tilemap"> <section id="tilemap">
<option id="show_delete_unused_tileset_alert" type="bool" default="true" /> <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. as index 1 (by default, one-based index) or other value.
E.g. you can use 0 here for zero-based indexing. E.g. you can use 0 here for zero-based indexing.
END END
allow_flipped_tiles = Allow Flipped Tiles: allowed_flips = Allowed Flips:
allow_flipped_tiles_tooltip = <<<END allowed_flips_tooltip = <<<END
Aseprite can reuse tiles matching automatically with their flipped Aseprite can reuse tiles matching automatically with their flipped
versions (in X, Y, or Diagonal axes) in Auto/Stack modes. versions (in X, Y, or Diagonal axes) in Auto/Stack modes.
END END

View File

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

View File

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

View File

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

View File

@ -11,6 +11,7 @@
#include "app/ui/tileset_selector.h" #include "app/ui/tileset_selector.h"
#include "app/i18n/strings.h" #include "app/i18n/strings.h"
#include "app/pref/preferences.h"
#include "doc/sprite.h" #include "doc/sprite.h"
#include "doc/tilesets.h" #include "doc/tilesets.h"
#include "fmt/format.h" #include "fmt/format.h"
@ -22,7 +23,9 @@ namespace app {
using namespace ui; using namespace ui;
TilesetSelector::TilesetSelector(const doc::Sprite* sprite, TilesetSelector::TilesetSelector(const doc::Sprite* sprite,
const TilesetSelector::Info& info) : m_info(info) const TilesetSelector::Info& info)
: m_sprite(sprite)
, m_info(info)
{ {
initTheme(); initTheme();
@ -55,12 +58,22 @@ TilesetSelector::TilesetSelector(const doc::Sprite* sprite,
} }
if (m_info.enabled) { if (m_info.enabled) {
tilesets()->Change.connect( tilesets()->Change.connect([this]() {
[this, sprite]() { updateControlsState();
updateControlsState(sprite->tilesets());
}); });
} }
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, 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); 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) { if (m_info.enabled) {
const int index = getSelectedItemIndex(); const int index = getSelectedItemIndex();
const bool isNewTileset = (index == 0); 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() TilesetSelector::Info TilesetSelector::getInfo()
{ {
int itemIndex = getSelectedItemIndex(); int itemIndex = getSelectedItemIndex();
@ -126,15 +152,34 @@ TilesetSelector::Info TilesetSelector::getInfo()
info.tsi = itemIndex-1; info.tsi = itemIndex-1;
} }
info.name = name()->text(); info.name = name()->text();
// 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.baseIndex = baseIndex()->textInt();
info.matchFlags = info.matchFlags =
(xflip()->isSelected() ? doc::tile_f_xflip: 0) | (xflip()->isSelected() ? doc::tile_f_xflip: 0) |
(yflip()->isSelected() ? doc::tile_f_yflip: 0) | (yflip()->isSelected() ? doc::tile_f_yflip: 0) |
(dflip()->isSelected() ? doc::tile_f_dflip: 0); (dflip()->isSelected() ? doc::tile_f_dflip: 0);
}
return info; return info;
} }
void TilesetSelector::saveAdvancedPreferences()
{
Preferences& pref = Preferences::instance();
pref.tileset.advanced(advanced()->isSelected());
}
int TilesetSelector::getSelectedItemIndex() int TilesetSelector::getSelectedItemIndex()
{ {
int index = tilesets()->getSelectedItemIndex(); int index = tilesets()->getSelectedItemIndex();

View File

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

View File

@ -1,5 +1,5 @@
// Aseprite Code Generator // Aseprite Code Generator
// Copyright (c) 2021 Igara Studio S.A. // Copyright (c) 2021-2023 Igara Studio S.A.
// Copyright (c) 2014-2018 David Capello // Copyright (c) 2014-2018 David Capello
// //
// This file is released under the terms of the MIT license. // 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") if (name == "box")
return item.typeIncl("ui::Box", return item.typeIncl("ui::Box",
"ui/box.h"); "ui/box.h");
if (name == "boxfiller")
return item.typeIncl("ui::Box",
"ui/box.h");
if (name == "button") if (name == "button")
return item.typeIncl("ui::Button", return item.typeIncl("ui::Button",
"ui/button.h"); "ui/button.h");