This formula divides the total number of pages by the current page, takes the remainder, and adds 1. Using the remainder makes sure that the pages "loop" back around when you reach the last page.
This formula takes the current page number, subtracts 1, and then, if you were already on page 1, adds the total number of pages in order to loop back to the last page. (Thanks to smurfier for simplifying my original formulas a bit.)
From here, there are a number of ways to change what the skin displays based on the current page number:
1) Meter Groups
This is the simplest method, and also the lightest in terms of system resources. All you have to do is assign each page's meters to a "group", and then use a !bang command to show and hide the appropriate groups.
If you want to make the command a little "safer," you can also assign all pages to a common group, and send a !bang to hide all paged meters, regardless of which page is currently showing. This can be helpful, or at least reassuring, in large skins with lots of complex showing/hiding actions. It's also best if you want to have "tabs" to switch to specific pages:
Since most of the time, the only difference between paged meters is whether they're visible or not, you can tell your meters to show or hide automatically, based on the current page number. Unfortunately, you can't use formulas in the "Hidden" key, so this requires a few extra measures. On the bright side, however, the page and "switch" meters are much easier to write. For small- to medium-sized skins, this is probably the ideal method.
Start by creating a new measure for each page, which returns true ("1") or false ("0") depending on whether the page is showing, and takes action accordingly.
This is the most complex method, but also the most powerful. This is used when you don't want to simply hide meters based on the current page number, but to change other aspects of their appearance and behavior. For example, you might want your tab buttons to light up when the corresponding page is showing.
Start with measures similar to the ones from method #2:
Now, as is, this just gets you the same results as the last method, which isn't very helpful. However, we can use these styles to create additional options. For example, you could have each page show up in a different place:
You can also tell a meter to use different styles based on the page number. This is great for the example of changing tab buttons to "light up" only when their page is currently showing. You can tell the button meters to use options from either [StyleButton1] or [StyleButton0], based on the "Hide State" of the corresponding page:
The last option is for very large skins, with a great deal of content on each page. With this method, your skin file serves only as a shell, or frame, and draws the page content from separate ".inc" files. This allows you to load only the resources that you need, instead of taking up memory with measures and meters that aren't even visible. The downside is that the skin must be refreshed when switching pages, so any cumulative measure values or dynamic variables will be reset, and WebParser measures will be forced to reconnect.
In terms of actual code, this is actually the simplest of all the methods:
And that's it. All you have to do is create separate files in the skin folder, called "Page1.inc", "Page2.inc", etc. Then just cut-and-paste all of your paged meters into those files.
As for your switch meters, make sure to change their !bang commands from "!SetVariable" to "!WriteKeyValue." For this to work, the new page number needs to be actually written to the file.
You can also choose to remove "DynamicVariables=1" from your original [MeasureNextPage] and [MeasurePreviousPage] measures, since the value of #CurrentPage# will not be changing dynamically anymore.
These are just a few ways of getting this job done. I can think of about fifty more things you could do with it - particularly with the Styles method - but this post has already grown much longer than I expected. Feel free to post your own variations below. :)
I believe the method you used in the Enigma Options panel deserves a spot here as it's quite ingenious and cuts down on lengthy skin codes.
GitHub | DeviantArt | Tumblr
This is the song that never ends. It just goes on and on my friends. Some people started singing it not knowing what it was, and they'll continue singing it forever just because . . .
smurfier wrote:I believe the method you used in the Enigma Options panel deserves a spot here as it's quite ingenious and cuts down on lengthy skin codes.
Thankye. :) I'll add that at the end. Probably most appropriate for skins with an extremely large numbers of meters on each page (for which Options certainly qualifies).