@WorldView.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. /******************************************************************************/
  2. /******************************************************************************/
  3. class WorldView : Viewport4Region, WorldData
  4. {
  5. enum MODE
  6. {
  7. HEIGHTMAP,
  8. OBJECT ,
  9. WAYPOINT ,
  10. WATER ,
  11. PATH ,
  12. };
  13. static cchar8 *mode_t[]
  14. ;
  15. enum OBJ_OP
  16. {
  17. OP_INS ,
  18. OP_MOVE ,
  19. OP_ROT ,
  20. OP_SCALE ,
  21. OP_SEPARATE ,
  22. OP_MOVE_Y ,
  23. OP_ROT_Y ,
  24. OP_ROT_GROUP,
  25. OP_SEL ,
  26. };
  27. enum WAYPOINT_OP
  28. {
  29. WPO_INS ,
  30. WPO_DEL ,
  31. WPO_MOVE ,
  32. WPO_MOVE_ALL ,
  33. WPO_MOVE_Y ,
  34. WPO_MOVE_ALL_Y,
  35. WPO_ROT ,
  36. };
  37. static cchar8 *waypoint_loop_t[]
  38. ; ASSERT(Game::Waypoint::SINGLE==0 && Game::Waypoint::LOOP==1 && Game::Waypoint::PING_PONG==2);
  39. enum WATER_OP
  40. {
  41. WAO_NEW_POINT ,
  42. WAO_NEW_WATER ,
  43. WAO_DEL_POINT ,
  44. WAO_MOVE ,
  45. WAO_MOVE_ALL ,
  46. WAO_ROT ,
  47. WAO_MOVE_ALL_Y ,
  48. WAO_MOVE_Y ,
  49. WAO_RIVER_POINT_SIZE, // river point radius
  50. WAO_RIVER_SIZE , // river radius
  51. WAO_LAKE_NUM =WAO_MOVE_Y ,
  52. WAO_RIVER_NUM=WAO_RIVER_SIZE+1,
  53. };
  54. Button show_cur_pos, show_grid, undo, redo;
  55. Tabs mode, show_obj_grid;
  56. ComboBox show_menu;
  57. Menu *show_menu_objs;
  58. Memb<UID> show_menu_objs_id; // use Memb because we store pointer to elements
  59. Button set_grid_level, obj_hm_align, play, locate;
  60. Memx<Property> view_props;
  61. TextWhite ts;
  62. flt grid_plane_level;
  63. int visible_radius;
  64. bool show_world_center, show_objs, show_obj_access[OBJ_ACCESS_NUM], show_obj_box, show_obj_phys, show_world_path,
  65. cur_collides_with_hm, cur_collides_with_obj,
  66. obj_center_points, obj_matrix_points,
  67. obj_random_angle,
  68. hm_align, hm_align_nrm,
  69. grid_align, grid_align_round;
  70. flt grid_align_size_xz, grid_align_size_y;
  71. RectI visible_area, visible_area_1, valid_area;
  72. Cursor cur;
  73. Memc<Cursor> cur_touch;
  74. bool changed_settings; // if changed world settings
  75. flt grass_range2, validate_refs_time;
  76. Memc<Edit::EditorInterface::Line> lines;
  77. WorldUndo undos; void undoVis();
  78. // heightmap
  79. Button hm_add_rem, hm_import;
  80. MaterialPtr hm_mtrl;
  81. ImageSkin hm_mtrl_img;
  82. Text hm_mtrl_text;
  83. flt hm_mtrl_highlight;
  84. int hm_sel_size;
  85. bool hm_ao;
  86. Memx<Property> hm_props;
  87. bool hm_use_shader;
  88. Shader *hm_shader;
  89. int update_count;
  90. uint update_time;
  91. // object
  92. Tabs obj_op, obj_params;
  93. ComboBox obj_menu;
  94. Button obj_list, obj_paint;
  95. int obj_axis;
  96. flt obj_edit_angle, obj_edit_speed;
  97. Vec obj_edit_vec;
  98. ParamEditor param_edit;
  99. ObjGrid obj_grid;
  100. ObjPos obj_pos;
  101. ObjScale obj_scale;
  102. ObjRot obj_rot;
  103. GridPlaneLevel grid_plane_level_win;
  104. GoToArea goto_area;
  105. Memc<Obj*> obj_update, obj_visible, obj_blend, obj_palette[2];
  106. Mesh dummy_mesh;
  107. Material dummy_mtrl;
  108. Memc<UID> hide_obj_classes; // id's of ELM_OBJ_CLASS that want to be hidden in the world
  109. // waypoint
  110. class Waypoint : EditWaypoint
  111. {
  112. ~Waypoint();
  113. };
  114. Tabs waypoint_op;
  115. ComboBox waypoint_menu;
  116. WaypointPos waypoint_pos;
  117. Region waypoint_props_region;
  118. Memx<Property> waypoint_props, waypoint_global_props;
  119. Button waypoint_list;
  120. flt waypoint_edit_speed;
  121. int waypoint_subdivide;
  122. ThreadSafeMap<UID, EditWaypoint> waypoints;
  123. Memc<EditWaypoint*> visible_waypoints, changed_waypoints;
  124. EditWaypoint *sel_waypoint, *lit_waypoint;
  125. UID sel_waypoint_point, lit_waypoint_point;
  126. flt last_waypoint_flush_time;
  127. // water
  128. ComboBox water_menu;
  129. WaterMtrlPtr water_mtrl;
  130. ImageSkin water_mtrl_img;
  131. Text water_mtrl_text;
  132. flt water_edit_speed, water_mtrl_highlight;
  133. Tabs water_op, water_mode;
  134. Region water_props_region;
  135. Memx<Property> water_props;
  136. Property *water_mtrl_p, *water_tex_scale, *water_smooth;
  137. ThreadSafeMap<UID, Lake> lakes;
  138. ThreadSafeMap<UID, River> rivers;
  139. Memc<Lake *> visible_lakes , changed_lakes ;
  140. Memc<River*> visible_rivers, changed_rivers;
  141. Lake *sel_lake , *lit_lake ;
  142. River *sel_river, *lit_river;
  143. int sel_lake_poly, sel_lake_point , lit_lake_poly, lit_lake_point ,
  144. sel_river_point, lit_river_point;
  145. flt last_water_flush_time;
  146. // path
  147. PathProps path_props;
  148. WorldView();
  149. static void Grid (WorldView &world);
  150. static void GridLevel (WorldView &world);
  151. static void GotoArea (WorldView &world);
  152. static void HmAddRem (WorldView &world);
  153. static void HmSelMtrl (WorldView &world);
  154. static void HmImport (WorldView &world);
  155. static void DecRadius (WorldView &world);
  156. static void IncRadius (WorldView &world);
  157. static void DecSel (WorldView &world);
  158. static void IncSel (WorldView &world);
  159. static void Mode1 (WorldView &world);
  160. static void Mode2 (WorldView &world);
  161. static void Mode3 (WorldView &world);
  162. static void Mode4 (WorldView &world);
  163. static void Mode5 (WorldView &world);
  164. static void ModeS0 (WorldView &world);
  165. static void ModeS1 (WorldView &world);
  166. static void ModeS2 (WorldView &world);
  167. static void ModeS3 (WorldView &world);
  168. static void ModeS4 (WorldView &world);
  169. static void ModeS5 (WorldView &world);
  170. static void ModeS6 (WorldView &world);
  171. static void ModeS7 (WorldView &world);
  172. static void ModeS8 (WorldView &world);
  173. static void ModeS9 (WorldView &world);
  174. static void ModeS10 (WorldView &world);
  175. static void ModeS11 (WorldView &world);
  176. static void OpMove (WorldView &world);
  177. static void OpRot (WorldView &world);
  178. static void OpScale (WorldView &world);
  179. static void Op4 (WorldView &world);
  180. static void Op5 (WorldView &world);
  181. static void Op6 (WorldView &world);
  182. static void Op7 (WorldView &world);
  183. static void AlignHm (WorldView &world);
  184. static void AlignGrid (WorldView &world);
  185. static void CurPos (WorldView &world);
  186. static void ShowObjList (WorldView &world);
  187. static void ShowObjPaint (WorldView &world);
  188. static void ShowObjPoint (WorldView &world);
  189. static void ShowObjBox (WorldView &world);
  190. static void ShowObjPhys (WorldView &world);
  191. static void ShowWorldPath (WorldView &world);
  192. static void ShowWorldCenter (WorldView &world);
  193. static void ShowObjs (WorldView &world);
  194. static void ShowObjTerrain (WorldView &world);
  195. static void ShowObjGrass (WorldView &world);
  196. static void ShowObjCustom (WorldView &world);
  197. static void ShowObjClass (UID &id );
  198. static void ShowWaypointList(WorldView &world);
  199. static void ModeChanged (WorldView &world);
  200. static void ObjOpChanged (WorldView &world);
  201. static void WaterOpChanged (WorldView &world);
  202. static void Play (WorldView &world);
  203. static void Undo (WorldView &world);
  204. static void Redo (WorldView &world);
  205. static void Locate (WorldView &world);
  206. void modeS(int i);
  207. static void AreaDrawPrepare(Cell<Area> &cell, ptr);
  208. static void AreaDrawShadow (Cell<Area> &cell, ptr);
  209. static void AreaDraw2D (Cell<Area> &cell, ptr);
  210. static void Render();
  211. void render();
  212. static void Draw(Viewport &viewport);
  213. void draw(Edit::Viewport4::View&view);
  214. void drawGrid();
  215. void drawAreaSelection();
  216. void drawHeightmapImport();
  217. void drawObjPoints();
  218. void drawArea2D();
  219. void higlight();
  220. // get / set
  221. bool selected()C;
  222. Cursor& curAll (int i); // get cursor from all cursors, including mouse and touches
  223. int curTotal( )C; // get number of all cursors, including mouse and touches
  224. Cursor* findCur(Touch *touch);
  225. class HeightmapY
  226. {
  227. Vec2 xz;
  228. VecI2 xzi;
  229. flt dist;
  230. Area *find;
  231. public:
  232. HeightmapY();
  233. };
  234. static void HeightNearestFunc(Cell<Area> &cell, HeightmapY &hy);
  235. flt hmHeight(C Vec &pos, bool *found=null);
  236. flt hmHeight(C Vec2 &xz , bool *found=null);
  237. flt hmHeightNearest(C Vec2 &xz);
  238. Vec hmNormalAvg(C Matrix &matrix, C Box &box);
  239. bool hmColor(C Vec &pos, Vec &color);
  240. bool hmColor(C Vec2 &xz , Vec &color);
  241. MaterialPtr hmMtrl(C Vec &pos, C MaterialPtr &cur_mtrl=null);
  242. MaterialPtr hmMtrl(C Vec2 &xz , C MaterialPtr &cur_mtrl=null);
  243. bool gridAlign ()C;
  244. bool gridAlignRound()C;
  245. flt gridAlignSize ()C;
  246. flt gridAlignSizeY()C;
  247. RectI visibleArea ()C; // visible area rectangle
  248. int visibleRadius()C; // visible area radius
  249. void visibleRadius(int r);
  250. int hmSelSize ()C;
  251. void hmSelSize (int r);
  252. bool selectionCenter(Vec &center);
  253. bool selectionZoom(flt &dist);
  254. C UID* ID(C EditWaypoint *waypoint)C;
  255. C UID* ID(C Lake *lake )C;
  256. C UID* ID(C River *river )C;
  257. // create
  258. void setMenu();
  259. void setMenu(Node<MenuElm> &menu, C Str &prefix);
  260. void createTerrain();
  261. void createObj();
  262. void createWaypoint();
  263. void createWater();
  264. void createPath();
  265. WorldView& create();
  266. // operations
  267. void modeChanged();
  268. void selectedChanged();
  269. void skinChanged();
  270. void camCenter(bool only_with_selection, bool zoom);
  271. virtual void camCenter(bool zoom)override;
  272. void flushSettings();
  273. void flushWaypoints();
  274. void flushWater ();
  275. void flush();
  276. void setVisibleWaypoints();
  277. void setVisibleWaters ();
  278. void setChangedWaypoint(EditWaypoint *waypoint, bool refresh_gui=true); // if belongs to this world
  279. void setChangedLake (Lake *lake ); // if belongs to this world, call rebuild water after setting mesh so vertexes and area coverage is up to date
  280. void setChangedRiver (River *river ); // if belongs to this world, call rebuild water after setting mesh so vertexes and area coverage is up to date
  281. void selWaypoint(EditWaypoint *waypoint, C UID &point);
  282. void waterToGui ();
  283. void setWaterVis();
  284. void reloadEnv();
  285. void set(Elm *elm);
  286. void activate(Elm *elm);
  287. void toggle(Elm *elm);
  288. class IDName
  289. {
  290. UID id;
  291. Str name;
  292. void set(C UID &id, C Str &name);
  293. static int CompareName(C IDName &a, C IDName &b);
  294. };
  295. void enumChanged();
  296. void meshVariationChanged();
  297. void elmChanged(C UID &elm_id);
  298. void erasing(C UID &elm_id);
  299. void objTransChanged();
  300. void objToGui();
  301. virtual void resize()override;
  302. void setHmMtrl(C UID &id);
  303. void setWaterMtrl(C UID &id);
  304. void setSelWaterMtrl(C UID &id);
  305. static bool SameNameExcludeIndex(Str a, Str b);
  306. void drag(Memc<UID> &elms, GuiObj* &focus_obj, C Vec2 &screen_pos);
  307. static void SetShader(Cell<Area> &cell, ptr user, int thread_index);
  308. void setShader( );
  309. // update
  310. void updateAligning();
  311. static void UpdateVisibility(Cell<Area> &cell, WorldView &world);
  312. void updateVisibility(Cell<Area> &cell);
  313. void updateVisibility();
  314. void updateCursors();
  315. void updateCamCenter();
  316. virtual void update(C GuiPC &gpc)override;
  317. static void HmCreate(Cell<Area> &cell, Memt<Area*> &created);
  318. static void HmDel (Cell<Area> &cell, Memt<Area*> &created);
  319. static void HmBuild ( Area* &area, ptr user, int thread_index);
  320. void highlightHmMtrl ();
  321. void highlightWaterMtrl();
  322. void editHm(bool insert, Cursor &cur);
  323. static void DragHmMtrl(ptr, GuiObj *obj, C Vec2 &screen_pos);
  324. void updateHm();
  325. void updateObj();
  326. static void ValidateRefs(Cell<Area>&cell, ptr);
  327. void validateRefs();
  328. void delayedValidateRefs(); // update after 2 seconds
  329. void updateValidateRefs();
  330. void updateWaypoint();
  331. void updateWater();
  332. void lakeDel(Lake *lake , int poly, int point);
  333. void riverDel(River *river, int vtx);
  334. void editObj();
  335. void removed(Obj &obj);
  336. void hmDel(C VecI2 &area_xy, C TimeStamp *time=null);
  337. void setObjVisibility();
  338. virtual void draw(C GuiPC &gpc)override;
  339. };
  340. /******************************************************************************/
  341. /******************************************************************************/
  342. extern WorldView WorldEdit;
  343. /******************************************************************************/