Monday, 24 December 2007

Maps Within Maps!


I managed a big breakthrough today. I worked out how to have a second world map open from an icon in a first world map. This is very useful as it allows me to break up a world map into "chunks" and reveal them as and when I want to, as well as making it easier to spread icons around. E.g. If you click on a city, I can bring up a complete "world map" of the city with the various sectors within it, accessible from individual icons. It acts as though you have "zoomed in" on the location. (I feel it's better than having about four icons on the world map all around a main city representing the sectors.) There may, of course, be other benefits from gaining this knowledge, in that I can now use the code to have a picture open up other pictures or texts. Time and inspiration will determine this. (EDIT: Video demostration now added.)


There is a hook SelectScript in the world map icon editor that allows a script to immediately fire when it is clicked upon. I then added the following script to this hook:

#include "ginc_transition"
void main()
object oPC = OBJECT_SELF;
if (GetIsPC( oPC ) == FALSE){return;}
// Determine Map To Call
string sMap = GetSelectedMapPointTag();
int Length = GetStringLength(sMap) - 4; // E.g. MAP_NorthTear = 13-4 = 9.
sMap = GetSubString(sMap, 4, 9); // E.g. NorthTear.
string sOrigin = "";
AssignCommand(oPC, ClearAllActions(TRUE));
DelayCommand(0.1, ShowWorldMap(sMap, oPC, sOrigin ));
DelayCommand(0.1, FadeFromBlack(oPC, FADE_SPEED_FASTEST));

NB: The TAG of the icon that calls the map must begin with "MAP_" as referred to in the above code example.

However, alone this does not work, as the worldmap.xml UI needs a parameter added to ensure the new image is loaded from the disc rather than cache. This is achieved by adding idleexpiretime="0.1" to the top of the worldmap.xml, as follows:

<UIScene name="SCREEN_WORLDMAP" x=0 y=0 width=SCREEN_WIDTH height=SCREEN_HEIGHT fullscreen=true idleexpiretime="0.1"
OnRemove=UIScene_OnRemove_CloseWorldMap "WORLDMAP_IMAGE_PANE","DEST_LISTBOX") />

I experimented with the fastest reload times and discovered that 0.1 was the fastest time I could unload and reload a new map. However, with the use of the BlackScreen function and FadeFromBlack, I made this transition appear seemless. Now I just need to get to better grips with XML coding and I may be able to get from crawling to walking. :)

No comments: