Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Pop-up windows (sugarcube)

So the player enters a new room. There are a couple of routes out, but he might like to examine some things in the room first. How about having a pop-up window appear with the description in it, instead of going to a new page, and the player then clicking back?

This can be done with the <<click>> macro and some CSS in Sugarcube. Here is an example passage:

You are in a large gloomy hallway. To the left, stand a &lt;&lt;click &quot;suit of armour&quot;&gt;&gt;&lt;&lt;set document.getElementById(&quot;hidden1&quot;).style.display=&quot;block&quot;&gt;&gt;&lt;&lt;/click&gt;&gt;, and beside it hangs a &lt;&lt;click &quot;portrait of a lady&quot;&gt;&gt;&lt;&lt;set document.getElementById(&quot;hidden1&quot;).style.display=&quot;block&quot;&gt;&gt;&lt;&lt;/click&gt;&gt;. There is a [[door to the right]], and at the far end [[stairs lead upwards]].<br /><br />&lt;&lt;id &quot;hidden1&quot;&gt;&gt;&lt;&lt;click &quot;The armour has seen better days, and has a few dented, suggesting it has been used in anger on more than one occasion.&quot;&gt;&gt;&lt;&lt;set document.getElementById(&quot;hidden1&quot;).style.display=&quot;none&quot;&gt;&gt;&lt;&lt;/click&gt;&gt;&lt;&lt;/id&gt;&gt;<br /><br />&lt;&lt;id &quot;hidden2&quot;&gt;&gt;&lt;&lt;click &quot;The eyes of the rather severe-looking woman seem to follow you round the room.&quot;&gt;&gt;&lt;&lt;set document.getElementById(&quot;hidden1&quot;).style.display=&quot;none&quot;&gt;&gt;&lt;&lt;/click&gt;&gt;&lt;&lt;/id&gt;&gt;

The second and third paragraphs contain the text that will be displayed in the player clicks on a red link (blue links take her to another page).


Here is the required CSS, to be pasted into a stylesheet passage (this can handle up to 5 objects in a passage):

/* This is the panel that will appear */<br />#hidden1, #hidden2, #hidden3, #hidden4, #hidden5 {<br />&nbsp; display:none;<br />&nbsp; position:fixed;<br />&nbsp; top:300px;<br />&nbsp; left:200px;<br />&nbsp; background-color:#eef;<br />&nbsp; padding:20px;<br />&nbsp; border-radius: 15px;<br />&nbsp; border-color: #004;<br />} <br />/* This is the text in the panel&nbsp; */<br />#hidden1 a, #hidden2 a, #hidden3 a, #hidden4 a, #hidden5 a {<br />&nbsp; font-style:italic;<br />&nbsp; color:#004;<br />}<br /><br />/* links in the main passage */<br />.link-click {<br />&nbsp; color:red;<br />}

Comments

  • That's more like a hidden info panel, rather than an actual pop-up (which SugarCube also allows you do to via the UISystem API; example attached).

    Also, I advise against using the deprecated <<id>> macro, it will be removed at some point.  You can accomplish the same thing using the <div> element.  For example:

    <div id="hidden1"><<click "The armour has seen better days, and has a few dented, suggesting it has been used in anger on more than one occasion.">><<set document.getElementById("hidden1").style.display="none">><</click>></div>

    <div id="hidden2"><<click "The eyes of the rather severe-looking woman seem to follow you round the room.">><<set document.getElementById("hidden2").style.display="none">><</click>></div>
  • Thanks. Half the point of starting a thread like this is so I can heard about better ways to do something.
Sign In or Register to comment.