mirror of
https://github.com/ninjamuffin99/Funkin.git
synced 2025-03-21 01:19:26 +00:00
finalize prompts and uix
This commit is contained in:
parent
80e7539deb
commit
e6b9ec2100
20
Project.xml
20
Project.xml
|
@ -113,7 +113,7 @@
|
|||
|
||||
<!--In case you want to use the ui package-->
|
||||
<haxelib name="flixel-ui" />
|
||||
<haxelib name="newgrounds"/>
|
||||
<haxelib name="newgrounds" unless="switch"/>
|
||||
<haxelib name="faxe" if='switch'/>
|
||||
<haxelib name="polymod"/>
|
||||
<!-- <haxelib name="hxcpp-debug-server" if="desktop"/> -->
|
||||
|
@ -167,11 +167,17 @@
|
|||
|
||||
<!-- <haxedef name="SKIP_TO_PLAYSTATE" if="debug" /> -->
|
||||
|
||||
<!-- Enables Ng.core.verbose -->
|
||||
<!-- <haxedef name="NG_VERBOSE" /> -->
|
||||
<!-- Enables a NG debug session, so medals don't permently unlock -->
|
||||
<!-- <haxedef name="NG_DEBUG" /> -->
|
||||
<!-- pretends that the saved session Id was expired, forcing the reconnect prompt -->
|
||||
<!-- <haxedef name="NG_FORCE_EXPIRED_SESSION" if="debug" /> -->
|
||||
<haxedef name="CAN_OPEN_LINKS" unless="switch"/>
|
||||
|
||||
<section if="newgrounds">
|
||||
<!-- Enables Ng.core.verbose -->
|
||||
<haxedef name="NG_VERBOSE" />
|
||||
|
||||
<!-- Enables a NG debug session, so medals don't permently unlock -->
|
||||
<!-- <haxedef name="NG_DEBUG" /> -->
|
||||
|
||||
<!-- pretends that the saved session Id was expired, forcing the reconnect prompt -->
|
||||
<!-- <haxedef name="NG_FORCE_EXPIRED_SESSION" if="debug" /> -->
|
||||
</section>
|
||||
|
||||
</project>
|
||||
|
|
|
@ -211,9 +211,7 @@ class FreeplayState extends MusicBeatState
|
|||
if (curDifficulty > 2)
|
||||
curDifficulty = 0;
|
||||
|
||||
#if !switch
|
||||
intendedScore = Highscore.getScore(songs[curSelected], curDifficulty);
|
||||
#end
|
||||
|
||||
switch (curDifficulty)
|
||||
{
|
||||
|
@ -228,9 +226,7 @@ class FreeplayState extends MusicBeatState
|
|||
|
||||
function changeSelection(change:Int = 0)
|
||||
{
|
||||
#if !switch
|
||||
NGio.logEvent('Fresh');
|
||||
#end
|
||||
|
||||
// NGio.logEvent('Fresh');
|
||||
FlxG.sound.play(Paths.sound('scrollMenu'), 0.4);
|
||||
|
@ -244,10 +240,8 @@ class FreeplayState extends MusicBeatState
|
|||
|
||||
// selector.y = (70 * curSelected) + 30;
|
||||
|
||||
#if !switch
|
||||
intendedScore = Highscore.getScore(songs[curSelected], curDifficulty);
|
||||
// lerpScore = 0;
|
||||
#end
|
||||
|
||||
#if PRELOAD_ALL
|
||||
FlxG.sound.playMusic(Paths.inst(songs[curSelected]), 0);
|
||||
|
|
|
@ -13,51 +13,55 @@ class Highscore
|
|||
|
||||
public static function saveScore(song:String, score:Int = 0, ?diff:Int = 0):Void
|
||||
{
|
||||
var daSong:String = formatSong(song, diff);
|
||||
var formattedSong:String = formatSong(song, diff);
|
||||
|
||||
|
||||
#if !switch
|
||||
#if newgrounds
|
||||
NGio.postScore(score, song);
|
||||
#end
|
||||
|
||||
|
||||
if (songScores.exists(daSong))
|
||||
if (songScores.exists(formattedSong))
|
||||
{
|
||||
if (songScores.get(daSong) < score)
|
||||
setScore(daSong, score);
|
||||
if (songScores.get(formattedSong) < score)
|
||||
setScore(formattedSong, score);
|
||||
}
|
||||
else
|
||||
setScore(daSong, score);
|
||||
setScore(formattedSong, score);
|
||||
}
|
||||
|
||||
public static function saveWeekScore(week:Int = 1, score:Int = 0, ?diff:Int = 0):Void
|
||||
{
|
||||
|
||||
#if !switch
|
||||
#if newgrounds
|
||||
NGio.postScore(score, "Week " + week);
|
||||
#end
|
||||
|
||||
var formattedSong:String = formatSong('week' + week, diff);
|
||||
|
||||
var daWeek:String = formatSong('week' + week, diff);
|
||||
|
||||
if (songScores.exists(daWeek))
|
||||
if (songScores.exists(formattedSong))
|
||||
{
|
||||
if (songScores.get(daWeek) < score)
|
||||
setScore(daWeek, score);
|
||||
if (songScores.get(formattedSong) < score)
|
||||
setScore(formattedSong, score);
|
||||
}
|
||||
else
|
||||
setScore(daWeek, score);
|
||||
setScore(formattedSong, score);
|
||||
}
|
||||
|
||||
/**
|
||||
* YOU SHOULD FORMAT SONG WITH formatSong() BEFORE TOSSING IN SONG VARIABLE
|
||||
*/
|
||||
static function setScore(song:String, score:Int):Void
|
||||
static function setScore(formattedSong:String, score:Int):Void
|
||||
{
|
||||
/** GeoKureli
|
||||
* References to Highscore were wrapped in `#if !switch` blocks. I wasn't sure if this
|
||||
* is because switch doesn't use NGio, or because switch has a different saving method.
|
||||
* I moved the compiler flag here, rather than using it everywhere else.
|
||||
*/
|
||||
#if !switch
|
||||
|
||||
// Reminder that I don't need to format this song, it should come formatted!
|
||||
songScores.set(song, score);
|
||||
songScores.set(formattedSong, score);
|
||||
FlxG.save.data.songScores = songScores;
|
||||
FlxG.save.flush();
|
||||
#end
|
||||
}
|
||||
|
||||
public static function formatSong(song:String, diff:Int):String
|
||||
|
|
|
@ -15,7 +15,6 @@ import flixel.tweens.FlxEase;
|
|||
import flixel.tweens.FlxTween;
|
||||
import flixel.util.FlxColor;
|
||||
import flixel.util.FlxTimer;
|
||||
import io.newgrounds.NG;
|
||||
import lime.app.Application;
|
||||
|
||||
import ui.MenuItemList;
|
||||
|
@ -81,11 +80,11 @@ class MainMenuState extends MusicBeatState
|
|||
menuItems.createItem('story mode', function () startExitState(new StoryMenuState()));
|
||||
menuItems.createItem('freeplay', function () startExitState(new FreeplayState()));
|
||||
// addMenuItem('options', function () startExitState(new OptionMenu()));
|
||||
#if (!switch)
|
||||
#if CAN_OPEN_LINKS
|
||||
menuItems.createItem('donate', selectDonate, hasPopupBlocker);
|
||||
#end
|
||||
#if newgrounds
|
||||
if (NG.core.loggedIn)
|
||||
if (NGio.isLoggedIn)
|
||||
menuItems.createItem("logout", selectLogout);
|
||||
else
|
||||
menuItems.createItem("login", selectLogin);
|
||||
|
@ -119,8 +118,10 @@ class MainMenuState extends MusicBeatState
|
|||
|
||||
menuItems.enabled = true;
|
||||
|
||||
#if newgrounds
|
||||
if (NGio.savedSessionFailed)
|
||||
showSavedSessionFailed();
|
||||
#end
|
||||
}
|
||||
|
||||
function onMenuItemChange(selected:MenuItem)
|
||||
|
@ -150,32 +151,37 @@ class MainMenuState extends MusicBeatState
|
|||
|
||||
function showNgPrompt(fromUi:Bool)
|
||||
{
|
||||
menuItems.enabled = false;
|
||||
|
||||
var prompt = new Prompt("prompt-ng_login", "Talking to server...", None);
|
||||
prompt.closeCallback = function() menuItems.enabled = true;
|
||||
var prompt = createNGPrompt("Talking to server...", None);
|
||||
openSubState(prompt);
|
||||
function onLoginComplete(result:ConnectionResult)
|
||||
{
|
||||
switch (result)
|
||||
{
|
||||
case Success:
|
||||
{
|
||||
menuItems.resetItem("login", "logout", selectLogout);
|
||||
prompt.setText("Login Successful");
|
||||
prompt.setButtons(Ok);
|
||||
prompt.onYes = prompt.close;
|
||||
}
|
||||
case Fail(msg):
|
||||
{
|
||||
trace("Login Error:" + msg);
|
||||
prompt.setText("Login failed");
|
||||
prompt.setButtons(Ok);
|
||||
prompt.onYes = prompt.close;
|
||||
}
|
||||
case Cancelled:
|
||||
{
|
||||
if (prompt != null)
|
||||
{
|
||||
prompt.setText("Login cancelled by user");
|
||||
prompt.setButtons(Ok);
|
||||
prompt.onYes = prompt.close;
|
||||
}
|
||||
else
|
||||
trace("Login cancelled via prompt");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -196,7 +202,7 @@ class MainMenuState extends MusicBeatState
|
|||
#end
|
||||
prompt.onYes = function()
|
||||
{
|
||||
prompt.setText("Connecting...");
|
||||
prompt.setText("Connecting..." #if web + "\n(check your popup blocker)" #end);
|
||||
prompt.setButtons(None);
|
||||
openPassportUrl();
|
||||
};
|
||||
|
@ -204,7 +210,7 @@ class MainMenuState extends MusicBeatState
|
|||
{
|
||||
prompt.close();
|
||||
prompt = null;
|
||||
NG.core.cancelLoginRequest();
|
||||
NGio.cancelLogin();
|
||||
};
|
||||
}
|
||||
else
|
||||
|
@ -219,9 +225,8 @@ class MainMenuState extends MusicBeatState
|
|||
|
||||
function selectLogout()
|
||||
{
|
||||
menuItems.enabled = false;
|
||||
var prompt = new Prompt("prompt-ng_login", "Log out of " + NG.core.user.name + "?", Yes_No);
|
||||
prompt.closeCallback = function () menuItems.enabled = true;
|
||||
var user = io.newgrounds.NG.core.user.name;
|
||||
var prompt = createNGPrompt('Log out of $user?', Yes_No);
|
||||
prompt.onYes = function()
|
||||
{
|
||||
NGio.logout();
|
||||
|
@ -231,6 +236,22 @@ class MainMenuState extends MusicBeatState
|
|||
prompt.onNo = prompt.close;
|
||||
openSubState(prompt);
|
||||
}
|
||||
|
||||
public function createNGPrompt(text:String, style:ButtonStyle = Yes_No)
|
||||
{
|
||||
var oldAutoPause = FlxG.autoPause;
|
||||
FlxG.autoPause = false;
|
||||
menuItems.enabled = false;
|
||||
|
||||
var prompt = new Prompt("prompt-ng_login", text, style);
|
||||
prompt.closeCallback = function ()
|
||||
{
|
||||
menuItems.enabled = true;
|
||||
FlxG.autoPause = oldAutoPause;
|
||||
}
|
||||
|
||||
return prompt;
|
||||
}
|
||||
#end
|
||||
|
||||
function startExitState(state:FlxState)
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
package;
|
||||
#if newgrounds
|
||||
|
||||
import flixel.FlxG;
|
||||
import flixel.util.FlxSignal;
|
||||
|
@ -17,19 +18,24 @@ import lime.app.Application;
|
|||
import openfl.display.Stage;
|
||||
|
||||
using StringTools;
|
||||
|
||||
#end
|
||||
/**
|
||||
* MADE BY GEOKURELI THE LEGENED GOD HERO MVP
|
||||
*/
|
||||
class NGio
|
||||
{
|
||||
#if newgrounds
|
||||
/**
|
||||
* True, if the saved sessionId was used in the initial login, and failed to connect.
|
||||
* Used in MainMenuState to show a popup to establish a new connection
|
||||
*/
|
||||
public static var savedSessionFailed(default, null):Bool = false;
|
||||
public static var isLoggedIn:Bool = false;
|
||||
public static var scoreboardsLoaded:Bool = false;
|
||||
public static var isLoggedIn(get, never):Bool;
|
||||
inline static function get_isLoggedIn()
|
||||
{
|
||||
return NG.core != null && NG.core.loggedIn;
|
||||
}
|
||||
|
||||
public static var scoreboardArray:Array<Score> = [];
|
||||
|
||||
|
@ -38,7 +44,6 @@ class NGio
|
|||
|
||||
public static var GAME_VER:String = "";
|
||||
|
||||
|
||||
static public function checkVersion(callback:String->Void)
|
||||
{
|
||||
trace('checking NG.io version');
|
||||
|
@ -54,7 +59,7 @@ class NGio
|
|||
.send();
|
||||
}
|
||||
|
||||
static public function init(api:String, encKey:String)
|
||||
static public function init()
|
||||
{
|
||||
var api = APIStuff.API;
|
||||
if (api == null || api.length == 0)
|
||||
|
@ -149,11 +154,15 @@ class NGio
|
|||
|
||||
NG.core.requestLogin(onSuccess, onPending, onFail, onCancel);
|
||||
}
|
||||
|
||||
inline static public function cancelLogin():Void
|
||||
{
|
||||
NG.core.cancelLoginRequest();
|
||||
}
|
||||
|
||||
static function onNGLogin():Void
|
||||
{
|
||||
trace('logged in! user:${NG.core.user.name}');
|
||||
isLoggedIn = true;
|
||||
FlxG.save.data.sessionId = NG.core.sessionId;
|
||||
FlxG.save.flush();
|
||||
// Load medals then call onNGMedalFetch()
|
||||
|
@ -216,24 +225,6 @@ class NGio
|
|||
// more info on scores --- http://www.newgrounds.io/help/components/#scoreboard-getscores
|
||||
}
|
||||
|
||||
inline static public function postScore(score:Int = 0, song:String)
|
||||
{
|
||||
if (isLoggedIn)
|
||||
{
|
||||
for (id in NG.core.scoreBoards.keys())
|
||||
{
|
||||
var board = NG.core.scoreBoards.get(id);
|
||||
|
||||
if (song == board.name)
|
||||
{
|
||||
board.postScore(score, "Uhh meow?");
|
||||
}
|
||||
|
||||
// trace('loaded scoreboard id:$id, name:${board.name}');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static function onNGScoresFetch():Void
|
||||
{
|
||||
scoreboardsLoaded = true;
|
||||
|
@ -252,21 +243,52 @@ class NGio
|
|||
|
||||
// NGio.scoreboardArray = NG.core.scoreBoards.get(8004).scores;
|
||||
}
|
||||
#end
|
||||
|
||||
inline static public function logEvent(event:String)
|
||||
static public function logEvent(event:String)
|
||||
{
|
||||
#if newgrounds
|
||||
NG.core.calls.event.logEvent(event).send();
|
||||
trace('should have logged: ' + event);
|
||||
#else
|
||||
#if debug trace('event:$event - not logged, missing NG.io lib'); #end
|
||||
#end
|
||||
}
|
||||
|
||||
inline static public function unlockMedal(id:Int)
|
||||
static public function unlockMedal(id:Int)
|
||||
{
|
||||
#if newgrounds
|
||||
if (isLoggedIn)
|
||||
{
|
||||
var medal = NG.core.medals.get(id);
|
||||
if (!medal.unlocked)
|
||||
medal.sendUnlock();
|
||||
}
|
||||
#else
|
||||
#if debug trace('medal:$id - not unlocked, missing NG.io lib'); #end
|
||||
#end
|
||||
}
|
||||
|
||||
static public function postScore(score:Int = 0, song:String)
|
||||
{
|
||||
#if newgrounds
|
||||
if (isLoggedIn)
|
||||
{
|
||||
for (id in NG.core.scoreBoards.keys())
|
||||
{
|
||||
var board = NG.core.scoreBoards.get(id);
|
||||
|
||||
if (song == board.name)
|
||||
{
|
||||
board.postScore(score, "Uhh meow?");
|
||||
}
|
||||
|
||||
// trace('loaded scoreboard id:$id, name:${board.name}');
|
||||
}
|
||||
}
|
||||
#else
|
||||
#if debug trace('Song:$song, Score:$score - not posted, missing NG.io lib'); #end
|
||||
#end
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -93,9 +93,7 @@ class OptionsMenu extends MusicBeatState
|
|||
|
||||
function changeSelection(change:Int = 0)
|
||||
{
|
||||
#if !switch
|
||||
NGio.logEvent('Fresh');
|
||||
#end
|
||||
|
||||
FlxG.sound.play(Paths.sound('scrollMenu'), 0.4);
|
||||
|
||||
|
|
|
@ -1604,9 +1604,7 @@ class PlayState extends MusicBeatState
|
|||
vocals.volume = 0;
|
||||
if (SONG.validScore)
|
||||
{
|
||||
#if !switch
|
||||
Highscore.saveScore(SONG.song, songScore, storyDifficulty);
|
||||
#end
|
||||
}
|
||||
|
||||
if (isStoryMode)
|
||||
|
|
|
@ -352,10 +352,6 @@ class StoryMenuState extends MusicBeatState
|
|||
sprDifficulty.y = leftArrow.y - 15;
|
||||
intendedScore = Highscore.getWeekScore(curWeek, curDifficulty);
|
||||
|
||||
#if !switch
|
||||
intendedScore = Highscore.getWeekScore(curWeek, curDifficulty);
|
||||
#end
|
||||
|
||||
FlxTween.tween(sprDifficulty, {y: leftArrow.y + 15, alpha: 1}, 0.07);
|
||||
}
|
||||
|
||||
|
@ -431,8 +427,6 @@ class StoryMenuState extends MusicBeatState
|
|||
txtTracklist.screenCenter(X);
|
||||
txtTracklist.x -= FlxG.width * 0.35;
|
||||
|
||||
#if !switch
|
||||
intendedScore = Highscore.getWeekScore(curWeek, curDifficulty);
|
||||
#end
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@ import flixel.tweens.FlxEase;
|
|||
import flixel.tweens.FlxTween;
|
||||
import flixel.util.FlxColor;
|
||||
import flixel.util.FlxTimer;
|
||||
import io.newgrounds.NG;
|
||||
import lime.app.Application;
|
||||
import openfl.Assets;
|
||||
|
||||
|
@ -56,9 +55,11 @@ class TitleState extends MusicBeatState
|
|||
|
||||
FlxG.save.bind('funkin', 'ninjamuffin99');
|
||||
Highscore.load();
|
||||
|
||||
NGio.init(APIStuff.API, APIStuff.EncKey);
|
||||
|
||||
|
||||
#if newgrounds
|
||||
NGio.init();
|
||||
#end
|
||||
|
||||
if (FlxG.save.data.weekUnlocked != null)
|
||||
{
|
||||
// FIX LATER!!!
|
||||
|
@ -242,13 +243,11 @@ class TitleState extends MusicBeatState
|
|||
|
||||
if (pressedEnter && !transitioning && skippedIntro)
|
||||
{
|
||||
#if !switch
|
||||
NGio.unlockMedal(60960);
|
||||
|
||||
// If it's Friday according to da clock
|
||||
if (Date.now().getDay() == 5)
|
||||
NGio.unlockMedal(61034);
|
||||
#end
|
||||
|
||||
titleText.animation.play('press');
|
||||
|
||||
|
@ -258,6 +257,7 @@ class TitleState extends MusicBeatState
|
|||
transitioning = true;
|
||||
// FlxG.sound.music.stop();
|
||||
|
||||
#if newgrounds
|
||||
if (!OutdatedSubState.leftState)
|
||||
{
|
||||
NGio.checkVersion(function(version)
|
||||
|
@ -278,6 +278,9 @@ class TitleState extends MusicBeatState
|
|||
}
|
||||
});
|
||||
}
|
||||
#else
|
||||
FlxG.switchState(new MainMenuState());
|
||||
#end
|
||||
// FlxG.sound.play(Paths.music('titleShoot'), 0.7);
|
||||
}
|
||||
|
||||
|
|
|
@ -114,7 +114,8 @@ class MenuTypedItemList<T:MenuItem> extends FlxTypedGroup<T>
|
|||
if (controls.RIGHT_P || controls.DOWN_P) next();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Todo: bypass popup blocker on firefox
|
||||
if (controls.ACCEPT)
|
||||
accept();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue