Skip to content
This repository has been archived by the owner on Aug 27, 2024. It is now read-only.

Commit

Permalink
Merge pull request #7 from dankmeme01/0.3.0
Browse files Browse the repository at this point in the history
0.3.1
  • Loading branch information
dankmeme01 authored Sep 27, 2023
2 parents 27d0337 + 1e51eea commit 75789bd
Show file tree
Hide file tree
Showing 13 changed files with 212 additions and 39 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.5.0)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

project(globed VERSION 0.3.0)
project(globed VERSION 0.3.1)

file(GLOB_RECURSE SOURCES
src/*.cpp
Expand Down
10 changes: 10 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# v0.3.1

* Hide progress indicators of other players when the progress bar is hidden
* Add an option to change the size of the progress indicator
* Add an option to show your own icon below the progress bar too
* Add lines to the progress indicators
* Add a button on the level page to open the server levels list
* Fixed a very obscure crash
* Fixed a small Mac issue

# v0.3.0

* Made it so that you can see other players move while paused (thanks mat for helping to figure it out)
Expand Down
38 changes: 36 additions & 2 deletions mod.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"geode": "1.3.0",
"version": "0.3.0",
"version": "0.3.1",
"id": "dankmeme.globed",
"name": "Globed",
"developer": "dankmeme",
Expand Down Expand Up @@ -103,7 +103,41 @@
"name": "Player progress",
"type": "bool",
"default": true,
"description": "Shows an icon of a player below your <cj>progress bar</c>, indicating how far the player is into the level.s"
"description": "Shows an icon of a player below your <cj>progress bar</c>, indicating how far the player is into the level."
},
"show-progress-self": {
"name": "Self progress",
"type": "bool",
"default": true,
"description": "Shows your icon under the <cj>progress bar</c> as well, along with other players."
},
"show-progress-scale": {
"name": "Progress scale",
"type": "float",
"default": 1.0,
"min": 0.1,
"max": 2.0,
"description": "If <cy>Player progress</c> is <cg>enabled</c>, this defines the <cj>size</c> of the cube icon below the progress bar.",
"control": {
"slider": true,
"slider-step": 0.01,
"arrows": true,
"big-arrows": false
}
},
"show-progress-offset": {
"name": "Progress offset",
"type": "int",
"default": -5,
"min": -20,
"max": 20,
"description": "If <cy>Player progress</c> is <cg>enabled</c>, higher values will move the <cj>cube icon</c> of every player closer to the <cy>center of the screen</c>.",
"control": {
"slider": true,
"slider-step": 1,
"arrows": true,
"big-arrows": false
}
},
"old-progress": {
"name": "Old progress",
Expand Down
4 changes: 4 additions & 0 deletions src/data/settings_game.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@ struct GlobedGameSettings {
bool displayProgress;
bool newProgress;
unsigned char playerOpacity;
float progressScale;
bool showSelfProgress;
float progressOffset;

RemotePlayerSettings rpSettings;
};
2 changes: 0 additions & 2 deletions src/hooked/error_check_layer_hooks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <Geode/modify/LevelSearchLayer.hpp>
#include <Geode/modify/LeaderboardsLayer.hpp>
#include <Geode/modify/GJGarageLayer.hpp>
#include <Geode/modify/LevelInfoLayer.hpp>
#include <Geode/modify/EditLevelLayer.hpp>
#include <Geode/modify/LevelEditorLayer.hpp>

Expand Down Expand Up @@ -50,7 +49,6 @@ GENERATE_ERROR_CHECK_HOOK_ARG1(LevelBrowserLayer, GJSearchObject*)
GENERATE_ERROR_CHECK_HOOK(LevelSearchLayer)
GENERATE_ERROR_CHECK_HOOK_ARG1(LeaderboardsLayer, LeaderboardState)
GENERATE_ERROR_CHECK_HOOK(GJGarageLayer)
GENERATE_ERROR_CHECK_HOOK_ARG1(LevelInfoLayer, GJGameLevel*)
GENERATE_ERROR_CHECK_HOOK_ARG1(EditLevelLayer, GJGameLevel*)
GENERATE_ERROR_CHECK_HOOK_ARG1(LevelEditorLayer, GJGameLevel*)

Expand Down
1 change: 1 addition & 0 deletions src/hooked/hooked.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
#include "play_layer.hpp"
#include "pause_layer.hpp"
#include "gj_base_game_layer.hpp"
#include "level_info_layer.hpp"

#include "error_check_layer_hooks.hpp"
45 changes: 45 additions & 0 deletions src/hooked/level_info_layer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include <Geode/Geode.hpp>
#include <Geode/modify/LevelInfoLayer.hpp>

#include <global_data.hpp>
#include <ui/levels/globed_levels_layer.hpp>

class $modify(ModifiedLevelInfoLayer, LevelInfoLayer) {
bool init(GJGameLevel* level) {
if (!LevelInfoLayer::init(level)) return false;

if (!g_networkHandler->established()) {
return true;
}

auto backMenu = getChildByID("left-side-menu");

// add a button for viewing levels
auto levelsSprite = CircleButtonSprite::createWithSpriteFrameName("menuicon.png"_spr, 1.f, CircleBaseColor::Green, CircleBaseSize::Medium);
// levelsSprite->setScale(0.8f);
auto levelsButton = CCMenuItemSpriteExtra::create(levelsSprite, this, menu_selector(ModifiedLevelInfoLayer::onOpenLevelsButton));
backMenu->addChild(levelsButton);

backMenu->updateLayout();

// error checking
CCScheduler::get()->scheduleSelector(schedule_selector(ModifiedLevelInfoLayer::checkErrors), this, 0.1f, false);

return true;
}

void onOpenLevelsButton(CCObject* sender) {
auto director = CCDirector::get();
auto layer = GlobedLevelsLayer::create();
layer->setID("dankmeme.globed/layer-globed-levels");

auto destScene = globed_util::sceneWithLayer(layer);

auto transition = CCTransitionFade::create(0.5f, destScene);
director->pushScene(transition);
}

void checkErrors(float dt) {
globed_util::handleErrors();
}
};
103 changes: 78 additions & 25 deletions src/hooked/play_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class $modify(ModifiedPlayLayer, PlayLayer) {
float m_ptTimestamp = 0.0;
bool m_wasSpectating;

PlayerProgressNew* m_selfProgress = nullptr;

// settings
GlobedGameSettings m_settings;

Expand All @@ -46,6 +48,9 @@ class $modify(ModifiedPlayLayer, PlayLayer) {
.displayProgress = Mod::get()->getSettingValue<bool>("show-progress"),
.newProgress = !Mod::get()->getSettingValue<bool>("old-progress"),
.playerOpacity = static_cast<unsigned char>(Mod::get()->getSettingValue<int64_t>("player-opacity")),
.progressScale = static_cast<float>(Mod::get()->getSettingValue<double>("show-progress-scale")),
.showSelfProgress = Mod::get()->getSettingValue<bool>("show-progress-self"),
.progressOffset = static_cast<float>(Mod::get()->getSettingValue<int64_t>("show-progress-offset")),
.rpSettings = RemotePlayerSettings {
.defaultMiniIcons = Mod::get()->getSettingValue<bool>("default-mini-icon"),
.practiceIcon = Mod::get()->getSettingValue<bool>("practice-icon"),
Expand All @@ -72,9 +77,14 @@ class $modify(ModifiedPlayLayer, PlayLayer) {
// use a workaround for it
// thanks mat <3
Loader::get()->queueInMainThread([=] {
this->getParent()->schedule(schedule_selector(ModifiedPlayLayer::sendPlayerData), m_fields->m_targetUpdateDelay);
this->getParent()->schedule(schedule_selector(ModifiedPlayLayer::updateStuff), 1.0f);
this->getParent()->schedule(schedule_selector(ModifiedPlayLayer::updateTick), 0.f);
auto parent = this->getParent();
if (parent == nullptr) {
log::debug("hey ca7x3 you broke things again :(");
return;
}
parent->schedule(schedule_selector(ModifiedPlayLayer::sendPlayerData), m_fields->m_targetUpdateDelay);
parent->schedule(schedule_selector(ModifiedPlayLayer::updateStuff), 1.0f);
parent->schedule(schedule_selector(ModifiedPlayLayer::updateTick), 0.f);
});
}

Expand Down Expand Up @@ -110,6 +120,17 @@ class $modify(ModifiedPlayLayer, PlayLayer) {
this->addChild(m_fields->m_overlay);
}

// add self progress
if (m_fields->m_settings.showSelfProgress && m_fields->m_settings.displayProgress) {
m_fields->m_selfProgress = PlayerProgressNew::create(0, m_fields->m_settings.progressOffset);
m_fields->m_selfProgress->setIconScale(0.55f * m_fields->m_settings.progressScale);
m_fields->m_selfProgress->setZOrder(9);
m_fields->m_selfProgress->setID("dankmeme.globed/player-progress-self");
m_fields->m_selfProgress->setAnchorPoint({0.f, 1.f});
m_fields->m_selfProgress->updateData(*g_accountData.lock());
this->addChild(m_fields->m_selfProgress);
}

return true;
}

Expand All @@ -126,14 +147,14 @@ class $modify(ModifiedPlayLayer, PlayLayer) {
if (!g_networkHandler->established())
return;

if (!self->m_isDead && self->m_fields->m_markedDead) {
self->m_fields->m_markedDead = false;
}
// if (!self->m_isDead && self->m_fields->m_markedDead) {
// self->m_fields->m_markedDead = false;
// }

if (self->m_isDead && !self->m_fields->m_markedDead) {
self->sendMessage(NMPlayerDied {});
self->m_fields->m_markedDead = true;
}
// if (self->m_isDead && !self->m_fields->m_markedDead) {
// self->sendMessage(NMPlayerDied {});
// self->m_fields->m_markedDead = true;
// }

// update everyone
for (const auto &[key, players] : self->m_fields->m_players) {
Expand Down Expand Up @@ -171,6 +192,8 @@ class $modify(ModifiedPlayLayer, PlayLayer) {
self->leaveSpectate();
}

self->updateSelfProgress();

if (g_debug) {
self->m_player1->setOpacity(64);
self->m_player2->setOpacity(64);
Expand Down Expand Up @@ -242,7 +265,7 @@ class $modify(ModifiedPlayLayer, PlayLayer) {
void updateProgress(int playerId, const std::pair<RemotePlayer*, RemotePlayer*>& players) {
auto playerPos = players.first->getPosition();
auto progress = m_fields->m_playerProgresses.at(playerId);
float progressVal = playerPos.x / m_levelLength;
float progressVal = std::clamp(playerPos.x / m_levelLength, 0.0f, 0.99f);

if (progress->m_isDefault) {
auto cache = g_accDataCache.lock();
Expand All @@ -254,17 +277,14 @@ class $modify(ModifiedPlayLayer, PlayLayer) {
// new progress
if (m_fields->m_settings.newProgress) {
auto progressBar = m_sliderGrooveSprite;
if (!progressBar || !progressBar->isVisible()) return;

auto pbSize = progressBar->getScaledContentSize();
auto pbBase = progressBar->getPositionX() - pbSize.width / 2;
auto prOffset = pbSize.width * progressVal;
auto prPos = pbBase + prOffset;
progress->setPosition({
prPos,
CCDirector::get()->getWinSize().height - pbSize.height - 10.f,
});
progress->updateValues(progressVal * 100, false); // onrightside is unused here
if (!progressBar || !progressBar->isVisible()) {
progress->setVisible(false);
return;
};

progress->setVisible(true);

updateNewProgress(progressVal, static_cast<PlayerProgressNew*>(progress));
} else { // old progress
if (!isPlayerVisible(players.first->getPosition()) || g_debug) {
bool onRightSide = playerPos.x > m_player1->getPositionX();
Expand All @@ -284,6 +304,37 @@ class $modify(ModifiedPlayLayer, PlayLayer) {
}
}

void updateSelfProgress() {
if (!m_fields->m_selfProgress) return;
auto progress = m_fields->m_selfProgress;

auto progressBar = m_sliderGrooveSprite;
if (!progressBar || !progressBar->isVisible()) {
progress->setVisible(false);
return;
}

progress->setVisible(true);
updateNewProgress(std::clamp(m_player1->getPositionX() / m_levelLength, 0.0f, 0.99f), progress);
}

// progressVal is between 0.f and 1.f
void updateNewProgress(float progressVal, PlayerProgressNew* progress) {
auto progressBar = m_sliderGrooveSprite;
auto pbSize = progressBar->getScaledContentSize();
auto pbBase = progressBar->getPositionX() - pbSize.width / 2;
auto prOffset = pbSize.width * progressVal;
auto prPos = pbBase + prOffset;

const float pbBorder = 4.f;
progress->setPosition({
prPos,
CCDirector::get()->getWinSize().height,
});

progress->updateValues(progressVal * 100, false); // onrightside is unused here
}

bool isPlayerVisible(CCPoint nodePosition) {
auto camera = m_pCamera;
auto cameraPosition = m_cameraPosition;
Expand Down Expand Up @@ -316,13 +367,15 @@ class $modify(ModifiedPlayLayer, PlayLayer) {
// note - playerprogress must be initialized here, before locking g_accDataCache
PlayerProgressBase* progress;
if (m_fields->m_settings.newProgress) {
progress = PlayerProgressNew::create(playerId);
progress->setScale(0.6f);
progress = PlayerProgressNew::create(playerId, m_fields->m_settings.progressOffset);
progress->setAnchorPoint({0.f, 1.f});
static_cast<PlayerProgressNew*>(progress)->setIconScale(0.55f * m_fields->m_settings.progressScale);
} else {
progress = PlayerProgress::create(playerId);
progress->setScale(1.0f * m_fields->m_settings.progressScale);
}

progress->setZOrder(99);
progress->setZOrder(9);
progress->setID(fmt::format("dankmeme.globed/player-progress-{}", playerId));
if (!m_fields->m_settings.displayProgress) {
progress->setVisible(false);
Expand Down
2 changes: 1 addition & 1 deletion src/net/udp_socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ bool UdpSocket::poll(long msDelay) {

int result = select(0, &readSet, NULL, NULL, &timeout);
#ifdef GEODE_IS_MACOS
if (result == 1) {
if (result == -1) {
#else
if (result == SOCKET_ERROR) {
#endif
Expand Down
2 changes: 0 additions & 2 deletions src/ui/game/player_progress_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
using namespace geode::prelude;

class PlayerProgressBase : public CCNode {
protected:
virtual bool init(int playerId_) = 0;
public:
bool m_isDefault;
// updateValues updates the percentage values and the position
Expand Down
Loading

0 comments on commit 75789bd

Please sign in to comment.