1# Copyright 2004-2021 Tom Rothamel <pytom@bishoujo.us>
2#
3# Permission is hereby granted, free of charge, to any person
4# obtaining a copy of this software and associated documentation files
5# (the "Software"), to deal in the Software without restriction,
6# including without limitation the rights to use, copy, modify, merge,
7# publish, distribute, sublicense, and/or sell copies of the Software,
8# and to permit persons to whom the Software is furnished to do so,
9# subject to the following conditions:
10#
11# The above copyright notice and this permission notice shall be
12# included in all copies or substantial portions of the Software.
13#
14# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
22init -1500 python:
23
24    @renpy.pure
25    class NullAction(Action, DictEquality):
26        """
27        :doc: control_action
28
29        Does nothing.
30
31        This can be used to make a button responsive to hover/unhover events,
32        without actually doing anything.
33        """
34
35        def __call__(self):
36            return
37
38    @renpy.pure
39    class Return(Action, DictEquality):
40        """
41         :doc: control_action
42
43         Causes the current interaction to return the supplied value, which
44         must not be None. This is often used with menus and imagemaps, to
45         select what the return value of the interaction is. If the screen
46         was called using the ``call screen`` statement, the return value
47         is placed in the `_return` variable.
48
49         When in a menu, this returns from the menu. (The value should be
50         None in this case.)
51         """
52
53        def __init__(self, value=None):
54            self.value = value
55
56        def __call__(self):
57
58            if self.value is None:
59                if main_menu:
60                    ShowMenu("main_menu")()
61                else:
62                    return True
63
64            else:
65                return self.value
66
67    @renpy.pure
68    class Jump(Action, DictEquality):
69        """
70        :doc: control_action
71
72        Causes control to transfer to `label`.
73        """
74
75        def __init__(self, label):
76            self.label = label
77
78        def __call__(self):
79            renpy.jump(self.label)
80
81    @renpy.pure
82    class Call(Action, DictEquality):
83        """
84        :doc: control_action
85
86        Ends the current statement, and calls `label`. Arguments and
87        keyword arguments are passed to :func:`renpy.call`.
88        """
89
90        args = tuple()
91        kwargs = dict()
92
93        def __init__(self, label, *args, **kwargs):
94            self.label = label
95            self.args = args
96            self.kwargs = kwargs
97
98        def __call__(self):
99            renpy.call(self.label, *self.args, **self.kwargs)
100
101    @renpy.pure
102    class Show(Action, DictEquality):
103        """
104         :doc: control_action
105
106         This causes another screen to be shown. `screen` is a string
107         giving the name of the screen. The arguments are
108         passed to the screen being shown.
109
110         If not None, `transition` is use to show the new screen.
111         """
112
113
114        args = None
115
116        def __init__(self, screen, transition=None, *args, **kwargs):
117            self.screen = screen
118            self.transition = transition
119            self.args = args
120            self.kwargs = kwargs
121
122        def predict(self):
123            renpy.predict_screen(self.screen, *self.args, **self.kwargs)
124
125        def __call__(self):
126            renpy.show_screen(self.screen, *self.args, **self.kwargs)
127
128            if self.transition is not None:
129                renpy.transition(self.transition)
130
131            renpy.restart_interaction()
132
133        def get_selected(self):
134            return renpy.get_screen(self.screen, self.kwargs.get("_layer", None)) is not None
135
136    @renpy.pure
137    class ToggleScreen(Action, DictEquality):
138        """
139        :doc: control_action
140
141        This toggles the visibility of `screen`. If it is not currently
142        shown, the screen is shown with the provided arguments. Otherwise,
143        the screen is hidden.
144
145        If not None, `transition` is use to show and hide the screen.
146        """
147
148        args = None
149
150        def __init__(self, screen, transition=None, *args, **kwargs):
151            self.screen = screen
152            self.transition = transition
153            self.args = args
154            self.kwargs = kwargs
155
156        def predict(self):
157            renpy.predict_screen(self.screen, *self.args, **self.kwargs)
158
159        def __call__(self):
160            if renpy.get_screen(self.screen, layer=self.kwargs.get("_layer", None)):
161                renpy.hide_screen(self.screen, layer=self.kwargs.get("_layer", None))
162            else:
163                renpy.show_screen(self.screen, *self.args, **self.kwargs)
164
165            if self.transition is not None:
166                renpy.transition(self.transition)
167
168            renpy.restart_interaction()
169
170        def get_selected(self):
171            return renpy.get_screen(self.screen, self.kwargs.get("_layer", None)) is not None
172
173
174    @renpy.pure
175    def ShowTransient(screen, transition=None, *args, **kwargs):
176        """
177         :doc: control_action
178
179         Shows a transient screen. A transient screen will be hidden when
180         the current interaction completes. The arguments are
181         passed to the screen being shown.
182
183         If not None, `transition` is use to show the new screen.
184         """
185
186        return Show(screen, transition, _transient=True, *args, **kwargs)
187
188    @renpy.pure
189    class Hide(Action, DictEquality):
190        """
191        :doc: control_action
192
193        This causes the screen named `screen` to be hidden, if it is shown.
194
195        `transition`
196            If not None, a transition that occurs when hiding the screen.
197
198        `_layer`
199            This is passed as the layer argument to :func:`renpy.hide_screen`.
200        """
201
202        _layer = None
203
204        def __init__(self, screen, transition=None, _layer=None):
205            self.screen = screen
206            self.transition = transition
207            self._layer = _layer
208
209        def __call__(self):
210            renpy.hide_screen(self.screen, layer=self._layer)
211
212            if self.transition is not None:
213                renpy.transition(self.transition)
214
215            renpy.restart_interaction()
216
217