annotate clients/rio_de_hola/scripts/world.py @ 246:8156de05a544

Documentation for the World class in rio de hola.
author phoku@33b003aa-7bff-0310-803a-e67f0ece8222
date Wed, 25 Mar 2009 15:42:14 +0000
parents ed1565a5a2a0
children 040387b7167f
rev   line source
245
ed1565a5a2a0 Fixed second camera in rio.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 129
diff changeset
1 # -*- coding: utf-8 -*-
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
2 import fife, math, random
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
3 import pychan
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
4 import pychan.widgets as widgets
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
5
98
214e3eb81eb2 better structure for techdemo scripts + svn:ignore fixes
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 48
diff changeset
6 from scripts.common.eventlistenerbase import EventListenerBase
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
7 from loaders import loadMapFile
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
8 from savers import saveMapFile
98
214e3eb81eb2 better structure for techdemo scripts + svn:ignore fixes
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 48
diff changeset
9 from agents.hero import Hero
214e3eb81eb2 better structure for techdemo scripts + svn:ignore fixes
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 48
diff changeset
10 from agents.girl import Girl
214e3eb81eb2 better structure for techdemo scripts + svn:ignore fixes
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 48
diff changeset
11 from agents.cloud import Cloud
214e3eb81eb2 better structure for techdemo scripts + svn:ignore fixes
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 48
diff changeset
12 from agents.beekeeper import Beekeeper
214e3eb81eb2 better structure for techdemo scripts + svn:ignore fixes
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 48
diff changeset
13 from agents.agent import create_anonymous_agents
121
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 98
diff changeset
14 from settings import Setting
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 98
diff changeset
15
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 98
diff changeset
16 TDS = Setting()
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
17
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
18 class MapListener(fife.MapChangeListener):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
19 def __init__(self, map):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
20 fife.MapChangeListener.__init__(self)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
21 map.addChangeListener(self)
129
9a1529f9625e * Indentation patch by GreyGhost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 121
diff changeset
22
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
23 def onMapChanged(self, map, changedLayers):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
24 return
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
25 print "Changes on map ", map.getId()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
26 for layer in map.getLayers():
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
27 print layer.getId()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
28 print " ", ["%s, %x" % (i.getObject().getId(), i.getChangeInfo()) for i in layer.getChangedInstances()]
129
9a1529f9625e * Indentation patch by GreyGhost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 121
diff changeset
29
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
30 def onLayerCreate(self, map, layer):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
31 pass
129
9a1529f9625e * Indentation patch by GreyGhost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 121
diff changeset
32
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
33 def onLayerDelete(self, map, layer):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
34 pass
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
35
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
36
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
37 class World(EventListenerBase):
246
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
38 """
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
39 The world!
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
40
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
41 This class handles:
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
42 setup of map view (cameras ...)
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
43 loading the map
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
44 GUI for right clicks
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
45 handles mouse/key events which aren't handled by the GUI.
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
46 ( by inheriting from EventlistenerBase )
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
47
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
48 That's obviously too much, and should get factored out.
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
49 """
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
50 def __init__(self, engine):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
51 super(World, self).__init__(engine, regMouse=True, regKeys=True)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
52 self.engine = engine
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
53 self.eventmanager = engine.getEventManager()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
54 self.model = engine.getModel()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
55 self.view = self.engine.getView()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
56 self.filename = ''
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
57 self.pump_ctr = 0 # for testing purposis
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
58 self.ctrldown = False
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
59 self.instancemenu = None
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
60 self.instance_to_agent = {}
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
61 self.dynamic_widgets = {}
129
9a1529f9625e * Indentation patch by GreyGhost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 121
diff changeset
62
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
63 def show_instancemenu(self, clickpoint, instance):
246
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
64 """
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
65 Build and show a popupmenu for an instance that the player
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
66 clicked on. The available actions are dynamically added to
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
67 the menu (and mapped to the onXYZ functions).
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
68 """
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
69 if instance.getFifeId() == self.hero.agent.getFifeId():
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
70 return
129
9a1529f9625e * Indentation patch by GreyGhost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 121
diff changeset
71
246
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
72 # Create the popup.
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
73 self.build_instancemenu()
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
74 self.instancemenu.clickpoint = clickpoint
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
75 self.instancemenu.instance = instance
129
9a1529f9625e * Indentation patch by GreyGhost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 121
diff changeset
76
246
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
77 # Add the buttons according to circumstances.
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
78 self.instancemenu.addChild(self.dynamic_widgets['inspectButton'])
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
79 target_distance = self.hero.agent.getLocationRef().getLayerDistanceTo(instance.getLocationRef())
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
80 if target_distance > 3.0:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
81 self.instancemenu.addChild(self.dynamic_widgets['moveButton'])
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
82 else:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
83 if self.instance_to_agent.has_key(instance.getFifeId()):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
84 self.instancemenu.addChild(self.dynamic_widgets['talkButton'])
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
85 self.instancemenu.addChild(self.dynamic_widgets['kickButton'])
246
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
86 # And show it :)
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
87 self.instancemenu.position = (clickpoint.x, clickpoint.y)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
88 self.instancemenu.show()
129
9a1529f9625e * Indentation patch by GreyGhost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 121
diff changeset
89
246
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
90 def build_instancemenu(self):
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
91 """
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
92 Just loads the menu from an XML file
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
93 and hooks the events up.
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
94 The buttons are removed and later re-added if appropiate.
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
95 """
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
96 dynamicbuttons = ('moveButton', 'talkButton', 'kickButton', 'inspectButton')
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
97 self.instancemenu = pychan.loadXML('gui/instancemenu.xml')
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
98 self.instancemenu.mapEvents({
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
99 'moveButton' : self.onMoveButtonPress,
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
100 'talkButton' : self.onTalkButtonPress,
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
101 'kickButton' : self.onKickButtonPress,
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
102 'inspectButton' : self.onInspectButtonPress,
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
103 })
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
104 for btn in dynamicbuttons:
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
105 self.dynamic_widgets[btn] = self.instancemenu.findChild(name=btn)
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
106 self.instancemenu.removeAllChildren()
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
107
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
108 def hide_instancemenu(self):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
109 if self.instancemenu:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
110 self.instancemenu.hide()
129
9a1529f9625e * Indentation patch by GreyGhost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 121
diff changeset
111
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
112 def reset(self):
246
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
113 """
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
114 Clear the agent information and reset the moving secondary camera state.
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
115 """
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
116 self.map, self.agentlayer = None, None
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
117 self.cameras = {}
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
118 self.hero, self.girl, self.clouds, self.beekeepers = None, None, [], []
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
119 self.cur_cam2_x, self.initial_cam2_x, self.cam2_scrolling_right = 0, 0, True
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
120 self.target_rotation = 0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
121 self.instance_to_agent = {}
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
122
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
123 def load(self, filename):
246
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
124 """
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
125 Load a xml map and setup agents and cameras.
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
126 """
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
127 self.filename = filename
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
128 self.reset()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
129 self.map = loadMapFile(filename, self.engine)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
130 self.maplistener = MapListener(self.map)
129
9a1529f9625e * Indentation patch by GreyGhost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 121
diff changeset
131
246
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
132 self.initAgents()
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
133 self.initCameras()
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
134
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
135 def initAgents(self):
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
136 """
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
137 Setup agents.
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
138
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
139 For this techdemo we have a very simple 'active things on the map' model,
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
140 which is called agents. All rio maps will have a separate layer for them.
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
141
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
142 Note that we keep a mapping from map instances (C++ model of stuff on the map)
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
143 to the python agents for later reference.
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
144 """
5
427bb0de3e29 small fixes to techdemo to enable usage of beach map. Still segfaults when enabled from settings.py
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 0
diff changeset
145 self.agentlayer = self.map.getLayer('TechdemoMapGroundObjectLayer')
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
146 self.hero = Hero(self.model, 'PC', self.agentlayer)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
147 self.instance_to_agent[self.hero.agent.getFifeId()] = self.hero
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
148 self.hero.start()
129
9a1529f9625e * Indentation patch by GreyGhost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 121
diff changeset
149
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
150 self.girl = Girl(self.model, 'NPC:girl', self.agentlayer)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
151 self.instance_to_agent[self.girl.agent.getFifeId()] = self.girl
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
152 self.girl.start()
129
9a1529f9625e * Indentation patch by GreyGhost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 121
diff changeset
153
48
097996ee0b3d fixed talk functionality in techdemo
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 20
diff changeset
154 self.beekeepers = create_anonymous_agents(self.model, 'beekeeper', self.agentlayer, Beekeeper)
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
155 for beekeeper in self.beekeepers:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
156 self.instance_to_agent[beekeeper.agent.getFifeId()] = beekeeper
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
157 beekeeper.start()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
158
246
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
159 # Clouds are currently defunct.
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
160 cloudlayer = self.map.getLayer('TechdemoMapTileLayer')
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
161 self.clouds = create_anonymous_agents(self.model, 'Cloud', cloudlayer, Cloud)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
162 for cloud in self.clouds:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
163 cloud.start(0.1, 0.05)
129
9a1529f9625e * Indentation patch by GreyGhost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 121
diff changeset
164
246
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
165
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
166 def initCameras(self):
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
167 """
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
168 Before we can actually see something on screen we have to specify the render setup.
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
169 This is done through Camera objects which offer a viewport on the map.
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
170
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
171 For this techdemo two cameras are used. One follows the hero(!) via 'attach'
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
172 the other one scrolls around a bit (see the pump function).
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
173 """
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
174 for cam in self.view.getCameras():
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
175 self.cameras[cam.getId()] = cam
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
176 self.cameras['main'].attach(self.hero.agent)
129
9a1529f9625e * Indentation patch by GreyGhost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 121
diff changeset
177
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
178 self.view.resetRenderers()
246
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
179 # Floating text renderers currntly only support one font.
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
180 # ... so we set that up.
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
181 # You'll se that for our demo we use a image font, so we have to specify the font glyphs
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
182 # for that one.
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
183 renderer = fife.FloatingTextRenderer.getInstance(self.cameras['main'])
121
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 98
diff changeset
184 textfont = self.engine.getGuiManager().createFont('fonts/rpgfont.png', 0, str(TDS.readSetting("FontGlyphs", strip=False)));
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
185 renderer.changeDefaultFont(textfont)
129
9a1529f9625e * Indentation patch by GreyGhost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 121
diff changeset
186
246
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
187 # The small camera shouldn't be cluttered by the 'humm di dums' of our hero.
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
188 # So we disable the renderer simply by setting its font to None.
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
189 renderer = fife.FloatingTextRenderer.getInstance(self.cameras['small'])
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
190 renderer.changeDefaultFont(None)
129
9a1529f9625e * Indentation patch by GreyGhost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 121
diff changeset
191
246
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
192 # The following renderers are used for debugging.
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
193 # Note that by default ( that is after calling View.resetRenderers or Camera.resetRenderers )
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
194 # renderers will be handed all layers. That's handled here.
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
195 renderer = self.cameras['main'].getRenderer('CoordinateRenderer')
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
196 renderer.clearActiveLayers()
121
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 98
diff changeset
197 renderer.addActiveLayer(self.map.getLayer(str(TDS.readSetting("CoordinateLayerName"))))
129
9a1529f9625e * Indentation patch by GreyGhost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 121
diff changeset
198
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
199 renderer = self.cameras['main'].getRenderer('QuadTreeRenderer')
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
200 renderer.setEnabled(True)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
201 renderer.clearActiveLayers()
121
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 98
diff changeset
202 if str(TDS.readSetting("QuadTreeLayerName")):
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 98
diff changeset
203 renderer.addActiveLayer(self.map.getLayer(str(TDS.readSetting("QuadTreeLayerName"))))
129
9a1529f9625e * Indentation patch by GreyGhost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 121
diff changeset
204
246
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
205 # Set up the second camera
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
206 # NOTE: We need to explicitly call setLocation, there's a bit of a messup in the Camera code.
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
207 self.cameras['small'].setLocation(self.hero.agent.getLocation())
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
208 #self.cameras['small'].getLocationRef().setExactLayerCoordinates( fife.ExactModelCoordinate( 40.0, 40.0, 0.0 ))
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
209 self.initial_cam2_x = self.cameras['small'].getLocation().getExactLayerCoordinates().x
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
210 self.cur_cam2_x = self.initial_cam2_x
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
211 self.cam2_scrolling_right = True
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
212 self.target_rotation = self.cameras['main'].getRotation()
129
9a1529f9625e * Indentation patch by GreyGhost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 121
diff changeset
213
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
214 def save(self, filename):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
215 saveMapFile(filename, self.engine, self.map)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
216
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
217 def keyPressed(self, evt):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
218 keyval = evt.getKey().getValue()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
219 keystr = evt.getKey().getAsString().lower()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
220 if keystr == 't':
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
221 r = self.cameras['main'].getRenderer('GridRenderer')
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
222 r.setEnabled(not r.isEnabled())
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
223 elif keystr == 'c':
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
224 r = self.cameras['main'].getRenderer('CoordinateRenderer')
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
225 r.setEnabled(not r.isEnabled())
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
226 elif keystr == 's':
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
227 c = self.cameras['small']
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
228 c.setEnabled(not c.isEnabled())
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
229 elif keystr == 'r':
246
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
230 self.model.deleteMaps()
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
231 self.view.clearCameras()
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
232 self.load(self.filename)
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
233 elif keystr == 'o':
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
234 self.target_rotation = (self.target_rotation + 90) % 360
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
235 elif keyval in (fife.Key.LEFT_CONTROL, fife.Key.RIGHT_CONTROL):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
236 self.ctrldown = True
129
9a1529f9625e * Indentation patch by GreyGhost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 121
diff changeset
237
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
238 def keyReleased(self, evt):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
239 keyval = evt.getKey().getValue()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
240 if keyval in (fife.Key.LEFT_CONTROL, fife.Key.RIGHT_CONTROL):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
241 self.ctrldown = False
129
9a1529f9625e * Indentation patch by GreyGhost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 121
diff changeset
242
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
243 def mouseWheelMovedUp(self, evt):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
244 if self.ctrldown:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
245 self.cameras['main'].setZoom(self.cameras['main'].getZoom() * 1.05)
129
9a1529f9625e * Indentation patch by GreyGhost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 121
diff changeset
246
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
247 def mouseWheelMovedDown(self, evt):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
248 if self.ctrldown:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
249 self.cameras['main'].setZoom(self.cameras['main'].getZoom() / 1.05)
129
9a1529f9625e * Indentation patch by GreyGhost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 121
diff changeset
250
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
251 def changeRotation(self):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
252 currot = self.cameras['main'].getRotation()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
253 if self.target_rotation != currot:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
254 self.cameras['main'].setRotation((currot + 5) % 360)
129
9a1529f9625e * Indentation patch by GreyGhost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 121
diff changeset
255
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
256 def mousePressed(self, evt):
20
47fff0eee32e event consumption fix for techdemo, pop-menu now works and gui clicks do not cause agent movement
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 11
diff changeset
257 if evt.isConsumedByWidgets():
47fff0eee32e event consumption fix for techdemo, pop-menu now works and gui clicks do not cause agent movement
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 11
diff changeset
258 return
129
9a1529f9625e * Indentation patch by GreyGhost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 121
diff changeset
259
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
260 clickpoint = fife.ScreenPoint(evt.getX(), evt.getY())
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
261 if (evt.getButton() == fife.MouseEvent.LEFT):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
262 self.hide_instancemenu()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
263 target_mapcoord = self.cameras['main'].toMapCoordinates(clickpoint, False)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
264 target_mapcoord.z = 0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
265 l = fife.Location(self.agentlayer)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
266 l.setMapCoordinates(target_mapcoord)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
267 self.hero.run(l)
129
9a1529f9625e * Indentation patch by GreyGhost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 121
diff changeset
268
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
269 if (evt.getButton() == fife.MouseEvent.RIGHT):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
270 instances = self.cameras['main'].getMatchingInstances(clickpoint, self.agentlayer)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
271 print "selected instances on agent layer: ", [i.getObject().getId() for i in instances]
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
272 if instances:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
273 self.show_instancemenu(clickpoint, instances[0])
129
9a1529f9625e * Indentation patch by GreyGhost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 121
diff changeset
274
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
275 def mouseMoved(self, evt):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
276 renderer = fife.InstanceRenderer.getInstance(self.cameras['main'])
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
277 renderer.removeAllOutlines()
11
b153abbd9900 Fixed instance outlining for rio_de_hola.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 5
diff changeset
278
b153abbd9900 Fixed instance outlining for rio_de_hola.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 5
diff changeset
279 pt = fife.ScreenPoint(evt.getX(), evt.getY())
b153abbd9900 Fixed instance outlining for rio_de_hola.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 5
diff changeset
280 instances = self.cameras['main'].getMatchingInstances(pt, self.agentlayer);
b153abbd9900 Fixed instance outlining for rio_de_hola.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 5
diff changeset
281 for i in instances:
b153abbd9900 Fixed instance outlining for rio_de_hola.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 5
diff changeset
282 if i.getObject().getId() in ('girl', 'beekeeper'):
b153abbd9900 Fixed instance outlining for rio_de_hola.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 5
diff changeset
283 renderer.addOutlined(i, 173, 255, 47, 2)
129
9a1529f9625e * Indentation patch by GreyGhost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 121
diff changeset
284
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
285 def onConsoleCommand(self, command):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
286 result = ''
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
287 try:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
288 result = str(eval(command))
246
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
289 except Exception, e:
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
290 result = str(e)
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
291 return result
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
292
246
8156de05a544 Documentation for the World
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 245
diff changeset
293 # Callbacks from the popupmenu
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
294 def onMoveButtonPress(self):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
295 self.hide_instancemenu()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
296 self.hero.run(self.instancemenu.instance.getLocationRef())
129
9a1529f9625e * Indentation patch by GreyGhost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 121
diff changeset
297
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
298 def onTalkButtonPress(self):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
299 self.hide_instancemenu()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
300 instance = self.instancemenu.instance
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
301 self.hero.talk(instance.getLocationRef())
48
097996ee0b3d fixed talk functionality in techdemo
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 20
diff changeset
302 if instance.getObject().getId() == 'beekeeper':
121
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 98
diff changeset
303 beekeeperTexts = TDS.readSetting("beekeeperTexts", type='list', text=True)
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 98
diff changeset
304 txtindex = random.randint(0, len(beekeeperTexts) - 1)
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 98
diff changeset
305 instance.say(beekeeperTexts[txtindex], 5000)
48
097996ee0b3d fixed talk functionality in techdemo
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 20
diff changeset
306 if instance.getObject().getId() == 'girl':
121
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 98
diff changeset
307 girlTexts = TDS.readSetting("girlTexts", type='list', text=True)
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 98
diff changeset
308 txtindex = random.randint(0, len(girlTexts) - 1)
ae3b8139c7c7 * Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 98
diff changeset
309 instance.say(girlTexts[txtindex], 5000)
129
9a1529f9625e * Indentation patch by GreyGhost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 121
diff changeset
310
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
311 def onKickButtonPress(self):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
312 self.hide_instancemenu()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
313 self.hero.kick(self.instancemenu.instance.getLocationRef())
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
314 self.instancemenu.instance.say('Hey!', 1000)
129
9a1529f9625e * Indentation patch by GreyGhost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 121
diff changeset
315
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
316 def onInspectButtonPress(self):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
317 self.hide_instancemenu()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
318 inst = self.instancemenu.instance
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
319 saytext = ['Engine told me that this instance has']
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
320 if inst.getId():
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
321 saytext.append(' name %s,' % inst.getId())
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
322 saytext.append(' ID %s and' % inst.getFifeId())
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
323 saytext.append(' object name %s' % inst.getObject().getId())
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
324 self.hero.agent.say('\n'.join(saytext), 3500)
129
9a1529f9625e * Indentation patch by GreyGhost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 121
diff changeset
325
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
326 def pump(self):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
327 if self.cameras['small'].isEnabled():
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
328 loc = self.cameras['small'].getLocation()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
329 c = loc.getExactLayerCoordinatesRef()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
330 if self.cam2_scrolling_right:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
331 self.cur_cam2_x = c.x = c.x+0.1
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
332 if self.cur_cam2_x > self.initial_cam2_x+10:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
333 self.cam2_scrolling_right = False
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
334 else:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
335 self.cur_cam2_x = c.x = c.x-0.1
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
336 if self.cur_cam2_x < self.initial_cam2_x-10:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
337 self.cam2_scrolling_right = True
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
338 self.cameras['small'].setLocation(loc)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
339 self.changeRotation()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
340 self.pump_ctr += 1