a
    V$c                     @   s  d dl mZmZmZmZmZ d dlmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZ d dlmZ d dlZd dlZd dlmZmZ G dd dejjZG dd	 d	ejjZG d
d deZG dd deZG dd deZ G dd deZ!G dd deZ"G dd deZ#g a$g a%da&g a'dd Z(ej)j*+e( dddZ,dd Z-dd Z.dd  Z/d!d" Z0d#d$ Z1d%d& Z2d'd( Z3d)d* Z4dd+d,Z5d-d. Z6d/d0 Z7d1d2 Z8ej9d3Z:d4d5 Z;d6d7 Z<dZ=G d8d9 d9ejjZ>d:d; Z?e>e?Z@d<d= ZAe>eAZBd>d? ZCe>eCZDe>ejEjFjGZHe>ejIjIjJd@dAdBZIe>ejEjFjKdCdDdAdEZLe>ejEjFjKdFdGdAdEZMe>ejEjFjKdHdHdAdEZNe>ejEjFjKdHdAdIZOe>ejEjFjPdJdAdKZQe>ejEjFjRdLdAdKZSddMdNZTe>eTdAdOZUe>ejEjFjVdPdAddQZWe>ejEjFjVdRdAddQZXe>ejEjYjZZ[e>ejEjYj\Z]e>ejEjYj^Z_e>ejEjYj`ZaddSdTZbe>ebZcG dUdV dVeZdG dWdX dXedZeG dYdZ dZedZfddbd[Zge>ejEjYjhdcdddAdeZiddhdiZje>ejEjYjkdjdAdkZlddldmZme>emdndoZnddpdqZoe>eoZpddrdsZqe>eqZrejEjYjsZtdtdu Zue>eudadAdvZve>eudAdAdvZwe>eudwdAdBZxe>eudxdAdBZye>eudydAdBZze>eudzdAdBZ{d{d| Z|ej}}e|Z~d}d~ Ze>eZe>ejEjjdAddZe>ejEjjdAdAddZe>ejEjjdAdAddZdZdddZdd Zdd Ze>ejEjYjdAdOZe>ejEjYjdAdZe>ejEjjdAdAdZe>ejEjjdAdAdZe>ejEjYjdAdZG dd deZdddZe>edAdfdZdddZe>edgdAdkZddg ZdddZe>eddAdBZdd Zej}}eZdddZej}}eZdd Zej}}eZdd Zdd Zdd Ze>ejEjYjZdd Zd\ZZe  D ]\ZZeee>ree_qdS )    )divisionabsolute_importwith_statementprint_functionunicode_literals)PY2
basestringbchrbordchropenpystrrangeroundstrtobytesunicode)OptionalN)is_selectedis_sensitivec                   @   sD   e Zd ZdZdZdd Zdd Zdd Zd	d
 Zdd Z	dd Z
dS )Actionz
    This can be passed to the clicked method of a button or hotspot. It is
    called when the action is selected. The other methods determine if the
    action should be displayed insensitive or disabled.
    Nc                 C   s   dS NT selfr   r   renpy/ui.pyget_sensitive5   s    zAction.get_sensitivec                 C   s   dS NFr   r   r   r   r   get_selected8   s    zAction.get_selectedc                 C   s   d S Nr   r   r   r   r   get_tooltip;   s    zAction.get_tooltipc                 C   s   d S r   r   r   str   r   r   periodic>   s    zAction.periodicc                 C   s   d S r   r   r   r   r   r   predictA   s    zAction.predictc                 C   s   t dd S NzNot implemented	Exceptionr   r   r   r   __call__D   s    zAction.__call__)__name__
__module____qualname____doc__altr   r   r    r#   r$   r(   r   r   r   r   r   +   s   r   c                   @   s@   e Zd ZdZdZdZdd Zdd Zdd	 Zd
d Z	dd Z
dS )BarValuezC
    This can be passed to the value method of bar and hotbar.
    BarFc                 C   s   d S r   r   )r   otherr   r   r   replacesR   s    zBarValue.replacesc                 C   s   d S r   r   r!   r   r   r   r#   U   s    zBarValue.periodicc                 C   s   t dd S r%   r&   r   r   r   r   get_adjustmentX   s    zBarValue.get_adjustmentc                 C   s   dS )N)barvbarr   r   r   r   r   	get_style[   s    zBarValue.get_stylec                 C   s   d S r   r   r   r   r   r   r    ^   s    zBarValue.get_tooltipN)r)   r*   r+   r,   r-   
force_stepr1   r#   r2   r5   r    r   r   r   r   r.   H   s   r.   c                   @   s   e Zd ZdZdd ZdS )AddableNc                 C   s   t dS )Nz+Operation can only be performed on a layer.r&   r   r   r   r   	get_layerk   s    zAddable.get_layer)r)   r*   r+   style_prefixr8   r   r   r   r   r7   g   s   r7   c                   @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )Layerc                 C   s
   || _ d S r   name)r   r<   r   r   r   __init__q   s    zLayer.__init__c                 C   s    t jdjj| j||d d S )N)key)renpygamecontextscene_listsaddr<   r   dr?   r   r   r   rD   t   s    z	Layer.addc                 C   s,   t   |r(|| jkr(td| j|f d S )Nz.ui.close closed layer %s, not the expected %r.)stackpopr<   r'   r   rF   r   r   r   closew   s    zLayer.closec                 C   s   | j S r   r;   r   r   r   r   r8   }   s    zLayer.get_layerc                 C   s
   d| j  S )Nz<Layer: %r>r;   r   r   r   r   __repr__   s    zLayer.__repr__N)r)   r*   r+   r=   rD   rJ   r8   rK   r   r   r   r   r:   o   s
   r:   c                   @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )Manyz,
    A widget that takes many children.
    c                 C   s   || _ || _|| _d S r   )displayableimagemapr9   )r   rM   rN   r9   r   r   r   r=      s    zMany.__init__c                 C   s   | j | d S r   )rM   rD   rE   r   r   r   rD      s    zMany.addc                 C   sD   t   | jr t }|j  |r@|| jkr@td| j|f d S )Nz(ui.close closed %r, not the expected %r.)rG   rH   rN   imagemap_stackcachefinishrM   r'   )r   rF   rN   r   r   r   rJ      s    
z
Many.closec                 C   s
   d| j  S )Nz
<Many: %r>rM   r   r   r   r   rK      s    zMany.__repr__Nr)   r*   r+   r,   r=   rD   rJ   rK   r   r   r   r   rL      s
   
rL   c                   @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )Onez2
    A widget that expects exactly one child.
    c                 C   s   || _ || _d S r   )rM   r9   )r   rM   r9   r   r   r   r=      s    zOne.__init__c                 C   s   | j | t  d S r   )rM   rD   rG   rH   rE   r   r   r   rD      s    zOne.addc                 C   s   t d| j d S )NzWidget %r expects a child.)r'   rM   rI   r   r   r   rJ      s    z	One.closec                 C   s
   d| j  S )Nz	<One: %r>rR   r   r   r   r   rK      s    zOne.__repr__NrS   r   r   r   r   rT      s
   rT   c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	Detachedz?
    Used to indicate a widget is detached from the stack.
    c                 C   s
   || _ d S r   )r9   r   r9   r   r   r   r=      s    zDetached.__init__c                 C   s   || _ t  d S r   )childrG   rH   rE   r   r   r   rD      s    zDetached.addc                 C   s   t dd S )Nz%Detached expects to be given a child.r&   rI   r   r   r   rJ      s    zDetached.closeNr)   r*   r+   r,   r=   rD   rJ   r   r   r   r   rU      s   rU   c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	ChildOrFixedz
    If one widget is added, then it is added directly to our
    parent. Otherwise, a fixed is added to our parent, and all
    the widgets are added to that.
    c                 C   s   g | _ || _d S r   )queuer9   rV   r   r   r   r=      s    zChildOrFixed.__init__c                 C   s   | j | d S r   )rZ   appendrE   r   r   r   rD      s    zChildOrFixed.addc                 C   s^   t   t| jdkr&t| jd  n t  | jD ]}t| q2t  |d urZtd| d S )N   r   zDid not expect to close %r.)rG   rH   lenrZ   implicit_addfixedrJ   r'   )r   rF   ir   r   r   rJ      s    

zChildOrFixed.closeNrX   r   r   r   r   rY      s   rY   c                   C   s   t dgag ag ad S )N	transient)r:   rG   at_stackrO   r   r   r   r   reset   s    
rc   miscc                 K   s   t du rtdtjjdkr$dtj_tt dkrLtdddd t D  trXtd	| tj	 j
_tjjjf d
|i|}| tj	 j
_tj r|dur|S |S dS )a  
    :doc: ui
    :args: (roll_forward=None, mouse='default')

    Causes an interaction with the user, and returns the result of that
    interaction. This causes Ren'Py to redraw the screen and begin processing
    input events. When a displayable returns a value in response to an event,
    that value is returned from ui.interact, and the interaction ends.

    This function is rarely called directly. It is usually called by other
    parts of Ren'Py, including the say statement, menu statement, with statement,
    pause statement, call screen, :func:`renpy.input`, among many other
    functions. However, it can be called directly if necessary.

    When an interaction ends, the transient layer and all screens shown with
    transient=True are cleared from the scene lists.

    The following arguments are documented. As other, undocumented arguments
    exist for Ren'Py's internal use, please pass all arguments as keyword
    arguments.

    `roll_forward`
        The information that will be returned by this function when a
        roll forward occurs. (If None, the roll forward is ignored.) This
        should usually be passed the result of the :func:`renpy.roll_forward_info`
        function.

    `mouse`
        The style of mouse cursor to use during this function.
    Nz*Interaction not allowed during init phase.fastr\   zgui.interact called with non-empty widget/layer stack. Did you forget a ui.close() somewhere?
Stack was 
c                 S   s   g | ]}t |qS r   )r   ).0itemr   r   r   
<listcomp>%      zinteract.<locals>.<listcomp>z+ui.interact called with non-empty at stack.roll_forward)rG   r'   r@   configskippingr]   joinrb   rA   rB   info_current_interact_type	interfaceinteract_last_interact_typeexportsin_fixed_rollback)typerk   kwargsrvr   r   r   rr      s     rr   c                 C   s   | a d S r   )add_tagr;   r   r   r   tag4  s    rz   c                   C   s   t tt d j dS )a  
    Causes the current widget to be given child-fixed semantics. This
    means that we will queue up children added to it. If there is one
    child, that child will be added to the widget directly. Otherwise,
    a fixed will be created, and the children will be added to that.
    r>   N)rG   r[   rY   r9   r   r   r   r   child_or_fixed9  s    r{   c                 C   s&   t d  }tjdj||  d S Nr>   )rG   r8   r@   rA   rB   rC   removerF   layerr   r   r   r}   D  s    r}   c                 C   s&   t d  }tjdj||  d S r|   )rG   r8   r@   rA   rB   rC   remove_abover~   r   r   r   r   I  s    r   c                 C   s   t |  dS )z
    :undocumented:

    Specifies a transform that is applied to the next displayable to
    be created. This is largely obsolete, as all UI functions now take
    an `at` argument.
    N)rb   r[   )	transformr   r   r   atN  s    	r   c                  C   s$   t d  } tjdj|  d S r|   )rG   r8   r@   rA   rB   rC   clear)r   r   r   r   r   Z  s    r   c                  C   s   t td j} t|  | S )z
    :undocumented:

    Do not add the next displayable to any later or container. Use this if
    you want to assign the result of a ui function to a variable.
    r>   )rU   rG   r9   r[   )rx   r   r   r   detached_  s    
r   c                 C   s   t t|  dS )z~
    :undocumented:

    Adds displayables to the layer named `name`. The later must be
    closed with :func:`ui.close`.
    N)rG   r[   r:   r;   r   r   r   r   l  s    r   c                 C   s   t d |  t stddS )z
    :undocumented:
    :args: ()

    Closes a displayable created with by a UI function. When a
    displayable is closed, we add new displayables to its parent,
    or to the layer if no displayable is open.
    r>   z2ui.close() called when no layer or widget is open.N)rG   rJ   r'   rF   r   r   r   rJ   w  s    
rJ   c                 C   s(   t t| d d  |r$g | jd d < d S r   )rG   r[   rL   children)wr   r   r   r   reopen  s    r   c                 C   s@   t tjjd tjjr,tjjd j| u r,d S tdt| jd S )Nr>   z'%r cannot be used as a context manager.)	
isinstancer@   uirG   rL   rM   r'   rv   r)   r   r   r   r   context_enter  s    (r   c                 C   s   t |  d S r   )rJ   r   r   r   r   context_exit  s    r   NoStylePrefixGivenc                 C   s&   | du r|}n| d | }t j|S )z
    Combines a style prefix and style suffix to create a style name, then
    returns the style object corresoinding to that name.
    N_)r@   styler5   )r9   style_suffix	new_styler   r   r   combine_style  s    r   c                 C   s   t td j| S )z@
    Combines the default style prefix with a style suffix.
    r>   )r   rG   r9   )r   r   r   r   prefixed_style  s    r   c                   @   s&   e Zd Zdd Zd	ddZdd ZdS )
Wrapperc                 C   s   t rt| jS | jS d S r   )r   bytesr<   r   r   r   r   
__reduce__  s    
zWrapper.__reduce__FNc                 K   s8   d| _ || _|| _|p|| _|| _|| _|| _|| _d S )N )r<   functiononemanyrN   r1   rw   r   )r   r   r   r   rN   r1   r   rw   r   r   r   r=     s    
zWrapper.__init__c              
   O   s  t std|dd }|dg }t|ttfs8|g}t d j}d|v rT|d}d|v rf|d}| jr| j }|	| n|}t
ot
j}d}t
r|t
jv r|	t
j|  |t
jv rd}|rt
j|d }	| jr|	d ur|	|d	< nd }	|d
d p| j}
|
rd|vrt||
|d< z| j|i |}W n` ty } zFt \}}}|jd u rz|jd dd| j f|_~ W Y d }~n
d }~0 0 |jp|}|	d urt
js|tjjj t!|	< |}t"r|#t"  q|D ],}t|tjj$j%r||d}n||}q|r(t d &|t' | j(rBt #t)|| n| j*r^t #t+|| j,| t
r|d ur|t
j-|< t|tjj$j%r|t
j.|< |rt
j/|d }nd }|0| |1| d a'|S )Nz(Can't add displayable during init phase.idr   r>   style_groupr9   TFr1   r   r   r   r(   zui.)rW   )2rG   r'   rH   r   listtupler9   rw   copyupdatescreenold_transferswidget_propertieshidden_widgetsold_widgetsgetr1   r   r   r   	TypeErrorsysexc_infotb_nextargsreplacer<   _mainhidingr@   displayfocusreplaced_byr   rb   r[   motion	TransformrD   ry   r   rT   r   rL   rN   widgets
transformsold_transforms
take_statetake_execution_state)r   r   rw   	widget_idat_listr9   keywordr   do_addold_mainr   r   eetypetbmainatwatfoldtr   r   r   r(     s    











zWrapper.__call__)FFFFN)r)   r*   r+   r   r=   r(   r   r   r   r   r     s   
r   c                 K   sH   t j| } | jr$| d } |   | }|rDt jjjf d| i|}|S )NrW   )	r@   easyrM   _duplicatable
_duplicate_uniquer   r   r   )rF   rw   rx   r   r   r   _addO  s    
r   c                 C   s   | S )ze
    A faster version of add to use when we know `d` is a displayable and isn't
    transformed.
    r   r   r   r   r   _implicit_adda  s    r   c                 K   s6   t jjj| fddi|}|jr2|d }|  |S )NlooseT)r@   r   imimager   r   r   )r   
propertiesrF   r   r   r   _imagem  s
    
r   textT)r   r1   
horizontalhbox)layoutr   r   verticalvboxr_   )r   r   grid)r   r   sidec                 K   s   t jjjf | |d|S )N)xmaximumymaximum)r@   r   r   	Container)maxwidth	maxheightr   r   r   r   _sizer  s    r   )r   window)r   r   rW   framec                    sD   t | ttfr" fdd| D }n|  i}tjjjf ||d|S )Nc                    s   i | ]
}| qS r   r   )rg   kactionr   r   
<dictcomp>  rj   z_key.<locals>.<dictcomp>)activate_soundcapture)r   r   r   r@   r   behaviorKeymap)r?   r   r   r   keymapr   r   r   _key  s    r   c                   @   sB   e Zd ZdZdZdddZdd Zdd	 Zed
d Z	dd Z
dS )ChoiceActionBaseaa  
    Base class for choice actions. The choice is identified by a label
    and value. The class will automatically determine the rollback state
    and supply correct "sensitive" and "selected" information to the
    widget.
    If a location is supplied, it will check whether the choice was
    previously visited and mark it so if it is chosen.
    TNc                 C   sB   || _ || _|| _|| _|d u r,tjj| _n|| _|| _|| _	d S r   )
labelvaluelocation	sensitiver@   rl   fix_rollback_without_choice	block_allr   rw   )r   r   r   r   r   r   r   rw   r   r   r   r=     s    zChoiceActionBase.__init__c                 C   s"   | j rtj  p | j o |  S r   )r   r@   rt   ru   r   r   r   r   r   r   r     s
    
zChoiceActionBase.get_sensitivec                 C   s   t j }t j o|| jkS r   )r@   rt   roll_forward_inforu   r   r   rk   r   r   r   r     s    
zChoiceActionBase.get_selectedc                 C   s   | j s
d S tjjjS r   )r   r@   rA   
persistent_chosenr   r   r   r   chosen  s    zChoiceActionBase.chosenc                 C   s    | j d u rdS | j| jf| j v S r   )r   r   r   r   r   r   r   
get_chosen  s    
zChoiceActionBase.get_chosen)NNTNN)r)   r*   r+   r,   r   r=   r   r   propertyr   r   r   r   r   r   r     s   	

r   c                   @   s   e Zd ZdZdd ZdS )ChoiceReturna  
    :doc: blockrollback

    A menu choice action that returns `value`, while managing the button
    state in a manner consistent with fixed rollback. (See block_all for
    a description of the behavior.)


    `label`
        The label text of the button. For imagebuttons and hotspots this
        can be anything. This label is used as a unique identifier of
        the options within the current screen. Together with `location`
        it is used to store whether this option has been chosen.

    `value`
        The value this is returned when the choice is chosen.

    `location`
        A unique location identifier for the current choices screen.

    `block_all`
        If false, the button is given the selected role if it was
        the chosen choice, and insensitive if it was not selected.

        If true, the button is always insensitive during fixed
        rollback.

        If None, the value is taken from the :var:`config.fix_rollback_without_choice`
        variable.

        When true is given to all items in a screen, it will
        become unclickable (rolling forward will still work). This can
        be changed by calling :func:`ui.saybehavior` before the call
        to :func:`ui.interact`.
    c                 C   s"   | j d urd| j | j| jf< | jS r   )r   r   r   r   r   r   r   r   r(     s    
zChoiceReturn.__call__N)r)   r*   r+   r,   r(   r   r   r   r   r     s   $r   c                   @   s    e Zd ZdZdd Zdd ZdS )
ChoiceJumpa  
    :doc: blockrollback

    A menu choice action that returns `value`, while managing the button
    state in a manner consistent with fixed rollback. (See block_all for
    a description of the behavior.)


    `label`
        The label text of the button. For imagebuttons and hotspots this
        can be anything. This label is used as a unique identifier of
        the options within the current screen. Together with `location`
        it is used to store whether this option has been chosen.

    `value`
        The location to jump to.

    `location`
        A unique location identifier for the current choices screen.

    `block_all`
        If false, the button is given the selected role if it was
        the chosen choice, and insensitive if it was not selected.

        If true, the button is always insensitive during fixed
        rollback.

        If None, the value is taken from the :var:`config.fix_rollback_without_choice`
        variable.

        When true is given to all items in a screen, it will
        become unclickable (rolling forward will still work). This can
        be changed by calling :func:`ui.saybehavior` before the call
        to :func:`ui.interact`.
    c                 C   s6   t j }t|t jjr"|jd }t j o4|| jkS )Nr   )	r@   rt   r   r   rA   JumpExceptionr   ru   r   r   r   r   r   r      s    

zChoiceJump.get_selectedc                 C   s.   | j d urd| j | j| jf< tj| j d S r   )r   r   r   r@   rt   jumpr   r   r   r   r   r(   )  s    
zChoiceJump.__call__N)r)   r*   r+   r,   r   r(   r   r   r   r   r     s   $	r   menumenu_captionmenu_choicemenu_choice_chosenmenu_choice_buttonmenu_choice_chosen_buttonFc
              	   K   s   t jjf d|i|
 | D ]\}}|d u r<t jj||d q|}|}t|trT|}nt|||}| rp|}|}t|trtt j	j
|}t|trtt j	j
|}|| }|| }t jj||||||	d qt  d S )Nr   r   )r   
text_styleclickedr   default)r@   r   r   r   r   r   r   r   getattrrA   r   
textbuttonrJ   )	menuitemsr   caption_stylechoice_stylechoice_chosen_stylechoice_button_stylechoice_chosen_button_styler   r   r  r   r   valr   buttonr  r   r   r   r   0  s4    


z{}input)excluder   r1   rN   hotspotc                 K   s   t |trttjj|}tf d|i| |d u r6| }t|  |D ]\}}}	}
}|d u rZqBt||}tj	j
|||	| |
| f|}ttj	j
|||	| |
| f||||||| |d|ddd qBt  d S )Nr   r   T)	selected_idle_imageselected_insensitive_imager  r   xposxanchoryposyanchor
focus_mask)r   r   r  r@   rA   r   r_   rD   r   r   r   LiveCropimagebuttonrJ   )groundselectedhotspots
unselectedr   button_styler   x0y0x1y1resultr   selected_imgr   r   r   imagemap_compatd  s0    

  r(  r  )r   r   c              	      s   d fdd	}||| ddd}||	|d}	||
|d}
|||d	}|||d
}|||d}t jjj||	f|
|||||d|S )NFc                    s^   | r| S |r|S  d ur2t j |}|d ur2|S |rZ rLtd| f ntd|f d S )Nz0Imagebutton does not have a %s image. (auto=%r).z%Imagebutton does not have a %s image.r@   rl   imagemap_auto_functionr'   )abr<   requiredrx   autor   r   choice  s    z_imagebutton.<locals>.choiceidleT)r-  hoverinsensitiveselected_idleselected_hoverselected_insensitive)insensitive_imageactivate_imager  selected_hover_imager  selected_activate_image)F)r@   r   r   ImageButton)
idle_imagehover_imager7  r8  r  r9  r  r:  r1  r2  r3  r4  r5  r6  image_styler/  r   r0  r   r.  r   _imagebutton  s(    	r?  image_buttonr  c                 K   s   t j|dd\}}d|v r4t|d tr4|d |dd  |d u rPtd}|d u rjt j|td}t j	j
jf ||d|}	t jjj| f|||d|}
|	|
 |
|	_|
g|	_|	S )	Ntext_r   aligny_fudger  button_text)r   r  r   
substitutescope)r@   r   split_propertiesr   floatrH   r   r   get_text_styler   r   Buttonr   TextrD   r   _composite_parts)r   r  r   r  rF  rG  rw   text_kwargsbutton_kwargsrx   r   r   r   r   _textbutton  s    

rP  c           
      K   s   t j|dd\}}|d u r$td}|d u r>t j|td}t jjjdd|i|}t j	j	j
| f|||d|}	||	 |	|_|	g|_|S )NrA  r   r   
label_textr   rE  )N)r@   r   rH  r   r   rJ  r   r   Windowr   rL  rD   r   rM  )
r   r   r  rF  rG  rw   rN  label_kwargsrx   r   r   r   r   _label  s    
rT  c                  O   s   t | dkr| \}}}}t | dkr6| \}}d }d }nd}d}d }d }d|v rX|d}d|v rj|d}d|v r||d}d|v r|d}d	|vrt|tr|d
 r| d }n| d }t|trt|}||d	< tjj	j
||||fi |S )N      r\   r   widthheightr   r   r   r   )r]   rH   r   r.   r5   r   r   r@   r   r   r/   )r   r   rW  rX  r   r   r   r   r   r   _bar  s6    





rY  )r   r1   slidervslider	scrollbar
vscrollbarc           
      K   sN   ||krd}d }n|| }d}||||   }	t jjj| |	d d fi ||fS )Ng      ?r   )r@   r   r   r/   )
r   startendtimer"   r   r   tredrawr   r   r   r   _autobar_interpolate2  s    rc  c                 K   s    t jjt| |||fi |S r   )r@   r   r   DynamicDisplayableautobar_interpolate)r   r^  r_  r`  r   r   r   r   _autobarB  s    rf  r   )r   r   viewport)r   r1   r   vpgrid)r   r1   r   i  c                 K   s  |d u r| f i |S t j|ddddd\}}}}}t jjrddlm}	 | D ]R\}
}t jjrt|
dv rt|||
< qR|
|	v r|||
< qR|r|
d	kr|||
< qR|||
< qRn
|	| t jj
r|d
kr|dtd n|dd t jj
r|dkr|dtd n|dd |dd}|dt j|d t jd  |dt j|d t jd  |d
krt jjr|dd tf tdi | | f i |}t }tf d|ji| t  t| |S |dkrFt jjr|dtd f tdi | | f i |}t }tf d|ji| t  t| |S t jjr`|dttf tdi | | f i |}t }tf d|ji| tf d|ji| t  t| |S d S )Nvscrollbar_
scrollbar_side_	viewport_r   r   )position_property_names>   yminimumxminimumminimumspacingr   r   r\  r   r]  r-   rg   zhorizontal scrollzvertical scroll
child_sizec r
adjustmentc bc r b)rt  )rv  )rw  )r@   r   rH  rl   position_viewport_siderenpy.sl2.slpropertiesrm  itemscompat_viewport_minimumr    prefix_viewport_scrollbar_styles
setdefaultr   r   minstore__scrollbar_child_sizeVIEWPORT_SIZEr   rG   rH   r]  yadjustmentrJ   r[   r\  xadjustment)vpfunc_spacing_to_side
scrollbarsr   vscrollbar_propertiesscrollbar_propertiesside_propertiesviewport_propertiescore_propertiesrm  r   vr-   rx   addabler   r   r   viewport_commonO  sl    



$$







r  c                  K   s   t tdfi | S r   )r  	_viewportr   r   r   r   rg    s    c                  K   s   t tdfi | S r   )r  _vpgridr  r   r   r   rh    s    )r1   )r1   r   )r1   r   c                   @   s(   e Zd ZdZdZdZdd Zdd ZdS )ImagemapzB
    Stores information about the images used by an imagemap.
    Tc	           	      C   st   t j|| _t j|| _t j|| _t j|| _t j|| _t j|| _|| _	|| _
t jj|| _d S r   )r@   r   rM   r3  r1  r4  r2  r5  r6  alphacache_paramr   rN   ImageMapCacherP   )	r   r3  r1  r4  r2  r5  r6  r  rP   r   r   r   r=     s    zImagemap.__init__c                 C   s   t jj| j| _d S r   )r@   r   rN   r  r  rP   r   r   r   r   reuse  s    zImagemap.reuseN)r)   r*   r+   r,   r  r  r=   r  r   r   r   r   r    s
   r  c                    s    fdd}|| d|} ||d| }||d|}||d| }||d|}||d| }||d	|}t t||||||||	 |d
d tjjjf ddi|}g }| r|tj	
|  ||  tjjjdd}|| || ||_||_|S )Nc                    sT   | r| S  r4|D ]"}t j |}|d ur|  S q|d ur@|S td|d  d S )Nz'Could not find a %s image for imagemap.r   r)  )variabler<   r0   r`   fnr.  r   r   pick  s    
z_imagemap.<locals>.pick)r  r1  )r1  )r4  )r2  )r5  )r3  )r6  	fit_firstTr   r_   )r   )rO   r[   r  r}  r@   r   r   MultiBoxrD   r   rM   r   rM  )r  r2  r3  r1  r5  r4  r6  r/  r  rP   r   r   r  rx   partsboxr   r.  r   	_imagemap  s@    


r  )rN   r   c              
   K   s:  t stdt d }| \}}}}|j}|j}	|j}
|j}|j}|j}|j	|| }|j	|	| }	|j	|
| }
|j	|| }|j	|| }|j	|| }|
d| |
dd |
d| |
dd |
d| |
d	| |
d
| |
d| |jrd}nd }|
d| tjjjd||
|	||||d|S )Nz*hotspot expects an imagemap to be defined.r>   r  r  r   r  r  ro  r   rn  r   Tr  )idle_backgroundselected_idle_backgroundhover_backgroundselected_hover_backgroundinsensitive_backgroundselected_insensitive_backgroundr   )N)rO   r'   r1  r2  r4  r5  r3  r6  rP   cropr}  r  r@   r   r   rK  )spotr   r   rN   xyr   hr1  r2  r4  r5  r3  r6  r  r   r   r   _hotspot  sR     	r  c                  O   s   t | i | t  d S r   )hotspot_with_childnullr   rw   r   r   r   r  E  s    c                 K   s  |d u r |d u r |d u r t dts,t dtd }| \}}}}	|d| |d| |dd |dd |j|j| }
|j|j| }|j|j| }|j|j| }|	|kr|d	d
 |dd
 ||
 }
}|| }}t	j
jjf ||||
|||dddd d d||	d|S )Nz:hotbar requires either an adjustment or a range and value.z)hotbar expects an imagemap to be defined.r>   r  r  r  r   r  bar_verticalT
bar_invertF)ru  r   r   fore_baraft_barhover_fore_barhover_aft_barfore_gutter
aft_gutterbar_resizingthumbthumb_shadowthumb_offsetr   r   )r'   rO   r}  rP   r  r4  r1  r5  r2  r@   r   r   r/   )r  ru  r   r   r   rN   r  r  r   r  r  r  r  r  r   r   r   _hotbarJ  sL    


r  hotbarc                 C   s   | S r   r   )r  r   r   r   _returns  s    r  c                 C   s:   t |trttj|}|d ur*tj| tj|  d S r   )r   r   r  r@   rl   rt   
transitionr   )r   r  r   r   r   _jumps  s
    
r  c                 C   s   t j| d S r   )r@   rA   JumpOutException)r   r   r   r   _jumpsoutofcontext  s    r  c                  O   s   t jj| i |S r   )r@   rt   curried_call_in_new_contextr  r   r   r   callsinnewcontext  s    r  c                  O   s   t jj| i |S r   )r@   rt   curried_invoke_in_new_contextr  r   r   r   invokesinnewcontext  s    r  c                  G   s    | rt d| d dS t dS d S )N
_game_menur   )_game_menu_screen)r  )r   r   r   r   	gamemenus  s    r  c                 C   s.   t du rtd|jp|t j| < |t j| < dS )z
    :undocumented:

    Assigns the displayable `d` the screen widget id `id_`, as if it had
    been created by a screen statement with that id.
    Nz1ui.screen_id must be called from within a screen.)r   r'   r   r   base_widgets)id_rF   r   r   r   	screen_id  s    r  )NN)rd   N)N)NN)NNT)	r   r   r   r   r  r  NNF)NrN   r  )NNNNNNNNNNNNNNNN)NNNTN)NNTN)N)NNNNNNNNTTrN   )r  )NNN)N)
__future__r   r   r   r   r   renpy.compatr   r   r	   r
   r   r   r   r   r   r   r   r   typingr   r   r@   renpy.display.behaviorr   r   objectObjectr   r.   r7   r:   rL   rT   rU   rY   rG   rb   ry   rO   rc   rA   	post_initr[   rr   rz   r{   r}   r   r   r   r   r   rJ   r   r   r   Sentinelr   r   r   r   r   r   rD   r   r^   r   r   r   r   Nullr  r   rL  r  r   r   r_   default_fixedGridr   Sider   r   sizerrR  r   r   r   r   r   SayBehaviorsaybehaviorPauseBehaviorpausebehaviorSoundStopBehaviorsoundstopbehaviorr   r?   r   r   r   r   Inputr  r(  rK  r  r?  r  rP  r  rT  r   
Adjustmentru  rY  r3   r4   rZ  r[  r\  r]  rc  curryre  rf  autobarr   r   r   rg  Viewportr  VPGridr  r  r  rh  ConditionalconditionalTimertimerdragdropDragdrag	DragGroup	draggroup	MouseArea	mousearear  r  rN   r  r  r  r  r  r  returnsr  jumpsr  jumpsoutofcontextr  r  r  OnEventonr  r   r  globalsrz  r   r<   r   r   r   r   <module>   s,  8 

6

 	



1,6         
1   
+                
9


)
[
7
3
0
