Package horizons :: Package gui :: Package mousetools :: Module buildingtool :: Class BuildingTool
[hide private]
[frames] | no frames]

Class BuildingTool

source code

              object --+            
                       |            
fife.fife.IMouseListener --+        
                           |        
       cursortool.CursorTool --+    
                               |    
   navigationtool.NavigationTool --+
                                   |
                                  BuildingTool

Represents a dangling tool after a building was selected from the list.
Builder visualizes if and why a building can not be built under the cursor position.
@param building: selected building type"
@param ship: If building from a ship, restrict to range of ship

The building tool has been under heavy development for several years, it's a collection
of random artifacts that used to have a purpose once.

Terminology:
- Related buildings: Buildings lower in the hierarchy, needed by current building to operate (tree when building lumberjack)
- Inversely related building: lumberjack for tree. Need to show its range to place building, it must be in range.
- Building instances/fife instances: the image of a building, that is dragged around.

Main features:
- Display tab to the right, showing build preview icon and rotation button (draw_gui(), load_gui())
- Show buildable ground (highlight buildable) as well as ranges of inversely related buildings
        - This also is called for tiles that need to be recolored, other highlights sometimes draw over
          tiles, then this is called again to redo the original coloring.
- Catch mouse events and handle preview on map:
        - Get tentative fife instances for buildings, draw them colored according to buildability
        - Check for resources missing for build
        - Making surrounding of preview transparent, so you see where you are building in a forest
        - Highlight related buildings, that are in range
        - Draw building range and highlight related buildings that are in range in this position (_color_preview_building)
- Initiate actual build (do_build)
        - Clean up coloring, possibly end build mode
- Several buildability logics, strategy pattern via self._build_logic.

Interaction sequence:
- Init, comprises mainly of gui init and highlight_buildable
- Update, which is mainly controlled by preview_build
        - Update highlights related to build
                - Transparency
                - Inversely related buildings in range (highlight_related_buildings)
                - Related buildings in range (_color_preview_build)
        - Set new instances
        - During this time, don't touch anything set by highlight_buildable, or restore it later
- End, possibly do_build and on_escape

Instance Methods [hide private]
 
__init__(self, session, building, ship=None, build_related=None)
__init__(FIFE::IMouseListener self) -> IMouseListener
source code
 
__init_selectable_component(self) source code
 
highlight_buildable(self, tiles_to_check=None, new_buildings=True)
Highlights all buildable tiles and select buildings that are inversely related in order to show their range.
source code
 
_color_buildable_tile(self, tile) source code
 
remove(self) source code
 
_on_worldobject_deleted(self, message) source code
 
load_gui(self) source code
 
draw_gui(self) source code
 
preview_build(self, point1, point2, force=False)
Display buildings as preview if build requirements are met
source code
 
_color_preview_building(self, building)
Draw fancy stuff for build preview
source code
 
_draw_preview_building_range(self, building, settlement)
Color the range as if the building was selected
source code
 
_highlight_related_buildings_in_range(self, building, settlement)
Highlight directly related buildings (tree for lumberjacks) that are in range of the build preview
source code
 
_make_surrounding_transparent(self, building)
Makes the surrounding of building_position transparent and hide buildings that are built upon (tearset)
source code
 
_highlight_inversely_related_buildings(self, building, settlement)
Point out buildings that are inversely related (e.g.
source code
 
_restore_highlighted_buildings(self)
Inverse of highlight_related_buildings
source code
 
on_escape(self) source code
 
mouseMoved(self, evt)
mouseMoved(IMouseListener self, MouseEvent evt)
source code
 
mousePressed(self, evt)
mousePressed(IMouseListener self, MouseEvent evt)
source code
 
mouseDragged(self, evt)
mouseDragged(IMouseListener self, MouseEvent evt)
source code
 
mouseReleased(self, evt)
Actually build.
source code
 
do_build(self)
Actually builds the previews @return a set of tiles where buildings have really been built
source code
 
_check_update_preview(self, end_point)
Used internally if the end_point changes
source code
 
_remove_listeners(self)
Resets the ChangeListener for update_preview.
source code
 
_add_listeners(self, instance) source code
 
force_update(self) source code
 
update_preview(self, force=False)
Used as callback method
source code
 
_rotate(self, degrees) source code
 
rotate_left(self) source code
 
rotate_right(self) source code
 
_remove_building_instances(self)
Deletes fife instances of buildings
source code
 
_restore_transparencified_instances(self)
Removes transparency
source code
 
_remove_coloring(self)
Removes coloring from tiles, that indicate that the tile is buildable as well as all highlights.
source code

Inherited from fife.fife.IMouseListener: __disown__, __repr__

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__, __sizeof__, __str__, __subclasshook__

    Inherited from navigationtool.NavigationTool
 
_schedule_hover_instance_update(self)
Hover instances have potentially changed, do an update in a timely fashion (but not right away)
source code
 
_send_hover_instance_upate(self)
Broadcast update with new instances below mouse (hovered).
source code
 
end(self) source code
 
get_hover_instances(self, where, layers=None)
Utility method, returns the instances under the cursor
source code
 
mouseWheelMovedDown(self, evt)
mouseWheelMovedDown(IMouseListener self, MouseEvent evt)
source code
 
mouseWheelMovedUp(self, evt)
mouseWheelMovedUp(IMouseListener self, MouseEvent evt)
source code
 
onCommand(self, command)
Called when some kind of command-event happens.
source code
    Inherited from cursortool.CursorTool
 
_get_screenpoint(self, arg)
Python lacks polymorphism.
source code
 
_round_map_coords(self, map_x, map_y)
Returns the coordinates of an event at the map.
source code
 
disable(self)
Call this to not get events.
source code
 
enable(self)
Call this to get events.
source code
 
get_exact_world_location(self, evt)
Returns the coordinates of an event at the map.
source code
 
get_world_location(self, evt) source code
 
mouseClicked(self, evt)
mouseClicked(IMouseListener self, MouseEvent evt)
source code
 
mouseEntered(self, evt)
mouseEntered(IMouseListener self, MouseEvent evt)
source code
 
mouseExited(self, evt)
mouseExited(IMouseListener self, MouseEvent evt)
source code
Class Variables [hide private]
  log = logging.getLogger("gui.buildingtool")
  buildable_color = 255, 255, 255
  not_buildable_color = 255, 0, 0, 160
  related_building_color = 0, 192, 0, 160
  related_building_outline = 32, 192, 32, 3
  nearby_objects_radius = 4
  _last_road_built = []
  send_hover_instances_update = False
  gui = None
hash(x)

Inherited from fife.fife.IMouseListener: __del__, __swig_destroy__, thisown

    Inherited from navigationtool.NavigationTool
  HOVER_INSTANCES_UPDATE_DELAY = 1
  last_event_pos = fife.ScreenPoint(0, 0)
  last_hover_instances = WeakList()
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, session, building, ship=None, build_related=None)
(Constructor)

source code 

__init__(FIFE::IMouseListener self) -> IMouseListener

Overrides: object.__init__
(inherited documentation)

highlight_buildable(self, tiles_to_check=None, new_buildings=True)

source code 

Highlights all buildable tiles and select buildings that are inversely related in order to show their range.

Parameters:
  • tiles_to_check - list of tiles to check for coloring.
  • new_buildings - Set to True if you have set tiles_to_check and there are new buildings. An internal structure for optimization will be amended.

remove(self)

source code 
Overrides: cursortool.CursorTool.remove

_color_preview_building(self, building)

source code 

Draw fancy stuff for build preview

Parameters:
  • building - return value from buildable, _BuildPosition

_highlight_inversely_related_buildings(self, building, settlement)

source code 

Point out buildings that are inversely related (e.g. lumberjacks when building trees) This is triggered on each preview change and highlights only those in range

mouseMoved(self, evt)

source code 

mouseMoved(IMouseListener self, MouseEvent evt)

Overrides: fife.fife.IMouseListener.mouseMoved
(inherited documentation)

mousePressed(self, evt)

source code 

mousePressed(IMouseListener self, MouseEvent evt)

Overrides: fife.fife.IMouseListener.mousePressed
(inherited documentation)

mouseDragged(self, evt)

source code 

mouseDragged(IMouseListener self, MouseEvent evt)

Overrides: fife.fife.IMouseListener.mouseDragged
(inherited documentation)

mouseReleased(self, evt)

source code 

Actually build.

Overrides: fife.fife.IMouseListener.mouseReleased

_remove_coloring(self)

source code 

Removes coloring from tiles, that indicate that the tile is buildable as well as all highlights. Called when building mode is finished.