inventory.py (5423B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\objectives\client\objective_task\inventory.py 2 import evetypes 3 import eveformat 4 import threadutils 5 import eveicon 6 from objectives.client.ui.objective_task_widget import ProgressBarTaskWidget 7 from objectives.client.objective_task.base import ObjectiveTask, ObjectiveTaskGroup 8 9 class ItemInInventoryTask(ObjectiveTask): 10 objective_task_content_id = None 11 WIDGET = ProgressBarTaskWidget 12 __notifyevents__ = ['OnMultipleItemChange', 'OnSessionChanged'] 13 USE_TYPE_ICON = True 14 15 def __init__(self, item = None, location_id = None, **kwargs): 16 super(ItemInInventoryTask, self).__init__(**kwargs) 17 self._item = None 18 self.item = item 19 self._location_id = location_id 20 self._current_quantity = 0 21 22 def get_values(self): 23 result = super(ItemInInventoryTask, self).get_values() 24 result['current_quantity'] = self._current_quantity 25 result['progress'] = self.progress 26 return result 27 28 @property 29 def item(self): 30 return self._item 31 32 @item.setter 33 def item(self, value): 34 if self._item == value: 35 return 36 self._item = value 37 self._title = evetypes.GetName(self.type_id) 38 self.update() 39 40 @property 41 def location_id(self): 42 return self._location_id 43 44 @location_id.setter 45 def location_id(self, value): 46 if self.location_id == value: 47 return 48 self.location_id = value 49 self.update() 50 51 def _update(self): 52 self._check_inventory() 53 54 def OnMultipleItemChange(self, items, change): 55 for item in items: 56 if self.group_id: 57 if evetypes.GetGroupID(item.typeID) == self.group_id: 58 self._check_inventory() 59 return 60 elif item.typeID == self.type_id: 61 self._check_inventory() 62 return 63 64 def OnSessionChanged(self, is_remote, session, change): 65 if 'shipid' in change or 'locationid' in change: 66 self._check_inventory() 67 68 @property 69 def item_id(self): 70 return self.item.get('item_id', None) 71 72 @property 73 def type_id(self): 74 return self.item.get('type_id', None) 75 76 @property 77 def group_id(self): 78 return self.item.get('group_id', None) 79 80 @property 81 def quantity(self): 82 return self.item.get('quantity', 1) 83 84 @threadutils.threaded 85 def _check_inventory(self): 86 if self.group_id: 87 kwargs = {'group_id': self.group_id} 88 else: 89 kwargs = {'type_id': self.type_id} 90 result = self._quantity_function(location_id=self.location_id, **kwargs).get_values() 91 if result: 92 value = max(min(result['quantity'], self.quantity), 0) 93 else: 94 value = 0 95 if self._current_quantity == value: 96 return 97 self._current_quantity = value 98 self.on_update(objective_task=self) 99 self.completed = self._current_quantity >= self.quantity 100 101 @property 102 def _quantity_function(self): 103 from nodegraph.client.getters.inventory import GetItemQuantity 104 return GetItemQuantity 105 106 @property 107 def value(self): 108 return u'{}/{}'.format(eveformat.number(self._current_quantity, 0), eveformat.number(self.quantity, 0)) 109 110 @property 111 def progress(self): 112 return min(self._current_quantity / float(self.quantity), 1.0) 113 114 def get_context_menu(self): 115 return sm.GetService('menu').GetMenuFromItemIDTypeID(itemID=self.item_id, typeID=self.type_id, includeMarketDetails=True) 116 117 118 class ItemInInventoryTaskGroup(ObjectiveTaskGroup): 119 objective_task_content_id = 4 120 TASK = ItemInInventoryTask 121 122 def __init__(self, items = None, location_id = None, **kwargs): 123 super(ItemInInventoryTaskGroup, self).__init__(**kwargs) 124 self._location_id = location_id 125 self._update_items(items) 126 127 def update_value(self, key, value): 128 if key == 'items': 129 self._update_items(value) 130 elif key == 'location_id': 131 self._update_location(value) 132 133 def _update_items(self, items): 134 self.clear_tasks() 135 if items is None: 136 items = [] 137 elif not isinstance(items, list): 138 items = [items] 139 for item in items: 140 task_id = item.get('item_id') or item.get('type_id') or item.get('group_id') 141 self.add_task(task_id=task_id, item=item, location_id=self._location_id) 142 143 self.all_tasks_added() 144 145 def _update_location(self, location_id): 146 self._location_id = location_id 147 for task in self.tasks: 148 task.update_value('location_id', location_id) 149 150 151 class ItemInShipCargoTask(ItemInInventoryTask): 152 153 @property 154 def _quantity_function(self): 155 from nodegraph.client.getters.inventory import GetItemQuantityInShipCargo 156 return GetItemQuantityInShipCargo 157 158 159 class ItemInShipCargoTaskGroup(ItemInInventoryTaskGroup): 160 objective_task_content_id = 2 161 TASK = ItemInShipCargoTask 162 163 164 class ItemInHangarTask(ItemInInventoryTask): 165 166 @property 167 def _quantity_function(self): 168 from nodegraph.client.getters.inventory import GetItemQuantityInHangar 169 return GetItemQuantityInHangar 170 171 172 class ItemInHangarTaskGroup(ItemInInventoryTaskGroup): 173 objective_task_content_id = 3 174 TASK = ItemInHangarTask