mirror of
https://github.com/aseprite/aseprite.git
synced 2025-04-18 02:42:59 +00:00
Show, duplicate and delete tilesets in Sprite Properties dialog (fix #3875)
This commit is contained in:
parent
a2d8a080f5
commit
4926f4c1fc
@ -62,6 +62,12 @@ Automatic Remap
|
|||||||
||&OK||&Cancel"
|
||&OK||&Cancel"
|
||||||
END
|
END
|
||||||
cannot_delete_all_layers = Error<<You cannot delete all layers.||&OK
|
cannot_delete_all_layers = Error<<You cannot delete all layers.||&OK
|
||||||
|
cannot_delete_used_tileset = <<<END
|
||||||
|
Error
|
||||||
|
<<Cannot delete tileset used by the following tilemaps:
|
||||||
|
<<'{0}'
|
||||||
|
||&OK
|
||||||
|
END
|
||||||
deleting_tilemaps_will_delete_tilesets = <<<END
|
deleting_tilemaps_will_delete_tilesets = <<<END
|
||||||
Warning
|
Warning
|
||||||
<<Deleting the following layers will delete their tilesets:
|
<<Deleting the following layers will delete their tilesets:
|
||||||
@ -606,6 +612,8 @@ TilesetMode = Tileset Mode: {}
|
|||||||
TilesetMode_Manual = Manual
|
TilesetMode_Manual = Manual
|
||||||
TilesetMode_Auto = Auto
|
TilesetMode_Auto = Auto
|
||||||
TilesetMode_Stack = Stack
|
TilesetMode_Stack = Stack
|
||||||
|
TilesetDelete = Delete Tileset
|
||||||
|
TilesetDuplicate = Duplicate Tileset
|
||||||
Undo = Undo
|
Undo = Undo
|
||||||
UndoHistory = Undo History
|
UndoHistory = Undo History
|
||||||
UnlinkCel = Unlink Cel
|
UnlinkCel = Unlink Cel
|
||||||
@ -1966,6 +1974,9 @@ indexed_image_only = (only for indexed images)
|
|||||||
assign_color_profile = Assign Color Profile
|
assign_color_profile = Assign Color Profile
|
||||||
convert_color_profile = Convert Color Profile
|
convert_color_profile = Convert Color Profile
|
||||||
change_sprite_props = Change Sprite Properties
|
change_sprite_props = Change Sprite Properties
|
||||||
|
tilesets = Tilesets
|
||||||
|
delete_tileset = Delete
|
||||||
|
duplicate_tileset = Duplicate
|
||||||
|
|
||||||
[sprite_size]
|
[sprite_size]
|
||||||
title = Sprite Size
|
title = Sprite Size
|
||||||
|
@ -43,6 +43,14 @@
|
|||||||
</hbox>
|
</hbox>
|
||||||
</hbox>
|
</hbox>
|
||||||
</grid>
|
</grid>
|
||||||
|
|
||||||
|
<vbox expansive="true" id="tilesets_placeholder">
|
||||||
|
<separator text="@.tilesets" horizontal="true" />
|
||||||
|
<view id="tilesets_view" expansive="true">
|
||||||
|
<listbox id="tilesets"></listbox>
|
||||||
|
</view>
|
||||||
|
</vbox>
|
||||||
|
|
||||||
<separator horizontal="true" />
|
<separator horizontal="true" />
|
||||||
<hbox>
|
<hbox>
|
||||||
<boxfiller />
|
<boxfiller />
|
||||||
|
@ -694,6 +694,7 @@ add_library(app-lib
|
|||||||
util/range_utils.cpp
|
util/range_utils.cpp
|
||||||
util/readable_time.cpp
|
util/readable_time.cpp
|
||||||
util/resize_image.cpp
|
util/resize_image.cpp
|
||||||
|
util/tileset_utils.cpp
|
||||||
util/wrap_point.cpp
|
util/wrap_point.cpp
|
||||||
xml_document.cpp
|
xml_document.cpp
|
||||||
xml_exception.cpp
|
xml_exception.cpp
|
||||||
|
@ -11,6 +11,8 @@
|
|||||||
|
|
||||||
#include "app/cmd/assign_color_profile.h"
|
#include "app/cmd/assign_color_profile.h"
|
||||||
#include "app/cmd/convert_color_profile.h"
|
#include "app/cmd/convert_color_profile.h"
|
||||||
|
#include "app/cmd/add_tileset.h"
|
||||||
|
#include "app/cmd/remove_tileset.h"
|
||||||
#include "app/cmd/set_pixel_ratio.h"
|
#include "app/cmd/set_pixel_ratio.h"
|
||||||
#include "app/cmd/set_user_data.h"
|
#include "app/cmd/set_user_data.h"
|
||||||
#include "app/color.h"
|
#include "app/color.h"
|
||||||
@ -20,15 +22,18 @@
|
|||||||
#include "app/i18n/strings.h"
|
#include "app/i18n/strings.h"
|
||||||
#include "app/modules/gui.h"
|
#include "app/modules/gui.h"
|
||||||
#include "app/pref/preferences.h"
|
#include "app/pref/preferences.h"
|
||||||
|
#include "app/util/tileset_utils.h"
|
||||||
#include "app/tx.h"
|
#include "app/tx.h"
|
||||||
#include "app/ui/color_button.h"
|
#include "app/ui/color_button.h"
|
||||||
#include "app/ui/user_data_view.h"
|
#include "app/ui/user_data_view.h"
|
||||||
|
#include "app/ui/skin/skin_theme.h"
|
||||||
#include "app/util/pixel_ratio.h"
|
#include "app/util/pixel_ratio.h"
|
||||||
#include "base/mem_utils.h"
|
#include "base/mem_utils.h"
|
||||||
#include "doc/image.h"
|
#include "doc/image.h"
|
||||||
#include "doc/palette.h"
|
#include "doc/palette.h"
|
||||||
#include "doc/sprite.h"
|
#include "doc/sprite.h"
|
||||||
#include "doc/user_data.h"
|
#include "doc/user_data.h"
|
||||||
|
#include "doc/tilesets.h"
|
||||||
#include "fmt/format.h"
|
#include "fmt/format.h"
|
||||||
#include "os/color_space.h"
|
#include "os/color_space.h"
|
||||||
#include "os/system.h"
|
#include "os/system.h"
|
||||||
@ -40,6 +45,92 @@ namespace app {
|
|||||||
|
|
||||||
using namespace ui;
|
using namespace ui;
|
||||||
|
|
||||||
|
class TilesetListItem : public ui::ListItem {
|
||||||
|
public:
|
||||||
|
TilesetListItem(const doc::Tileset* tileset, doc::tileset_index tsi)
|
||||||
|
: ListItem(app::tileset_label(tileset, tsi))
|
||||||
|
{
|
||||||
|
m_buttons.setTransparent(true);
|
||||||
|
m_buttons.setExpansive(true);
|
||||||
|
m_buttons.setVisible(false);
|
||||||
|
|
||||||
|
auto filler = new BoxFiller();
|
||||||
|
filler->setTransparent(true);
|
||||||
|
m_buttons.addChild(filler);
|
||||||
|
|
||||||
|
auto theme = skin::SkinTheme::get(this);
|
||||||
|
auto duplicateBtn = new Button(Strings::sprite_properties_duplicate_tileset());
|
||||||
|
duplicateBtn->setStyle(theme->styles.miniButton());
|
||||||
|
duplicateBtn->setTransparent(true);
|
||||||
|
duplicateBtn->Click.connect([this, tileset]{ onDuplicate(tileset); });
|
||||||
|
m_buttons.addChild(duplicateBtn);
|
||||||
|
|
||||||
|
auto deleteBtn = new Button(Strings::sprite_properties_delete_tileset());
|
||||||
|
deleteBtn->setStyle(theme->styles.miniButton());
|
||||||
|
deleteBtn->setTransparent(true);
|
||||||
|
deleteBtn->Click.connect([this, tileset]{ onDelete(tileset); });
|
||||||
|
m_buttons.addChild(deleteBtn);
|
||||||
|
|
||||||
|
addChild(&m_buttons);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool onProcessMessage(Message* msg) override
|
||||||
|
{
|
||||||
|
switch (msg->type()) {
|
||||||
|
case kMouseLeaveMessage:
|
||||||
|
m_buttons.setVisible(false);
|
||||||
|
invalidate();
|
||||||
|
break;
|
||||||
|
case kMouseEnterMessage:
|
||||||
|
m_buttons.setVisible(true);
|
||||||
|
invalidate();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ui::ListItem::onProcessMessage(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
obs::signal<void(TilesetListItem *)> TilesetDeleted;
|
||||||
|
obs::signal<void(const Tileset*)> TilesetDuplicated;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void onDuplicate(const doc::Tileset* tileset)
|
||||||
|
{
|
||||||
|
auto tilesetClone = Tileset::MakeCopyCopyingImages(tileset);
|
||||||
|
|
||||||
|
Tx tx(fmt::format(Strings::commands_TilesetDuplicate()));
|
||||||
|
tx(new cmd::AddTileset(tileset->sprite(), tilesetClone));
|
||||||
|
tx.commit();
|
||||||
|
|
||||||
|
TilesetDuplicated(tilesetClone);
|
||||||
|
}
|
||||||
|
|
||||||
|
void onDelete(const doc::Tileset* tileset)
|
||||||
|
{
|
||||||
|
doc::tileset_index tsi = tileset->sprite()->tilesets()->getIndex(tileset);
|
||||||
|
std::string tilemapsNames;
|
||||||
|
for (auto layer : tileset->sprite()->allTilemaps()) {
|
||||||
|
auto tilemap = static_cast<doc::LayerTilemap*>(layer);
|
||||||
|
if (tilemap->tilesetIndex() == tsi) {
|
||||||
|
tilemapsNames += tilemap->name() + ", ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!tilemapsNames.empty()) {
|
||||||
|
tilemapsNames = tilemapsNames.substr(0, tilemapsNames.size()-2);
|
||||||
|
ui::Alert::show(fmt::format(Strings::alerts_cannot_delete_used_tileset(), tilemapsNames));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Tx tx(fmt::format(Strings::commands_TilesetDelete()));
|
||||||
|
tx(new cmd::RemoveTileset(tileset->sprite(), tsi));
|
||||||
|
tx.commit();
|
||||||
|
|
||||||
|
TilesetDeleted(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
ui::HBox m_buttons;
|
||||||
|
};
|
||||||
|
|
||||||
class SpritePropertiesWindow : public app::gen::SpriteProperties {
|
class SpritePropertiesWindow : public app::gen::SpriteProperties {
|
||||||
public:
|
public:
|
||||||
SpritePropertiesWindow(Sprite* sprite)
|
SpritePropertiesWindow(Sprite* sprite)
|
||||||
@ -52,21 +143,75 @@ public:
|
|||||||
m_userDataView.configureAndSet(m_sprite->userData(),
|
m_userDataView.configureAndSet(m_sprite->userData(),
|
||||||
propertiesGrid());
|
propertiesGrid());
|
||||||
|
|
||||||
remapWindow();
|
if (sprite->tilesets()->size() == 0) {
|
||||||
centerWindow();
|
tilesetsPlaceholder()->parent()->removeChild(tilesetsPlaceholder());
|
||||||
load_window_pos(this, "SpriteProperties");
|
}
|
||||||
manager()->invalidate();
|
else {
|
||||||
|
for (int i = 0; i < sprite->tilesets()->size(); ++i) {
|
||||||
|
auto tileset = (*sprite->tilesets()).get(i);
|
||||||
|
addTilesetListItem(tileset, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
Open.connect([this]{ adjustSize(); });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const UserData& getUserData() const { return m_userDataView.userData(); }
|
const UserData& getUserData() const { return m_userDataView.userData(); }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void onSizeHint(SizeHintEvent& ev) override {
|
||||||
|
app::gen::SpriteProperties::onSizeHint(ev);
|
||||||
|
auto sz = ev.sizeHint();
|
||||||
|
sz.h += getTilesetsViewHeight();
|
||||||
|
ev.setSizeHint(sz);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
int getTilesetsViewHeight() {
|
||||||
|
auto sz = tilesetsView()->viewport()->calculateNeededSize();
|
||||||
|
return std::min(72, sz.h);
|
||||||
|
}
|
||||||
|
|
||||||
|
void addTilesetListItem(const doc::Tileset* tileset, doc::tileset_index tsi) {
|
||||||
|
auto item = new TilesetListItem(tileset, tsi);
|
||||||
|
item->TilesetDeleted.connect(&SpritePropertiesWindow::onTilesetDeleted, this);
|
||||||
|
item->TilesetDuplicated.connect(&SpritePropertiesWindow::onTilesedDuplicated, this);
|
||||||
|
tilesets()->addChild(item);
|
||||||
|
}
|
||||||
|
|
||||||
void onToggleUserData() {
|
void onToggleUserData() {
|
||||||
m_userDataView.toggleVisibility();
|
m_userDataView.toggleVisibility();
|
||||||
remapWindow();
|
remapWindow();
|
||||||
manager()->invalidate();
|
manager()->invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void onTilesedDuplicated(const Tileset* tilesetClone) {
|
||||||
|
addTilesetListItem(tilesetClone, tilesets()->children().size());
|
||||||
|
layout();
|
||||||
|
}
|
||||||
|
|
||||||
|
void onTilesetDeleted(TilesetListItem *item) {
|
||||||
|
int i = tilesets()->getChildIndex(item);
|
||||||
|
tilesets()->removeChild(item);
|
||||||
|
// Update text for items below the removed one, because tileset indexes
|
||||||
|
// have changed.
|
||||||
|
for (;i < tilesets()->children().size(); ++i) {
|
||||||
|
auto it = tilesets()->children()[i];
|
||||||
|
it->setText(app::tileset_label(m_sprite->tilesets()->get(i), i));
|
||||||
|
}
|
||||||
|
layout();
|
||||||
|
}
|
||||||
|
|
||||||
|
void adjustSize() {
|
||||||
|
// If the tilesets view is too small, lets inflate the windows height a bit.
|
||||||
|
if (tilesetsView()->childrenBounds().h < 36) {
|
||||||
|
auto bounds = this->bounds();
|
||||||
|
bounds.inflate(0, getTilesetsViewHeight() - tilesetsView()->clientBounds().h);
|
||||||
|
setBounds(bounds);
|
||||||
|
remapWindow();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Sprite* m_sprite;
|
Sprite* m_sprite;
|
||||||
UserDataView m_userDataView;
|
UserDataView m_userDataView;
|
||||||
};
|
};
|
||||||
|
45
src/app/util/tileset_utils.cpp
Normal file
45
src/app/util/tileset_utils.cpp
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
// Aseprite
|
||||||
|
// Copyright (C) 2023 Igara Studio S.A.
|
||||||
|
//
|
||||||
|
// This program is distributed under the terms of
|
||||||
|
// the End-User License Agreement for Aseprite.
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "doc/layer_tilemap.h"
|
||||||
|
#include "doc/sprite.h"
|
||||||
|
#include "tileset_utils.h"
|
||||||
|
|
||||||
|
#include <fmt/format.h>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace app {
|
||||||
|
|
||||||
|
std::string tileset_label(const doc::Tileset* tileset, doc::tileset_index tsi)
|
||||||
|
{
|
||||||
|
std::string tilemapsNames;
|
||||||
|
for (auto layer : tileset->sprite()->allTilemaps()) {
|
||||||
|
auto tilemap = static_cast<doc::LayerTilemap*>(layer);
|
||||||
|
if (tilemap->tilesetIndex() == tsi) {
|
||||||
|
tilemapsNames += tilemap->name() + ", ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!tilemapsNames.empty()) {
|
||||||
|
tilemapsNames = tilemapsNames.substr(0, tilemapsNames.size()-2);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string name = tileset->name();
|
||||||
|
if (!tilemapsNames.empty()) {
|
||||||
|
name += " (" + tilemapsNames + ")";
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt::format("#{0} ({1}x{2}): {3}",
|
||||||
|
tsi,
|
||||||
|
tileset->grid().tileSize().w,
|
||||||
|
tileset->grid().tileSize().h,
|
||||||
|
name);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace app
|
23
src/app/util/tileset_utils.h
Normal file
23
src/app/util/tileset_utils.h
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
// Aseprite
|
||||||
|
// Copyright (C) 2023 Igara Studio S.A.
|
||||||
|
//
|
||||||
|
// This program is distributed under the terms of
|
||||||
|
// the End-User License Agreement for Aseprite.
|
||||||
|
|
||||||
|
#ifndef APP_TILESET_UTILS_H_INCLUDED
|
||||||
|
#define APP_TILESET_UTILS_H_INCLUDED
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "doc/tileset.h"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace app {
|
||||||
|
|
||||||
|
// Builds a string representation of a tileset for using in
|
||||||
|
// labels in the UI.
|
||||||
|
std::string tileset_label(const doc::Tileset* tileset, doc::tileset_index index);
|
||||||
|
|
||||||
|
} // namespace app
|
||||||
|
|
||||||
|
#endif
|
@ -33,6 +33,7 @@ namespace doc {
|
|||||||
const UserData& data) : image(image), data(data) { }
|
const UserData& data) : image(image), data(data) { }
|
||||||
};
|
};
|
||||||
static UserData kNoUserData;
|
static UserData kNoUserData;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
typedef std::vector<Tile> Tiles;
|
typedef std::vector<Tile> Tiles;
|
||||||
typedef Tiles::iterator iterator;
|
typedef Tiles::iterator iterator;
|
||||||
|
@ -249,9 +249,11 @@ bool ListBox::onProcessMessage(Message* msg)
|
|||||||
if (dynamic_cast<ui::Separator*>(picked))
|
if (dynamic_cast<ui::Separator*>(picked))
|
||||||
picked = nullptr;
|
picked = nullptr;
|
||||||
|
|
||||||
// If the picked widget is a child of the list, select it
|
// If the picked widget has this list as an ancestor, select the item containing it.
|
||||||
if (picked && hasChild(picked))
|
if (picked && picked->hasAncestor(this)) {
|
||||||
selectChild(picked, msg);
|
ListItem *it = findParentListItem(picked);
|
||||||
|
selectChild(it, msg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -463,4 +465,16 @@ int ListBox::advanceIndexThroughVisibleItems(
|
|||||||
return lastVisibleIndex;
|
return lastVisibleIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ListItem* ListBox::findParentListItem(Widget* descendant)
|
||||||
|
{
|
||||||
|
if (descendant->parent() == this)
|
||||||
|
return static_cast<ListItem*>(descendant);
|
||||||
|
|
||||||
|
for (Widget* widget=descendant->parent(); widget; widget=widget->parent()) {
|
||||||
|
return findParentListItem(widget);
|
||||||
|
}
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace ui
|
} // namespace ui
|
||||||
|
@ -66,6 +66,10 @@ namespace ui {
|
|||||||
// items in case that the user is Ctrl+clicking items several
|
// items in case that the user is Ctrl+clicking items several
|
||||||
// items at the same time.
|
// items at the same time.
|
||||||
std::vector<bool> m_states;
|
std::vector<bool> m_states;
|
||||||
|
|
||||||
|
private:
|
||||||
|
// Finds the parent ListItem that contains the specified descendant.
|
||||||
|
ListItem* findParentListItem(Widget* descendant);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ui
|
} // namespace ui
|
||||||
|
Loading…
x
Reference in New Issue
Block a user