Package horizons :: Package world :: Module status
[hide private]
[frames] | no frames]

Source Code for Module horizons.world.status

  1  # ################################################### 
  2  # Copyright (C) 2008-2017 The Unknown Horizons Team 
  3  # team@unknown-horizons.org 
  4  # This file is part of Unknown Horizons. 
  5  # 
  6  # Unknown Horizons is free software; you can redistribute it and/or modify 
  7  # it under the terms of the GNU General Public License as published by 
  8  # the Free Software Foundation; either version 2 of the License, or 
  9  # (at your option) any later version. 
 10  # 
 11  # This program is distributed in the hope that it will be useful, 
 12  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 13  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 14  # GNU General Public License for more details. 
 15  # 
 16  # You should have received a copy of the GNU General Public License 
 17  # along with this program; if not, write to the 
 18  # Free Software Foundation, Inc., 
 19  # 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
 20  # ################################################### 
 21   
 22  import operator 
 23   
 24  from horizons.i18n import gettext as T, gettext_lazy as LazyT 
 25   
 26   
 27  """Classes used for StatusIcon. 
 28   
 29  Code design note: 
 30  The conditions for the statuses could also have been placed here, 
 31  for more modularity and flexiblity. 
 32  This way, we'd need to touch the objects' privates sometimes though, 
 33  and we'd lose some direct interaction flexiblity. Therefore, the objects 
 34  now contain all the logic, this module just covers the data. 
 35   
 36  Priority: 
 37  [   0-1000[: low 
 38  [1000-2000[: medium 
 39  [2000-3000[: high 
 40  Keep the numbers unique to avoid confusion when sorting. 
 41  """ 
42 43 44 -class StatusIcon:
45 # integer 46 priority = None # type: int 47 # fife identifier for animations or icons. Must be supported by either the animationloader 48 # or the imagemanager. (i.e. either file path or something like "as_buoy0+idle+45") 49 icon = None # type: str 50 # use _lazy 51 helptext = "" 52
53 - def __init__(self, instance):
54 """ 55 @param instance: the instance the icon is to be attached to 56 """ 57 self.instance = instance
58 59 @staticmethod
60 - def get_sorting_key():
61 """Use like this: 62 sorted(mylist, key=mylist.get_sorting_key()) 63 or 64 mylist.sort(key=mylist.get_sorting_key()) 65 """ 66 return operator.attrgetter("priority")
67
68 - def __str__(self):
69 return str(self.__class__) + "(prio:{},icon:{})".format(self.priority, self.icon)
70
71 72 -class BlackDeathStatusIcon(StatusIcon):
73 """ Black Death disaster """ 74 priority = 3000 75 icon = 'as_pestilence+idle+45' 76 _helptext = LazyT("The inhabitants are infected by the Black Death!")
77
78 79 -class FireStatusIcon(StatusIcon):
80 """ Fire disaster """ 81 priority = 3000 82 icon = 'as_on_fire+idle+45' 83 helptext = LazyT("This building is on fire!")
84
85 86 -class SettlerUnhappyStatus(StatusIcon):
87 # threshold is the inhabitants decrease level 88 priority = 1700 89 icon = 'as_attention_please+idle+45' 90 helptext = LazyT("These residents are unhappy.")
91
92 93 -class SettlerNotConnectedStatus(StatusIcon):
94 # threshold is the inhabitants decrease level 95 priority = 1700 96 icon = 'as_mainsquare_access+idle+45' 97 helptext = LazyT("These residents don't have access to a main square.")
98
99 100 -class InventoryFullStatus(StatusIcon):
101 priority = 1200 102 icon = 'as_inventory_full+idle+45' 103 helptext = LazyT("The inventory of this building is full.") 104
105 - def __init__(self, instance, reslist):
106 """ 107 @param reslist: list of integers describing the resources 108 """ 109 super().__init__(instance) 110 self.reslist = reslist
111
112 113 -class ProductivityLowStatus(StatusIcon):
114 """Terminology: productivity = capacity utilization""" 115 threshold = 0.25 # display when productivity lower than this 116 priority = 400 117 icon = 'as_attention_please+idle+45' 118 helptext = LazyT("This building has a very low productivity.")
119
120 121 -class DecommissionedStatus(StatusIcon):
122 priority = 800 123 icon = 'as_decommissioned+idle+45' 124 helptext = LazyT("This building is decommissioned.")
125