Skip to content

Commit

Permalink
Added a pause persisting confirmation
Browse files Browse the repository at this point in the history
  • Loading branch information
SMJSGaming committed Sep 26, 2024
1 parent 2036492 commit 5853578
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 32 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# GDIntercept Changelog

## v0.6.3-alpha.6 (2024-09-26) - Pause Persisting

- Added a confirmation setting to persist the pause state between sessions

## v0.6.2-alpha.6 (2024-09-25) - Minor Semantic Fixes

- Fixed the release date of the previous version
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_OSX_ARCHITECTURES "arm64;x86_64")
set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreadedDLL)

project(GDIntercept VERSION 0.6.2)
project(GDIntercept VERSION 0.6.3)

file(GLOB_RECURSE SOURCES "src/*.cpp")
add_library(${PROJECT_NAME} SHARED ${SOURCES})
Expand Down
8 changes: 7 additions & 1 deletion mod.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"geode": "3.7.1",
"version": "v0.6.2-alpha.6",
"version": "v0.6.3-alpha.6",
"id": "smjs.gdintercept",
"name": "GDIntercept",
"api": {
Expand Down Expand Up @@ -138,6 +138,12 @@
"name": "Proxy Settings",
"description": "Settings related to the proxy server."
},
"confirm-pause-between-plays": {
"name": "Confirm Pause Between Plays",
"description": "If this is enabled, GDI will remember the pause option between session.",
"type": "bool",
"default": false
},
"cache-limit": {
"name": "Cache Limit",
"description": "The amount of requests to cache before removing the oldest one.",
Expand Down
4 changes: 4 additions & 0 deletions src/mods/MenuLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ bool ModMenuLayer::init() {
closeMenu = this->getChildByID("top-right-menu");
}

if (ProxyHandler::isPaused()) {
Warning::show();
}

menuItem->setID("GDI"_spr);
closeMenu->addChild(menuItem);
closeMenu->updateLayout();
Expand Down
2 changes: 2 additions & 0 deletions src/mods/MenuLayer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include <Geode/modify/MenuLayer.hpp>
#include "../include.hpp"
#include "../nodes/Warning.hpp"
#include "../proxy/ProxyHandler.hpp"
#include "../nodes/InterceptPopup.hpp"

class $modify(ModMenuLayer, MenuLayer) {
Expand Down
29 changes: 29 additions & 0 deletions src/nodes/Warning.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include "Warning.hpp"

CCScale9Sprite* Warning::warning = nullptr;

void Warning::show() {
ESCAPE_WHEN(Warning::warning,);
const CCSize winSize = CCDirector::sharedDirector()->getWinSize();
Warning::warning = CCScale9Sprite::create("square02_001.png");
CCLabelBMFont* label = CCLabelBMFont::create("Requests Paused", "bigFont.fnt");

label->setScale(2);
Warning::warning->setScale(0.25f);
Warning::warning->setOpacity(0x7F);
Warning::warning->setAnchorPoint(TOP_CENTER);
Warning::warning->setContentSize(label->getScaledContentSize() + ccp(PADDING, PADDING) * 4);
Warning::warning->setPosition({ winSize.width / 2, winSize.height - PADDING });
label->setPosition(Warning::warning->getContentSize() / 2);
Warning::warning->addChild(label);

ProxyHandler::pauseAll();
SceneManager::get()->keepAcrossScenes(Warning::warning);
}

void Warning::hide() {
ESCAPE_WHEN(!Warning::warning,);
SceneManager::get()->forget(Warning::warning);
Warning::warning->removeFromParent();
Warning::warning = nullptr;
}
11 changes: 11 additions & 0 deletions src/nodes/Warning.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

#include "../include.hpp"

class Warning {
public:
static void show();
static void hide();
private:
static CCScale9Sprite* warning;
};
30 changes: 5 additions & 25 deletions src/nodes/codeblock/CodeBlock.events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ const SideBar::Categories CodeBlock::actions({
} }
});

CCScale9Sprite* CodeBlock::pauseWarning = nullptr;

bool CodeBlock::acceptedPauses = false;

void CodeBlock::setup() {
Expand Down Expand Up @@ -223,7 +221,8 @@ bool CodeBlock::onSave() {

bool CodeBlock::onPause() {
if (CodeBlock::acceptedPauses) {
this->onPauseAction();
Warning::show();
this->showMessage("Requests Paused");

return true;
} else {
Expand All @@ -239,8 +238,7 @@ bool CodeBlock::onPause() {

bool CodeBlock::onResume() {
ProxyHandler::resumeAll();
SceneManager::get()->forget(CodeBlock::pauseWarning);
OPT(CodeBlock::pauseWarning)->removeFromParent();
Warning::hide();
this->showMessage("Requests Resumed");

return true;
Expand Down Expand Up @@ -325,30 +323,12 @@ void CodeBlock::onResponseHeaders() {
}
}

void CodeBlock::onPauseAction() {
const CCSize winSize = CCDirector::sharedDirector()->getWinSize();
CCLabelBMFont* label = CCLabelBMFont::create("Requests Paused", "bigFont.fnt");
CodeBlock::pauseWarning = CCScale9Sprite::create("square02_001.png");

label->setScale(2);
CodeBlock::pauseWarning->setScale(0.25f);
CodeBlock::pauseWarning->setOpacity(0x7F);
CodeBlock::pauseWarning->setAnchorPoint(TOP_CENTER);
CodeBlock::pauseWarning->setContentSize(label->getScaledContentSize() + ccp(PADDING, PADDING) * 4);
CodeBlock::pauseWarning->setPosition({ winSize.width / 2, winSize.height - PADDING });
label->setPosition(CodeBlock::pauseWarning->getContentSize() / 2);
CodeBlock::pauseWarning->addChild(label);

ProxyHandler::pauseAll();
SceneManager::get()->keepAcrossScenes(CodeBlock::pauseWarning);
this->showMessage("Requests Paused");
}

void CodeBlock::FLAlert_Clicked(FLAlertLayer* alert, const bool state) {
if (state) {
CodeBlock::acceptedPauses = true;

this->onPauseAction();
Warning::show();
this->showMessage("Requests Paused");
m_bar->reloadState();
}
}
3 changes: 1 addition & 2 deletions src/nodes/codeblock/CodeBlock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "../../include.hpp"
#include "SideBar.hpp"
#include "../Warning.hpp"
#include "cells/ViewCell.hpp"
#include "cells/ActionCell.hpp"
#include "cells/CategoryCell.hpp"
Expand All @@ -25,7 +26,6 @@ class CodeBlock : public KeybindNode<Border>, public FLAlertLayerProtocol {
private:
static const std::vector<SideBarCell::SideBarView> views;
static const SideBar::Categories actions;
static CCScale9Sprite* pauseWarning;
static bool acceptedPauses;

HttpInfo* m_info;
Expand Down Expand Up @@ -56,6 +56,5 @@ class CodeBlock : public KeybindNode<Border>, public FLAlertLayerProtocol {
void onRequestHeaders();
void onResponse();
void onResponseHeaders();
void onPauseAction();
void FLAlert_Clicked(FLAlertLayer* alert, const bool state) override;
};
6 changes: 3 additions & 3 deletions src/proxy/ProxyHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ std::deque<ProxyHandler*> proxy::ProxyHandler::cachedProxies;

std::vector<ProxyHandler*> proxy::ProxyHandler::pausedProxies;

bool proxy::ProxyHandler::paused = false;
bool proxy::ProxyHandler::paused = Mod::get()->getSettingValue<bool>("confirm-pause-between-plays") && Mod::get()->getSavedValue("paused", false);

ProxyHandler* ProxyHandler::create(CCHttpRequest* request) {
ProxyHandler* instance = new ProxyHandler(request);
Expand Down Expand Up @@ -89,12 +89,12 @@ bool ProxyHandler::isPaused() {
}

void ProxyHandler::pauseAll() {
ProxyHandler::paused = true;
Mod::get()->setSavedValue("paused", ProxyHandler::paused = true);
}

void ProxyHandler::resumeAll() {
const std::vector<ProxyHandler*> paused = std::vector<ProxyHandler*>(ProxyHandler::pausedProxies);
ProxyHandler::paused = false;
Mod::get()->setSavedValue("paused", ProxyHandler::paused = false);

std::thread([paused]{
for (ProxyHandler* proxy : paused) {
Expand Down

0 comments on commit 5853578

Please sign in to comment.