Changeset 654 for trunk/game/scripts


Ignore:
Timestamp:
09/22/10 18:44:41 (9 years ago)
Author:
beliar
Message:

Patch by Beliar.

  • Added "addDialog" method to ActionsBox?, this takes a name and a text and prints them in a format that makes it easy to distinguish between the speaker and the text said.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/game/scripts/gui/actionsbox.py

    r653 r654  
    2525    def __init__(self, **kwargs): 
    2626        ScrollArea.__init__(self, **kwargs) 
    27         self.ContentBox = VBox(parent = self, name = "ActionsContentBox", is_focusable=False) 
     27        self.ContentBox = VBox(name = "ActionsContentBox", is_focusable=False) 
    2828        self.addChild(self.ContentBox) 
    2929     
    3030    def refresh(self): 
    3131        """Refresh the actions box so that it displays the contents of 
    32            self.actions_text 
    33            @return: None""" 
     32        self.actions_text 
     33        @return: None""" 
    3434        self.adaptLayout() 
    3535        self.vertical_scroll_amount = self.getVerticalMaxScroll() 
     
    3737    def addAction(self, action): 
    3838        """Add an action to the actions box. 
    39            @type action: (unicode) string 
    40            @param action: The text that you want to display in the actions box 
    41            @return: None"""         
     39        @type action: (unicode) string 
     40        @param action: The text that you want to display in the actions box 
     41        @return: None"""       
     42       
    4243        if not type(action) is unicode: 
    4344            action = unicode(action) 
     
    4647        self.ContentBox.addChild(action_label) 
    4748        self.refresh() 
     49     
     50    def addDialog(self, name, text): 
     51        """Add a dialog text to the actions box. Prints first the name and then, indented to the right, the text. 
     52        @type name: (unicode) string 
     53        @param action: The name of the character that spoke 
     54        @type text:: (unicode) string 
     55        @param text: The text that was said 
     56        @return: None"""         
     57        if not type(name) is unicode: 
     58            name = unicode(name) 
     59        if not type(text) is unicode: 
     60            text = unicode(text) 
     61         
     62         
     63        name_label = pychan.widgets.Label(text = name, wrap_text = True) 
     64        self.ContentBox.addChild(name_label) 
     65        text_box = pychan.widgets.HBox() 
     66        spacer = pychan.widgets.Label() 
     67        spacer.min_width = int(self.ContentBox.width * 0.05) 
     68        spacer.max_width = int(self.ContentBox.width * 0.05) 
     69        text_box.addChild(spacer) 
     70        text_label = pychan.widgets.Label(text = text, wrap_text = True) 
     71        text_label.max_width = int(self.ContentBox.width * 0.95) 
     72        text_box.addChild(text_label) 
     73        self.ContentBox.addChild(text_box) 
     74        self.refresh() 
     75         
Note: See TracChangeset for help on using the changeset viewer.