PageRenderTime 68ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 1ms

/new_engine/bin/scripts/editor/editor-menus.lua

https://bitbucket.org/DerekMitnik/2chantra
Lua | 1871 lines | 1705 code | 58 blank | 108 comment | 146 complexity | 7e75caa6ae99a68a07b16023f7084f7e MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. menus = PagedMenu.create()
  2. menus2 = {}
  3. menus3 = PagedMenu.create()
  4. if not Editor then Editor = {} end
  5. menus:addPage( 1, SimpleMenu.create( {CONFIG.scr_width/2, CONFIG.scr_height/2}, 0, 0, 30, 10 ) )
  6. function Editor.show_dir( root_dir, filter, preprocess, event, cancel_event, preview )
  7. local dir, dirs = ListDirContents( Editor.path )
  8. dirs = dirs or 0
  9. dir = dir or {}
  10. local files = {}
  11. for i = #dir, dirs+1, -1 do
  12. table.insert( files, table.remove( dir, i ) )
  13. end
  14. table.sort( files )
  15. table.sort( dir )
  16. for i = 1, #files do
  17. table.insert( dir, files[i] )
  18. end
  19. Editor.menu:clear(2)
  20. if not preprocess then preprocess = function(a) return a end end
  21. if not filter then filter = function(a) return true end end
  22. if Editor.path ~= root_dir then
  23. menus:add(
  24. MWFunctionButton.create(
  25. {name="dialogue", color={1,1,1,1}, active_color={.2,.2,1,1}},
  26. "..",
  27. 0,
  28. function()
  29. if string.match(Editor.path, "/[^/]+$") then
  30. Editor.path = string.gsub(Editor.path, "/[^/]+$", "")
  31. else
  32. Editor.path = ""
  33. end
  34. Editor.show_dir( root_dir, filter, preprocess, event, cancel_event, preview )
  35. end,
  36. nil,
  37. {name="wakaba-widget"}
  38. ),
  39. 2
  40. )
  41. end
  42. menus:add(
  43. MWFunctionButton.create(
  44. {name="dialogue", color={1,1,1,1}, active_color={.2,.2,1,1}},
  45. "cancel",
  46. 0,
  47. function()
  48. Editor.menu:hide(2)
  49. cancel_event()
  50. end,
  51. nil,
  52. {name="wakaba-widget"}
  53. ),
  54. 2
  55. )
  56. for i=1,dirs do
  57. menus:add(
  58. MWFunctionButton.create(
  59. {name="dialogue", color={1,1,1,1}, active_color={.2,.2,1,1}},
  60. preprocess(dir[i]),
  61. 0,
  62. function()
  63. Editor.path = Editor.path.."/"..dir[i]
  64. Editor.show_dir( root_dir, filter, preprocess, event, cancel_event, preview )
  65. end,
  66. dir[i],
  67. {name="wakaba-widget"}
  68. ),
  69. 2
  70. )
  71. end
  72. for i=dirs+1, #dir do
  73. if filter(Editor.path.."/"..dir[i]) then
  74. menus:add(
  75. MWFunctionButton.create(
  76. {name="dialogue", color={.6,.6,.6,1}, active_color={.2,.2,.6,1}},
  77. preprocess(dir[i]),
  78. 0,
  79. function()
  80. Editor.path = Editor.path.."/"..dir[i]
  81. Editor.menu:hide(2)
  82. event( Editor.path )
  83. end,
  84. dir[i],
  85. {name="wakaba-widget"},
  86. nil, function() if preview then preview( Editor.path.."/"..dir[i] ) end end
  87. ),
  88. 2
  89. )
  90. end
  91. end
  92. Editor.menu:move( CONFIG.scr_width/2, CONFIG.scr_height/2, 2 )
  93. Editor.menu:show( 2 )
  94. end
  95. function Editor.ptype_show_dir()
  96. local dir, dirs = ListDirContents( Editor.path )
  97. Editor.menu:clear(2)
  98. if Editor.path ~= "proto" then
  99. menus:add(
  100. MWFunctionButton.create(
  101. {name="default", color={1,1,1,1}, active_color={.2,.2,1,1}},
  102. "..",
  103. 0,
  104. Editor.ptype_back,
  105. nil,
  106. {name="wakaba-widget"}
  107. ),
  108. 2
  109. )
  110. end
  111. for i=1,dirs do
  112. menus:add(
  113. MWFunctionButton.create(
  114. {name="default", color={1,1,1,1}, active_color={.2,.2,1,1}},
  115. dir[i],
  116. 0,
  117. Editor.ptype_dir,
  118. dir[i],
  119. {name="wakaba-widget"}
  120. ),
  121. 2
  122. )
  123. end
  124. for i=dirs+1, #dir do
  125. menus:add(
  126. MWFunctionButton.create(
  127. {name="default", color={.8,.8,.8,.8}, active_color={.2,.2,1,1}},
  128. dir[i],
  129. 0,
  130. Editor.ptype_file,
  131. dir[i],
  132. {name="wakaba-widget"}
  133. ),
  134. 2
  135. )
  136. end
  137. Editor.menu:move( CONFIG.scr_width/2, CONFIG.scr_height/2, 2 )
  138. Editor.menu:show( 2 )
  139. end
  140. function Editor.ptype_selected( id, ptype )
  141. Editor.ptype = ptype
  142. if ptype == "ENEMY" then
  143. Editor.path = "proto/enemies"
  144. elseif ptype == "SPRITE" then
  145. Editor.path = "proto/sprites"
  146. elseif ptype == "PLAYER" then
  147. Editor.path = "proto/characters"
  148. elseif ptype == "ITEM" then
  149. Editor.path = "proto/items"
  150. elseif ptype == "TILE" then
  151. Editor.path = "proto/sprites"
  152. elseif ptype == "PHYSIC GROUP" then
  153. Editor.path = "proto/sprites"
  154. elseif ptype == "ACTIVE GROUP" then
  155. Editor.path = "proto/items"
  156. elseif ptype == "RIBBON" then
  157. Editor.path = "proto/sprites"
  158. else
  159. Editor.path = "proto"
  160. end
  161. local preview
  162. local preview_window
  163. local preview_widget
  164. if ptype ~= "PHYSIC GROUP" and ptype ~= "ACTIVE GROUP" then
  165. preview_widget = CreateWidget( constants.wt_Button, "PREVIEW", nil, CONFIG.scr_width - 138, CONFIG.scr_height - 138, 128, 128 )
  166. preview_window = Window.create( CONFIG.scr_width - 148, CONFIG.scr_height - 148, 148, 148, "window1" )
  167. description_widget = CreateWidget( constants.wt_Label, "PREVIEW", nil, CONFIG.scr_width - 286, 20, 276, CONFIG.scr_height - 188 )
  168. description_window = Window.create( CONFIG.scr_width - 296, 10, 296, CONFIG.scr_height - 168, "window1" )
  169. description_window:setVisible(false)
  170. WidgetSetCaptionColor( description_widget, { 1, 1, 1, 1 }, false )
  171. WidgetSetCaptionFont( description_widget, "dialogue" )
  172. preview = function( filename )
  173. WidgetSetSize( preview_widget, 128, 128 )
  174. WidgetSetPos( preview_widget, CONFIG.scr_width - 138, CONFIG.scr_height - 138 )
  175. local info, sb = Editor.emulateObject( Editor.EDITOR_TYPES[Editor.ptype], filename )
  176. if info and info.texture then
  177. WidgetSetSprite( preview_widget, info.texture, true, info.num )
  178. WidgetSetSpriteColor( preview_widget, sb.color or {1,1,1,1} )
  179. else
  180. WidgetSetSprite( preview_widget, "editor_misc", true )
  181. end
  182. local var = Editor.extractVariables( filename )
  183. if var.description then
  184. description_window:setVisible(true)
  185. WidgetSetCaption( description_widget, var.description, true )
  186. WidgetSetVisible( description_widget, true )
  187. else
  188. description_window:setVisible(false)
  189. WidgetSetVisible( description_widget, false )
  190. end
  191. WidgetSetZ( preview_widget, 1 )
  192. end
  193. end
  194. Editor.show_dir( Editor.path, nil,
  195. function(a)
  196. return string.gsub(a, "%.lua", "")
  197. end,
  198. function (filename)
  199. Editor.ptype_file( -1, filename )
  200. if preview_window then
  201. preview_window:destroy()
  202. description_window:destroy()
  203. end
  204. if preview_widget then
  205. DestroyWidget( preview_widget )
  206. DestroyWidget( description_widget )
  207. end
  208. end,
  209. function ()
  210. Editor.changeState( Editor.STATE.RUNNING )
  211. if preview_window then
  212. preview_window:destroy()
  213. description_window:destroy()
  214. end
  215. if preview_widget then
  216. DestroyWidget( preview_widget )
  217. DestroyWidget( description_widget )
  218. end
  219. end,
  220. preview
  221. )
  222. end
  223. function Editor.ptype_back()
  224. Editor.path = string.gsub(Editor.path, "/[^/]+$", "")
  225. Editor.ptype_show_dir()
  226. end
  227. function Editor.ptype_dir( id, name )
  228. Editor.path = Editor.path.."/"..name
  229. Editor.ptype_show_dir()
  230. end
  231. function Editor.ptype_file( id, name )
  232. local proto_name = string.gsub(name, "%.lua$", "")
  233. proto_name = string.gsub( proto_name, "proto/", "" )
  234. full_path = Editor.path .. "/" .. name
  235. if Editor.ptype == "SPRITE" then
  236. proto_name = string.gsub( proto_name, "^sprites/", "" )
  237. elseif Editor.ptype == "ENEMY" then
  238. proto_name = string.gsub( proto_name, "^enemies/", "" )
  239. elseif Editor.ptype == "PLAYER" then
  240. proto_name = string.gsub( proto_name, "^characters/", "" )
  241. elseif Editor.ptype == "TILE" then
  242. proto_name = string.gsub( proto_name, "^sprites/", "" )
  243. elseif Editor.ptype == "ITEM" then
  244. proto_name = string.gsub( proto_name, "^items/", "" )
  245. elseif Editor.ptype == "PHYSIC GROUP" then
  246. proto_name = string.gsub( proto_name, "^sprites/", "" )
  247. elseif Editor.ptype == "ACTIVE GROUP" then
  248. proto_name = string.gsub( proto_name, "^items/", "" )
  249. elseif Editor.ptype == "RIBBON" then
  250. proto_name = string.gsub( proto_name, "^sprites/", "" )
  251. end
  252. Editor.menu:hide()
  253. Editor.changeState( Editor.STATE.RUNNING )
  254. Editor.SelectObject(proto_name, Editor.ptype, name)
  255. end
  256. for key, value in pairs( {"PLAYER", "SPRITE", "TILE", "ENEMY", "ITEM", "PHYSIC GROUP", "ACTIVE GROUP", "RIBBON"} ) do
  257. menus:add(
  258. MWFunctionButton.create(
  259. {name="default", color={1,1,1,1}, active_color={.2,.2,1,1}},
  260. value,
  261. 0,
  262. Editor.ptype_selected,
  263. value,
  264. {name="wakaba-widget"}
  265. ),
  266. 1
  267. )
  268. end
  269. menus:add(
  270. MWSpace.create( 10, 5 ),
  271. 1
  272. )
  273. menus:add(
  274. MWFunctionButton.create(
  275. {name="default", color={1,1,1,1}, active_color={.2,.2,1,1}},
  276. "CANCEL",
  277. 0,
  278. function() Editor.menu:hide() Editor.changeState( Editor.STATE.RUNNING ) end,
  279. nil,
  280. {name="wakaba-widget"}
  281. ),
  282. 1
  283. )
  284. menus:addPage( 2, ScrollingMenu.create( {CONFIG.scr_width/2, CONFIG.scr_height/2}, 0, 0, 30, 10 ) )
  285. menus:addPage( 3, SimpleMenu.create( {CONFIG.scr_width/2, CONFIG.scr_height/2}, 0, 0, 30, 10 ) )
  286. if not RestoreKeyProcessors then
  287. function RestoreKeyProcessors()
  288. end
  289. end
  290. function RemoveKeyProcessors()
  291. local on_press = GlobalGetKeyDownProc()
  292. local on_release = GlobalGetKeyReleaseProc()
  293. local mouse_press = GlobalGetMouseKeyDownProc()
  294. local mouse_release = GlobalGetMouseKeyReleaseProc()
  295. local restore_proc = RestoreKeyProcessors
  296. GlobalSetKeyDownProc( nil )
  297. GlobalSetKeyReleaseProc( nil )
  298. GlobalSetMouseKeyDownProc( nil )
  299. GlobalSetMouseKeyReleaseProc( nil )
  300. RestoreKeyProcessors = function()
  301. GlobalSetKeyDownProc( on_press )
  302. GlobalSetKeyReleaseProc( on_release )
  303. GlobalSetMouseKeyDownProc( mouse_press )
  304. GlobalSetMouseKeyReleaseProc( mouse_release )
  305. RestoreKeyProcessors = restore_proc
  306. end
  307. end
  308. function Editor.confirm( message, sure, not_sure )
  309. RemoveKeyProcessors()
  310. local l_window = SimpleMenu.create( {CONFIG.scr_width/2, CONFIG.scr_height/2}, 0, 0, 30, 10 )
  311. l_window:add( MWSpace.create( 15, 15 ) )
  312. l_window:add( MWCaption.create( {name="dialogue", color={1,1,1,1}}, message, 0 ) )
  313. l_window:add( MWSpace.create( 15, 15 ) )
  314. l_window:add( MWComposition.create( 10, {
  315. MWFunctionButton.create( {name = "default", color = {1,1,1,1}, active_color={.2,.2,1,1}},
  316. "YES",
  317. 0,
  318. function()
  319. l_window:clear()
  320. l_window:hide()
  321. RestoreKeyProcessors()
  322. sure()
  323. end,
  324. nil,
  325. {name="wakaba-widget"} ),
  326. MWFunctionButton.create( {name = "default", color = {1,1,1,1}, active_color={.2,.2,1,1}},
  327. "NO",
  328. 0,
  329. function()
  330. l_window:clear()
  331. l_window:hide()
  332. RestoreKeyProcessors()
  333. not_sure()
  334. end,
  335. nil,
  336. {name="wakaba-widget"} )
  337. }))
  338. l_window:add( MWSpace.create( 15, 15 ) )
  339. l_window:show()
  340. end
  341. function Editor.popup( message, event )
  342. RemoveKeyProcessors()
  343. local l_window = SimpleMenu.create( {CONFIG.scr_width/2, CONFIG.scr_height/2}, 0, 0, 30, 10 )
  344. l_window:add( MWSpace.create( 15, 15 ) )
  345. l_window:add( MWCaption.create( {name="dialogue", color={1,1,1,1}}, message, 0 ) )
  346. l_window:add( MWSpace.create( 15, 15 ) )
  347. l_window:add( MWFunctionButton.create( {name = "default", color = {1,1,1,1}, active_color={.2,.2,1,1}},
  348. "OK",
  349. 0,
  350. function()
  351. l_window:clear()
  352. l_window:hide()
  353. RestoreKeyProcessors()
  354. event()
  355. end,
  356. nil,
  357. {name="wakaba-widget"} ))
  358. l_window:add( MWSpace.create( 15, 15 ) )
  359. l_window:show()
  360. end
  361. function Editor.longPopup( var )
  362. var = var or {}
  363. var.event = var.event or function() end
  364. RemoveKeyProcessors()
  365. local l_window = SimpleMenu.create( {CONFIG.scr_width/2, CONFIG.scr_height/2}, 0, 0, 30, 10 )
  366. l_window:add( MWSpace.create( 15, 15 ) )
  367. if var.title then
  368. l_window:add( MWCaption.create( {name="default", color={.8,.9,.3,1}}, var.title, 0 ) )
  369. l_window:add( MWSpace.create( 15, 15 ) )
  370. end
  371. var.message = var.message or { "Someone forgot to put a message here, that jerk." }
  372. if #var.message > 16 then
  373. var.message[17] = "... and "..(#var.message-16).." more."
  374. end
  375. for i=1,math.min(17, #var.message) do
  376. l_window:add( MWCaption.create( {name="dialogue", color={1,1,1,1}}, var.message[i], 0 ) ) --TODO: multiline
  377. end
  378. l_window:add( MWSpace.create( 15, 15 ) )
  379. l_window:add( MWFunctionButton.create( {name = "default", color = {1,1,1,1}, active_color={.2,.2,1,1}},
  380. "OK",
  381. 0,
  382. function()
  383. l_window:clear()
  384. l_window:hide()
  385. RestoreKeyProcessors()
  386. var.event()
  387. end,
  388. nil,
  389. {name="wakaba-widget"} ))
  390. l_window:add( MWSpace.create( 15, 15 ) )
  391. l_window:show()
  392. end
  393. function Editor.popup_enter( message, ok, cancel, default )
  394. if not default then default = (Editor.current_map or "map") end
  395. vars.__input = default
  396. RemoveKeyProcessors()
  397. local l_window = SimpleMenu.create( {CONFIG.scr_width/2, CONFIG.scr_height/2}, 0, 0, 30, 10 )
  398. l_window:add( MWSpace.create( 15, 15 ) )
  399. l_window:add( MWCaption.create( {name="dialogue", color={1,1,1,1}}, message, 0 ) )
  400. l_window:add( MWInputField.create( {name="dialogue", color={1,1,1,1}, active_color={.8,.8,1,1}},
  401. default, 0, {name="wakaba-widget"}, nil, "__input", 20 ) )
  402. l_window:add( MWSpace.create( 15, 15 ) )
  403. l_window:add( MWComposition.create( 10, {
  404. MWFunctionButton.create( {name = "default", color = {1,1,1,1}, active_color={.2,.2,1,1}},
  405. "OK",
  406. 0,
  407. function()
  408. l_window:clear()
  409. l_window:hide()
  410. RestoreKeyProcessors()
  411. ok(vars.__input)
  412. end,
  413. nil,
  414. {name="wakaba-widget"} ),
  415. MWFunctionButton.create( {name = "default", color = {1,1,1,1}, active_color={.2,.2,1,1}},
  416. "CANCEL",
  417. 0,
  418. function()
  419. l_window:clear()
  420. l_window:hide()
  421. RestoreKeyProcessors()
  422. cancel()
  423. end,
  424. nil,
  425. {name="wakaba-widget"} )
  426. }))
  427. l_window:add( MWSpace.create( 15, 15 ) )
  428. l_window:show()
  429. end
  430. function str2col( str )
  431. if not str then str = { 0, 0, 0, 1 } end
  432. local r,g,b,a = string.match( str, "%[([^,]+),([^,]+),([^,]+),([^%]]+)%]" )
  433. if r then
  434. return { tonumber(r), tonumber(g), tonumber(b), tonumber(a) }
  435. else
  436. return { 0, 0, 0, 0 }
  437. end
  438. end
  439. function Editor.valuesPopup( title, subtitle, properties, event, cancel_event, object )
  440. Editor.changeState( Editor.STATE.IN_MENU )
  441. RemoveKeyProcessors()
  442. local l_window = SimpleMenu.create( {CONFIG.scr_width/2, CONFIG.scr_height/2}, 0, 0, 30, 10 )
  443. l_window:add( MWSpace.create( 15, 15 ) )
  444. if title then l_window:add( MWCaption.create( {name="default", color={1,1,.2,1}}, title, 0 ) ) end
  445. if subtitle then l_window:add( MWCaption.create( {name="dialogue", color={1,1,.2,1}}, subtitle, 0 ) ) end
  446. l_window:add( MWSpace.create( 15, 15 ) )
  447. local p = {}
  448. local p_back = {}
  449. for i=1, #properties do
  450. p[i] = properties[i]
  451. if p[i][2] == "FLOAT" then
  452. l_window:add( MWComposition.create( 10, {
  453. MWCaption.create( {name = "dialogue", color = {1,1,1,1}},
  454. p[i][1],
  455. -1 ),
  456. MWInputField.create( {name = "dialogue", color = {1,1,1,1}, active_color={.8,.8,1,1}},
  457. p[i][3],
  458. -1,
  459. nil,
  460. function( sender, value )
  461. local vf = tonumber(value)
  462. if vf or value == "nil" then
  463. p_back[p[i][1]] = value
  464. WidgetSetCaptionColor( sender, {1,1,1,1}, false )
  465. WidgetSetCaptionColor( sender, {.8,.8,1,1}, true )
  466. else
  467. WidgetSetCaptionColor( sender, {1,.6,.6,1}, false )
  468. WidgetSetCaptionColor( sender, {1,.2,.2,1}, true )
  469. end
  470. end,
  471. p[i][1],
  472. 20 )
  473. }))
  474. elseif p[i][2] == "INT" then
  475. l_window:add( MWComposition.create( 10, {
  476. MWCaption.create( {name = "dialogue", color = {1,1,1,1}},
  477. p[i][1],
  478. -1 ),
  479. MWInputField.create( {name = "dialogue", color = {1,1,1,1}, active_color={.8,.8,1,1}},
  480. p[i][3],
  481. -1,
  482. nil,
  483. function( sender, value )
  484. local vf = tonumber(value)
  485. if (vf and vf == math.floor(vf)) or value == "nil" then
  486. p_back[p[i][1]] = value
  487. WidgetSetCaptionColor( sender, {1,1,1,1}, false )
  488. WidgetSetCaptionColor( sender, {.8,.8,1,1}, true )
  489. else
  490. WidgetSetCaptionColor( sender, {1,.6,.6,1}, false )
  491. WidgetSetCaptionColor( sender, {1,.2,.2,1}, true )
  492. end
  493. end,
  494. p[i][1],
  495. 20 )
  496. }))
  497. elseif p[i][2] == "BOOL" then
  498. local val = {"true", "false"}
  499. if p[i][3] == "false" then val = {"false", "true"} end
  500. l_window:add( MWComposition.create( 10, {
  501. MWCaption.create( {name = "dialogue", color = {1,1,1,1}},
  502. p[i][1],
  503. -1 ),
  504. MWCycleButton.create( {name = "dialogue", color = {1,1,1,1}, active_color={.8,.8,1,1}},
  505. p[i][3],
  506. -1,
  507. nil,
  508. function( sender, value )
  509. p_back[p[i][1]] = value
  510. end,
  511. p[i][1],
  512. val )
  513. }))
  514. elseif p[i][2] == "LIST" then
  515. local val = {}
  516. local capt = {}
  517. for k, v in pairs( p[i][4] ) do
  518. table.insert( val, k )
  519. table.insert( capt, v )
  520. end
  521. local shifts = #val
  522. while shifts > 0 and p[i][3] ~= val[1] do
  523. shifts = shifts - 1
  524. table.insert( val, table.remove( val, 1 ) )
  525. table.insert( capt, table.remove( capt, 1 ) )
  526. end
  527. vars[p[i][1]] = p[i][3]
  528. l_window:add( MWComposition.create( 10, {
  529. MWCaption.create( {name = "dialogue", color = {1,1,1,1}},
  530. p[i][1],
  531. -1 ),
  532. MWCycleButton.create( {name = "dialogue", color = {1,1,1,1}, active_color={.8,.8,1,1}},
  533. capt[p[i][3]],
  534. -1,
  535. nil,
  536. function( sender, value )
  537. p_back[p[i][1]] = value
  538. end,
  539. p[i][1],
  540. val,
  541. capt,
  542. p[i][3] )
  543. }))
  544. elseif p[i][2] == "STACK" then
  545. p_back[p[i][1]] = p[i][3]
  546. local capt = "empty"
  547. if p[i][3] then
  548. capt = "{ "..table.concat(p[i][3], ", ").." }"
  549. end
  550. local element = 0
  551. local change_func = function()
  552. if #p_back[p[i][1]] > 0 then
  553. l_window.contents[element].elements[2]:setText( "{ "..table.concat(p_back[p[i][1]], ", ").." }" )
  554. else
  555. l_window.contents[element].elements[2]:setText( "empty" )
  556. end
  557. end
  558. element = l_window:add( MWComposition.create( 10, {
  559. MWCaption.create( {name = "dialogue", color = {1,1,1,1}},
  560. p[i][1],
  561. -1 ),
  562. MWCaption.create( {name = "dialogue", color = {1,1,.3,1}},
  563. capt,
  564. -1 ),
  565. MWFunctionButton.create( {name = "dialogue", color = {1,1,1,1}, active_color={.8,.8,1,1}},
  566. "PUSH",
  567. -1,
  568. function( sender )
  569. l_window:hide()
  570. Editor.popup_enter( "Enter int value: ",
  571. function( new_val )
  572. new_val = tonumber( new_val )
  573. if new_val then
  574. if not p_back[p[i][1]] then p_back[p[i][1]] = {} end
  575. table.insert( p_back[p[i][1]], new_val )
  576. l_window:show()
  577. change_func()
  578. end
  579. end,
  580. function()
  581. l_window:show()
  582. end,
  583. "0" )
  584. end),
  585. MWFunctionButton.create( {name = "dialogue", color = {1,1,1,1}, active_color={.8,.8,1,1}},
  586. "POP",
  587. -1,
  588. function( sender )
  589. if p_back[p[i][1]] then
  590. table.remove( p_back[p[i][1]], #p_back[p[i][1]] )
  591. change_func()
  592. end
  593. end
  594. )
  595. }))
  596. elseif p[i][2] == "COLOR" then
  597. p_back[p[i][1]] = p[i][3]
  598. l_window:add( MWComposition.create( 10, {
  599. MWCaption.create( {name = "dialogue", color = {1,1,1,1}},
  600. p[i][1],
  601. -1 ),
  602. MWFunctionButton.create( {name = "dialogue", color = {1,1,1,1}, active_color={.8,.8,1,1}},
  603. p[i][3],
  604. -1,
  605. function( sender )
  606. RestoreKeyProcessors()
  607. l_window:hide()
  608. local col = str2col( p_back[p[i][1]] )
  609. local butte = sender
  610. ColorPicker( col )
  611. Editor.colorSelected = function()
  612. RemoveKeyProcessors()
  613. local col = {}
  614. table.insert( col, tostring(vars.red) )
  615. table.insert( col, tostring(vars.green) )
  616. table.insert( col, tostring(vars.blue) )
  617. table.insert( col, tostring(vars.alpha) )
  618. local str = "["..table.concat(col, ", ").."]"
  619. p_back[p[i][1]] = str
  620. col = {}
  621. table.insert( col, string.sub(tostring(vars.red),1,3) )
  622. table.insert( col, string.sub(tostring(vars.green),1,3) )
  623. table.insert( col, string.sub(tostring(vars.blue),1,3) )
  624. table.insert( col, string.sub(tostring(vars.alpha),1,3) )
  625. local str = "["..table.concat(col, ", ").."]"
  626. WidgetSetCaption( butte, str )
  627. l_window:show()
  628. end
  629. end )
  630. }))
  631. end
  632. end
  633. l_window:add( MWComposition.create( 10, {
  634. MWCaption.create( {name = "dialogue", color = {1,1,1,1}},
  635. "obstruction",
  636. -1 ),
  637. MWFunctionButton.create( {name = "dialogue", color = {1,1,1,1}, active_color={.8,.8,1,1}},
  638. "[...]",
  639. -1,
  640. function( sender, value )
  641. local solid = object.solid_to or 255
  642. local bits = {}
  643. for i=7,0,-1 do
  644. if solid >= math.pow( 2, i ) then
  645. solid = solid - math.pow( 2, i )
  646. bits[i] = true
  647. else
  648. bits[i] = false
  649. end
  650. end
  651. l_window:hide()
  652. local window = CreateWidget( constants.wt_Panel, "", nil, CONFIG.scr_width/2 - 100, CONFIG.scr_height/2 - 100, 200, 200 )
  653. WidgetSetSprite( window, "window1" )
  654. WidgetSetFocusable( window, false )
  655. local y = 15
  656. local values = {
  657. { constants.physPlayer, "Characters" },
  658. { constants.physBullet, "Projectiles" },
  659. { constants.physEffect, "Effects" },
  660. { constants.physSprite, "Sprites" },
  661. { constants.physItem, "Items" },
  662. { constants.physEnemy, "Enemies" },
  663. { constants.physEnvironment, "Environments" },
  664. { constants.physParticles, "Particles" }
  665. }
  666. local w
  667. local color
  668. for i=1, #values do
  669. w = CreateWidget( constants.wt_Label, "", window, 0, 0, 1, 1 )
  670. WidgetSetPos( w, 15, y, true )
  671. WidgetSetCaptionFont( w, "dialogue" )
  672. WidgetSetCaptionColor( w, {1,1,1,1}, false )
  673. WidgetSetCaption( w, values[i][2] )
  674. local checkbox = CreateWidget( constants.wt_Button, "", window, 0, 0, 10, 10 )
  675. WidgetSetPos( checkbox, 150, y, true )
  676. color = { 0, 0, 0, 1 }
  677. if bits[i-1] then
  678. color = { 1, 1, 1, 1 }
  679. end
  680. WidgetSetColorBox( checkbox, color )
  681. WidgetSetLMouseClickProc( checkbox, function(sender)
  682. bits[i-1] = not bits[i-1]
  683. local color = { 0, 0, 0, 1 }
  684. if bits[i-1] then
  685. color = { 1, 1, 1, 1 }
  686. end
  687. WidgetSetColorBox( sender, color )
  688. end )
  689. y = y + 15
  690. end
  691. local back = CreateWidget( constants.wt_Button, "", window, 0, 0, 50, 10 )
  692. WidgetSetPos( back, 75, 200-15-15, true )
  693. WidgetSetCaptionFont( back, "dialogue" )
  694. WidgetSetCaption( back, "BACK" )
  695. WidgetSetCaptionColor( back, {1,1,1,1}, true )
  696. WidgetSetLMouseClickProc( back, function()
  697. DestroyWidget( window )
  698. l_window:show()
  699. local ret = 0
  700. for i=0,7 do
  701. if bits[i] then
  702. ret = ret + math.pow( 2, i )
  703. end
  704. end
  705. Log( ret )
  706. p_back["obstruction"] = ret
  707. end )
  708. end,
  709. nil,
  710. nil )
  711. }))
  712. l_window:add( MWSpace.create( 15, 15 ) )
  713. l_window:add( MWComposition.create( 10, {
  714. MWFunctionButton.create( {name = "default", color = {1,1,1,1}, active_color={.2,.2,1,1}},
  715. "OK",
  716. 0,
  717. function()
  718. l_window:clear()
  719. l_window:hide()
  720. RestoreKeyProcessors()
  721. if event then event( p_back ) end
  722. end,
  723. nil,
  724. {name="wakaba-widget"} ),
  725. MWFunctionButton.create( {name = "default", color = {1,1,1,1}, active_color={.2,.2,1,1}},
  726. "CANCEL",
  727. 0,
  728. function()
  729. l_window:clear()
  730. l_window:hide()
  731. RestoreKeyProcessors()
  732. if cancel_event then cancel_event() end
  733. end,
  734. nil,
  735. {name="wakaba-widget"} )
  736. }))
  737. l_window:add( MWSpace.create( 15, 15 ) )
  738. l_window.lock_size = true
  739. l_window:show()
  740. end
  741. function Editor.PropertiesMenu()
  742. local prop = 0
  743. local obj
  744. for k, v in pairs( Editor.selection ) do
  745. if not Editor.getObjParam( v.id, "NO_PROPERTIES" ) then
  746. prop = prop + 1
  747. obj = v
  748. end
  749. end
  750. if prop ~= 1 then
  751. return
  752. end
  753. local properties = Editor.getProperties( obj.type, obj.id )
  754. Editor.valuesPopup( (obj.proto or "Something without a name"), "id "..(obj.id or "-1"), properties,
  755. function(p_back)
  756. Editor.setProperties( obj.type, obj.id, p_back )
  757. Editor.changeState( Editor.STATE.RUNNING )
  758. end,
  759. function()
  760. Editor.changeState( Editor.STATE.RUNNING )
  761. end,
  762. obj
  763. )
  764. end
  765. function Editor.ContextMenu()
  766. Editor.changeState( Editor.STATE.IN_MENU )
  767. RemoveKeyProcessors()
  768. local x,y = GetMousePos()
  769. local cx, cy = GetCamPos()
  770. x,y = x - cx + CONFIG.scr_width/2, y - cy + CONFIG.scr_height/2
  771. local l_window = SimpleMenu.create( {x, y}, -1, -1, 10, 10 )
  772. local fclose = function()
  773. l_window:clear()
  774. l_window:hide()
  775. RestoreKeyProcessors()
  776. Editor.changeState( Editor.STATE.RUNNING )
  777. end
  778. local enemies = 0
  779. local spawners = 0
  780. local waypoints = 0
  781. local properties = 0
  782. local polygons = 0
  783. local complete_polygons = 0
  784. local sprites = 0
  785. if Editor.selection then
  786. for k, v in pairs( Editor.selection ) do
  787. if v.type == Editor.TYPES.OBJ_ENEMY then
  788. if Editor.getObjParam( v.id, "CONVERTED" ) then
  789. spawners = spawners + 1
  790. else
  791. enemies = enemies + 1
  792. end
  793. end
  794. if v.type == Editor.TYPES.OBJ_WAYPOINT then
  795. waypoints = waypoints + 1
  796. end
  797. if not Editor.getObjParam( v.id, "NO_PROPERTIES" ) then
  798. properties = properties + 1
  799. end
  800. if Editor.getObjParam( v.id, "POLYGON" ) then
  801. polygons = polygons + 1
  802. end
  803. if v.polygon then
  804. complete_polygons = complete_polygons + 1
  805. end
  806. if v.sprite then
  807. sprites = sprites + 1
  808. end
  809. end
  810. end
  811. l_window:add( MWFunctionButton.create( {name = "dialogue", color = {1,1,1,1}, active_color={.2,.2,1,1}},
  812. "Undo (Ctrl+Z)",
  813. 0,
  814. function()
  815. fclose()
  816. Editor.Undo()
  817. end ))
  818. l_window:add( MWFunctionButton.create( {name = "dialogue", color = {1,1,1,1}, active_color={.2,.2,1,1}},
  819. "Redo (Ctrl+Y)",
  820. 0,
  821. function()
  822. fclose()
  823. Editor.Redo()
  824. end ))
  825. if #Editor.selection > 1 then
  826. l_window:add( MWSpace.create( 0, 5 ) )
  827. l_window:add( MWFunctionButton.create( {name = "dialogue", color = {1,1,1,1}, active_color={.2,.2,1,1}},
  828. "Group (Alt+G)",
  829. 0,
  830. function()
  831. fclose()
  832. Editor.GroupObjects()
  833. end ))
  834. l_window:add( MWFunctionButton.create( {name = "dialogue", color = {1,1,1,1}, active_color={.2,.2,1,1}},
  835. "Ungroup (Ctrl+Alt+G)",
  836. 0,
  837. function()
  838. fclose()
  839. Editor.UngroupObjects()
  840. end ))
  841. end
  842. if #Editor.selection > 0 then
  843. l_window:add( MWSpace.create( 0, 5 ) )
  844. l_window:add( MWFunctionButton.create( {name = "dialogue", color = {1,1,1,1}, active_color={.2,.2,1,1}},
  845. "Move (Ctrl+rclick, WASD)",
  846. 0,
  847. function()
  848. fclose()
  849. Editor.action = { type = "MOVEMENT", from = {}, to = {}, text = "move object" }
  850. local tab
  851. for k, v in pairs(Editor.selection) do
  852. tab = { obj = v, pos = { x = v.aabb.p.x, y = v.aabb.p.y } }
  853. if v.sprite then
  854. tab.pos.z = v.sprite.z
  855. end
  856. table.insert( Editor.action.from, tab )
  857. end
  858. table.insert( Editor.threads, { Editor.drag_objects_thread, param =
  859. { x = Editor.mouse_x, y = Editor.mouse_y, stop_condition = function() return Editor.held.mouse0 end,
  860. event = function()
  861. local tab
  862. for k, v in pairs(Editor.selection) do
  863. tab = { obj = v, pos = { x = v.aabb.p.x, y = v.aabb.p.y } }
  864. if v.sprite then
  865. tab.pos.z = v.sprite.z
  866. end
  867. table.insert( Editor.action.to, tab )
  868. end
  869. end }})
  870. Editor.AddHistoryEvent( Editor.action )
  871. end ))
  872. l_window:add( MWFunctionButton.create( {name = "dialogue", color = {1,1,1,1}, active_color={.2,.2,1,1}},
  873. "Directional cloning (L+dir)",
  874. 0,
  875. function()
  876. fclose()
  877. Editor.DirectionalCloning( Editor.selection )
  878. end ))
  879. l_window:add( MWFunctionButton.create( {name = "dialogue", color = {1,1,1,1}, active_color={.2,.2,1,1}},
  880. "Set snapping anchor (Ctrl+P)",
  881. 0,
  882. function()
  883. fclose()
  884. Editor.SetAnchor( Editor.selection )
  885. end ))
  886. if Editor.anchor then
  887. l_window:add( MWFunctionButton.create( {name = "dialogue", color = {1,1,1,1}, active_color={.2,.2,1,1}},
  888. "Snap to anchor (P)",
  889. 0,
  890. function()
  891. fclose()
  892. Editor.DropToAnchor( Editor.selection )
  893. end ))
  894. end
  895. l_window:add( MWSpace.create( 0, 5 ) )
  896. l_window:add( MWFunctionButton.create( {name = "dialogue", color = {1,1,1,1}, active_color={.2,.2,1,1}},
  897. "Previous tile ([)",
  898. 0,
  899. function()
  900. fclose()
  901. Editor.prevTile()
  902. end ))
  903. l_window:add( MWFunctionButton.create( {name = "dialogue", color = {1,1,1,1}, active_color={.2,.2,1,1}},
  904. "Next tile (])",
  905. 0,
  906. function()
  907. fclose()
  908. Editor.nextTile()
  909. end ))
  910. l_window:add( MWSpace.create( 0, 5 ) )
  911. l_window:add( MWFunctionButton.create( {name = "dialogue", color = {1,1,1,1}, active_color={.2,.2,1,1}},
  912. "Copy (Ctrl+C)",
  913. 0,
  914. function()
  915. fclose()
  916. Editor.copy()
  917. end ))
  918. if polygons == 1 then
  919. l_window:add( MWFunctionButton.create( {name = "dialogue", color = {1,1,1,1}, active_color={.2,.2,1,1}},
  920. "Add next polygon vertex (.)",
  921. 0,
  922. function()
  923. fclose()
  924. Editor.nextPolygonMarker()
  925. end ))
  926. end
  927. if polygons > 0 then
  928. l_window:add( MWFunctionButton.create( {name = "dialogue", color = {1,1,1,1}, active_color={.2,.2,1,1}},
  929. "Complete polygon (Ctrl+.)",
  930. 0,
  931. function()
  932. fclose()
  933. Editor.completePolygon(false)
  934. end ))
  935. l_window:add( MWFunctionButton.create( {name = "dialogue", color = {1,1,1,1}, active_color={.2,.2,1,1}},
  936. "Complete one-sided polygon (Ctrl+Shift+.)",
  937. 0,
  938. function()
  939. fclose()
  940. Editor.completePolygon(true)
  941. end ))
  942. elseif complete_polygons == 1 then
  943. l_window:add( MWFunctionButton.create( {name = "dialogue", color = {1,1,1,1}, active_color={.2,.2,1,1}},
  944. "Alter polygon (Ctrl+.)",
  945. 0,
  946. function()
  947. fclose()
  948. Editor.decomposePolygon()
  949. end ))
  950. end
  951. else
  952. l_window:add( MWFunctionButton.create( {name = "dialogue", color = {1,1,1,1}, active_color={.2,.2,1,1}},
  953. "Create polygon (.)",
  954. 0,
  955. function()
  956. fclose()
  957. Editor.createPolygon()
  958. end ))
  959. end
  960. if Editor.clipboard and #Editor.clipboard > 0 then
  961. l_window:add( MWFunctionButton.create( {name = "dialogue", color = {1,1,1,1}, active_color={.2,.2,1,1}},
  962. "Paste (Ctrl+V)",
  963. 0,
  964. function()
  965. fclose()
  966. Editor.paste()
  967. end ))
  968. end
  969. if enemies > 0 then
  970. l_window:add( MWFunctionButton.create( {name = "dialogue", color = {1,1,1,1}, active_color={.2,.2,1,1}},
  971. "Convert enemy to spawner",
  972. 0,
  973. function()
  974. fclose()
  975. Editor.SpawnerConversion( Editor.selection )
  976. end ))
  977. end
  978. if sprites > 0 then
  979. l_window:add( MWFunctionButton.create( {name = "dialogue", color = {1,1,1,1}, active_color={.2,.2,1,1}},
  980. "Mirror objects (Ctrl+F)",
  981. 0,
  982. function()
  983. fclose()
  984. Editor.FlipObjects()
  985. end ))
  986. end
  987. if spawners > 0 then
  988. l_window:add( MWFunctionButton.create( {name = "dialogue", color = {1,1,1,1}, active_color={.2,.2,1,1}},
  989. "Convert spawner to enemy",
  990. 0,
  991. function()
  992. fclose()
  993. Editor.EnemyConversion( Editor.selection )
  994. end ))
  995. end
  996. if enemies + waypoints == 1 then
  997. l_window:add( MWSpace.create( 0, 5 ) )
  998. l_window:add( MWFunctionButton.create( {name = "dialogue", color = {1,1,1,1}, active_color={.2,.2,1,1}},
  999. "Add waypoint (Ctrl+W)",
  1000. 0,
  1001. function()
  1002. fclose()
  1003. Editor.Waypoint()
  1004. end ))
  1005. end
  1006. if properties == 1 then
  1007. l_window:add( MWSpace.create( 0, 5 ) )
  1008. l_window:add( MWFunctionButton.create( {name = "dialogue", color = {1,1,1,1}, active_color={.2,.2,1,1}},
  1009. "Import creation script...",
  1010. 0,
  1011. function()
  1012. fclose()
  1013. Editor.changeState( Editor.STATE.ADDITIONAL_MENU )
  1014. Editor._ImportScript( "temp", function()
  1015. local obj
  1016. for k,v in pairs( Editor.selection ) do
  1017. if not Editor.getObjParam( v.id, "NO_PROPERTIES" ) then
  1018. obj = v
  1019. break
  1020. end
  1021. end
  1022. Editor.setObjParam( obj.id, "CREATION_SCRIPT", Editor.scripts.temp )
  1023. Editor.setObjParam( obj.id, "SPECIAL_CREATION", true )
  1024. end,
  1025. function() Editor.changeState( Editor.STATE.RUNNING ) end )
  1026. end ))
  1027. l_window:add( MWFunctionButton.create( {name = "dialogue", color = {1,1,1,1}, active_color={.2,.2,1,1}},
  1028. "Properties... (Enter)",
  1029. 0,
  1030. function()
  1031. fclose()
  1032. Editor.PropertiesMenu()
  1033. end ))
  1034. end
  1035. l_window:show()
  1036. local w, h = l_window.window.w, l_window.window.h
  1037. if x + w > CONFIG.scr_width then
  1038. x = CONFIG.scr_width - w
  1039. end
  1040. if y + h > CONFIG.scr_height then
  1041. y = CONFIG.scr_height - h
  1042. end
  1043. l_window:move( x, y )
  1044. local func = function()
  1045. local mx, my = GetMousePos()
  1046. local cmx, cmy = GetCamPos()
  1047. mx,my = mx - cmx + CONFIG.scr_width/2, my - cmy + CONFIG.scr_height/2
  1048. if mx < x or mx > x + w or my < y or my > y + h then
  1049. fclose()
  1050. end
  1051. end
  1052. GlobalSetMouseKeyDownProc( func )
  1053. GlobalSetKeyDownProc( func )
  1054. end
  1055. menus:hide(1)
  1056. menus:hide(2)
  1057. menus:hide(3)
  1058. --menus2:addPage( 1, ScrollingMenu.create( {0, 0}, -1, -1, 30, 5, 16 ) )
  1059. function menus2.show()
  1060. Editor.palette.show()
  1061. end
  1062. function menus2.hide()
  1063. Editor.palette.hide()
  1064. end
  1065. function Editor.newMapMenu()
  1066. Editor.confirm( "Are you sure you want to close this map and create a new one?",
  1067. function()
  1068. Editor.new()
  1069. Editor.current_map = nil
  1070. Editor.changeState( Editor.STATE.RUNNING )
  1071. end,
  1072. function()
  1073. Editor.changeState( Editor.STATE.RUNNING )
  1074. end)
  1075. end
  1076. menus3:addPage( 1, SimpleMenu.create( {CONFIG.scr_width, 0}, 1, -1, 30, 10 ) )
  1077. menus3:add(
  1078. MWFunctionButton.create(
  1079. {name="dialogue", color={1,1,1,1}, active_color={.2,.2,1,1}},
  1080. "START GAME (F5)",
  1081. 0,
  1082. function(sender)
  1083. Editor.held[keys.tab] = false
  1084. Editor.menu3:hide()
  1085. Editor.menu2:hide()
  1086. Editor.startMap(Editor.current_map)
  1087. end,
  1088. nil,
  1089. {name="wakaba-widget"}
  1090. ),
  1091. 1
  1092. )
  1093. menus3:add( MWSpace.create( 0, 15 ) )
  1094. menus3:add(
  1095. MWFunctionButton.create(
  1096. {name="dialogue", color={1,1,1,1}, active_color={.2,.2,1,1}},
  1097. "NEW MAP (Ctrl+Shift+N)",
  1098. 0,
  1099. function(sender)
  1100. Editor.held[keys.tab] = false
  1101. Editor.menu3:hide()
  1102. Editor.menu2:hide()
  1103. Editor.newMapMenu()
  1104. end,
  1105. nil,
  1106. {name="wakaba-widget"}
  1107. ),
  1108. 1
  1109. )
  1110. menus3:add(
  1111. MWFunctionButton.create(
  1112. {name="dialogue", color={1,1,1,1}, active_color={.2,.2,1,1}},
  1113. "OPEN MAP (Ctrl+O)",
  1114. 0,
  1115. function(sender)
  1116. Editor.held[keys.tab] = false
  1117. Editor.menu3:hide()
  1118. Editor.menu2:hide()
  1119. Editor.openMenu()
  1120. end,
  1121. nil,
  1122. {name="wakaba-widget"}
  1123. ),
  1124. 1
  1125. )
  1126. menus3:add(
  1127. MWFunctionButton.create(
  1128. {name="dialogue", color={1,1,1,1}, active_color={.2,.2,1,1}},
  1129. "SAVE MAP (Ctrl+S)",
  1130. 0,
  1131. function(sender)
  1132. Editor.held[keys.tab] = false
  1133. Editor.menu3:hide()
  1134. Editor.menu2:hide()
  1135. Editor.saveMenu()
  1136. end,
  1137. nil,
  1138. {name="wakaba-widget"}
  1139. ),
  1140. 1
  1141. )
  1142. menus3:add(
  1143. MWFunctionButton.create(
  1144. {name="dialogue", color={1,1,1,1}, active_color={.2,.2,1,1}},
  1145. "SAVE MAP AS... (Ctrl+Shift+S)",
  1146. 0,
  1147. function(sender)
  1148. Editor.held[keys.tab] = false
  1149. Editor.menu3:hide()
  1150. Editor.menu2:hide()
  1151. Editor.saveAsMenu()
  1152. end,
  1153. nil,
  1154. {name="wakaba-widget"}
  1155. ),
  1156. 1
  1157. )
  1158. menus3:add( MWSpace.create( 0, 15 ) )
  1159. menus3:add(
  1160. MWFunctionButton.create(
  1161. {name="dialogue", color={1,1,1,1}, active_color={.2,.2,1,1}},
  1162. "LOAD PROTOTYPE... (Ctrl+L)",
  1163. 0,
  1164. function(sender)
  1165. Editor.menu3:hide()
  1166. Editor.menu2:hide()
  1167. Editor.loadProtoMenu()
  1168. end,
  1169. nil,
  1170. {name="wakaba-widget"}
  1171. ),
  1172. 1
  1173. )
  1174. menus3:add(
  1175. MWFunctionButton.create(
  1176. {name="dialogue", color={1,1,1,1}, active_color={.2,.2,1,1}},
  1177. "IMPORT TILES... ",
  1178. 0,
  1179. function(sender)
  1180. Editor.menu3:hide()
  1181. Editor.menu2:hide()
  1182. Editor.ImportTiles()
  1183. end,
  1184. nil,
  1185. {name="wakaba-widget"}
  1186. ),
  1187. 1
  1188. )
  1189. menus3:add(
  1190. MWFunctionButton.create(
  1191. {name="dialogue", color={1,1,1,1}, active_color={.2,.2,1,1}},
  1192. "SCRIPTS...",
  1193. 0,
  1194. function(sender)
  1195. Editor.menu3:hide()
  1196. Editor.menu2:hide()
  1197. Editor.ScriptMenu()
  1198. end,
  1199. nil,
  1200. {name="wakaba-widget"}
  1201. ),
  1202. 1
  1203. )
  1204. menus3:add(
  1205. MWFunctionButton.create(
  1206. {name="dialogue", color={1,1,1,1}, active_color={.2,.2,1,1}},
  1207. "SELECT MUSIC...",
  1208. 0,
  1209. function(sender)
  1210. Editor.menu3:hide()
  1211. Editor.menu2:hide()
  1212. Editor.path = "sounds/music"
  1213. Editor.changeState( Editor.STATE.ADDITIONAL_MENU )
  1214. Editor.show_dir( "sounds", nil, nil,
  1215. function( filename )
  1216. Editor.mus_track = string.gsub( filename, "^sounds/", "" )
  1217. StopBackMusic()
  1218. Editor.changeState( Editor.STATE.RUNNING )
  1219. end,
  1220. function()
  1221. Editor.mus_track = nil
  1222. StopBackMusic()
  1223. Editor.changeState( Editor.STATE.RUNNING )
  1224. end,
  1225. function( filename )
  1226. PlayBackMusic(string.gsub( filename, "^sounds/", "" ))
  1227. end)
  1228. end,
  1229. nil,
  1230. {name="wakaba-widget"}
  1231. ),
  1232. 1
  1233. )
  1234. menus3:add( MWSpace.create( 0, 15 ) )
  1235. menus3:add(
  1236. MWFunctionButton.create(
  1237. {name="dialogue", color={1,1,1,1}, active_color={.2,.2,1,1}},
  1238. "SAVE PALETTE...",
  1239. 0,
  1240. function(sender)
  1241. Editor.palette.saveMenu()
  1242. end,
  1243. nil,
  1244. {name="wakaba-widget"}
  1245. ),
  1246. 1
  1247. )
  1248. menus3:add(
  1249. MWFunctionButton.create(
  1250. {name="dialogue", color={1,1,1,1}, active_color={.2,.2,1,1}},
  1251. "OPEN PALETTE...",
  1252. 0,
  1253. function(sender)
  1254. Editor.palette.openMenu()
  1255. end,
  1256. nil,
  1257. {name="wakaba-widget"}
  1258. ),
  1259. 1
  1260. )
  1261. menus3:add( MWSpace.create( 0, 15 ) )
  1262. menus3:add(
  1263. MWFunctionButton.create(
  1264. {name="dialogue", color={1,1,1,1}, active_color={.2,.2,1,1}},
  1265. "GRID...",
  1266. 0,
  1267. function(sender)
  1268. Editor.menu3:hide()
  1269. Editor.menu2:hide()
  1270. Editor.changeState( Editor.STATE.ADDITIONAL_MENU )
  1271. local param = {
  1272. {"show grid", "BOOL", tostring(Editor.grid.show) },
  1273. {"snap to grid", "BOOL", tostring(Editor.grid.snap) },
  1274. {"snap distance", "FLOAT", Editor.grid.dist},
  1275. {"x", "INT", Editor.grid.x},
  1276. {"y", "INT", Editor.grid.y},
  1277. {"color", "COLOR", "["..table.concat(Editor.grid.color, ", ").."]"},
  1278. }
  1279. Editor.valuesPopup( "GRID SETUP", nil, param,
  1280. function(p_back)
  1281. Editor.grid_menu( p_back )
  1282. Editor.changeState( Editor.STATE.RUNNING )
  1283. end,
  1284. function()
  1285. Editor.changeState( Editor.STATE.RUNNING )
  1286. end
  1287. )
  1288. end,
  1289. nil,
  1290. {name="wakaba-widget"}
  1291. ),
  1292. 1
  1293. )
  1294. menus3:add( MWSpace.create( 0, 15 ) )
  1295. menus3:add(
  1296. MWFunctionButton.create(
  1297. {name="dialogue", color={1,1,1,1}, active_color={.2,.2,1,1}},
  1298. "OPTIONS...",
  1299. 0,
  1300. function(sender)
  1301. Editor.held[keys.tab] = false
  1302. Editor.menu3:hide()
  1303. Editor.menu2:hide()
  1304. Editor.changeState( Editor.STATE.ADDITIONAL_MENU )
  1305. Editor.menu:show(4)
  1306. end,
  1307. nil,
  1308. {name="wakaba-widget"}
  1309. ),
  1310. 1
  1311. )
  1312. --[[
  1313. menus3:add(
  1314. MWFunctionButton.create(
  1315. {name="dialogue", color={1,1,1,1}, active_color={.2,.2,1,1}},
  1316. "RESET K",
  1317. 0,
  1318. function(sender)
  1319. for key, value in pairs(Editor.selection) do
  1320. if value.type == 13 then
  1321. SetRibbonObjK(value.id, 0, 0)
  1322. end
  1323. end
  1324. end,
  1325. nil,
  1326. {name="wakaba-widget"}
  1327. ),
  1328. 1
  1329. )
  1330. menus3:add(
  1331. MWFunctionButton.create(
  1332. {name="dialogue", color={1,1,1,1}, active_color={.2,.2,1,1}},
  1333. "TOGGLE X REPETITION",
  1334. 0,
  1335. function(sender)
  1336. for key, value in pairs(Editor.selection) do
  1337. if value.type == 13 then
  1338. value.repeat_x = not value.repeat_x
  1339. SetRibbonObjRepitition(value.id, value.repeat_x, value.repeat_y)
  1340. end
  1341. end
  1342. end,
  1343. nil,
  1344. {name="wakaba-widget"}
  1345. ),
  1346. 1
  1347. )
  1348. menus3:add(
  1349. MWFunctionButton.create(
  1350. {name="dialogue", color={1,1,1,1}, active_color={.2,.2,1,1}},
  1351. "TOGGLE Y REPETITION",
  1352. 0,
  1353. function(sender)
  1354. for key, value in pairs(Editor.selection) do
  1355. if value.type == 13 then
  1356. value.repeat_y = not value.repeat_y
  1357. SetRibbonObjRepitition(value.id, value.repeat_x, value.repeat_y)
  1358. end
  1359. end
  1360. end,
  1361. nil,
  1362. {name="wakaba-widget"}
  1363. ),
  1364. 1
  1365. )
  1366. menus3:add(
  1367. MWFunctionButton.create(
  1368. {name="dialogue", color={1,1,1,1}, active_color={.2,.2,1,1}},
  1369. "MINIMAP: OFF",
  1370. 0,
  1371. function(sender)
  1372. Editor.minimap.show = not (Editor.minimap.show or false)
  1373. if Editor.minimap.show then
  1374. Editor.updateMinimap("RESIZE")
  1375. else
  1376. Editor.updateMinimap("HIDE")
  1377. end
  1378. WidgetSetCaption( sender, "MINIMAP: "..iff( Editor.minimap.show, "ON", "OFF" ) )
  1379. end,
  1380. nil,
  1381. {name="wakaba-widget"}
  1382. ),
  1383. 1
  1384. )
  1385. --]]
  1386. menus3:hide(1)
  1387. function hsb2rgb( h, s, b )
  1388. local hi = math.floor( h / 60 ) % 6
  1389. local f = h/60 - math.floor(h/60)
  1390. local p = b*(1-s)
  1391. local q = b*(1-f*s)
  1392. local t = b*(1-(1-f)*s)
  1393. if hi == 0 then
  1394. return b, t, p
  1395. elseif hi == 1 then
  1396. return q, b, p
  1397. elseif hi == 2 then
  1398. return p, b, t
  1399. elseif hi == 3 then
  1400. return p, q, b
  1401. elseif hi == 4 then
  1402. return t, p, b
  1403. else
  1404. return b, p, q
  1405. end
  1406. end
  1407. function rgb2hsb( r, g, b )
  1408. local max, min = math.max( r, g, b ), math.min( r, g, b )
  1409. local h, s, v
  1410. if max == min then
  1411. h = 0
  1412. elseif max == r and g >= b then
  1413. h = 60 * (g-b)/(max-min)
  1414. elseif max == r and g < b then
  1415. h = 60 * (g-b)/(max-min) + 360
  1416. elseif max == g then
  1417. h = 60 * (b-r)/(max-min) + 120
  1418. else
  1419. h = 60 * (r-g)/(max-min) + 240
  1420. end
  1421. if max == 0 then
  1422. s = 0
  1423. else
  1424. s = 1 - min/max
  1425. end
  1426. v = max
  1427. return h, s, v
  1428. end
  1429. function ColorPicker( color )
  1430. local color_str_length = 6
  1431. RemoveKeyProcessors()
  1432. local _color_picker_widgets = {}
  1433. vars.r, vars.g, vars.b, vars.a = unpack( color )
  1434. vars.h, vars.s, vars.v = rgb2hsb( vars.r, vars.g, vars.b )
  1435. local window = Window.create( CONFIG.scr_width/2 - 200, CONFIG.scr_height/2 - 150, 400, 400, "window1" )
  1436. local hsw = CreateWidget(constants.wt_Picture, "window", nil, CONFIG.scr_width/2-160, CONFIG.scr_height/2-128, 256, 256)
  1437. table.insert( _color_picker_widgets, hsw )
  1438. WidgetSetSprite(hsw, "editor_hs")
  1439. local hsx, hsy = CONFIG.scr_width/2-160, CONFIG.scr_height/2-128
  1440. local hsp = CreateWidget(constants.wt_Picture, "window", nil, CONFIG.scr_width/2-160, CONFIG.scr_height/2-128, 9, 9)
  1441. table.insert( _color_picker_widgets, hsp )
  1442. WidgetSetSprite(hsp, "editor_colorpicker", "hs")
  1443. local bw = CreateWidget(constants.wt_Picture, "window", nil, CONFIG.scr_width/2+128, CONFIG.scr_height/2-128, 32, 256)
  1444. table.insert( _color_picker_widgets, bw )
  1445. local bx, by = CONFIG.scr_width/2+128, CONFIG.scr_height/2-128
  1446. WidgetSetSprite(bw, "editor_b")
  1447. local bp = CreateWidget(constants.wt_Picture, "window", nil, CONFIG.scr_width/2-160, CONFIG.scr_height/2-128, 9, 9)
  1448. table.insert( _color_picker_widgets, bp )
  1449. WidgetSetSprite(bp, "editor_colorpicker", "b")
  1450. Editor.changeState( Editor.STATE.IN_MENU )
  1451. local lr, lg, lb = hsb2rgb( vars.h, vars.s, 1 )
  1452. WidgetSetSpriteColor( bw, { lr, lg, lb, 1 } )
  1453. WidgetSetSpriteColor( hsw, { vars.v, vars.v, vars.v, 1 } )
  1454. WidgetSetPos( hsp, hsx + (vars.h/360)*256-4, hsy + (1-vars.s)*256 - 4)
  1455. WidgetSetPos( bp, bx - 15, by + (1-vars.v)*256 - 5 )
  1456. local awl = CreateWidget( constants.wt_Label, "MWInputField", nil, CONFIG.scr_width/2 - 160, CONFIG.scr_height/2 + 138, 60, 15 )
  1457. table.insert( _color_picker_widgets, awl )
  1458. WidgetSetCaptionFont( awl, "dialogue" )
  1459. WidgetSetCaption( awl, "ALPHA: " )
  1460. local aw = CreateWidget( constants.wt_Textfield, "MWInputField", nil, CONFIG.scr_width/2 - 100, CONFIG.scr_height/2 + 138, 100, 15 )
  1461. table.insert( _color_picker_widgets, aw )
  1462. WidgetSetCaptionFont( aw, "dialogue" )
  1463. WidgetSetCaption( aw, (vars.a or "as fuck!") )
  1464. WidgetSetCaptionColor( aw, {.8, .8, .1, 1}, true )
  1465. WidgetSetCaptionColor( aw, {1, 1, 1, 1}, false )
  1466. local rwl = CreateWidget( constants.wt_Label, "MWInputField", nil, CONFIG.scr_width/2 - 160, CONFIG.scr_height/2 + 158, 60, 15 )
  1467. table.insert( _color_picker_widgets, rwl )
  1468. WidgetSetCaptionFont( rwl, "dialogue" )
  1469. WidgetSetCaption( rwl, "RED: " )
  1470. local rw = CreateWidget( constants.wt_Textfield, "MWInputField", nil, CONFIG.scr_width/2 - 100, CONFIG.scr_height/2 + 158, 100, 15 )
  1471. table.insert( _color_picker_widgets, rw )
  1472. WidgetSetCaptionFont( rw, "dialogue" )
  1473. WidgetSetCaption( rw, (vars.r or "as fuck!") )
  1474. WidgetSetCaptionColor( rw, {.8, .8, .1, 1}, true )
  1475. WidgetSetCaptionColor( rw, {1, 1, 1, 1}, false )
  1476. local rwb = CreateWidget( constants.wt_Textfield, "MWInputField", nil, CONFIG.scr_width/2 - 20, CONFIG.scr_height/2 + 158, 100, 15 )
  1477. table.insert( _color_picker_widgets, rwb )
  1478. WidgetSetCaptionFont( rwb, "dialogue" )
  1479. WidgetSetCaption( rwb, math.floor((vars.r or 0) * 255) )
  1480. WidgetSetCaptionColor( rwb, {.4, .4, .1, 1}, true )
  1481. WidgetSetCaptionColor( rwb, {.8, .8, .8, 1}, false )
  1482. local gwl = CreateWidget( constants.wt_Label, "MWInputField", nil, CONFIG.scr_width/2 - 160, CONFIG.scr_height/2 + 173, 60, 15 )
  1483. table.insert( _color_picker_widgets, gwl )
  1484. WidgetSetCaptionFont( gwl, "dialogue" )
  1485. WidgetSetCaption( gwl, "GREEN: " )
  1486. local gw = CreateWidget( constants.wt_Textfield, "MWInputField", nil, CONFIG.scr_width/2 - 100, CONFIG.scr_height/2 + 173, 100, 15 )
  1487. table.insert( _color_picker_widgets, gw )
  1488. WidgetSetCaptionFont( gw, "dialogue" )
  1489. WidgetSetCaption( gw, (vars.g or "as fuck!") )
  1490. WidgetSetCaptionColor( gw, {.8, .8, .1, 1}, true )
  1491. WidgetSetCaptionColor( gw, {1, 1, 1, 1}, false )
  1492. local gwb = CreateWidget( constants.wt_Textfield, "MWInputField", nil, CONFIG.scr_width/2 - 20, CONFIG.scr_height/2 + 173, 100, 15 )
  1493. table.insert( _color_picker_widgets, gwb )
  1494. WidgetSetCaptionFont( gwb, "dialogue" )
  1495. WidgetSetCaption( gwb, math.floor((vars.g or 0)*255) )
  1496. WidgetSetCaptionColor( gwb, {.4, .4, .1, 1}, true )
  1497. WidgetSetCaptionColor( gwb, {.8, .8, .8, 1}, false )
  1498. local bwl = CreateWidget( constants.wt_Label, "MWInputField", nil, CONFIG.scr_width/2 - 160, CONFIG.scr_height/2 + 188, 60, 15 )
  1499. table.insert( _color_picker_widgets, bwl )
  1500. WidgetSetCaptionFont( bwl, "dialogue" )
  1501. WidgetSetCaption( bwl, "BLUE: " )
  1502. local cbw = CreateWidget( constants.wt_Textfield, "MWInputField", nil, CONFIG.scr_width/2 - 100, CONFIG.scr_height/2 + 188, 100, 15 )
  1503. table.insert( _color_picker_widgets, cbw )
  1504. WidgetSetCaptionFont( cbw, "dialogue" )
  1505. WidgetSetCaption( cbw, (vars.b or "as fuck!") )
  1506. WidgetSetCaptionColor( cbw, {.8, .8, .1, 1}, true )
  1507. WidgetSetCaptionColor( cbw, {1, 1, 1, 1}, false )
  1508. local cbwb = CreateWidget( constants.wt_Textfield, "MWInputField", nil, CONFIG.scr_width/2 - 20, CONFIG.scr_height/2 + 188, 100, 15 )
  1509. table.insert( _color_picker_widgets, cbwb )
  1510. WidgetSetCaptionFont( cbwb, "dialogue" )
  1511. WidgetSetCaption( cbwb, math.floor((vars.b or 0) * 255) )
  1512. WidgetSetCaptionColor( cbwb, {.4, .8, .4, 1}, true )
  1513. WidgetSetCaptionColor( cbwb, {.8, .8, .8, 1}, false )
  1514. local function update_color()
  1515. WidgetSetCaption( rw, string.sub( tostring(vars.r), 1, color_str_length ) )
  1516. WidgetSetCaption( gw, string.sub( tostring(vars.g), 1, color_str_length ) )
  1517. WidgetSetCaption( cbw, string.sub( tostring(vars.b), 1, color_str_length ) )
  1518. WidgetSetCaption( rwb, tostring( math.floor(vars.r*255)) )
  1519. WidgetSetCaption( gwb, tostring( math.floor(vars.g*255)) )
  1520. WidgetSetCaption( cbwb, tostring( math.floor(vars.b*255)) )
  1521. end
  1522. local preview_back1 = CreateWidget(constants.wt_Widget, "preview", nil, CONFIG.scr_width/2+116, CONFIG.scr_height/2+138, 32, 84)
  1523. table.insert( _color_picker_widgets, preview_back1 )
  1524. WidgetSetColorBox( preview_back1, {0, 0, 0, 1} )
  1525. WidgetSetZ( preview_back1, 0.95 )
  1526. local preview_back2 = CreateWidget(constants.wt_Widget, "preview", nil, CONFIG.scr_width/2+90, CONFIG.scr_height/2+164, 84, 32)
  1527. table.insert( _color_picker_widgets, preview_back2 )
  1528. WidgetSetColorBox( preview_back2, {1, 1, 1, 1} )
  1529. WidgetSetZ( preview_back2, 0.94 )
  1530. local preview = CreateWidget(constants.wt_Widget, "preview", nil, CONFIG.scr_width/2+100, CONFIG.scr_height/2+148, 64, 64)
  1531. table.insert( _color_picker_widgets, preview )
  1532. WidgetSetColorBox( preview, color )
  1533. WidgetSetBorder( preview, true )
  1534. WidgetSetBorderColor( preview, { 1-color[1], 1-color[2], 1-color[3], 1 }, false )
  1535. WidgetSetKeyInputProc( aw, function()
  1536. local text = WidgetGetCaption( aw )
  1537. text = tonumber( text )
  1538. if text then
  1539. WidgetSetCaptionColor( aw, {.8, .8, .1, 1}, true )
  1540. WidgetSetCaptionColor( aw, {1, 1, 1, 1}, false )
  1541. vars.a = text
  1542. WidgetSetColorBox( preview, { vars.r, vars.g, vars.b, vars.a } )
  1543. WidgetSetBorderColor( preview, { 1-vars.r, 1-vars.g, 1-vars.b, 1 }, false )
  1544. else
  1545. WidgetSetCaptionColor( aw, {1, .5, .5, 1}, true )
  1546. WidgetSetCaptionColor( aw, {.5, 0, 0, 1}, false )
  1547. end
  1548. end )
  1549. local function colorInput( widget, color, other_widget )
  1550. WidgetSetKeyInputProc( widget, function()
  1551. local text = WidgetGetCaption( widget )
  1552. text = tonumber( text )
  1553. if text and text >= 0 and text <= 1 then
  1554. WidgetSetCaptionColor( widget, {.8, .8, .1, 1}, true )
  1555. WidgetSetCaptionColor( widget, {1, 1, 1, 1}, false )
  1556. vars[color] = text
  1557. vars.h, vars.s, vars.v = rgb2hsb( vars.r, vars.g, vars.b )
  1558. local lr, lg, lb = hsb2rgb( vars.h, vars.s, 1 )
  1559. WidgetSetCaption( other_widget, tostring(math.floor(255 * text)) )
  1560. WidgetSetSpriteColor( bw, { lr, lg, lb, 1 } )
  1561. WidgetSetSpriteColor( hsw, { vars.v, vars.v, vars.v, 1 } )
  1562. WidgetSetColorBox( preview, { vars.r, vars.g, vars.b, vars.a } )
  1563. WidgetSetBorderColor( preview, { 1-vars.r, 1-vars.g, 1-vars.b, 1 }, false )
  1564. WidgetSetPos( hsp, hsx + (vars.h/360)*256-4, hsy + (1-vars.s)*256 - 4)
  1565. WidgetSetPos( bp, bx - 15, by + (1-vars.v)*256 - 5 )
  1566. else
  1567. WidgetSetCaptionColor( widget, {1, .5, .5, 1}, true )
  1568. WidgetSetCaptionColor( widget, {.5, 0, 0, 1}, false )
  1569. end
  1570. end)
  1571. end
  1572. local function colorInputByte( widget, color, other_widget )
  1573. WidgetSetKeyInputProc( widget, function()
  1574. local text = WidgetGetCaption( widget )
  1575. text = tonumber( text )
  1576. if text and text >= 0 and text <= 255 and math.floor(text) == text then
  1577. WidgetSetCaptionColor( widget, {.4, .4,

Large files files are truncated, but you can click here to view the full file