Добавление несколько усложненного цифрового календаря (Adding a slightly-complicated Digital Calendar)

Материал из Ren'Py Wiki
Перейти к навигации Перейти к поиску

Следующие переменные должны располагаться в вашей игровой ветке/руте (метка label start или блок инициализации – удачный выбор для этого) для правильной работы цифрового календаря (фактические значения – просто примеры):

    $ minutes = 750 # Переменная должна быть определена первоначально.
    $ clock = True # Чтобы скрыть календарь, поменяйте значение True на False.
    $ theweekday = 3 # Вторник, номер дня недели, меняется автоматически, но следует задать изначально.
    $ themonth = 9 # Сентябрь, число месяца, меняется автоматически, но следует задать изначально.
    $ theday = 21 # Меняется автоматически, но следует задать изначально.
    $ theyear = 2010 # Меняется автоматически, но следует задать изначально.
    $ dayofyear = 264 # вы должны рассчитать переменную правильно, меняется автоматически.
    $ yearlim = 365 # сначала определите переменную как 265 или 366, в зависимости от того, какое из этих чисел является правильным, эта переменная автоматически изменится позже.
    $ daylim = 30 # сначала определите переменную как 28, 29, 30 или 31, в зависимости от того, какое из этих чисел является правильным, эта переменная автоматически изменится позже.
    $ stringweekday = "Вторник" # 3, строка дня недели, меняется автоматически, но следует задать изначально.
    $ stringmonth = "Сентябрь" # 9, строка месяца, меняется автоматически, но следует задать изначально.

Код, приведённый ниже, должен располагаться в любом из ваших файлов с кодом, желательно как отдельный файл с расширением .rpy. При желании можно изменить X/yalign...

init python:
    def time_callback(): # непрерывно рассчитывает время.
        if (hasattr(store, 'minutes')):
            if (store.minutes > 1440):
                store.minutes = store.minutes - 1440
                store.theweekday = store.theweekday + 1
                store.theday = store.theday + 1
                store.dayofyear = dayofyear + 1
                
        if (hasattr(store, 'theweekday')): # устанавливает день недели
            if store.theweekday > 7:
                store.theweekday = store.theweekday - 7
            if store.theweekday == 1:
                store.stringweekday = "Воскресенье"
            elif store.theweekday == 2:
                store.stringweekday = "Понедельник"
            elif store.theweekday == 3:
                store.stringweekday = "Вторник"
            elif store.theweekday == 4:
                store.stringweekday = "Среда"
            elif store.theweekday == 5:
                store.stringweekday = "Четверг"
            elif store.theweekday == 6:
                store.stringweekday = "Пятница"
            elif store.theweekday == 7:
                store.stringweekday = "Суббота"
            else:
                store.stringweekday = "Ошибка"
                
        if (hasattr(store, 'theday')):# ограничить месяц
            if store.theday > store.daylim:
                store.theday = store.theday - store.daylim
                store.themonth = store.themonth + 1

        if (hasattr(store, 'themonth')): # устанавливает месяц
            if store.themonth == 1:
                store.stringmonth = "Январь"
                store.daylim = 31
            if store.themonth == 2:
                store.stringmonth = "Февраль"
                if ((((int(store.theyear) / 4)*4) - store.theyear) == 0):
                    store.daylim = 29
                else:
                    store.daylim = 28
            if store.themonth == 3:
                store.stringmonth = "Март"
                store.daylim = 31
            if store.themonth == 4:
                store.stringmonth = "Апрель"
                store.daylim = 30
            if store.themonth == 5:
                store.stringmonth = "Май"
                store.daylim = 31
            if store.themonth == 6:
                store.stringmonth = "Июнь"
                store.daylim = 30
            if store.themonth == 7:
                store.stringmonth = "Июль"
                store.daylim = 31
            if store.themonth == 8:
                store.stringmonth = "Август"
                store.daylim = 31
            if store.themonth == 9:
               store.stringmonth = "Сентябрь"
               store.daylim = 30
            if store.themonth == 10:
               store.stringmonth = "Октябрь"
               store.daylim = 31
            if store.themonth == 11:
               store.stringmonth = "Ноябрь"
               store.daylim = 30
            if store.themonth == 12:
               store.stringmonth = "Декабрь"
               store.daylim = 31
            
            if (hasattr(store, 'dayofyear') and hasattr(store, 'yearlim')): # содержимое года
               if store.dayofyear > store.yearlim:
                   store.dayofyear = store.dayofyear - store.yearlim
                   store.theyear = store.theyear + 1
               if ((((int(store.theyear) / 4)*4) - store.theyear) == 0):
                   store.yearlim = 366
               else:
                   store.yearlim = 365
    config.python_callbacks.append(time_callback)
    
    def Calendar():
        ui.frame(xfill=False, xminimum = 400, yminimum=None, xalign=1.0, yalign = 0.805)
        ui.vbox()
        ui.text("(%s) - %s %d %d" % (stringweekday, stringmonth, theday, theyear), xalign=1.0, size=20)
        ui.close()
        
    def Clocks():
        ui.frame(xfill=False, xminimum = 110, yminimum=None, xalign=1.0, yalign = 0.76)
        ui.vbox()
        if (minutes > 719): # Для 24-ёх часового формата времени, удалите этот блок (до строчки ui.close()), и вставьте:
        #ui.text("%d:0%d" % (int(minutes/60), (minutes - (int(minutes/60))*60)), xalign=1.0, size=20) # удалите решётку вначале.
            if ((minutes - (int(minutes/60))*60) < 10):
                if((int(minutes/60)) == 12):
                    ui.text("12:0%d PM" % ((minutes - (int(minutes/60))*60)), xalign=1.0, size=20)
                else:
                    ui.text("%d:0%d PM" % ((int(minutes/60)-12), (minutes - (int(minutes/60))*60)), xalign=1.0, size=20)
            else:
                if((int(minutes/60)) == 12):
                    ui.text("12:%d PM" % ((minutes - (int(minutes/60))*60)), xalign=1.0, size=20)
                else:
                    ui.text("%d:%d PM" % ((int(minutes/60)-12), (minutes - (int(minutes/60))*60)), xalign=1.0, size=20)
        else:
            if ((minutes - (int(minutes/60))*60) < 10):
                if((int(minutes/60)) == 0):
                    ui.text("12:0%d AM" % ((minutes - (int(minutes/60))*60)), xalign=1.0, size=20)
                else:
                    ui.text("%d:0%d AM" % ((int(minutes/60)), (minutes - (int(minutes/60))*60)), xalign=1.0, size=20)
            else:
                if((int(minutes/60)) == 0):
                    ui.text("12:%d AM" % ((minutes - (int(minutes/60))*60)), xalign=1.0, size=20)
                else:
                    ui.text("%d:%d AM" % ((int(minutes/60)), (minutes - (int(minutes/60))*60)), xalign=1.0, size=20)
        ui.close()

Затем сделайте так, чтобы цифровой календарь появился на экране. Я использую следующий код:

screen say:
    if(clock):
        $ Calendar()
        $ Clocks()

После того, как вы это сделали, все что тебе нужно сделать, это вот так добавить минуты (в текущий скрипт игры):

    $ minutes = minutes + 112 # или что-либо другое.

Источник[править | править код]

Статья "Adding a slightly-complicated Digital Calendar" на английском языке


На главную страницу Книга рецептов Энциклопедии Ren'Py Книга рецептов Ren'Py Вернуться к началу статьи