Design Diary:
Balance of the Planet 2011
June 23rd, 2011
How to implement background explanations?
11:00 AM
Today’s problem arises from my attempt to explanation Generation III nuclear reactors. The explanation is long and complicated, and there’s really no way to shorten it without reducing it to something like “Generation III reactors are better than Generation II reactors.” Moreover, the explanation would work best with multiple illustrations, not the single drawing I put on the page. What I’d like is something that allows the player to bring up different pages that explain different technologies, one chunk at a time.
No prob! Just use hyperlinks — right? Well, yes, I could do something like that, but it raises some new problems. In the first place, my hyperlinks would not jump to new URLs, they would simply select new page descriptions. That I can probably handle. But the real killer is this: my dataset is stored in an XML document. The HTML would be embedded inside other XML elements. Right now, I don’t know how to incorporate HTML into XML. Do I use some sort of complex element that includes HTML as one of its attributes? I suppose so, but this would take a lot of research to figure out. Besides, I’m not sure that simply embedding HTML inside my document would get what I want — and it might well give me behavior that I don’t want.
Another way is to fake the hyperlinks. In other words, I build my own little rendering engine that recognizes some special escape characters that I define, and uses those escape characters to mimic hyperlink behavior inside my program. The problem here is that Java controls the drawing of the text and I have to go through its own system, figuring out how to handle AttributeSets (or maybe it’s Styles). Either way, this is going to be painful. I suppose that I’m just going to have to plow into this mess and experiment, see if I can get anything working.