Changeset 202


Ignore:
Timestamp:
07/10/09 23:20:30 (10 years ago)
Author:
bretzel_parpg
Message:

Fixed some things in the drag and drop code

Location:
trunk/PARPG/scripts
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/PARPG/scripts/inventory.py

    r161 r202  
    1717 
    1818import sys, os, fife, fifelog, pychan 
     19from scripts import drag_drop_data as data_drag 
    1920from pychan.tools import callbackWithArguments as cbwa 
    2021 
     
    3334        self.engine = engine 
    3435        self.readyCallback = readyCallback 
    35         self.dragging = False 
    36         self.dragged_image = None 
    37         self.dragged_type = None 
    38         self.dragged_item = None 
    39         self.dropped_type = None 
    4036        self.original_cursor_id = self.engine.getCursor().getId() 
    4137        # TODO: remove hard-coded string? 
     
    152148                       the dictionary 'self.buttons' 
    153149           @return: None""" 
    154         if(self.dragging == True): 
     150        if(data_drag.dragging == True): 
    155151            self.dropObject(obj) 
    156         elif(self.dragging == False): 
     152        elif(data_drag.dragging == False): 
    157153            self.dragObject(obj) 
    158154                 
     
    165161        # get the widget from the inventory with the name obj 
    166162        drag_widget = self.inventory.findChild(name = obj) 
    167         # get it's type (e.g. main_inv) 
    168         self.dragged_type = self.buttons[obj] 
    169         # get the item that the widget is 'storing' 
    170         self.dragged_item = drag_widget.item 
    171         # get the up and down images of the widget 
    172         up_image = drag_widget._getUpImage() 
    173         down_image = drag_widget._getDownImage() 
    174         # set the mouse cursor to be the widget's image 
    175         self.setMouseCursor(up_image,down_image) 
    176         self.dragged_image = up_image 
    177         self.dragging = True 
    178         # after dragging the 'item', set the widgets' images 
    179         # so that it has it's default 'empty' images 
    180         drag_widget._setUpImage(self.empty_images[obj]) 
    181         drag_widget._setDownImage(self.empty_images[obj]) 
    182         drag_widget._setHoverImage(self.empty_images[obj]) 
    183          
     163        # only drag if the widget is not empty 
     164        if (drag_widget.up_image != self.empty_images[obj]): 
     165            # get it's type (e.g. main_inv) 
     166            data_drag.dragged_type = self.buttons[obj] 
     167            # get the item that the widget is 'storing' 
     168            data_drag.dragged_item = drag_widget.item 
     169            # get the up and down images of the widget 
     170            up_image = drag_widget._getUpImage() 
     171            down_image = drag_widget._getDownImage() 
     172            # set the mouse cursor to be the widget's image 
     173            self.setMouseCursor(up_image,down_image) 
     174            data_drag.dragged_image = up_image 
     175            data_drag.dragging = True 
     176            # after dragging the 'item', set the widgets' images 
     177            # so that it has it's default 'empty' images 
     178            drag_widget._setUpImage(self.empty_images[obj]) 
     179            drag_widget._setDownImage(self.empty_images[obj]) 
     180            drag_widget._setHoverImage(self.empty_images[obj]) 
     181            # then set it's item to nothing 
     182            drag_widget.item = "" 
     183             
    184184    def dropObject(self, obj): 
    185185        """Drops the object being dropped 
     
    190190        # find the type of the place that the object 
    191191        # is being dropped onto 
    192         self.dropped_type  =  self.buttons[obj] 
     192        data_drag.dropped_type  =  self.buttons[obj] 
    193193        # if the dragged obj or the place it is being dropped is 
    194194        # in the main inventory, drop the object 
    195         if((self.dragged_type == 'main_inv') or 
    196            (self.dropped_type == 'main_inv')): 
     195        if((data_drag.dragged_type == 'main_inv') or 
     196           (data_drag.dropped_type == 'main_inv')): 
    197197            drag_widget = self.inventory.findChild(name = obj) 
    198             drag_widget._setUpImage(self.dragged_image) 
    199             drag_widget._setHoverImage(self.dragged_image) 
    200             drag_widget._setDownImage(self.dragged_image) 
    201             drag_widget.item = self.dragged_item 
    202             self.dragging = False 
     198            drag_widget._setUpImage(data_drag.dragged_image) 
     199            drag_widget._setHoverImage(data_drag.dragged_image) 
     200            drag_widget._setDownImage(data_drag.dragged_image) 
     201            drag_widget.item = data_drag.dragged_item 
     202            print 'Item: ' + drag_widget.item 
     203            data_drag.dragging = False 
    203204            #reset the mouse cursor to the normal cursor 
    204205            self.resetMouseCursor() 
    205206            # if the object was dropped onto a ready slot, then 
    206207            # update the hud 
    207             if (self.dropped_type == 'ready'): 
     208            if (data_drag.dropped_type == 'ready'): 
    208209                self.readyCallback() 
    209210         
     
    211212        # to drop it at's, and the dragged object's type is in 
    212213        # self.locations, then drop the object 
    213         elif((self.dragged_type == self.dropped_type) and 
    214              (self.dragged_type in self.locations)): 
     214        elif((data_drag.dragged_type == data_drag.dropped_type) and 
     215             (data_drag.dragged_type in self.locations)): 
    215216            drag_widget = self.inventory.findChild(name = obj) 
    216             drag_widget._setUpImage(self.dragged_image) 
    217             drag_widget._setHoverImage(self.dragged_image) 
    218             drag_widget._setDownImage(self.dragged_image) 
    219             drag_widget.item = self.dragged_item 
    220             self.dragging = False 
     217            drag_widget._setUpImage(data_drag.dragged_image) 
     218            drag_widget._setHoverImage(data_drag.dragged_image) 
     219            drag_widget._setDownImage(data_drag.dragged_image) 
     220            drag_widget.item = data_drag.dragged_item 
     221            print 'Item: ' + drag_widget.item 
     222            data_drag.dragging = False 
    221223            # reset the mouse cursor 
    222224            self.resetMouseCursor() 
    223225            # if the object was dropped onto a ready slot, then 
    224226            # update the hud 
    225             if(self.dropped_type == 'ready'): 
     227            if(data_drag.dropped_type == 'ready'): 
    226228                self.readyCallback() 
    227229        # otherwise, we assume that the player is trying to 
     
    230232            # reset the mouse cursor 
    231233            self.resetMouseCursor() 
    232             self.dragging = False 
    233  
     234            data_drag.dragging = False 
     235 
  • trunk/PARPG/scripts/popups.py

    r201 r202  
    212212        # get the widget from the container_gui with the name obj 
    213213        drag_widget = self.container_gui.findChild(name = obj) 
    214         # get it's type (e.g. main_inv) 
    215         data_drag.dragged_type = self.buttons[obj] 
    216         # get the item that the widget is 'storing' 
    217         data_drag.dragged_item = drag_widget.item 
    218         # get the up and down images of the widget 
    219         up_image = drag_widget._getUpImage() 
    220         down_image = drag_widget._getDownImage() 
    221         # set the mouse cursor to be the widget's image 
    222         self.setMouseCursor(up_image,down_image) 
    223         data_drag.dragged_image = up_image 
    224         data_drag.dragging = True 
    225         # after dragging the 'item', set the widgets' images 
    226         # so that it has it's default 'empty' images 
    227         drag_widget._setUpImage(self.empty_images[obj]) 
    228         drag_widget._setDownImage(self.empty_images[obj]) 
    229         drag_widget._setHoverImage(self.empty_images[obj]) 
    230         # then set it's item to nothing 
    231         drag_widget.item = "" 
    232          
     214        # only drag if the widget is not empty 
     215        if (drag_widget.up_image != self.empty_images[obj]): 
     216            # get it's type (e.g. main_inv) 
     217            data_drag.dragged_type = self.buttons[obj] 
     218            # get the item that the widget is 'storing' 
     219            data_drag.dragged_item = drag_widget.item 
     220            # get the up and down images of the widget 
     221            up_image = drag_widget._getUpImage() 
     222            down_image = drag_widget._getDownImage() 
     223            # set the mouse cursor to be the widget's image 
     224            self.setMouseCursor(up_image,down_image) 
     225            data_drag.dragged_image = up_image 
     226            data_drag.dragging = True 
     227            # after dragging the 'item', set the widgets' images 
     228            # so that it has it's default 'empty' images 
     229            drag_widget._setUpImage(self.empty_images[obj]) 
     230            drag_widget._setDownImage(self.empty_images[obj]) 
     231            drag_widget._setHoverImage(self.empty_images[obj]) 
     232            # then set it's item to nothing 
     233            drag_widget.item = "" 
     234             
    233235    def dropObject(self, obj): 
    234236        """Drops the object being dropped 
Note: See TracChangeset for help on using the changeset viewer.