Package horizons :: Package gui :: Package widgets :: Module minimap :: Class Minimap
[hide private]
[frames] | no frames]

Class Minimap

source code

A basic minimap.

USAGE: Minimap can be drawn via GenericRenderer on an arbitrary position (determined by rect in ctor) or via Pychan Icon. In this case, the rect parameter only determines the size, the Minimap will scroll by default on clicks, overwrite on_click if you don't want that.

TODO: * Remove renderer when used in icon node * Clear up distinction of coords where the minimap image or screen is the origin * Create a minimap tag for pychan ** Handle clicks, remove overlay icon

Instance Methods [hide private]
 
__init__(self, position, session, view, targetrenderer, imagemanager, renderer=None, world=None, cam_border=True, use_rotation=True, on_click=None, preview=False, tooltip=None) source code
 
end(self) source code
 
disable(self)
Due to the way the minimap works, there isn't really a show/hide, but you can disable it with this and enable again with draw().
source code
 
draw(self)
Recalculates and draws the whole minimap of self.session.world or world.
source code
 
draw_data(self, data)
Display data from dump_data
source code
 
_get_render_name(self, key) source code
 
update_cam(self)
Redraw camera border.
source code
 
_update(self, tup)
Recalculate and redraw minimap for real world coord tup
source code
 
use_overlay_icon(self, icon)
Configures icon so that clicks get mapped here.
source code
 
default_on_click(self, event, drag)
Handler for clicks (pressed and dragged) Scrolls screen to the point, where the cursor points to on the minimap.
source code
 
_on_click(self, event) source code
 
_on_drag(self, event) source code
 
_get_event_coords(self, event)
Returns position of event as uh map coordinate tuple or None
source code
 
_mouse_entered(self, event) source code
 
_mouse_moved(self, event) source code
 
_mouse_exited(self, event) source code
 
_show_tooltip(self, event) source code
 
highlight(self, tup, factor=1.0, speed=1.0, finish_callback=None, color=(0,0,0))
Try to get the users attention on a certain point of the minimap.
source code
 
show_unit_path(self, unit)
Show the path a unit is moving along
source code
 
_recalculate(self, where=None)
Calculate which pixel of the minimap should display what and draw it
source code
 
_timed_update(self, force=False)
Regular updates for domains we can't or don't want to keep track of.
source code
 
_update_image(self, img_path, name, coord_tuple)
Updates image as part of minimap (e.g.
source code
 
rotate_right(self) source code
 
rotate_left(self) source code
 
_world_to_minimap(self, coords, use_rotation)
Complete coord transformation, batteries included.
source code
 
_get_rotation_setting(self) source code
 
_on_setting_changed(self, message) source code
 
_get_rotated_coords(self, tup)
Rotates according to current rotation settings.
source code
 
_get_from_rotated_coords(self, tup) source code
 
_rotate(self, tup, rotations) source code
 
_update_world_to_minimap_ratio(self) source code
 
_world_coords_to_minimap_coords(self, tup)
Calculates which pixel in the minimap contains a coord in the real map.
source code
 
_minimap_coords_to_world_coords(self, tup)
Inverse to _world_coords_to_minimap_coords
source code
 
get_size(self) source code
Class Methods [hide private]
 
update(cls, tup) source code
Class Variables [hide private]
  COLORS = {"island":(137, 117, 87), "cam":(1, 1, 1), "water":(1...
  WAREHOUSE_IMAGE = "content/gui/icons/minimap/warehouse.png"
  SHIP_NEUTRAL = "content/gui/icons/minimap/ship_neutral.png"
  SHIP_PIRATE = "content/gui/icons/minimap/pirate.png"
  GROUND_UNIT_IMAGE = "content/gui/icons/minimap/groundunit.png"
  SHIP_DOT_UPDATE_INTERVAL = 0.5
  RENDER_NAMES = {"background": "c", "base": "d", "warehouse": "...
  __minimap_id_counter = itertools.count()
  __ship_route_counter = itertools.count()
  _instances = []
  _dummy_fife_point = fife.Point(0, 0)
  _rotations = {0: 0, 1: 3* math.pi/ 2, 2: math.pi, 3: math.pi/ 2}
  _from_rotations = {0: 0, 1: math.pi/ 2, 2: math.pi, 3: 3* math...
Method Details [hide private]

__init__(self, position, session, view, targetrenderer, imagemanager, renderer=None, world=None, cam_border=True, use_rotation=True, on_click=None, preview=False, tooltip=None)
(Constructor)

source code 
Parameters:
  • position - a Rect or a Pychan Icon, where we will draw to
  • world - World object or fake thereof
  • view - View object for cam control. Can be None to disable this
  • renderer - renderer to be used if position isn't an icon
  • targetrenderer - fife target renderer for drawing on icons
  • imagemanager - fife imagemanager for drawing on icons
  • cam_border - boolean, whether to draw the cam border
  • use_rotation - boolean, whether to use rotation (it must also be enabled in the settings)
  • on_click - function taking 1 argument or None for scrolling
  • preview - flag, whether to only show the map as preview
  • tooltip - always show this tooltip when cursor hovers over minimap

    NOTE: Preview generation in a different process overwrites this method.

disable(self)

source code 

Due to the way the minimap works, there isn't really a show/hide, but you can disable it with this and enable again with draw(). Stops all updates.

draw(self)

source code 

Recalculates and draws the whole minimap of self.session.world or world. The world you specified is reused for every operation until the next draw().

_update(self, tup)

source code 

Recalculate and redraw minimap for real world coord tup

Parameters:
  • tup - (x, y)

use_overlay_icon(self, icon)

source code 

Configures icon so that clicks get mapped here. The current gui requires, that the minimap is drawn behind an icon.

default_on_click(self, event, drag)

source code 

Handler for clicks (pressed and dragged) Scrolls screen to the point, where the cursor points to on the minimap. Overwrite this method to your convenience.

highlight(self, tup, factor=1.0, speed=1.0, finish_callback=None, color=(0,0,0))

source code 

Try to get the users attention on a certain point of the minimap.

Parameters:
  • tup - world coords
  • factor - float indicating importance of event
  • speed - animation speed as factor
  • finish_callback - executed when animation finishes
  • color - color of anim, (r,g,b), r,g,b of [0,255] @return duration of full animation in seconds

_recalculate(self, where=None)

source code 

Calculate which pixel of the minimap should display what and draw it

Parameters:
  • where - Rect of minimap coords. Defaults to self.location

_update_image(self, img_path, name, coord_tuple)

source code 

Updates image as part of minimap (e.g. when it has moved)

_world_to_minimap(self, coords, use_rotation)

source code 

Complete coord transformation, batteries included. The methods below are for more specialized purposes.

_get_rotated_coords(self, tup)

source code 

Rotates according to current rotation settings. Input coord must be relative to screen origin, not minimap origin

_world_coords_to_minimap_coords(self, tup)

source code 

Calculates which pixel in the minimap contains a coord in the real map.

Parameters:
  • tup - (x, y) as ints @return tuple

Class Variable Details [hide private]

COLORS

Value:
{"island":(137, 117, 87), "cam":(1, 1, 1), "water":(198, 188, 165), "h\
ighlight":(255, 0, 0),}

RENDER_NAMES

Value:
{"background": "c", "base": "d", "warehouse": "e", "ship": "f", "cam":\
 "g", "ship_route": "h", "highlight": "l",}

_from_rotations

Value:
{0: 0, 1: math.pi/ 2, 2: math.pi, 3: 3* math.pi/ 2}