Skip to content

Commit

Permalink
Add "selected" and "sensitive" options to buttons to manually control…
Browse files Browse the repository at this point in the history
… these.
  • Loading branch information
shizmob committed Apr 20, 2016
1 parent 67b011d commit 9e9e2ae
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 8 deletions.
16 changes: 14 additions & 2 deletions renpy/display/behavior.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,7 @@ class Button(renpy.display.layout.Window):
def __init__(self, child=None, style='button', clicked=None,
hovered=None, unhovered=None, action=None, role=None,
time_policy=None, keymap={}, alternate=None,
selected=None, sensitive=None,
**properties):

if isinstance(clicked, renpy.ui.Action):
Expand All @@ -631,6 +632,8 @@ def __init__(self, child=None, style='button', clicked=None,
super(Button, self).__init__(child, style=style, **properties)

self.action = action
self.selected = selected
self.sensitive = sensitive
self.clicked = clicked
self.hovered = hovered
self.unhovered = unhovered
Expand Down Expand Up @@ -725,16 +728,25 @@ def unfocus(self, default=False):
if self.child is not None:
self.child.set_transform_event(self.role + "idle")

def is_selected(self):
if self.selected is not None:
return self.selected
return is_selected(self.action)

def is_sensitive(self):
if self.sensitive is not None:
return self.sensitive
return is_sensitive(self.action)

def per_interact(self):

if self.action is not None:
if is_selected(self.action):
if self.is_selected():
role = 'selected_'
else:
role = ''

if is_sensitive(self.action):
if self.is_sensitive():
clicked = self.action
else:
clicked = None
Expand Down
6 changes: 6 additions & 0 deletions renpy/screenlang.py
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,8 @@ def add(thing):
Keyword("hovered")
Keyword("unhovered")
Keyword("alternate")
Keyword("selected")
Keyword("sensitive")
add(ui_properties)
add(position_properties)
add(window_properties)
Expand All @@ -754,6 +756,8 @@ def add(thing):
Keyword("unhovered")
Keyword("alternate")
Keyword("image_style")
Keyword("selected")
Keyword("sensitive")
add(ui_properties)
add(position_properties)
add(window_properties)
Expand All @@ -769,6 +773,8 @@ def add(thing):
Keyword("text_style")
Keyword("substitute")
Keyword("scope")
Keyword("selected")
Keyword("sensitive")
add(ui_properties)
add(position_properties)
add(window_properties)
Expand Down
2 changes: 2 additions & 0 deletions renpy/sl2/slproperties.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@
Keyword("hovered"),
Keyword("unhovered"),
Keyword("alternate"),
Keyword("selected"),
Keyword("sensitive"),
]

bar_properties = [ Style(i) for i in [
Expand Down
45 changes: 39 additions & 6 deletions sphinx/source/screens.rst
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,9 @@ action. A button takes no parameters, and the following properties.
`action`
The action to run when the button is activated. A button is activated
when it is clicked, or when the player selects it and hits enter on the
keyboard. This also controls if the button is sensitive, and if the button
is selected.
keyboard. This also controls if the button is sensitive if `sensitive`
is not provided, and if the button is selected if `selected` is not
provided.

`alternate`
An action that is run if the button is activated in an alternate manner.
Expand All @@ -335,6 +336,16 @@ action. A button takes no parameters, and the following properties.
`unhovered`
An action to run when the button loses focus.

`selected`
An expression that determines whether the button is selected or not.
This expression is evaluated at least once per interaction.
If not provided, the action will be used to determine selectedness.

`sensitive`
An expression that determines whether the button is sensitive or not.
This expression is evaluated at least once per interaction.
If not provided, the action will be used to determine sensitivity.

It also takes:

* :ref:`Common Properties <common-properties>`
Expand Down Expand Up @@ -514,8 +525,9 @@ properties:
The image used when the button is selected and hovered.

`action`
The action to run when the button is activated. This also controls
if the button is sensitive, and if the button is selected.
The action to run when the button is activated. This also controls if
the button is sensitive if `sensitive` is not provided, and if the button
is selected if `selected` is not provided.

`alternate`
An action that is run if the button is activated in an alternate manner.
Expand All @@ -529,6 +541,16 @@ properties:
`unhovered`
An action to run when the button loses focus.

`selected`
An expression that determines whether the button is selected or not.
This expression is evaluated at least once per interaction.
If not provided, the action will be used to determine selectedness.

`sensitive`
An expression that determines whether the button is sensitive or not.
This expression is evaluated at least once per interaction.
If not provided, the action will be used to determine sensitivity.

It also takes:

* :ref:`Common Properties <common-properties>`
Expand Down Expand Up @@ -842,8 +864,9 @@ parameter, the text to include as part of the button. It takes the
following properties:

`action`
The action to run when the button is activated. This also controls
if the button is sensitive, and if the button is selected.
The action to run when the button is activated. This also controls if
the button is sensitive if `sensitive` is not provided, and if the button
is selected if `selected` is not provided.

`alternate`
An action that is run if the button is activated in an alternate manner.
Expand All @@ -857,6 +880,16 @@ following properties:
`unhovered`
An action to run when the button loses focus.

`selected`
An expression that determines whether the button is selected or not.
This expression is evaluated at least once per interaction.
If not provided, the action will be used to determine selectedness.

`sensitive`
An expression that determines whether the button is sensitive or not.
This expression is evaluated at least once per interaction.
If not provided, the action will be used to determine sensitivity.

`text_style`
The name of the style to use for the button text. If not supplied,
and the `style` property is a string, then ``"_text"`` is appended
Expand Down

0 comments on commit 9e9e2ae

Please sign in to comment.