Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rift labels #56

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,8 @@ foreach(MODULE ${MODULES_LIST})
endif()
endforeach()

CPMAddPackage("gh:EclipseMenu/RIFT#c3f1c29") # specify a commit!

target_link_libraries(${PROJECT_NAME} rift)

setup_geode_mod(${PROJECT_NAME})
52 changes: 4 additions & 48 deletions src/Client/ClientSetup.h
Original file line number Diff line number Diff line change
Expand Up @@ -366,57 +366,13 @@ class ClientUtils

static void SetupStatus()
{
#ifndef STATUS_TEXTS
return;
#endif

Window* replay = new Labels();

replay->modules.push_back(new StatusOpacity());
replay->modules.push_back(new StatusScale());

//replay->modules.push_back(new Module("Testmode", "status-testmode", "Show the test mode text if there's a startpos"));
replay->modules.push_back(new Module("Labels In Editor", "labels-in-editor", "Shows your labels in the level editor <cr>[EXPERIMENTAL]</c>"));

replay->modules.push_back(new Module("Cheat Indicator", "cheat-indicator", "Shows if you are cheating"));
replay->modules.push_back(new Module("FPS Counter", "status-fps", "Shows your current game fps"));
replay->modules.push_back(new Module("Noclip Accuracy", "status-accuracy", "Shows your accuracy in noclip (hidden when noclip is disabled)"));
replay->modules.push_back(new Module("Noclip Deaths", "status-deaths", "Shows your deaths in noclip (hidden when noclip is disabled)"));
replay->modules.push_back(new Module("Attempts", "status-attempt", "Shows Attempt Count"));
//replay->modules.push_back(new Module("Clicks", "status-cps", "Shows Attempt Count"));

replay->modules.push_back(new Module("Replay Status", "status-replay", "Replay debug info"));
//replay->modules.push_back(new Module("Noclip Deaths (not fully accurate)", "status-death", "Shows your death count (hidden when noclip is disabled)"));
//replay->modules.push_back(new Module("Noclip Accuracy", "status-accuracy", "Shows your death accuracy (hidden when noclip is disabled)"));
//replay->modules.push_back(new Module("Attempts", "status-attempts", "Shows your attempt count"));
//replay->modules.push_back(new Module("Clicks", "status-clicks", "Shows your click count"));
replay->modules.push_back(new Module("Message", "status-message", "Write a message of your choice to be shown"));
replay->modules.push_back(new Module("Session Time", "status-session", "Shows the time you've had the game open for in the format <cg>hh::mm::ss</c>"));
replay->modules.push_back(new Module("CPS Counter", "status-cps", "Shows your clicks per second. Tints <cg>Green</c> while you are clicking"));
replay->modules.push_back(new Module("Best Run", "best-run", "Shows your best run"));
replay->modules.push_back(new Module("Clock", "status-clock", "Shows your current device time"));
//replay->modules.push_back(new StatusMessage());


Client::instance->windows.push_back(replay);

for (auto mod : replay->modules)
{
if (mod->id != "labels-in-editor")
mod->options.push_back(new DropdownModule({"Top Left", "Top Right", "Bottom Left", "Bottom Right"}, mod->id + "-side", 0));
}
#ifdef STATUS_TEXTS

auto messageOption = new InputModule("Message Text: ", "status-message-text", "Default Message");
messageOption->allowedChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_=+[]{};:\'\",.<>/?|`~ ";
messageOption->maxSize = 48; // its just a bit before it overflows on 16:9, perfect
Client::GetModule("status-message")->options.push_back(messageOption);
Client::GetModule("status-cps")->options.push_back(new Module("Total CPS", "status-cps-total", "Shows the total clicks in the attempt"));
Client::GetModule("status-cps")->options.push_back(new Module("Instant Fade Transition", "status-cps-instant-fade", "Makes the green fade transition when clicking instant"));
Window* status = new Labels();

Client::GetModule("status-clock")->options.push_back(new Module("24 Hour Time", "status-clock-24h-time", "Uses 24 hour time instead of 12 hour time"));
Client::instance->windows.push_back(status);
StatusNode::postSetup(status);

#ifdef STATUS_TEXTS
StatusNode::postSetup(replay);
#endif
}

Expand Down
73 changes: 71 additions & 2 deletions src/Client/Windows/Labels.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,43 @@
#include "Labels.hpp"

/*
replay->modules.push_back(new StatusOpacity());
replay->modules.push_back(new StatusScale());

//replay->modules.push_back(new Module("Testmode", "status-testmode", "Show the test mode text if there's a startpos"));
replay->modules.push_back(new Module("Cheat Indicator", "cheat-indicator", "Shows if you are cheating"));
replay->modules.push_back(new Module("FPS Counter", "status-fps", "Shows your current game fps"));
replay->modules.push_back(new Module("Noclip Accuracy", "status-accuracy", "Shows your accuracy in noclip (hidden when noclip is disabled)"));
replay->modules.push_back(new Module("Noclip Deaths", "status-deaths", "Shows your deaths in noclip (hidden when noclip is disabled)"));
replay->modules.push_back(new Module("Attempts", "status-attempt", "Shows Attempt Count"));
//replay->modules.push_back(new Module("Clicks", "status-cps", "Shows Attempt Count"));

replay->modules.push_back(new Module("Replay Status", "status-replay", "Replay debug info"));
//replay->modules.push_back(new Module("Noclip Deaths (not fully accurate)", "status-death", "Shows your death count (hidden when noclip is disabled)"));
//replay->modules.push_back(new Module("Noclip Accuracy", "status-accuracy", "Shows your death accuracy (hidden when noclip is disabled)"));
//replay->modules.push_back(new Module("Attempts", "status-attempts", "Shows your attempt count"));
//replay->modules.push_back(new Module("Clicks", "status-clicks", "Shows your click count"));
replay->modules.push_back(new Module("Message", "status-message", "Write a message of your choice to be shown"));
replay->modules.push_back(new Module("Session Time", "status-session", "Shows the time you've had the game open for in the format <cg>hh::mm::ss</c>"));
replay->modules.push_back(new Module("Clicks Per Second", "status-cps", "Shows your clicks per second. Tints <cg>Green</c> while you are clicking"));
//replay->modules.push_back(new StatusMessage());



for (auto mod : replay->modules)
{
mod->options.push_back(new DropdownModule({"Top Left", "Top Right", "Bottom Left", "Bottom Right"}, mod->id + "-side", 0));
}

auto messageOption = new InputModule("Message Text: ", "status-message-text", "Default Message");
messageOption->allowedChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_=+[]{};:\'\",.<>/?|`~ ";
messageOption->maxSize = 48; // its just a bit before it overflows on 16:9, perfect
Client::GetModule("status-message")->options.push_back(messageOption);
*/

void Labels::cocosCreate(CCMenu* menu)
{
return Window::cocosCreate(menu); // todo: finish ui
//return Window::cocosCreate(menu); // todo: finish ui

labels.clear();

Expand Down Expand Up @@ -85,6 +120,12 @@ void Labels::cocosCreate(CCMenu* menu)
labels.push_back(name);
scroll->m_contentLayer->addChild(cell);
}

error = TextArea::create("Nothing here yet <cl>:(</c>", "bigFont.fnt", 1, 1000, ccp(0.5f, 0.5f), 10, false);
error->setVisible(modules.size() == 0);
error->setPosition(bg->getPosition() + bg->getContentSize() / 2);
error->setScale(0.65f);
menu->addChild(error);
}

void Labels::onHide(CCObject* sender)
Expand Down Expand Up @@ -116,4 +157,32 @@ void Labels::onLabelOptions(CCObject* sender)
auto mod = as<Module*>(as<CCNode*>(sender)->getUserData());

mod->onOptionsAndroid(sender);
}
}

void Labels::loadConfig()
{
if (Mod::get()->hasSavedValue("labels-config"))
{
auto cfg = Mod::get()->getSavedValue<matjson::Array>("labels-config");

for (auto child : cfg)
{
auto obj = child.as_object();

auto mod = new LabelModule("", "");
mod->name = obj["name"].as_string();
mod->format = obj["format"].as_string();
mod->setFont(obj["font"].as_string());
mod->setSide(as<LabelSide>(obj["side"].as_int()));
mod->setOpacity(obj["opacity"].as_double());
mod->setScale(obj["scale"].as_double());

modules.push_back(mod);
}
}
}

void Labels::saveConfig()
{

}
9 changes: 7 additions & 2 deletions src/Client/Windows/Labels.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "../Client.h"
#include "../../Labels/Labels.h"
#include "../../Labels/LabelModule.hpp"

class Labels : public Window
{
Expand All @@ -10,15 +11,19 @@ class Labels : public Window
{
name = "Labels";
id = "labels-window";

loadConfig();
}

std::vector<CCLabelBMFont*> labels = {};
TextArea* error;

void cocosCreate(CCMenu* menu);

void onHide(CCObject*);

void onToggleLabel(CCObject* sender);

void onLabelOptions(CCObject* sender);

void loadConfig();
void saveConfig();
};
5 changes: 2 additions & 3 deletions src/Hacks/SafeMode/SafeMode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,11 @@ void SafeMode::updateIndicator()

if (auto a = StatusNode::get())
{
if (auto l = a->sLabels[0])
l->setColor(colourForState());
//if (auto l = a->sLabels[0])
//l->setColor(colourForState());

a->update(-1);
a->reorderSides();
a->reorderPosition();
}

#endif
Expand Down
68 changes: 68 additions & 0 deletions src/Labels/LabelModule.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#include "LabelModule.hpp"
#include "Labels.h"

LabelModule::LabelModule(std::string format, std::string font)
{
this->format = format;
this->font = font;
}

void LabelModule::setFont(std::string newFont)
{
this->font = newFont;

if (labelNode)
labelNode->setFntFile(getFont().c_str());
}

std::string LabelModule::getFont()
{
return CCFileUtils::sharedFileUtils()->isFileExist(CCFileUtils::sharedFileUtils()->fullPathForFilename(font.c_str(), false)) ? font : "bigFont.fnt";
}

void LabelModule::setScale(float newScale)
{
this->scale = newScale;

if (labelNode)
{
labelNode->setScale(newScale * 0.5f);
labelNode->getParent()->updateLayout();
}
}

float LabelModule::getScale()
{
return scale;
}

void LabelModule::setOpacity(float newOpacity)
{
this->opacity = newOpacity;

if (labelNode)
{
labelNode->setScale(newOpacity * 255);
labelNode->getParent()->updateLayout();
}
}

float LabelModule::getOpacity()
{
return opacity;
}

void LabelModule::setSide(LabelSide newSide)
{
this->side = newSide;

if (StatusNode::get())
{
StatusNode::get()->reorderSides();
}
}

LabelSide LabelModule::getSide()
{
return side;
}
42 changes: 42 additions & 0 deletions src/Labels/LabelModule.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#pragma once

#include <Geode/Geode.hpp>
#include "../Client/Client.h"

using namespace geode::prelude;

enum LabelSide
{
TopLeft,
TopRight,
BottomLeft,
BottomRight,
BottomCenter,
};

class LabelModule : public Module
{
private:
float scale = 1;
float opacity = 1;
std::string font = "bigFont.fnt";
LabelSide side = LabelSide::TopLeft;

public:
CCLabelBMFont* labelNode;
std::string format;

LabelModule(std::string format, std::string font);

void setFont(std::string newFont);
std::string getFont();

void setScale(float newScale);
float getScale();

void setOpacity(float newOpacity);
float getOpacity();

void setSide(LabelSide newSide);
LabelSide getSide();
};
54 changes: 54 additions & 0 deletions src/Labels/LabelNode.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include "LabelNode.hpp"
#include "Labels.h"

LabelNode* LabelNode::create(LabelModule* module)
{
auto pRet = new LabelNode();

if (pRet && pRet->init(module))
{
pRet->autorelease();
return pRet;
}

CC_SAFE_DELETE(pRet);
return nullptr;
}

bool LabelNode::init(LabelModule* module)
{
if (!CCLabelBMFont::initWithString("", module->getFont().c_str()))
return false;

this->module = module;
module->labelNode = this;

this->setScale(module->getScale() * 0.5f);
this->setOpacity(module->getOpacity() * 255);

return true;
}

void LabelNode::update(float delta)
{
auto res = rift::compile(module->format);

script = res.unwrapOr(nullptr);

if (!script)
{
return this->setString(fmt::format("Error Compiling Script: {}", res.getMessage()).c_str());
}

script->setVariable("fps", rift::Value::integer(StatusNode::get()->fps));
//script->setVariable("name", "World");

auto res2 = script->run();

this->setString(res2.c_str());
}

LabelNode::~LabelNode()
{
module->labelNode = nullptr;
}
Loading