I looked at the old cookbook for inspiration though, so under the impression no Screen Language-version tutorial for a calendar existed, I made this tutorial, too.
And now I see there's many calendars already. So.
But I'll put it up anyway.
It's nice and simple, cut n' paste-able, an instant-play example.
Also it has lots and lots of comments ^.^
For the thing to do something other than showing today's date though, some tinkering will be needed
Code: Select all
######################################################
# Section for initialization through Python
#
init python:
# Import the date-module from the python package 'datetime'.
# There's more things in the datetime package, but we're not using those so there's no need to import them.
# The date-module contains functions for calculating with dates, and converting them to and from strings.
from datetime import date
# Import the locale package, which has data structures for keeping locale settings, i.e. which country this
# computer is in and what language settings should be used.
# Also, notably, the local names of the days and months.
import locale
# Find out what day it is.
today = date.today()
# Find out where we are and which language should be used.
locale.setlocale(locale.LC_ALL, '')
# Set a local data structure (here, a dictionary containing key-value pairs) to store
# the strings we need to display the calendar.
# Things like the date and year, and the name of the day and month.
# More options available.. See strftime.org, or search for 'python strftime' if that site have disappeared since I wrote this.
date_inf = { "day": today.strftime("%A"),
"daynr": today.strftime("%d"),
"month": today.strftime("%B"),
"year": today.strftime("%Y")
}
#######################################################
# Section for initialization through Ren'Py
#
init:
# Make a character for telling us things. Well, thing. It's not used much, here.
define hh = Character('Helpful Helper:')
# Load a background image.
# Not necessary actually, but I created a 800x600 png with a 100x100 grid subdivided to a 20x20 grid.
# This makes it easier to see what keywords such as xpadding and xmargin actually does - hard to see otherwise.
# For the curious and/or intrepid, Gimp has a grid function for making such an image, under Filters->Render->Pattern->Grid.
# image bg_grid = "grid.png"
#######################################################
# Define how the calendar should look, using Ren'Py's Screen Language.
# This section would normally be placed in screens.rpy, but if you're
# me, for the moment you'd rather have something to copy-paste, and test, and play around with.
screen calendar(date_inf):
# Don't stop the user from interacting with other things - this screen is just showing stuff.
modal False
# The section of screen to which we'll place the rest.
frame:
xalign 1.0 # Place in the upper-right corner.
yalign 0.0 #
xsize 100 # Make it 100x100 pixels.
ysize 100 #
xmargin .05 # Leave some transparent space around the box.
ymargin .05 #
xpadding .15 # Leave some unused space between the box and its contents.
ypadding .15 #
vbox: # Arranges the things in it vertically.
text date_inf["daynr"] size 60 xalign 0.5 # Big text with the date in center of the box.
hbox: # Arranges the things in it horizontically.
text date_inf["month"] size 12 xalign 0.5 # Smallish texts with monthname and year in the center of the box.
text date_inf["year"] size 12 xalign 0.5 # ..and under the date because the hbox is the second item in the vbox.
spacing 10 # Makes sure there's a space between the two text-items, so that it doesn't read 'august2014' but 'august 2014'.
#######################################################
# Where things actually start to happen.
label start:
### Show the aforementioned background grid, if you made one.
# show bg_grid
# Show the screen defined above.
# The argument passed in the parantheses is the dictionary with date-related strings
# defined up in the 'init python' section.
show screen calendar(date_inf)
# Helpful comment from our Helpful Helper character. Who is very helpful.
hh "Click to continue"
return