0 votes
by (370 points)
This sidebar will be used to contain character stats such as HP or mana.Also i don't know how to put the stats into the bar.I'm using sugarcube 221.

1 Answer

0 votes
by (44.7k points)

Here's some code I got elsewhere (I don't remember where) that does what you're looking for.

Put this in your JavaScript section:

/* Create the Right UI Bar.  Swap the two lines below to start stowed instead of unstowed. */
var $rightUiBar = $('<div id="right-ui-bar"></div>').insertAfter("#ui-bar");
/* var $rightUiBar = $('<div id="right-ui-bar" class="stowed"></div>').insertAfter("#ui-bar"); */

var rightTray = $rightUiBar.append('<div id="right-ui-bar-tray"><button id="right-ui-bar-toggle" tabindex="0" title="Toggle the Right UI bar" aria-label="Toggle the Right UI bar" type="button"></button></div>');

var rightBody = $rightUiBar.append('<div id="right-ui-bar-body"></div>');

/* Attach the toggle button click. */
		label : "Toggle the Right UI bar"
	}, function () {

/* Automatically show the contents of the StoryRightSidebar passage in the right-ui-bar-body element. */
postrender["Display Right Sidebar Contents"] = function (content, taskName) {
	setPageElement('right-ui-bar-body', 'StoryRightSidebar');

	To have your code stow the bar use:
	<<addclass "#right-ui-bar" "stowed">>
	To unstow the bar use:
	<<removeclass "#right-ui-bar" "stowed">>

Put this in your Stylesheet section:

/* Styling and Colours of the Right UI Bar. */
#right-ui-bar {
	background-color: #222;
	border-right: 1px solid #444;
	text-align: center;
#right-ui-bar-toggle {
	font-size: 1.2em;
	line-height: inherit;
	color: #eee;
	background-color: transparent;
	border: 1px solid #444;
#right-ui-bar-toggle:before {
	font-family: tme-fa-icons;
	font-style: normal;
	font-weight: 400;
	font-variant: normal;
	text-transform: none;
	line-height: 1;
	speak: none;

/* Layout and Positioning of the Right UI Bar. */
#right-ui-bar {
	position: fixed;
	z-index: 50;
	top: 0;
	right: 0;
	width: 17.5em;
	height: 100%;
	margin: 0;
	padding: 0;
	-webkit-transition: right .2s ease-in;
	-o-transition: right .2s ease-in;
	transition: right .2s ease-in;
#right-ui-bar-tray {
	position: absolute;
	top: .2em;
	left: 0;
	right: 0;
#right-ui-bar-toggle {
	display: block;
	position: absolute;
	top: 0;
	left: 0;
	border-left: none;
	padding: .3em .45em .25em;
	-webkit-user-select: none;
#right-ui-bar-toggle:before {
	content: "\e81e";
#right-ui-bar-body {
	height: 90%;
	height: calc(100% - 2.5em);
	margin: 2.5em 0;
	padding: 0 1.5em;
#right-ui-bar-body {
	line-height: 1.5;
	overflow: auto;

#story {
	margin-right: 20em;

/* Stowing of the Right UI Bar. */
#right-ui-bar.stowed {
	right: -15.5em;
#right-ui-bar.stowed #right-ui-bar-toggle {
	padding: .3em .55em .25em .35em;
#right-ui-bar.stowed #right-ui-bar-toggle:before {
	content: "\e81d";
#right-ui-bar.stowed #right-ui-bar-body {
	visibility: hidden;
	-webkit-transition: visibility .2s step-end;
	-o-transition: visibility .2s step-end;
	transition: visibility .2s step-end;

#right-ui-bar.stowed~#story {
	margin-right: 4.5em;

And then create a passage named "StoryRightSidebar".  Now the text and code you put in that passage will appear in the right-side UI bar.


by (159k points)

@I know nothing (and @HiEv)

> Here's some code I got elsewhere...

The original of that code can be found in the [SugarCube 2.7.2] Creating A Panel Similar To The UI-Bar thread in the Old Forums Archive, the link to which is found on this sites right panel.

by (370 points)
A p p r e c i a t e!