Skip to content

Commit 84edf8c

Browse files
more qol features yay
1 parent 09dadf8 commit 84edf8c

File tree

5 files changed

+166
-21
lines changed

5 files changed

+166
-21
lines changed

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ This mod adds a scalable and moveable UI to the level editor with move, rotate,
99
In the mod's settings, you can customize button visuals and functionality.
1010
# How to use
1111
- Select an object to show the transform buttons in the editor.
12-
- Hold around the edge of the buttons to drag around the buttons.
12+
- Hold the draggable area of the buttons to move the menu.
1313
- Press the center button to toggle the move units.
1414
# Credits
15-
- Cheeseworks - For helping me make this mod possible since I barely understand some functionality to make things work
16-
- CyanBoi - For beta testing, finding bugs and giving me feedbacks
17-
- iCreate Pro - For inspiration on the Custom Move Button feature
15+
- **Cheeseworks** - For helping me make this mod possible since I barely understand some functionality to make things work
16+
- **CyanBoi** - For beta testing, finding bugs and giving me feedbacks
17+
- **iCreate Pro** - For inspiration on the Custom Move Button feature
1818
# Preview
1919
![Preview 1 with button background](preview1.png)
2020
![Preview 2 without button background](preview2.png)
2121
# Known Bugs
22-
- Buttons disappears whenever you copy + paste multiple objects. Appears again whenever you move your editor *(Best way to prevent this is enabling Button Presistent since I don't know how to fix this bug)*
22+
- Buttons disappears whenever you copy + paste multiple objects. Appears again whenever you move your editor
23+
*(Best way to prevent this is enabling Button Presistent since I don't know how to fix this bug)*

about.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ In the mod's settings, you can customize button visuals and functionality.
99
# How to use
1010

1111
- Select an object to show the transform buttons in the editor.
12-
- Hold around the edge of the buttons to drag around the buttons.
12+
- Hold the draggable area of the buttons to move the menu.
1313
- Press the center button to toggle the move units.
1414

1515
# Credits
@@ -26,4 +26,5 @@ In the mod's settings, you can customize button visuals and functionality.
2626

2727
# Known Bugs
2828

29-
- Buttons disappears whenever you copy + paste multiple objects. Appears again whenever you move your editor *(Best way to prevent this is enabling Button Presistent since I don't know how to fix this bug)*
29+
- Buttons disappears whenever you copy + paste multiple objects. Appears again whenever you move your editor
30+
*(Best way to prevent this is enabling Button Presistent since I don't know how to fix this bug)*

changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
# v1.0.1
22
- Added **Button Presistent** in the mod settings (Always show the transform buttons even when an object isn't selected)
3+
- Added **Show Draggable Area** in the mod settings and it's on by default (This is useful to know where exactly the draggable area is)
4+
- Added **Scale Draggable Area** in the mod settings (You can change the draggable area for ease of use)
5+
- Fixed the buttons size and positioning
36
# v1.0.0
47
- Initial release

mod.json

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
"version": "v1.0.1",
1212
"settings": {
1313
"scale-btns": {
14-
"name": "Scale Move Buttons",
15-
"description": "Change the size of the transform buttons. <cr>Required to reopen the editor to take effect.</cr>",
14+
"name": "Scale Button",
15+
"description": "Change the scale of the transform buttons, <co>draggable area also be affected.</co> <cr>Required to reopen the editor to take effect.</cr>",
1616
"type": "float",
1717
"default": 1,
1818
"min": 0.5,
@@ -34,12 +34,30 @@
3434
"slider-step": 5
3535
}
3636
},
37+
"scale-bg": {
38+
"name": "Scale Draggable Area",
39+
"description": "Change the scale of the draggable area. <cg>Useful if you can't drag properly due to the area size.</cg> <cr>Required to reopen the editor to take effect.</cr>",
40+
"type": "int",
41+
"default": 130,
42+
"min": 130,
43+
"max": 200,
44+
"control": {
45+
"slider": true,
46+
"slider-step": 10
47+
}
48+
},
3749
"visible-bg": {
38-
"name": "Button Background",
50+
"name": "Show Button Background",
3951
"description": "Show the background of the transform buttons. <cr>Required to reopen the editor to take effect.</cr>",
4052
"type": "bool",
4153
"default": false
4254
},
55+
"menu-btn": {
56+
"name": "Show Draggable Area",
57+
"description": "Show the draggable area for transform buttons. <cg>Useful if you want to know the draggable area.</cg>",
58+
"type": "bool",
59+
"default": true
60+
},
4361
"no-dragging": {
4462
"name": "Disable Dragging",
4563
"description": "Disable dragging on the transform buttons. <cg>Useful if you want your buttons to stay in a fixed position and prevent accidental dragging.</cg>",

src/main.cpp

Lines changed: 133 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ class $modify(MyEditorUI, EditorUI) {
122122

123123
CCMenu* m_buttonMenu;
124124
CCScale9Sprite* m_buttonMenuBg;
125+
CCScale9Sprite* m_buttonMenuBgDepth; // Second background for depth effect
125126

126127
// Move buttons
127128
CCMenuItemSpriteExtra* m_moveUpBtn;
@@ -182,18 +183,34 @@ class $modify(MyEditorUI, EditorUI) {
182183

183184
m_fields->m_buttonMenu->setPosition(CCPoint(savedX, savedY));
184185
m_fields->m_buttonMenu->setAnchorPoint({ 0.5f, 0.5f });
185-
m_fields->m_buttonMenu->setContentSize({ 140.0f, 140.0f });
186+
187+
// Get background size from settings
188+
int bgSize = Mod::get()->getSettingValue<int>("scale-bg");
189+
m_fields->m_buttonMenu->setContentSize({ static_cast<float>(bgSize), static_cast<float>(bgSize) });
190+
186191
m_fields->m_buttonMenu->ignoreAnchorPointForPosition(false);
187192
m_fields->m_buttonMenu->setVisible(false); // Initially invisible since no objects are selected
188193

189-
// create visible background for the menu
194+
// create depth background for the menu (behind the main background)
195+
auto buttonMenuBgDepth = CCScale9Sprite::create("square02_001.png");
196+
CCSize depthSize = { static_cast<float>(bgSize + 6), static_cast<float>(bgSize + 6) }; // Larger for depth
197+
buttonMenuBgDepth->setContentSize(depthSize);
198+
buttonMenuBgDepth->ignoreAnchorPointForPosition(false);
199+
buttonMenuBgDepth->setAnchorPoint({ 0.5, 0.5 });
200+
buttonMenuBgDepth->setOpacity(25); // Lower opacity for depth effect
201+
buttonMenuBgDepth->setPosition({ m_fields->m_buttonMenu->getContentWidth() / 2.f, m_fields->m_buttonMenu->getContentHeight() / 2.f }); // Same position as main background
202+
buttonMenuBgDepth->setColor({ 0, 0, 0 }); // Darker color for shadow effect
203+
204+
m_fields->m_buttonMenuBgDepth = buttonMenuBgDepth;
205+
m_fields->m_buttonMenu->addChild(buttonMenuBgDepth);
206+
207+
// create visible background for the menu (main background)
190208
auto buttonMenuBg = CCScale9Sprite::create("square02_001.png");
191209
buttonMenuBg->setContentSize(m_fields->m_buttonMenu->getContentSize());
192210
buttonMenuBg->ignoreAnchorPointForPosition(false);
193211
buttonMenuBg->setAnchorPoint({ 0.5, 0.5 });
194-
buttonMenuBg->setOpacity(100); // Slightly more visible for dragging
212+
buttonMenuBg->setOpacity(50); // Set opacity to 50 when visible
195213
buttonMenuBg->setPosition({ m_fields->m_buttonMenu->getContentWidth() / 2.f, m_fields->m_buttonMenu->getContentHeight() / 2.f });
196-
buttonMenuBg->setVisible(false); // Always invisible
197214

198215
m_fields->m_buttonMenuBg = buttonMenuBg;
199216
m_fields->m_buttonMenu->addChild(buttonMenuBg);
@@ -216,7 +233,7 @@ class $modify(MyEditorUI, EditorUI) {
216233
m_fields->m_moveUpBtn->setID("move-up");
217234
m_fields->m_moveUpBtn->ignoreAnchorPointForPosition(false);
218235
m_fields->m_moveUpBtn->setAnchorPoint({ 0.5, 0.5 });
219-
m_fields->m_moveUpBtn->setPosition({ m_fields->m_buttonMenu->getContentWidth() / 2.f, (m_fields->m_buttonMenu->getContentHeight() / 2.f) + 30.f });
236+
m_fields->m_moveUpBtn->setPosition({ m_fields->m_buttonMenu->getContentWidth() / 2.f, (m_fields->m_buttonMenu->getContentHeight() / 2.f) + 35.f });
220237

221238
// move up button
222239
auto moveUpBtnIcon = CCSprite::createWithSpriteFrameName(moveBtnIconSpriteName.c_str());
@@ -242,7 +259,7 @@ class $modify(MyEditorUI, EditorUI) {
242259
m_fields->m_moveDownBtn->setID("move-down");
243260
m_fields->m_moveDownBtn->ignoreAnchorPointForPosition(false);
244261
m_fields->m_moveDownBtn->setAnchorPoint({ 0.5, 0.5 });
245-
m_fields->m_moveDownBtn->setPosition({ m_fields->m_buttonMenu->getContentWidth() / 2.f, (m_fields->m_buttonMenu->getContentHeight() / 2.f) - 30.f });
262+
m_fields->m_moveDownBtn->setPosition({ m_fields->m_buttonMenu->getContentWidth() / 2.f, (m_fields->m_buttonMenu->getContentHeight() / 2.f) - 35.f });
246263

247264
// move down button icon
248265
auto moveDownBtnIcon = CCSprite::createWithSpriteFrameName(moveBtnIconSpriteName.c_str());
@@ -327,7 +344,7 @@ class $modify(MyEditorUI, EditorUI) {
327344
m_fields->m_buttonMenu->addChild(m_fields->m_moveSizeBtn);
328345

329346
// create rotate counter clockwise button
330-
auto rotateCounterClockwiseSprite = ButtonSprite::create("", 15, true, "bigFont.fnt", "GJ_button_01.png", 32.5f, 0.1f);
347+
auto rotateCounterClockwiseSprite = ButtonSprite::create("", 18.5f, true, "bigFont.fnt", "GJ_button_01.png", 33.5f, 0.1f);
331348
m_fields->m_rotateCounterClockwiseBtnBg = rotateCounterClockwiseSprite;
332349

333350
m_fields->m_rotateCounterClockwiseBtn = CCMenuItemSpriteExtra::create(
@@ -351,7 +368,7 @@ class $modify(MyEditorUI, EditorUI) {
351368
m_fields->m_buttonMenu->addChild(m_fields->m_rotateCounterClockwiseBtn);
352369

353370
// create rotate clockwise button
354-
auto rotateClockwiseSprite = ButtonSprite::create("", 15, true, "bigFont.fnt", "GJ_button_01.png", 32.5f, 0.1f);
371+
auto rotateClockwiseSprite = ButtonSprite::create("", 18.5f, true, "bigFont.fnt", "GJ_button_01.png", 33.5f, 0.1f);
355372
m_fields->m_rotateClockwiseBtnBg = rotateClockwiseSprite;
356373

357374
m_fields->m_rotateClockwiseBtn = CCMenuItemSpriteExtra::create(
@@ -375,7 +392,7 @@ class $modify(MyEditorUI, EditorUI) {
375392
m_fields->m_buttonMenu->addChild(m_fields->m_rotateClockwiseBtn);
376393

377394
// create flip x button
378-
auto flipXSprite = ButtonSprite::create("", 15, true, "bigFont.fnt", "GJ_button_01.png", 32.5f, 0.1f);
395+
auto flipXSprite = ButtonSprite::create("", 18.5f, true, "bigFont.fnt", "GJ_button_01.png", 33.5f, 0.1f);
379396
m_fields->m_flipXBtnBg = flipXSprite;
380397

381398
m_fields->m_flipXBtn = CCMenuItemSpriteExtra::create(
@@ -399,7 +416,7 @@ class $modify(MyEditorUI, EditorUI) {
399416
m_fields->m_buttonMenu->addChild(m_fields->m_flipXBtn);
400417

401418
// create flip y button
402-
auto flipYSprite = ButtonSprite::create("", 15, true, "bigFont.fnt", "GJ_button_01.png", 32.5f, 0.1f);
419+
auto flipYSprite = ButtonSprite::create("", 18.5f, true, "bigFont.fnt", "GJ_button_01.png", 33.5f, 0.1f);
403420
m_fields->m_flipYBtnBg = flipYSprite;
404421

405422
m_fields->m_flipYBtn = CCMenuItemSpriteExtra::create(
@@ -428,6 +445,12 @@ class $modify(MyEditorUI, EditorUI) {
428445
// Apply button background visibility setting
429446
updateButtonBackgroundVisibility();
430447

448+
// Apply menu background visibility setting
449+
updateMenuBackgroundVisibility();
450+
451+
// Apply menu size setting
452+
updateMenuSize();
453+
431454
// Apply scale setting
432455
updateMenuScale();
433456

@@ -747,6 +770,8 @@ class $modify(MyEditorUI, EditorUI) {
747770
// Also do periodic updates for settings changes
748771
if (timer >= 0.2f) { // Check settings every 0.2 seconds
749772
updateButtonBackgroundVisibility(); // Check setting changes
773+
updateMenuBackgroundVisibility(); // Check menu background setting changes
774+
updateMenuSize(); // Check menu size setting changes
750775
updateMenuScale(); // Check scale setting changes
751776
updateMenuOpacity(); // Check opacity setting changes
752777
timer = 0.0f;
@@ -956,11 +981,108 @@ class $modify(MyEditorUI, EditorUI) {
956981
// Get the opacity value from settings
957982
int baseOpacity = Mod::get()->getSettingValue<int>("opacity-btn");
958983

959-
// If dragging, reduce opacity by 30
984+
// If dragging, reduce opacity by 50
960985
int currentOpacity = m_fields->m_isDragging ? std::max(0, baseOpacity - 50) : baseOpacity;
961986

962987
// Apply the opacity to the entire button menu
963988
m_fields->m_buttonMenu->setOpacity(currentOpacity);
989+
990+
// Also update the menu background opacity separately if they exist and are visible
991+
if (m_fields->m_buttonMenuBg && m_fields->m_buttonMenuBg->isVisible()) {
992+
// Base opacity for main menu background is 50, reduce to 25 when dragging
993+
int menuBgOpacity = m_fields->m_isDragging ? 25 : 50;
994+
m_fields->m_buttonMenuBg->setOpacity(menuBgOpacity);
995+
}
996+
997+
if (m_fields->m_buttonMenuBgDepth && m_fields->m_buttonMenuBgDepth->isVisible()) {
998+
// Base opacity for depth background is 25, reduce to 15 when dragging
999+
int depthBgOpacity = m_fields->m_isDragging ? 15 : 25;
1000+
m_fields->m_buttonMenuBgDepth->setOpacity(depthBgOpacity);
1001+
}
1002+
};
1003+
1004+
void updateMenuBackgroundVisibility() {
1005+
if (!m_fields->m_buttonMenuBg || !m_fields->m_buttonMenuBgDepth) return;
1006+
1007+
bool showMenuBG = Mod::get()->getSettingValue<bool>("menu-btn");
1008+
1009+
// Update visibility for both backgrounds
1010+
m_fields->m_buttonMenuBg->setVisible(showMenuBG);
1011+
m_fields->m_buttonMenuBgDepth->setVisible(showMenuBG);
1012+
1013+
// Set proper opacity when visibility changes
1014+
if (showMenuBG) {
1015+
// Main background opacity
1016+
int menuBgOpacity = m_fields->m_isDragging ? 25 : 50;
1017+
m_fields->m_buttonMenuBg->setOpacity(menuBgOpacity);
1018+
1019+
// Depth background opacity (always lower for shadow effect)
1020+
int depthBgOpacity = m_fields->m_isDragging ? 15 : 25;
1021+
m_fields->m_buttonMenuBgDepth->setOpacity(depthBgOpacity);
1022+
}
1023+
};
1024+
1025+
void repositionButtons() {
1026+
if (!m_fields->m_buttonMenu) return;
1027+
1028+
float centerX = m_fields->m_buttonMenu->getContentWidth() / 2.f;
1029+
float centerY = m_fields->m_buttonMenu->getContentHeight() / 2.f;
1030+
1031+
// Reposition all buttons relative to the center
1032+
if (m_fields->m_moveUpBtn) {
1033+
m_fields->m_moveUpBtn->setPosition({ centerX, centerY + 35.f });
1034+
}
1035+
if (m_fields->m_moveDownBtn) {
1036+
m_fields->m_moveDownBtn->setPosition({ centerX, centerY - 35.f });
1037+
}
1038+
if (m_fields->m_moveLeftBtn) {
1039+
m_fields->m_moveLeftBtn->setPosition({ centerX - 35.f, centerY });
1040+
}
1041+
if (m_fields->m_moveRightBtn) {
1042+
m_fields->m_moveRightBtn->setPosition({ centerX + 35.f, centerY });
1043+
}
1044+
if (m_fields->m_moveSizeBtn) {
1045+
m_fields->m_moveSizeBtn->setPosition({ centerX, centerY });
1046+
}
1047+
if (m_fields->m_rotateCounterClockwiseBtn) {
1048+
m_fields->m_rotateCounterClockwiseBtn->setPosition({ centerX - 40.f, centerY + 40.f });
1049+
}
1050+
if (m_fields->m_rotateClockwiseBtn) {
1051+
m_fields->m_rotateClockwiseBtn->setPosition({ centerX + 40.f, centerY + 40.f });
1052+
}
1053+
if (m_fields->m_flipXBtn) {
1054+
m_fields->m_flipXBtn->setPosition({ centerX - 40.f, centerY - 40.f });
1055+
}
1056+
if (m_fields->m_flipYBtn) {
1057+
m_fields->m_flipYBtn->setPosition({ centerX + 40.f, centerY - 40.f });
1058+
}
1059+
}
1060+
1061+
void updateMenuSize() {
1062+
if (!m_fields->m_buttonMenu) return;
1063+
1064+
// Get background size from settings
1065+
int bgSize = Mod::get()->getSettingValue<int>("scale-bg");
1066+
CCSize newSize = { static_cast<float>(bgSize), static_cast<float>(bgSize) };
1067+
CCSize depthSize = { static_cast<float>(bgSize + 6), static_cast<float>(bgSize + 6) }; // Larger for depth
1068+
1069+
// Update menu content size
1070+
m_fields->m_buttonMenu->setContentSize(newSize);
1071+
1072+
// Reposition all buttons to match the new center
1073+
repositionButtons();
1074+
1075+
// Update main background size and position to keep it centered
1076+
if (m_fields->m_buttonMenuBg) {
1077+
m_fields->m_buttonMenuBg->setContentSize(newSize);
1078+
m_fields->m_buttonMenuBg->setPosition({ m_fields->m_buttonMenu->getContentWidth() / 2.f, m_fields->m_buttonMenu->getContentHeight() / 2.f });
1079+
}
1080+
1081+
// Update depth background size and position (larger but same center position)
1082+
if (m_fields->m_buttonMenuBgDepth) {
1083+
m_fields->m_buttonMenuBgDepth->setContentSize(depthSize);
1084+
m_fields->m_buttonMenuBgDepth->setPosition({ m_fields->m_buttonMenu->getContentWidth() / 2.f, m_fields->m_buttonMenu->getContentHeight() / 2.f });
1085+
}
9641086
};
9651087
};
9661088

0 commit comments

Comments
 (0)