Skip to content

Commit 1a1c6cd

Browse files
committed
start range system
1 parent 194f7ea commit 1a1c6cd

11 files changed

Lines changed: 197 additions & 1 deletion

File tree

src/Client/LayoutModule.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,26 @@ void LayoutModule::nodeUpdate(float dt)
116116
auto mod = reinterpret_cast<LayoutModule*>(self->getUserData());
117117

118118
self->setPosition(mod->getPosition());
119+
}
120+
121+
void LayoutModule::addOption(std::string key, std::string displayKey, float defaultV, float min, float max)
122+
{
123+
floatOptions.emplace(key, FloatOption{
124+
.display = displayKey,
125+
.defaultV = defaultV,
126+
.min = min,
127+
.max = max,
128+
.value = defaultV
129+
});
130+
}
131+
132+
void LayoutModule::setOption(std::string key, float value)
133+
{
134+
floatOptions[key].value = value;
135+
save();
136+
}
137+
138+
float LayoutModule::getOption(std::string key)
139+
{
140+
return floatOptions[key].value;
119141
}

src/Client/LayoutModule.hpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,23 @@ namespace qolmod
99

1010
class LayoutModule : public ButtonModule
1111
{
12+
friend class qolmod::EditLayoutUI;
1213
protected:
1314
std::function<cocos2d::CCNode*()> previewNode = nullptr;
1415
geode::Anchor anchor = geode::Anchor::Center;
1516
cocos2d::CCPoint offset = ccp(0, 0);
1617

1718
geode::Anchor defaultAnchor = geode::Anchor::Center;
1819
cocos2d::CCPoint defaultOffset = ccp(0, 0);
20+
struct FloatOption
21+
{
22+
std::string display = "";
23+
float defaultV = 1.0f;
24+
float min = 0.0f;
25+
float max = 1.0f;
26+
float value = 0.0f;
27+
};
28+
std::unordered_map<std::string, FloatOption> floatOptions = {};
1929

2030
virtual void save();
2131
virtual void load();
@@ -25,6 +35,8 @@ class LayoutModule : public ButtonModule
2535
void setPreviewNode(std::function<cocos2d::CCNode*()> preview);
2636
void setDefaults(geode::Anchor an, cocos2d::CCPoint off);
2737

38+
void addOption(std::string key, std::string displayKey, float defaultV, float min, float max);
39+
2840
void nodeUpdate(float);
2941

3042
public:
@@ -35,5 +47,8 @@ class LayoutModule : public ButtonModule
3547
void setPosition(cocos2d::CCPoint point);
3648
cocos2d::CCPoint getPosition();
3749

50+
void setOption(std::string key, float value);
51+
float getOption(std::string key);
52+
3853
virtual ModuleNode* getNode();
3954
};

src/Client/Range.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include "Range.hpp"
2+
3+
using namespace geode::prelude;
4+
using namespace qolmod;
5+
6+
bool Range::inRange(float v)
7+
{
8+
return v >= min && v <= max;
9+
}
10+
11+
matjson::Value Range::save()
12+
{
13+
matjson::Value value;
14+
value["min"] = min;
15+
value["max"] = max;
16+
value["enable"] = enable;
17+
18+
return value;
19+
}
20+
21+
void Range::load(const matjson::Value& value)
22+
{
23+
min = value["min"].asDouble().unwrapOr(min);
24+
max = value["max"].asDouble().unwrapOr(max);
25+
enable = value["enable"].asBool().unwrapOr(enable);
26+
}

src/Client/Range.hpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#pragma once
2+
3+
#include <Geode/Geode.hpp>
4+
5+
namespace qolmod
6+
{
7+
struct Range
8+
{
9+
double min = 0;
10+
double max = 1;
11+
bool enable = true;
12+
13+
bool inRange(float v);
14+
15+
matjson::Value save();
16+
void load(const matjson::Value& value);
17+
};
18+
};

src/Client/Ranges.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#include "Ranges.hpp"
2+
3+
using namespace geode::prelude;
4+
using namespace qolmod;
5+
6+
void Ranges::sort()
7+
{
8+
9+
}
10+
11+
bool Ranges::getEnable(float value, bool def)
12+
{
13+
for (auto& range : ranges)
14+
{
15+
if (range.inRange(value))
16+
return range.enable;
17+
}
18+
19+
return def;
20+
}
21+
22+
matjson::Value Ranges::save()
23+
{
24+
sort();
25+
matjson::Value value = matjson::Value::array();
26+
27+
for (auto& range : ranges)
28+
{
29+
value.push(range.save());
30+
}
31+
32+
return value;
33+
}
34+
35+
void Ranges::load(const matjson::Value& value)
36+
{
37+
ranges.clear();
38+
39+
if (!value.isArray())
40+
return;
41+
42+
for (auto& v : value.asArray().unwrap())
43+
{
44+
Range range;
45+
range.load(v);
46+
ranges.push_back(range);
47+
}
48+
49+
sort();
50+
}

src/Client/Ranges.hpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#pragma once
2+
3+
#include "Range.hpp"
4+
5+
namespace qolmod
6+
{
7+
struct Ranges
8+
{
9+
std::vector<Range> ranges = {};
10+
11+
void sort();
12+
13+
bool getEnable(float value, bool def);
14+
15+
matjson::Value save();
16+
void load(const matjson::Value& value);
17+
};
18+
};

src/GUI/EditLayoutUI.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#include <Button.hpp>
66
#include <LayoutModule.hpp>
77
#include <RealtimeAction.hpp>
8+
#include <BetterSlider.hpp>
9+
#include <../IconEffects/IconicPlayerHook.hpp>
810

911
using namespace geode::prelude;
1012
using namespace qolmod;
@@ -111,6 +113,8 @@ bool EditLayoutUI::setup()
111113
node->addChild(previewOutline, 7);
112114
node->addChild(grab, 7);
113115

116+
node->addChild(createOptions(), 2);
117+
114118
m_mainLayer->addChildAtPosition(clip, Anchor::Center);
115119
m_mainLayer->addChildAtPosition(menu, Anchor::Bottom, ccp(0, -5.0f));
116120
m_mainLayer->addChildAtPosition(titleBG, Anchor::Top, ccp(0, 15));
@@ -244,6 +248,38 @@ void EditLayoutUI::updateAnchorPoints()
244248
}
245249
}
246250

251+
void EditLayoutUI::onSliderChanged(CCObject* sender)
252+
{
253+
254+
}
255+
256+
CCMenu* EditLayoutUI::createOptions()
257+
{
258+
return CCMenu::create();
259+
260+
auto menu = CCMenu::create();
261+
262+
float y = 0;
263+
for (auto& option : module->floatOptions)
264+
{
265+
auto label = AdvLabelBMFont::createWithString(option.second.display, "bigFont.fnt");
266+
auto slider = BetterSlider::create(this, menu_selector(EditLayoutUI::onSliderChanged));
267+
slider->setRange(option.second.min, option.second.max);
268+
slider->setValueRanged(option.second.value);
269+
slider->setID(option.first);
270+
271+
label->setPosition(ccp(0, y));
272+
slider->setPosition(ccp(0, y));
273+
274+
menu->addChild(label);
275+
menu->addChild(slider);
276+
277+
y -= 30;
278+
}
279+
280+
return menu;
281+
}
282+
247283
CCNode* EditLayoutUI::createBackground(bool acu)
248284
{
249285
auto imageNode = CCNode::create();
@@ -277,6 +313,10 @@ CCNode* EditLayoutUI::createBackground(bool acu)
277313
player->setColor(GameManager::get()->colorForIdx(GameManager::get()->m_playerColor.value()));
278314
player->setSecondColor(GameManager::get()->colorForIdx(GameManager::get()->m_playerColor2.value()));
279315

316+
auto hook = IconicPlayerHook::create(player);
317+
hook->setGamemode(IconicGamemodeType::Cube, false);
318+
this->addChild(hook);
319+
280320
if (GameManager::get()->m_playerGlow)
281321
{
282322
player->enableCustomGlowColor(GameManager::get()->colorForIdx(GameManager::get()->m_playerGlowColor.value()));

src/GUI/EditLayoutUI.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,17 @@ namespace qolmod
2424
float anchorShowDis = 60;
2525
bool snapEnabled = true;
2626

27-
CCNode* createBackground(bool acu = true);
27+
cocos2d::CCNode* createBackground(bool acu = true);
2828

2929
void updateOutline();
3030
void updateAnchorPoints();
3131
void fixToAnchorPoints();
3232
void fixToScreenBounds();
3333

34+
void onSliderChanged(CCObject* sender);
35+
36+
cocos2d::CCMenu* createOptions();
37+
3438
public:
3539
static EditLayoutUI* create(LayoutModule* module);
3640

src/GUI/SetupRangeUI.cpp

Whitespace-only changes.

src/GUI/SetupRangeUI.hpp

Whitespace-only changes.

0 commit comments

Comments
 (0)