Dynamic menu generation from JSON in C#!
So it was nice having the fun text dialog boxes going, and I imagine they'll come in handy, but I really wanted to get generic menuing (there's that menu-as-a-verb thing again) implemented.
I got most of the way there, but I was spending too much time screwing around with getting the data structure initializations right in C# just to get test data in... so I dropped that and went straight to generating menus from JSON. I'm very pleased to have this working.
The menus there were generated from this (and navigated with this, which I just got recently and am completely in love with):
{:panels [{:dimensions {:width 0.3}
:options
[["Heading" nil]
["Pick me!"
{:action "panels"
:panels [{:dimensions {:left 0.3
:width 0.7}
:options
[["What would you like to do?" nil]
["Party" {:action "panels"
:panels [{:dimensions {:left 0.1
:top 0.5
:width 0.4
:height 0.2}
:options [["Woohoo!" nil]]}]}]
["Relax" {:action "panels"
:panels [{:dimensions {:left 0.3
:top 0.5
:width 0.4
:height 0.2}
:options [["Ahhhh." nil]]}]}]
["Contemplate" {:action "panels"
:panels [{:dimensions {:left 0.5
:top 0.5
:width 0.4
:height 0.2}
:options [["Hmmm..." nil]]}]}]]}]}]]}]}
Well... the JSON representation of that (it's a Clojure data structure). But this is a lot more compact than pretty-printed JSON, so hopefully it's easier for everyone else to read as well. If nothing else, it won't double the length of this page.
Anyway. The action parameter value panels tells Unity it needs to use these values to render one or more menu panels, as well as what options they should have in them, and what action those options should support (if any; a null/nil action is considered a heading and not an active menu item). They're added to the current menu's focus stack; a menu can have any number of panels, and it sends input events to the topmost one, which will close and destroy itself when you back out of it.
While this is potentially useful for generating menus on the server, and it'll certainly be used that way for things like item, unit, and equipment menus, I plan on having all of the menus built from JSON, even if they're baked into the build. It's just massively easier and less finicky to switch things around and fix them without introducing new bugs when it's in a dead simple notation like this than if it's baked into a C# file somewhere. Bleh.
The only other thing I had lined up with this -- which I expected to take longer than it did -- was centralizing input handling so changing bindings would be easy. That sounds... really dull, though. So I think I might start on battle mechanics, now that I've got the menus working. :)
Vigilant Carnival
A WIP FFVI-like multiplayer-capable RPG (probably starting out as a roguelike/generic dungeon crawler).
Status | Prototype |
Author | internationalfish |
Genre | Role Playing |
Tags | 2D, clojure, Unity |
More posts
- Jumping back in with server-side improvements, and battle updates to comeOct 21, 2020
- Reimplementation of client has (already) startedApr 23, 2020
- Working ATB-sensitive active unit switching in battleApr 20, 2020
- The first UI indications of working server-side ATB timingApr 17, 2020
- SNES FF-style battle UI startedApr 10, 2020
- Menu refactoring and map reformattingApr 04, 2020
- Upgrades. Meh.Mar 19, 2020
- First menu action!Mar 16, 2020
- Dialog updates, scaling trouble, and starting menusMar 16, 2020
Leave a comment
Log in with itch.io to leave a comment.