ComboMeter - Ranking Screen

ComboMeter - Ranking Screen

How does it work?

As shown above, the Rank screen works as  follows -

Stats

The Stats and BonusAndPenaltyItems are the two variables on the StageClearWidget you will primarily access.

As the name suggests, these arrays contains the list of stats(eg. Score, Clear time etc) and bonus/penalites(eg number of deaths, no items used etc) you want your player to be ranked on. You can have any stats you desire as these are fully configurable.


Ranker

Once you have decided upon what stats you should have for your game, now you need to decide how you want to calculate the player rank(A, B, C etc) based on these. You do this be providing one of the many strategies for ranking by configuring a ranker for each stat. 

The different types of Ranker available are - 

Each Ranker lets you configure how to map the score a player achieved to a particular Rank(A, B, C etc).


For example, if you want to rank a player score time like this -

You associate a LinearRanker with this stat configuring the maximum number Ranks, max score etc and let the computation be handled by the StageClearWidget. See below for a more detailed  demo.

Stage Clear Item Widgets

The StageClearItemWidget is how you actually show the stats on the screen. Each stat will be displayed in its own StageClearItemWidget along with the Rank.

You can configure Lifecycle(Init, Ranked, Exit) animations for these widget. Once configured these animations will be played when the StageClearWidget goes through the individual stats.


The score displayed on the screen with the StageClearItem widget is lerped from 0 to the actual value and once completed the OnItemRankComputed event will be triggered which can be used, for example, playing Rank animations etc. See below for an example.

With all these configured, you start the StageClearWidget by calling Activate on it after adding it to the viewport. And you can play the exit animations by calling Deactivate on it.

Creating a sample Ranking screen

Steps Involved for Creating a Ranking Screen

The StageClearWidget Is the widget that actually manages all the functionality of the Ranking Screen.

It takes care of adding the StageClearWidgetItems to the screen, manages their lifecycle animations etc.

You need to configure two canvas panels in the StageClearWidget - one to display your main stats and one to display any bonus and penalties.

Important: You need to name the CanvasPanels you have added for holding the main stats as Root and the one used to hold the bonus and penalties as BonusAndPenalty. The StageClearWidget looks for these to panels to add the widgets on the screen.


2. Create the StageClearItemWidgets

The StageClearItemWidget is the widget that displays your individual Stat or BonusAndPenalty items you want for your game. For eg. You can have stats such as clear time, score achieved and BonusAndPenalty such as number of deaths, retries for Penalties and Headshots, no items used for bonuses. Technically, there is difference between stats or bonus and penalties other than penalties will have most likely negative score where the stats and bonuses will have postive socre.


Since the Stats and BonusAndPenalties will look very similar, to reduce the amount of work, I recommend to create a base StageClearItemWidget with all the structure and style you need for your individual items with variables exposed to customize your individual items.

To facilitate this there is already a sample StageClearItemWidget provided in the plugin that you can extend as per your needs.

In the demo video, I extend the StageClearItemBaseBP provided along with the plugin to create my own ClearTimeStageClearItemBP widget. I also override the GetStatText BP function to convert the score that will be in seconds to display time in the format HH:MM:SS.

In a similar fasion, you can create StageClearItemWidgets for other stats such as Score Achieved, Enemies Killed etc


3. Create the Rankers

As mentioned above, Rankers actually determine how a score should be ranked from D-SSS(or whathever the ranks you have for your game).

For the ClearTimeStageClearItemBP I just created, I will create a CurveBasedRanker that uses the CurveFloat provided to it to rank the score achieved. I'm going to use the curve already provided in the plugin for a similar example StageClearItemBP in the examples provided along with the plugin.

Similarly, I created a LinearRanker for enemies killed and LogarithmicRanker for score achieved. You can find the details on how these work below.

4. Putting it all together

Now you have all the individual parts to put together a ranking screen. 

Let's assume you have varialbes setup in your PlayerController for each of the stat you want to rank your player on. When you want to show the rank screens, let's say at the end of your level, you will need to - 

5. Final Rank

Once all the Stats are displayed, then the StageClearWidget emits the final Rank computed based on the provided Stats. Again, you can customize the final rank in a few ways

This is suitable when you have items in your stat that aren't ranked(e.g, a negative stat for using revival items). To used this method, check the Compute the final rank based on the total score flag on the StageClearWidget and provide a suitable Ranker for computing the rank based on the total score(sum of all the indivual Stats)

This is suitable if all the stats and bonus and penalties you have for your game can be ranked. Then, the final rank will be the average of the individual ranks. To use this method, uncheck the Compute the final rank based on the total score flag on the StageClearWidget

Override the ComputeFinalRank on your StageClearWidget to provide custom ranking strategy.


See the implementation details in the demo

Lifecycle Animations

If you look at the example Ranking widget provided in the plugins directory, you will see that there are three ways in which you can incorporate animations thoroughout the lifecycle of the Ranking widget.

The lifecycle animations of the StageClearWidget is useful for showing titles or any other effects on the main screen before showing the individual stats

All you have to do is create animations for the StageClearWidget and set the StageClearWidgetLifecycleAnimations to a struct containing these animations and the StageClearWidget will automatically play these animations before showing any of the stats.

Each StageClearWidgetItem for the player stats, have thier own lifecycle animations that are played when the StageClearItemWidget is added/removed to the screen.

To avoid duplication of work creating the same animations for every StageClearItemWidget corresponding to the individual Stat, the best way is to create a base StageClearItemWidget and create the animations for this base widget alone, and create subclass of this base widget for each stat you plan to have for your game. Once you add the Init, Ranked and Exit animations to the corresponding properties of the LifecyleAnimations variable of the StageClearItemWidget, these animations will be automatically played when you Activate the StageClearWidget.

There are many instances where you need to add your own animations in response to the events emitted by the StageClearWidget and StageClearItemWidgets. For eg, when the final rank of the player is calculated based on the individual stats, you would want to animate the final rank by animating gradually the image on the widget. You do this by initially setting the Render Opacity of the image for the rank in the StageClearWidget  to 0 and when the OnFinalPlayerRankComputed event is emitted, you can play an animation that animates this value to 1.

Using Rankers

There are different types of rankers to suit different needs

Linear Ranker

The Linear Ranker ranks the stat with which it's associted with on a linear scale.

For example, if a stat has a maximum score of 10,000 and the number of ranks is 7 (D-SSS), as shown above, the rank will be as below -


The tick on the X axis is n * 10000 / 7

Logarithmic Ranker

The Logarithmic Ranker ranks player as follows - 

if Score is x, then rank is equal to r, where 

10^r = score.


This means that it's much harder to rank up from rank 5 to rank 6 than it is to rank up from rank 1 to rank 2.

Curve based Ranker

This is probably the most useful for many use cases. The curve based ranker lets you rank player based on a curve.

Here is an example configuring a Clear Time Ranker.

You can find the above TimeRankerBP in the plugin folder of the ComboMeter. The X axis is the score and the Y axis is the rank(zero index based). So, if the player clears the stage within 5 mins then the rank will be SSS etc.

The XScale property on this ranker scales the X axis. Let's say the score is in seconds, then to configure the X axis as minutes, set the XScale to 60. Then, the rank will be calculated as Y corresponding to (Score / XScale) value of the X axis.

Direct Ranker

The Direct ranker outputs the rank equal to the score passed to it. That is, if the score is 5, then rank is also 5. This is to allow for any custom ranking that you can provide for your game when it's not possible by the other rankers mentioned above.