Skip to content

Commit

Permalink
new ui implemented!
Browse files Browse the repository at this point in the history
  • Loading branch information
altalk23 committed Jul 18, 2024
1 parent e3fbe6a commit 2d1b38c
Show file tree
Hide file tree
Showing 27 changed files with 455 additions and 321 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ add_library(${PROJECT_NAME} SHARED
src/main.cpp
src/hooks/EditorUI.cpp
src/manager/BrushManager.cpp
src/ui/AlliumPopup.cpp
src/ui/AlliumButtonBar.cpp
src/ui/SupportPopup.cpp
src/util/BrushDrawer.cpp
src/util/CurveBrushDrawer.cpp
src/util/EditorUtilities.cpp
Expand Down
10 changes: 0 additions & 10 deletions include/Allium/manager/BrushManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,12 @@
#include <Geode/Geode.hpp>

namespace allium {
enum class BrushType {
None,
Line,
Curve,
Free
};

class BrushDrawer;

class BrushManager {
public:
static BrushManager* get();

BrushType m_currentBrush = BrushType::None;
BrushDrawer* m_currentDrawer = nullptr;

cocos2d::ccColor3B getColor();

int getColorID();
Expand Down
47 changes: 47 additions & 0 deletions include/Allium/ui/AlliumButtonBar.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#pragma once

#include <Geode/Geode.hpp>

namespace allium {
class BrushDrawer;
class AlliumButtonBar : public cocos2d::CCNode {
protected:
geode::Ref<EditButtonBar> m_buttonBar;
cocos2d::CCArray* m_buttons = nullptr;

CCMenuItemToggler* m_lineToggle = nullptr;
CCMenuItemToggler* m_curveToggle = nullptr;
CCMenuItemToggler* m_freeToggle = nullptr;
BrushDrawer* m_brushDrawer = nullptr;

public:
static AlliumButtonBar* create(EditorUI* editorUI);

bool init(EditorUI* editorUI);

void resetToggles(cocos2d::CCObject* sender);

EditButtonBar* getButtonBar() const;
BrushDrawer* getBrushDrawer() const;

CCMenuItemSpriteExtra* addButton(
std::string_view spriteName, std::string_view bgName, std::string_view id,
geode::utils::MiniFunction<void(CCMenuItemSpriteExtra*)> const& callback
);

CCMenuItemSpriteExtra* addDefaultButton(
std::string_view spriteName, std::string_view id,
geode::utils::MiniFunction<void(CCMenuItemSpriteExtra*)> const& callback
);

CCMenuItemToggler* addToggle(
std::string_view spriteName, std::string_view bgOnName, std::string_view bgOffName, std::string_view id,
geode::utils::MiniFunction<void(CCMenuItemToggler*)> const& callback
);

CCMenuItemToggler* addDefaultToggle(
std::string_view spriteName, std::string_view id,
geode::utils::MiniFunction<void(CCMenuItemToggler*)> const& callback
);
};
}
33 changes: 0 additions & 33 deletions include/Allium/ui/AlliumPopup.hpp

This file was deleted.

14 changes: 14 additions & 0 deletions include/Allium/ui/SupportPopup.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once

#include <Geode/Geode.hpp>

namespace allium {
class SupportPopup : public FLAlertLayer {
public:
static SupportPopup* create();
bool init() override;

void keyBackClicked() override;
void onClose(cocos2d::CCObject* sender);
};
}
47 changes: 46 additions & 1 deletion mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"win": "2.206",
"android": "2.206"
},
"version": "v0.2.0-alpha",
"version": "v0.3.0-alpha",
"id": "alk.allium",
"name": "Allium Drawing Tool",
"developer": "alk",
Expand All @@ -24,5 +24,50 @@
],
"links": {
"source": "https://github.com/altalk23/Allium"
},
"resources": {
"spritesheets": {
"AlliumSpritesheet": [
"resources/*.png",
"resources/icons/*.png"
]
},
"sprites": [
"resources/images/*.png"
]
},
"settings": {
"brush-line-width": {
"type": "float",
"default": 5,
"min": 0.5,
"name": "Brush Width",
"description": "(Temporary) The thickness of the brush",
"max": 30
},
"brush-color-id": {
"type": "int",
"default": 1011,
"name": "Brush Color ID",
"description": "(Temporary) The ID of the brush color",
"min": 1,
"max": 1020
},
"brush-curve-detail": {
"type": "float",
"default": 0.4,
"min": 0.05,
"name": "Curve detail",
"description": "(Temporary) The detail of the curve",
"max": 3
},
"brush-free-threshold": {
"type": "float",
"default": 0.4,
"min": 0.05,
"name": "Free Threshold",
"description": "(Temporary) The threshold of the free tool",
"max": 1.5
}
}
}
Binary file added resources/EditorIcon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/icons/BezierIcon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/icons/BrushIcon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/icons/FinalizeIcon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/icons/GiftIcon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/icons/LineIcon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/icons/PaletteIcon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/icons/PanIcon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/icons/SettingIcon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/icons/ThicknessIcon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/images/ActiveButton.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/images/ButtonGlow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/images/DeactiveButton.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/images/GiftButton.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/images/NeutralButton.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
125 changes: 71 additions & 54 deletions src/hooks/EditorUI.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <Geode/Geode.hpp>
#include <manager/BrushManager.hpp>
#include <ui/AlliumPopup.hpp>
#include <ui/AlliumButtonBar.hpp>
#include <util/BrushDrawer.hpp>

#ifdef GEODE_IS_WINDOWS
Expand All @@ -13,38 +13,78 @@ using namespace allium;
#include <Geode/modify/EditorUI.hpp>

struct EditorUIHook : Modify<EditorUIHook, EditorUI> {
struct Fields {
geode::Ref<AlliumButtonBar> m_buttonBar;
int tabTag = 0;
};

$override
void toggleMode(CCObject* sender) {
auto tag = sender->getTag();

if (tag != 1 && m_fields->m_buttonBar) {
m_fields->m_buttonBar->resetToggles(sender);
}
EditorUI::toggleMode(sender);
}

$override
void onSelectBuildTab(CCObject* sender) {
auto tag = sender->getTag();

if (tag != m_fields->tabTag && m_fields->m_buttonBar) {
m_fields->m_buttonBar->resetToggles(sender);
}
EditorUI::onSelectBuildTab(sender);
}

$override
bool init(LevelEditorLayer* editorLayer) {
if (!EditorUI::init(editorLayer)) return false;

BrushManager::get()->m_currentDrawer = nullptr;
BrushManager::get()->m_currentBrush = BrushType::None;
BrushManager::get()->m_panEditorInBrush = false;

auto buttonMenu = this->getChildByID("editor-buttons-menu");
if (!Mod::get()->getSavedValue<bool>("allium-build-tab-announcement-shown", false)) {
auto popup = createQuickPopup(
"Allium", "Allium is available in the build tab now! You can access it there.",
"OK", nullptr, nullptr, false
);
popup->m_scene = m_editorLayer;
popup->show();

// temporary, will be changed with a custom sprite
auto mySprite = BasedButtonSprite::create(
CCLabelBMFont::create("Allium", "bigFont.fnt"), BaseType::Editor,
static_cast<int>(EditorBaseSize::Normal), static_cast<int>(EditorBaseColor::LightBlue)
);
mySprite->setTopRelativeScale(1.6f);

auto myButton = CCMenuItemExt::createSpriteExtra(
mySprite, [this](CCObject* sender) {
if (BrushManager::get()->m_currentDrawer) {
BrushManager::get()->m_currentDrawer->clearOverlay();
BrushManager::get()->m_currentDrawer->updateLine();
}
AlliumPopup::create()->show();
Mod::get()->setSavedValue("allium-build-tab-announcement-shown", true);
}

m_fields->m_buttonBar = AlliumButtonBar::create(this);

m_fields->m_buttonBar->getButtonBar()->setZOrder(10);
m_fields->m_buttonBar->getButtonBar()->setVisible(false);
m_createButtonBars->addObject(m_fields->m_buttonBar->getButtonBar());

auto spriteOn = CCSprite::createWithSpriteFrameName("EditorIcon.png"_spr);
spriteOn->setScale(0.2f);
auto onBg = CCSprite::createWithSpriteFrameName("GJ_tabOn_001.png");
onBg->addChildAtPosition(spriteOn, Anchor::Center, ccp(0, 0));

auto spriteOff = CCSprite::createWithSpriteFrameName("EditorIcon.png"_spr);
spriteOff->setScale(0.2f);
auto offBg = CCSprite::createWithSpriteFrameName("GJ_tabOff_001.png");
offBg->addChildAtPosition(spriteOff, Anchor::Center, ccp(0, 0));
offBg->setOpacity(150);

m_fields->tabTag = m_tabsArray->count();

auto tabToggle = CCMenuItemExt::createToggler(
offBg, onBg, [this](CCObject* sender) {
this->onSelectBuildTab(sender);
static_cast<CCMenuItemToggler*>(sender)->toggle(false);
}
);
myButton->setID("allium-button"_spr);
// size set in Node IDs itself
myButton->setContentSize({ 40.f, 40.f });
tabToggle->setID("allium-tab-toggle"_spr);
tabToggle->setTag(m_fields->tabTag);
m_tabsArray->addObject(tabToggle);
m_tabsMenu->addChild(tabToggle);
m_tabsMenu->updateLayout();

buttonMenu->addChild(myButton);
buttonMenu->updateLayout();
this->addChild(m_fields->m_buttonBar->getButtonBar());

#ifdef GEODE_IS_WINDOWS

Expand Down Expand Up @@ -73,9 +113,9 @@ struct EditorUIHook : Modify<EditorUIHook, EditorUI> {

$override
bool ccTouchBegan(CCTouch* touch, CCEvent* event) {
if (!BrushManager::get()->panEditorInBrush() && BrushManager::get()->m_currentDrawer) {
if (!BrushManager::get()->panEditorInBrush() && m_fields->m_buttonBar->getBrushDrawer()) {
auto layerPosition = this->getLayerPosition(touch);
BrushManager::get()->m_currentDrawer->handleTouchStart(layerPosition);
m_fields->m_buttonBar->getBrushDrawer()->handleTouchStart(layerPosition);

return true;
}
Expand All @@ -84,9 +124,9 @@ struct EditorUIHook : Modify<EditorUIHook, EditorUI> {

$override
void ccTouchMoved(CCTouch* touch, CCEvent* event) {
if (!BrushManager::get()->panEditorInBrush() && BrushManager::get()->m_currentDrawer) {
if (!BrushManager::get()->panEditorInBrush() && m_fields->m_buttonBar->getBrushDrawer()) {
auto layerPosition = this->getLayerPosition(touch);
BrushManager::get()->m_currentDrawer->handleTouchMove(layerPosition);
m_fields->m_buttonBar->getBrushDrawer()->handleTouchMove(layerPosition);

return;
}
Expand All @@ -95,37 +135,14 @@ struct EditorUIHook : Modify<EditorUIHook, EditorUI> {

$override
void ccTouchEnded(CCTouch* touch, CCEvent* event) {
if (!BrushManager::get()->panEditorInBrush() && BrushManager::get()->m_currentDrawer) {
if (!BrushManager::get()->panEditorInBrush() && m_fields->m_buttonBar->getBrushDrawer()) {
auto layerPosition = this->getLayerPosition(touch);
BrushManager::get()->m_currentDrawer->handleTouchEnd(layerPosition);
m_fields->m_buttonBar->getBrushDrawer()->handleTouchEnd(layerPosition);

return;
}
return EditorUI::ccTouchEnded(touch, event);
}

$override
void showUI(bool show) {
EditorUI::showUI(show);

auto alliumButton = static_cast<CCMenuItemSpriteExtra*>(this->getChildByIDRecursive("allium-button"_spr));
if (alliumButton) {
alliumButton->setEnabled(show);
alliumButton->setVisible(show);
}

auto panButton = static_cast<CCMenuItem*>(this->getChildByIDRecursive("allium-panning-button"_spr));
if (panButton) {
panButton->setEnabled(show);
panButton->setVisible(show);
}

auto finalizeButton = static_cast<CCMenuItem*>(this->getChildByIDRecursive("allium-finalize-button"_spr));
if (finalizeButton) {
finalizeButton->setEnabled(show);
finalizeButton->setVisible(show);
}
}
};

#ifdef GEODE_IS_WINDOWS
Expand Down
Loading

0 comments on commit 2d1b38c

Please sign in to comment.