[nostalgia/core/studio] Add palette picker combo box

This commit is contained in:
2022-03-24 20:54:17 -05:00
parent ef3a28846c
commit 6eb4070d97
5 changed files with 82 additions and 7 deletions

View File

@@ -12,9 +12,22 @@
namespace nostalgia::core {
TileSheetEditorImGui::TileSheetEditorImGui(Context *ctx, const ox::String &path): m_tileSheetEditor(ctx, path) {
m_ctx = ctx;
m_itemPath = path;
const auto lastSlash = std::find(m_itemPath.rbegin(), m_itemPath.rend(), '/').offset();
m_itemName = m_itemPath.substr(lastSlash + 1);
// init palette idx
const auto palPath = model()->palPath();
auto sctx = applicationData<studio::StudioContext>(m_ctx);
const auto &palList = sctx->project->fileList(core::FileExt_npal + 1);
for (std::size_t i = 0; const auto &pal : palList) {
if (palPath == pal) {
m_selectedPaletteIdx = i;
break;
}
++i;
}
// connect signal/slots
undoStack()->changeTriggered.connect(this, &TileSheetEditorImGui::markUnsavedChanges);
m_subsheetEditor.inputSubmitted.connect(this, &TileSheetEditorImGui::updateActiveSubsheet);
}
@@ -76,7 +89,7 @@ void TileSheetEditorImGui::draw(core::Context*) noexcept {
// draw palette/color picker
ImGui::BeginChild("Palette", ImVec2(m_palViewWidth - 24, ySize / 2.07f), true);
{
drawPalettePicker();
drawPaletteSelector();
}
ImGui::EndChild();
ImGui::BeginChild("SubSheets", ImVec2(m_palViewWidth - 24, ySize / 2.07f), true);
@@ -200,7 +213,7 @@ void TileSheetEditorImGui::drawTileSheet(const geo::Vec2 &fbSize) noexcept {
const auto wheel = io.MouseWheel;
const auto wheelh = io.MouseWheelH;
if (wheel != 0) {
const auto zoomMod = ox::defines::OS == ox::OS::Darwin ? io.KeySuper : io.KeyCtrl;
const auto zoomMod = ox::defines::OS == ox::OS::Darwin ? io.KeySuper : core::buttonDown(m_ctx, core::Key::Mod_Ctrl);
m_tileSheetEditor.scrollV(fbSize, wheel, zoomMod);
}
if (wheelh != 0) {
@@ -233,7 +246,23 @@ void TileSheetEditorImGui::drawTileSheet(const geo::Vec2 &fbSize) noexcept {
}
}
void TileSheetEditorImGui::drawPalettePicker() noexcept {
void TileSheetEditorImGui::drawPaletteSelector() noexcept {
auto sctx = applicationData<studio::StudioContext>(m_ctx);
const auto &files = sctx->project->fileList(core::FileExt_npal + 1);
const auto first = m_selectedPaletteIdx < files.size() ? files[m_selectedPaletteIdx].c_str() : "";
if (ImGui::BeginCombo("Palette", first, 0)) {
for (auto n = 0u; n < files.size(); n++) {
const auto selected = (m_selectedPaletteIdx == n);
if (ImGui::Selectable(files[n].c_str(), selected) && m_selectedPaletteIdx != n) {
m_selectedPaletteIdx = n;
oxLogError(model()->setPalette(files[n]));
}
if (selected) {
ImGui::SetItemDefaultFocus();
}
}
ImGui::EndCombo();
}
// header
if (ImGui::BeginTable("PaletteTable", 3, ImGuiTableFlags_RowBg | ImGuiTableFlags_SizingStretchProp)) {
ImGui::TableSetupColumn("No.", 0, 0.45);