Post new topic    
Page 1, 2  »
Metal Slime
Send private message
Custom menus + slices 
 PostWed Jun 02, 2010 11:43 pm
Send private message Reply with quote
In my menu design, selecting a piece of the menu should open a new menu and all its related data on the side without closing the main menu. In this way I'm going to redo the equipment screen, spells screen, etc.

Opening the menus "into" the slice is easy enough, as is displaying the data I want. I'm doing the "Status" screen now to get used to using menus and slices. The problem that I have right now is that I have no good way to free the Status Data slice when, for example, press the cancel key (or maybe navigate away from the "Status" menu item on the main menu?)

I have a Status menu open up inside of the rectangle that covers up the screen, and to the left of that, display the status of the first character. The Status menu has the names of the rest of the party, and when I select them, their relevant data appears in the slice. All of that works fine, but when I cancel out of the Status menu to go back to the main menu, that data remains and I'm not sure how to catch that. It's easy enough to remove it when I select another character, since the stuff that loads the new data can just get rid of the old data, but I have no idea how to catch "canceling out of" a menu to do similar.

I figure some sort of combination of allowing gameplay during menus and key is pressed? I don't know enough about plotscripting though.
Liquid Metal King Slime
Send private message
 
 PostWed Jun 02, 2010 11:54 pm
Send private message Reply with quote
You should hold onto the slice handle you get when you load the status screen.

I don't know if you are loading your status screen with "load slice collection" or if you are creating it manually with various calls to "create rect" and "create text" and similar, but either way you should have access to a slice handle for the whole thing.

You can store the slice handle in a global variable, so you can do "free slice" on it later.

...or if for some reason you don't want to use a global variable, you can put the handle in a local variable just long enough to apply a lookup code to the slice with "set slice lookup". Then later on when you need to get the handle to the slice again, use "lookup slice" to find the lookup code that you used earlier.

Does that make sense?
Metal Slime
Send private message
 
 PostWed Jun 02, 2010 11:59 pm
Send private message Reply with quote
Yes - the problem is when to call free slice.

Honestly I currently have a mix of slice collection+creating slices until I have it exactly the way I want it, then I'll clean it up.

So I have the slice handle. When do I free it? Is there a "on menu exit" or something similar? Otherwise the Status Data slice remains up when I cancel out of the Status menu and worse - when I cancel out of the Main menu. Right now I'm having it go away on keypress, which functions outside of the menu, just for testing. But that's not the preferred way to do it.
Metal Slime
Send private message
 
 PostThu Jun 03, 2010 1:14 am
Send private message Reply with quote
Eh, I got it. I just used free slice on a keypress script to remove all slices that are valid.

I thought it would be more complicated than that for some reason, but it works.
Metal Slime
Send private message
 
 PostThu Jun 03, 2010 3:35 pm
Send private message Reply with quote
Part 2!

Okay so everything works fine.

Until we go into deeper menus. As it stands, I can view the status for the initial character and it works fine. Canceling out of status (or navigating to -Exit- and pressing it) correctly closes the status window.

Now I'm trying to implement changing which character's status you're looking at. Created the menu with the hero's names, using extra data, then the "write status" plotscript edits the data in the screen. All that seems fine.

But it doesn't matter because I can't execute the script when I select the menu item. If I allow gameplay & scripts, then selecting part of that menu triggers the "on keypress" script to close the status screen.

It feels like there should be a separate bitset for "allow gameplay" and "allow scripts" but I think really it's caused by my lack of understanding the engine exactly.
Liquid Metal King Slime
Send private message
 
 PostThu Jun 03, 2010 3:57 pm
Send private message Reply with quote
Mystic wrote:

But it doesn't matter because I can't execute the script when I select the menu item. If I allow gameplay & scripts, then selecting part of that menu triggers the "on keypress" script to close the status screen.


You are almost certainly going to want to use "allow gameplay & scripts"

You can make your keypress do different things in different situations.

For example, you could have a global called "viewing status". When you open the status screen, you set "viewing status := true" and then when you close the status menu you can set "viewing status := false"

In your keypress script, you can do something like this:

Code:

plotscript, my keypress script, begin
  if(viewing status) then(
    # handle keypresses when status is open
  )else(
    # handle keypresses everywhere else
  )
end
Metal Slime
Send private message
 
 PostThu Jun 03, 2010 4:13 pm
Send private message Reply with quote
That solution uses the same problem I'm trying to fix, I think.

If I could figure out when they were closing the menu, I could just free the slices then. It's that that I'm not sure on.

So, if I try to implement it that way, everything works except I'm not sure when to set viewing menu to false, because as far as I can tell there's no way to tell if they are closing the menu.

I'm also not very confident I understand how keypresses work. I could probably solve this by checking all of the cancel keys (but I'd have to use scancodes and not the global "cancel key" ?) and checking if they are in the menu, then setting viewing menu to false and freeing the slices. Or something like that. I'll just keep playing with it I suppose.

[edit] Okay yeah, that does it.

Code:
plotscript, check keys, begin
   if(key is pressed (56) || key is pressed (01)) then (
      if(viewing menu) then (
         free slices
      )
   )
end


And then I have the -Cancel- button on the menu itself call free slices and have the bitset Close menu set to on. That seems to catch all of it. For now.
Liquid Metal King Slime
Send private message
 
 PostThu Jun 03, 2010 4:40 pm
Send private message Reply with quote
Sounds like I need to add a script trigger for closing a menu. That would make this sort of thing a lot simpler.
Liquid Metal King Slime
Send private message
 
 PostThu Jun 03, 2010 4:42 pm
Send private message Reply with quote
seconded
Liquid Metal King Slime
Send private message
 
 PostSat Jun 05, 2010 3:50 pm
Send private message Reply with quote
Yesterday I added a menu "on close" script trigger. It is in last night's nightly build. Let me know how it works for you.
Liquid Metal King Slime
Send private message
 
 PostSat Jun 05, 2010 4:16 pm
Send private message Reply with quote
neat. You've been busy James.
Metal Slime
Send private message
 
 PostSat Jun 05, 2010 5:16 pm
Send private message Reply with quote
I feel like I might be able to shave off 50+ lines of scripting stuff by using that. I'll let you know how it goes.
Slime Knight
Send private message
 
 PostSun Jun 06, 2010 10:44 pm
Send private message Reply with quote
James: can you add a script trigger for when you open a menu, also?

this would be greatly useful for custom main menus. (though, honestly, probably not a whole lot else. i suppose it could simplify some things a bit, though.)

but if its something trivial, it would kind of make my life, a little bit. Smile
Metal Slime
Send private message
 
 PostWed Jun 09, 2010 8:05 pm
Send private message Reply with quote
I fear I'm going to sound like an idiot, but I can't find it in the latest nightly.

I see the new plotscripting stuff to set and get it, but nothing in CUSTOM that would let me set it from there.

Definitely the latest nightly. Windows .zip file.
Liquid Metal King Slime
Send private message
 
 PostWed Jun 09, 2010 8:56 pm
Send private message Reply with quote


Here it is
Display posts from previous:
Page 1, 2  »