Package horizons :: Package gui :: Package modules :: Module loadingscreen
[hide private]
[frames] | no frames]

Source Code for Module horizons.gui.modules.loadingscreen

  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 random 
 23   
 24  import horizons.globals 
 25  from horizons.constants import TIER 
 26  from horizons.ext.speaklater import make_lazy_string 
 27  from horizons.gui.util import load_uh_widget 
 28  from horizons.gui.windows import Window 
 29  from horizons.i18n import gettext as T, gettext_lazy as LazyT 
 30  from horizons.messaging import LoadingProgress 
 31   
 32  # list of quotes and gameplay tips that are displayed while loading a game 
 33  # NOTE: Try to use not more than 4 lines in a quote/gameplay tip ! 
 34   
 35  FUN_QUOTES = { 
 36          'name': LazyT("Quotes"), 
 37          # Fun Quotes should not be translated... 
 38          'items': [ 
 39                  "Beer, the cause and solution to all problems of humanity.", 
 40                  "Trying is the first step t'wards failing.", 
 41                  "# nobody actually knows how the code below works.", 
 42                  "Here are dragons.", 
 43                  "Procrastination is the first step towards getting stuff done.", 
 44                  "Patience is a virtue. \n(barra)", 
 45                  "You must really, really love to test. \n(portal 2)", 
 46                  "Here are bugs.", 
 47                  "Strength is the capacity to break a chocolate bar into four pieces with your bare hands - and then eat just one of the pieces.", 
 48                  "If one does not know to which port one is sailing, no wind is favorable.", 
 49                  "The pessimist complains about the wind; \nthe optimist expects it to change; \nthe realist adjusts the sails.", 
 50                  "Travel beyond the horizon and discover unknown worlds!", 
 51                  "War… war never changes.", 
 52                  "Support Unknown Horizons with Cookies!", 
 53                  "Wow, looks nearly completed. \n(Neomex)", 
 54                  "Anchor is missing ...", 
 55                  "Campfire is lighted.", 
 56                  "The fish was as large as the whole island.", 
 57                  "Bugs are for your personal fun.", 
 58                  "Your game is unique. Please wait.", 
 59                  "Take it easy, the shore is near.", 
 60                  "Come on, let's discover new land." 
 61      ] 
 62  } 
 63   
 64   
 65  GAMEPLAY_TIPS = { 
 66          'name': LazyT("Gameplay Tips"), 
 67          'items': [ 
 68                  LazyT("Press 'ESC' to access Game Menu."), 
 69                  LazyT("Use 'SHIFT' to place multiple buildings."), 
 70                  #TODO: This tip should be removed when all tiers are playable!! 
 71                  make_lazy_string(lambda: T("Currently only the first {tier} tiers are playable.").format(tier=TIER.CURRENT_MAX + 1)), 
 72                  LazyT("You can pause the game with 'P'."), 
 73                  LazyT("You can drag roads by holding the left mouse button."), 
 74                  LazyT("You can build multiple buildings by holding the 'SHIFT' key."), 
 75                  LazyT("You can increase the happiness of your inhabitants by lowering the taxes."), 
 76                  LazyT("Build fire stations and doctors to protect your inhabitants from fire and disease."), 
 77                  LazyT("Build storage tents to increase your storage capacity."), 
 78                  LazyT("Make sure every house is in range of a marketplace."), 
 79                  LazyT("Press 'T' to make trees transparent."), 
 80                  LazyT("Build storage tents and lookouts to expand your settlement range."), 
 81                  LazyT("To easily see whether the pavilion's range cover all your tents, select it from the build menu and hover it over your existing pavilion. Uncovered tents are shown in yellow. It's a good idea to build a new pavilion in their neighborhood."), 
 82                  LazyT("Make singleplayer more fun with additional computer players by increasing 'AI players' when starting a new game."), 
 83                  LazyT("First steps are easier by looking at how AI players are setting up their settlement."), 
 84                  LazyT("Want funny quotes only? Change the quote types shown here in the settings menu on the game page."), 
 85                  LazyT("A marketplace links your buildings like a road.") 
 86          ] 
 87  } 
 88   
 89  # This are the options you can select in the Settings what type of quotes should be 
 90  # displayed during load 
 91  QUOTES_SETTINGS = (GAMEPLAY_TIPS['name'], FUN_QUOTES['name'], LazyT("Mixed")) 
 92   
 93   
94 -def get_random_quote():
95 quote_type = int(horizons.globals.fife.get_uh_setting("QuotesType")) 96 if quote_type == 2: 97 quote_type = random.randint(0, 1) # choose a random type 98 99 if quote_type == 0: 100 name = GAMEPLAY_TIPS["name"] 101 items = GAMEPLAY_TIPS["items"] 102 elif quote_type == 1: 103 name = FUN_QUOTES["name"] 104 items = FUN_QUOTES["items"] 105 106 return name, random.choice(items)
107 108 109 stage_text = { 110 # translators: these are descriptions of the current task while loading a game 111 'session_create_world': LazyT('Starting engine…'), 112 'session_index_fish': LazyT('Catching fish…'), 113 'session_load_gui': LazyT('Drawing user interface…'), 114 'session_finish': LazyT('Activating timer…'), 115 'load_objects': LazyT('Chomping game data…'), 116 'world_load_map': LazyT('Shaping islands…'), 117 'world_load_buildings': LazyT('Preparing blueprints…'), 118 'world_init_water': LazyT('Filling world with water…'), 119 'world_load_units': LazyT('Raising animals…'), 120 'world_setup_ai': LazyT('Convincing AI…'), 121 'world_load_stuff': LazyT('Burying treasures…'), 122 } 123 124
125 -class LoadingScreen(Window):
126 """Show quotes/gameplay tips while loading the game""" 127 128 # how often the LoadingProgress message is send when loading a game, 129 # used to update the progress bar 130 total_steps = len(stage_text) 131
132 - def __init__(self):
133 (width, height) = horizons.globals.fife.get_fife_setting('ScreenResolution').split('x') 134 135 res_width = int(width) 136 res_height = int(height) 137 138 self._widget = load_uh_widget('loadingscreen.xml') 139 140 loadingscreen = self._widget.findChild(name='loadingscreen') 141 loadingscreen.size = res_width, res_height 142 143 # centered vertically and horizontally 144 loading_box = self._widget.findChild(name='loading_box') 145 loading_box.position = ( 146 (res_width - loading_box.size[0]) // 2, 147 (res_height - loading_box.size[1]) // 2 148 ) 149 150 # centered horizontally, aligned at bottom 151 quote_area = self._widget.findChild(name='quote_area') 152 153 # set size to visible size, to make aligning children resolution independent 154 quote_area.size = ( 155 min(res_width, quote_area.size[0]), 156 min(res_height, quote_area.size[1]) 157 ) 158 159 quote_area.position = ( 160 (res_width - quote_area.size[0]) // 2, 161 res_height - quote_area.size[1] 162 ) 163 164 loading_stage = self._widget.findChild(name='loading_stage') 165 loading_stage.position = 150, 90 166 167 quote_type_label = self._widget.findChild(name='quote_type_label') 168 quote_label = self._widget.findChild(name='quote_label') 169 170 quote_type_label.position = ( 171 quote_area.size[0] - 600, 172 80 173 ) 174 quote_label.position = ( 175 quote_area.size[0] - 600, 176 90 177 ) 178 179 self._current_step = 0
180
181 - def show(self):
182 quote_type_label = self._widget.findChild(name='quote_type_label') 183 quote_label = self._widget.findChild(name='quote_label') 184 185 name, quote = get_random_quote() 186 quote_type_label.text = name 187 quote_label.text = quote 188 189 self._widget.show() 190 LoadingProgress.subscribe(self._update)
191
192 - def hide(self):
193 self._current_step = 0 194 LoadingProgress.discard(self._update) 195 self._widget.hide()
196
197 - def on_escape(self):
198 """Hitting Esc should not attempt to close the loading screen. 199 200 See #2018 for what happens else.""" 201 pass
202
203 - def _update(self, message):
204 self._current_step += 1 205 206 label = self._widget.findChild(name='loading_stage') 207 label.text = stage_text.get(message.stage, message.stage) 208 label.adaptLayout() 209 210 self._widget.findChild(name='loading_box_progress').progress = (100 * self._current_step) // self.total_steps 211 212 horizons.globals.fife.engine.pump()
213