Skip to content

Commit

Permalink
fix: sonar cloud issues
Browse files Browse the repository at this point in the history
  • Loading branch information
phacUFPE committed Jun 18, 2024
1 parent 0ac53a3 commit 3d324b9
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 45 deletions.
14 changes: 7 additions & 7 deletions source/palette_brushlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,13 @@ bool BrushPalettePanel::SelectBrush(const Brush* whatBrush) {
}

if (panel->SelectBrush(whatBrush)) {
for (const auto &palettePanel : tool_bars) {
for (const auto palettePanel : tool_bars) {
palettePanel->SelectBrush(nullptr);
}
return true;
}

for (const auto &palettePanel : tool_bars) {
for (const auto palettePanel : tool_bars) {
if (palettePanel->SelectBrush(whatBrush)) {
panel->SelectBrush(nullptr);
return true;
Expand All @@ -181,7 +181,7 @@ bool BrushPalettePanel::SelectBrush(const Brush* whatBrush) {
panel = dynamic_cast<BrushPanel*>(choicebook->GetPage(pageIndex));
if (panel && panel->SelectBrush(whatBrush)) {
choicebook->ChangeSelection(pageIndex);
for (const auto &palettePanel : tool_bars) {
for (const auto palettePanel : tool_bars) {
palettePanel->SelectBrush(nullptr);
}
return true;
Expand Down Expand Up @@ -357,7 +357,7 @@ bool BrushPanel::SelectBrush(const Brush* whatBrush) {
return brushbox->SelectBrush(whatBrush);
}

for (const auto &brush : tileset->brushlist) {
for (const auto brush : tileset->brushlist) {
if (brush == whatBrush) {
LoadContents();
return brushbox->SelectBrush(whatBrush);
Expand All @@ -380,7 +380,7 @@ void BrushPanel::OnClickListBoxRow(wxCommandEvent &event) {
ASSERT(brushbox);
const auto index = event.GetSelection();

if (const auto &paletteWindow = g_gui.GetParentWindowByType<PaletteWindow*>(this); paletteWindow != nullptr) {
if (const auto paletteWindow = g_gui.GetParentWindowByType<PaletteWindow*>(this); paletteWindow != nullptr) {
g_gui.ActivatePalette(paletteWindow);
}

Expand Down Expand Up @@ -410,7 +410,7 @@ BrushIconBox::BrushIconBox(wxWindow* parent, const TilesetCategory* tileset, Ren

auto rowsizer = newd wxBoxSizer(wxHORIZONTAL);

for (const auto &brush : tileset->brushlist) {
for (const auto brush : tileset->brushlist) {
const auto brushButton = newd BrushButton(this, brush, rsz);
rowsizer->Add(brushButton);
brushButtons.emplace_back(brushButton);
Expand Down Expand Up @@ -448,7 +448,7 @@ bool BrushIconBox::SelectBrush(const Brush* whatBrush) {
return false;
}

const auto &it = std::ranges::find_if(brushButtons.begin(), brushButtons.end(), [&](const auto &brushButton) {
const auto it = std::ranges::find_if(brushButtons.begin(), brushButtons.end(), [&](const auto brushButton) {
return brushButton->brush == whatBrush;
});

Expand Down
8 changes: 4 additions & 4 deletions source/palette_brushlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class BrushBoxInterface {
class BrushListBox : public wxVListBox, public BrushBoxInterface {
public:
BrushListBox(wxWindow* parent, const TilesetCategory* tileset);
~BrushListBox() = default;
~BrushListBox() final = default;

wxWindow* GetSelfWindow() {
return this;
Expand Down Expand Up @@ -129,7 +129,7 @@ class BrushIconBox : public wxScrolledWindow, public BrushBoxInterface {
class BrushPanel : public wxPanel {
public:
BrushPanel(wxWindow* parent, const TilesetCategory* tileset);
~BrushPanel() = default;
~BrushPanel() final = default;

// Interface
// Flushes this panel and consequent views will feature reloaded data
Expand Down Expand Up @@ -171,7 +171,7 @@ class BrushPanel : public wxPanel {
class BrushPalettePanel : public PalettePanel {
public:
BrushPalettePanel(wxWindow* parent, const TilesetContainer &tilesets, TilesetCategoryType category, wxWindowID id = wxID_ANY);
~BrushPalettePanel() = default;
~BrushPalettePanel() final = default;

void AddTilesetEditor(wxSizer* sizer);

Expand All @@ -194,7 +194,7 @@ class BrushPalettePanel : public PalettePanel {
// Returns the currently selected brush (first brush if panel is not loaded)
Brush* GetSelectedBrush() const;
// Select the brush in the parameter, this only changes the look of the panel
bool SelectBrush(const Brush* whatBrush);
bool SelectBrush(const Brush* whatBrush) override;

// Called when this page is displayed
void OnSwitchIn();
Expand Down
72 changes: 39 additions & 33 deletions source/palette_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,22 @@ PalettePanel* PaletteWindow::CreateRAWPalette(wxWindow* parent, const TilesetCon
return panel;
}

bool PaletteWindow::CanSelectHouseBrush(PalettePanel* palette, const Brush* whatBrush) {
if (!palette || !whatBrush->isHouse()) {
return false;
}

return true;
}

bool PaletteWindow::CanSelectBrush(PalettePanel* palette, const Brush* whatBrush) {
if (!palette) {
return false;
}

return palette->SelectBrush(whatBrush);
}

void PaletteWindow::ReloadSettings(Map* map) {
if (terrainPalette) {
terrainPalette->SetListType(wxstr(g_settings.getString(Config::PALETTE_TERRAIN_STYLE)));
Expand Down Expand Up @@ -197,7 +213,7 @@ void PaletteWindow::ReloadSettings(Map* map) {
InvalidateContents();
}

void PaletteWindow::LoadCurrentContents() {
void PaletteWindow::LoadCurrentContents() const {
if (!choicebook) {
return;
}
Expand Down Expand Up @@ -312,7 +328,7 @@ bool PaletteWindow::OnSelectBrush(const Brush* whatBrush, PaletteType primary) {
return false;
}

if (whatBrush->isHouse() && housePalette) {
if (CanSelectHouseBrush(housePalette, whatBrush)) {
housePalette->SelectBrush(whatBrush);
SelectPage(TILESET_HOUSE);
return true;
Expand All @@ -325,35 +341,35 @@ bool PaletteWindow::OnSelectBrush(const Brush* whatBrush, PaletteType primary) {
}
case TILESET_DOODAD: {
// Ok, search doodad before terrain
if (doodadPalette && doodadPalette->SelectBrush(whatBrush)) {
if (CanSelectBrush(doodadPalette, whatBrush)) {
SelectPage(TILESET_DOODAD);
return true;
}
break;
}
case TILESET_ITEM: {
if (itemPalette && itemPalette->SelectBrush(whatBrush)) {
if (CanSelectBrush(itemPalette, whatBrush)) {
SelectPage(TILESET_ITEM);
return true;
}
break;
}
case TILESET_MONSTER: {
if (monsterPalette && monsterPalette->SelectBrush(whatBrush)) {
if (CanSelectBrush(monsterPalette, whatBrush)) {
SelectPage(TILESET_MONSTER);
return true;
}
break;
}
case TILESET_NPC: {
if (npcPalette && npcPalette->SelectBrush(whatBrush)) {
if (CanSelectBrush(npcPalette, whatBrush)) {
SelectPage(TILESET_NPC);
return true;
}
break;
}
case TILESET_RAW: {
if (rawPalette && rawPalette->SelectBrush(whatBrush)) {
if (CanSelectBrush(rawPalette, whatBrush)) {
SelectPage(TILESET_RAW);
return true;
}
Expand All @@ -364,49 +380,39 @@ bool PaletteWindow::OnSelectBrush(const Brush* whatBrush, PaletteType primary) {
}

// Test if it's a terrain brush
if (terrainPalette && terrainPalette->SelectBrush(whatBrush)) {
if (CanSelectBrush(terrainPalette, whatBrush)) {
SelectPage(TILESET_TERRAIN);
return true;
}

// Test if it's a doodad brush
if (primary != TILESET_DOODAD) {
if (doodadPalette && doodadPalette->SelectBrush(whatBrush)) {
SelectPage(TILESET_DOODAD);
return true;
}
if (primary != TILESET_DOODAD && CanSelectBrush(doodadPalette, whatBrush)) {
SelectPage(TILESET_DOODAD);
return true;
}

// Test if it's an item brush
if (primary != TILESET_ITEM) {
if (itemPalette && itemPalette->SelectBrush(whatBrush)) {
SelectPage(TILESET_ITEM);
return true;
}
if (primary != TILESET_ITEM && CanSelectBrush(itemPalette, whatBrush)) {
SelectPage(TILESET_ITEM);
return true;
}

// Test if it's a monster brush
if (primary != TILESET_MONSTER) {
if (monsterPalette && monsterPalette->SelectBrush(whatBrush)) {
SelectPage(TILESET_MONSTER);
return true;
}
if (primary != TILESET_MONSTER && CanSelectBrush(monsterPalette, whatBrush)) {
SelectPage(TILESET_MONSTER);
return true;
}

// Test if it's a npc brush
if (primary != TILESET_NPC) {
if (npcPalette && npcPalette->SelectBrush(whatBrush)) {
SelectPage(TILESET_NPC);
return true;
}
if (primary != TILESET_NPC && CanSelectBrush(npcPalette, whatBrush)) {
SelectPage(TILESET_NPC);
return true;
}

// Test if it's a raw brush
if (primary != TILESET_RAW) {
if (rawPalette && rawPalette->SelectBrush(whatBrush)) {
SelectPage(TILESET_RAW);
return true;
}
if (primary != TILESET_RAW && CanSelectBrush(rawPalette, whatBrush)) {
SelectPage(TILESET_RAW);
return true;
}

return false;
Expand Down
5 changes: 4 additions & 1 deletion source/palette_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class PaletteWindow : public wxPanel {
// Flushes all pages and forces them to be reloaded from the palette data again
void InvalidateContents();
// (Re)Loads all currently displayed data, called from InvalidateContents implicitly
void LoadCurrentContents();
void LoadCurrentContents() const;
// Goes to the selected page and selects any brush there
void SelectPage(PaletteType palette);
// The currently selected brush in this palette
Expand Down Expand Up @@ -78,6 +78,9 @@ class PaletteWindow : public wxPanel {
static PalettePanel* CreateZonesPalette(wxWindow* parent, const TilesetContainer &tilesets);
static PalettePanel* CreateRAWPalette(wxWindow* parent, const TilesetContainer &tilesets);

static bool CanSelectHouseBrush(PalettePanel* palette, const Brush* whatBrush);
static bool CanSelectBrush(PalettePanel* palette, const Brush* whatBrush);

wxChoicebook* choicebook = newd wxChoicebook(this, PALETTE_CHOICEBOOK, wxDefaultPosition, wxSize(230, 250));

BrushPalettePanel* terrainPalette = nullptr;
Expand Down

0 comments on commit 3d324b9

Please sign in to comment.