You've reached a page on the Ren'Py wiki. Due to massive spam, the wiki hasn't been updated in over 5 years, and much of the information here is very out of date. We've kept it because some of it is of historic interest, but all the information relevant to modern versions of Ren'Py has been moved elsewhere.
Some places to look are:
Please do not create new links to this page.
これはメインスクリーンに表示するボタンを追加するレシピです。 これらのボタンはゲームメニュー、スキップのトグル、設定へのショートカットやメニューインベントリを起動するために動作します。
# This file adds a number of buttons to the lower-right hand corner of
# the screen. Three of these buttons jump to the game menu, which
# giving quick access to Load, Save, and Prefs. The fourth button
# toggles skipping, to make that more convenient.
init python:
# Give us some space on the right side of the screen.
style.window.right_padding = 100
def toggle_skipping():
config.skipping = not config.skipping
show_button_game_menu = True
def button_game_menu():
if show_button_game_menu:
# to save typing
ccinc = renpy.curried_call_in_new_context
ui.vbox(xpos=0.99, ypos=0.98, xanchor='right', yanchor='bottom')
ui.textbutton("Skip", clicked=toggle_skipping, xminimum=80)
ui.textbutton("Save", clicked=ccinc("_game_menu_save"), xminimum=80)
ui.textbutton("Load", clicked=ccinc("_game_menu_load"), xminimum=80)
ui.textbutton("Prefs", clicked=ccinc("_game_menu_preferences"), xminimum=80)
ui.close()
config.window_overlay_functions.append(button_game_menu)
常に画面にボタンを表示し続けたいなら、上記コードを.rpyファイルにコピーするだけです。
ミニゲームのような間はボタンを非表示にしたいなら、例えばこのように書いてください。
label minigame:
e "Let's play Poker!"
# I want to disable the buttons, so I use:
$ show_button_game_menu = False
# Now the button is no longer shown.
# ... poker code ...
# Now I want to re-activate the buttons, so I use:
$ show_button_game_menu = True
e "That was fun."
jump ending
"$ show_button_game_menu = False"が実行されると再びshow_button_game_menuが真になるまでボタンを表示したくないとコンピューターに伝わります。
自分でメニューボタンを作成したいなら、先ず画面にボタンを表示するか否かの変更に使う変数を作成し、その後オーバーレイ関数を作り、最後にオーバーレイ関数リストにその関数を加えます。
この全てはinit pythonブロック内にある必要があります。
init python:
# Give us some space on the right side of the screen.
style.window.right_padding = 100
ボタンの表示、非表示を決定する変数を作成するためには、まず適切な名前を決めなければなりません。 良い名前はボタンの機能を説明するものです。 例えば、例示したコードではゲームメニューへのショートカットボタンの表示を決める変数なので、"show_button_game_menu" と名付けられます。 もしインベントリーを表示するボタンがほしいなら、"show_inventory_button"が良い変数名でしょう。
名前が決まったらゲーム本編開始時からボタンが表示されるのか、あとでアンロックするのかを決めなければなりません。 例示したゲームメニューではゲーム開始時にボタンを表示するのがいいですが、プレイヤーが呪文を唱えるときにスペルリストを表示したり、ゲームの中盤で呪文を学ばせるようなことがしたいなら、後でボタンをアンロックするといいです。
ゲーム開始時からボタンを表示したいなら"your_variable_name = True"を、そうでないなら"your_variable_name = False"を書きます。
init python:
# Give us some space on the right side of the screen.
style.window.right_padding = 100
your_variable_name = True or False #depending on your decision
次に、実際の関数を書きます。
init python:
# Give us some space on the right side of the screen.
style.window.right_padding = 100
your_variable_name = True or False #depending on your decision
def my_button_function():
if your_variable_name:
ui.vbox(xpos=0.99, ypos=0.98, xanchor='right', yanchor='bottom')
ui.textbutton("Button Name", clicked=do_something, xminimum=80)
ui.close()
最後に、この関数をconfig.overlayに加えます。
init python:
# Give us some space on the right side of the screen.
style.window.right_padding = 100
your_variable_name = True or False #depending on your decision
def my_button_function():
if your_variable_name:
ui.vbox(xpos=0.99, ypos=0.98, xanchor='right', yanchor='bottom')
ui.textbutton("Button Name", clicked=do_something, xminimum=80)
ui.close()
config.overlay_functions.append(my_button_function)