move.py 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # coding: utf-8
  2. import typing
  3. from synergine2_cocos2d.interaction import BaseActorInteraction
  4. from opencc.user_action import UserAction
  5. from synergine2.simulation import SimulationBehaviour
  6. from synergine2_cocos2d.actor import Actor
  7. from synergine2_cocos2d.gl import draw_line
  8. from synergine2_xyz.move.simulation import RequestMoveBehaviour
  9. class BaseMoveActorInteraction(BaseActorInteraction):
  10. gui_action = None
  11. color = None
  12. request_move_behaviour_class = RequestMoveBehaviour
  13. def draw_pending(self) -> None:
  14. for actor in self.layer_manager.edit_layer.selection:
  15. grid_position = self.layer_manager.grid_manager.get_grid_position(actor.position)
  16. pixel_position = self.layer_manager.grid_manager.get_world_position_of_grid_position(grid_position)
  17. draw_line(
  18. self.layer_manager.scrolling_manager.world_to_screen(*pixel_position),
  19. self.layer_manager.edit_layer.screen_mouse,
  20. self.color,
  21. )
  22. def get_behaviour(self, actor: Actor, mouse_grid_position) -> typing.Tuple[typing.Type[SimulationBehaviour], dict]:
  23. return self.request_move_behaviour_class, {
  24. 'subject_id': actor.subject.id,
  25. 'move_to': mouse_grid_position,
  26. 'gui_action': self.gui_action,
  27. }
  28. class MoveActorInteraction(BaseMoveActorInteraction):
  29. gui_action = UserAction.ORDER_MOVE
  30. color = (0, 0, 255)
  31. class MoveFastActorInteraction(BaseMoveActorInteraction):
  32. gui_action = UserAction.ORDER_MOVE_FAST
  33. color = (72, 244, 66)
  34. class MoveCrawlActorInteraction(BaseMoveActorInteraction):
  35. gui_action = UserAction.ORDER_MOVE_CRAWL
  36. color = (235, 244, 66)