PolycodeProps.cpp 86 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999
  1. /*
  2. Copyright (C) 2012 by Ivan Safrin
  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  17. THE SOFTWARE.
  18. */
  19. #include "PolycodeProps.h"
  20. #include "PolycodeFrame.h"
  21. #include "PolyCubemap.h"
  22. extern UIColorPicker *globalColorPicker;
  23. extern PolycodeFrame *globalFrame;
  24. extern UIGlobalMenu *globalMenu;
  25. PolycodeEditorPropActionData *PropDataBool(bool val) {
  26. PolycodeEditorPropActionData *data = new PolycodeEditorPropActionData();
  27. data->boolVal = val;
  28. return data;
  29. }
  30. PolycodeEditorPropActionData *PropDataInt(int val) {
  31. PolycodeEditorPropActionData *data = new PolycodeEditorPropActionData();
  32. data->intVal = val;
  33. return data;
  34. }
  35. PolycodeEditorPropActionData *PropDataNumber(Number val) {
  36. PolycodeEditorPropActionData *data = new PolycodeEditorPropActionData();
  37. data->numVal = val;
  38. return data;
  39. }
  40. PolycodeEditorPropActionData *PropDataString(String val) {
  41. PolycodeEditorPropActionData *data = new PolycodeEditorPropActionData();
  42. data->stringVal = val;
  43. return data;
  44. }
  45. PolycodeEditorPropActionData *PropDataColor(Color val) {
  46. PolycodeEditorPropActionData *data = new PolycodeEditorPropActionData();
  47. data->colorVal = val;
  48. return data;
  49. }
  50. PolycodeEditorPropActionData *PropDataVector3(Vector3 val) {
  51. PolycodeEditorPropActionData *data = new PolycodeEditorPropActionData();
  52. data->vector3Val = val;
  53. return data;
  54. }
  55. PolycodeEditorPropActionData *PropDataVector2(Vector2 val) {
  56. PolycodeEditorPropActionData *data = new PolycodeEditorPropActionData();
  57. data->vector2Val = val;
  58. return data;
  59. }
  60. PolycodeEditorPropActionData *PropDataEntity(Entity *entity) {
  61. PolycodeEditorPropActionData *data = new PolycodeEditorPropActionData();
  62. data->entity = entity->Clone(false, true);
  63. data->entity->ownsChildren = false;
  64. for(int i=0; i < data->entity->getNumChildren(); i++) {
  65. data->entity->removeChild(data->entity->getChildAtIndex(i));
  66. }
  67. return data;
  68. }
  69. PropEvent::PropEvent(PropProp *prop, PropSheet *sheet, PolycodeEditorPropActionData *beforeData, PolycodeEditorPropActionData *afterData) : Event() {
  70. this->prop = prop;
  71. this->sheet = sheet;
  72. this->beforeData = beforeData;
  73. this->afterData = afterData;
  74. this->eventType = "PropEvent";
  75. if(this->beforeData) {
  76. this->beforeData->sheet = sheet;
  77. this->beforeData->prop = prop;
  78. }
  79. if(this->afterData) {
  80. this->afterData->sheet = sheet;
  81. this->afterData->prop = prop;
  82. }
  83. }
  84. void PropEvent::setSheet(PropSheet *sheet) {
  85. if(this->beforeData) {
  86. this->beforeData->sheet = sheet;
  87. }
  88. if(this->afterData) {
  89. this->afterData->sheet = sheet;
  90. }
  91. }
  92. PropEvent::~PropEvent() {
  93. }
  94. PropList::PropList(String caption) : UIElement() {
  95. setAnchorPoint(-1.0, -1.0, 0.0);
  96. bg = new UIRect(10,10);
  97. bg->setAnchorPoint(-1.0, -1.0, 0.0);
  98. bg->color.setColorHexFromString(CoreServices::getInstance()->getConfig()->getStringValue("Polycode", "uiBgColor"));
  99. addChild(bg);
  100. bg->blockMouseInput = true;
  101. bg->processInputEvents = true;
  102. blockMouseInput = true;
  103. bg2 = new UIRect(10,10);
  104. bg2->setAnchorPoint(-1.0, -1.0, 0.0);
  105. bg2->color.setColorHexFromString(CoreServices::getInstance()->getConfig()->getStringValue("Polycode", "uiHeaderBgColor"));
  106. addChild(bg2);
  107. UILabel *label = new UILabel(caption, 18, "section", Label::ANTIALIAS_FULL);
  108. label->color.setColorHexFromString(CoreServices::getInstance()->getConfig()->getStringValue("Polycode", "uiHeaderFontColor"));
  109. addChild(label);
  110. label->setPosition(10, 3);
  111. propContents = new Entity();
  112. propContents->processInputEvents = true;
  113. scrollContainer = new UIScrollContainer(propContents, false, true, 100, 100);
  114. scrollContainer->setPosition(0, 30);
  115. addChild(scrollContainer);
  116. }
  117. PropList::~PropList() {
  118. }
  119. void PropList::updateProps() {
  120. for(int i=0; i < props.size(); i++) {
  121. props[i]->Update();
  122. }
  123. updateSize();
  124. }
  125. void PropList::updateSize() {
  126. Resize(getWidth(), getHeight());
  127. scrollContainer->setScrollValue(0, 0);
  128. }
  129. void PropList::Resize(Number width, Number height) {
  130. setWidth(width);
  131. setHeight(height);
  132. scrollContainer->Resize(width, height-30);
  133. bg->Resize(width, height);
  134. bg2->Resize(width, 30);
  135. Number offsetY = 0;
  136. for(int i=0; i < props.size(); i++) {
  137. props[i]->setPosition(0, offsetY);
  138. if(props[i]->enabled) {
  139. if(props[i]->collapsed) {
  140. offsetY += 30;
  141. } else {
  142. offsetY += props[i]->propHeight;
  143. }
  144. }
  145. props[i]->Resize(getWidth(), getHeight());
  146. }
  147. rebuildTransformMatrix();
  148. scrollContainer->setContentSize(width, offsetY);
  149. }
  150. void PropList::handleEvent(Event *event) {
  151. if(event->getEventType() == "" && event->getEventCode() == Event::COMPLETE_EVENT) {
  152. Resize(getWidth(), getHeight());
  153. } else if(event->getEventCode() == Event::CHANGE_EVENT) {
  154. }
  155. }
  156. void PropList::addPropSheet(PropSheet *sheet) {
  157. propContents->addChild(sheet);
  158. props.push_back(sheet);
  159. Resize(getWidth(), getHeight());
  160. sheet->addEventListener(this, Event::COMPLETE_EVENT);
  161. sheet->addEventListener(this, Event::CHANGE_EVENT);
  162. }
  163. PropSheet::PropSheet(String caption, String type) : UIElement() {
  164. this->caption = caption;
  165. this->type = type;
  166. customUndoHandler = false;
  167. bg = new UIRect(30,30);
  168. addChild(bg);
  169. bg->color.setColorHexFromString(CoreServices::getInstance()->getConfig()->getStringValue("Polycode", "uiSmallHeaderBgColor"));
  170. bg->setAnchorPoint(-1.0, -1.0, 0.0);
  171. UILabel *label = new UILabel(caption, 18, "section", Label::ANTIALIAS_FULL);
  172. label->color.a = 1.0;
  173. addChild(label);
  174. label->setPosition(25, 3);
  175. contents = new Entity();
  176. contents->processInputEvents = true;
  177. addChild(contents);
  178. contents->setPosition(20,35);
  179. collapseButton = new UIImageButton("main/collapse.png", 1.0, 12, 12);
  180. addChild(collapseButton);
  181. collapseButton->addEventListener(this, UIEvent::CLICK_EVENT);
  182. collapseButton->setPosition(5, 9);
  183. expandButton = new UIImageButton("main/expand.png", 1.0, 12, 12);
  184. addChild(expandButton);
  185. expandButton->addEventListener(this, UIEvent::CLICK_EVENT);
  186. expandButton->setPosition(5, 9);
  187. expandButton->enabled = false;
  188. collapsed = false;
  189. propTopPadding = 0;
  190. propHeight = 0;
  191. }
  192. void PropSheet::setCollapsed(bool val) {
  193. if(collapsed != val) {
  194. collapsed = val;
  195. if(collapsed) {
  196. collapseButton->enabled = false;
  197. expandButton->enabled = true;
  198. contents->enabled = false;
  199. contents->visible = false;
  200. } else {
  201. collapseButton->enabled = true;
  202. expandButton->enabled = false;
  203. contents->enabled = true;
  204. contents->visible = true;
  205. }
  206. }
  207. dispatchEvent(new Event(), Event::COMPLETE_EVENT);
  208. }
  209. void PropSheet::handleEvent(Event *event) {
  210. if(event->getEventType() == "UIEvent" && event->getEventCode() == UIEvent::CLICK_EVENT) {
  211. if(event->getDispatcher() == collapseButton) {
  212. setCollapsed(true);
  213. }
  214. if(event->getDispatcher() == expandButton) {
  215. setCollapsed(false);
  216. }
  217. }
  218. if(!customUndoHandler) {
  219. if(event->getEventCode() == PropEvent::EVENT_PROP_CHANGE ) {
  220. PropEvent *propEvent = (PropEvent*) event;
  221. PropEvent *newEvent = new PropEvent(propEvent->prop, this, propEvent->beforeData, propEvent->afterData);
  222. dispatchEvent(newEvent, PropEvent::EVENT_PROP_CHANGE);
  223. }
  224. }
  225. }
  226. PropSheet::~PropSheet() {
  227. }
  228. void PropSheet::setTopPadding(Number padding) {
  229. propTopPadding = padding;
  230. }
  231. void PropSheet::Resize(Number width, Number height) {
  232. setWidth(width);
  233. setHeight(height);
  234. bg->Resize(width, 30);
  235. Number yOffset = propTopPadding;
  236. for(int i=0; i < props.size(); i++) {
  237. props[i]->setPosition(0, yOffset);
  238. props[i]->setPropWidth(width);
  239. yOffset += props[i]->getHeight();
  240. }
  241. }
  242. void PropSheet::addProp(PropProp *prop) {
  243. contents->addChild(prop);
  244. props.push_back(prop);
  245. prop->addEventListener(this, Event::CHANGE_EVENT);
  246. prop->addEventListener(this, PropEvent::EVENT_PROP_CHANGE);
  247. Resize(getWidth(), getHeight());
  248. }
  249. void PropSheet::applyPropActionData(PolycodeEditorPropActionData *data) {
  250. data->prop->setPropData(data);
  251. }
  252. void PropProp::setPropName(String newName) {
  253. label->setText(newName);
  254. }
  255. PropProp::PropProp(String caption, String type) : UIElement() {
  256. suppressChangeEvent = false;
  257. propType = type;
  258. label = new UILabel(caption, 12);
  259. label->setPosition(0, 5);
  260. addChild(label);
  261. propContents = new Entity();
  262. propContents->processInputEvents = true;
  263. addChild(propContents);
  264. propContents->setPosition(100, 0);
  265. setHeight(20);
  266. }
  267. PropProp::~PropProp() {
  268. }
  269. Vector3Prop::Vector3Prop(String caption) : PropProp(caption, "Vector3") {
  270. labelX = new UILabel("X:", 11);
  271. labelX->color.a = 1.0;
  272. propContents->addChild(labelX);
  273. labelX->setPosition(-20, 6);
  274. labelY = new UILabel("Y:", 11);
  275. labelY->color.a = 1.0;
  276. propContents->addChild(labelY);
  277. labelY->setPosition(-20, 31);
  278. labelZ = new UILabel("Z:", 11);
  279. labelZ->color.a = 1.0;
  280. propContents->addChild(labelZ);
  281. labelZ->setPosition(-20, 56);
  282. xInput = new UITextInput(false, 50, 12);
  283. xInput->addEventListener(this, UIEvent::CHANGE_EVENT);
  284. xInput->setText("0");
  285. xInput->setNumberOnly(true);
  286. propContents->addChild(xInput);
  287. xInput->setPosition(0, 0);
  288. yInput = new UITextInput(false, 50, 12);
  289. yInput->addEventListener(this, UIEvent::CHANGE_EVENT);
  290. yInput->setText("0");
  291. yInput->setNumberOnly(true);
  292. propContents->addChild(yInput);
  293. yInput->setPosition(0, 25);
  294. zInput = new UITextInput(false, 50, 12);
  295. zInput->addEventListener(this, UIEvent::CHANGE_EVENT);
  296. zInput->setText("0");
  297. zInput->setNumberOnly(true);
  298. propContents->addChild(zInput);
  299. zInput->setPosition(0, 50);
  300. setHeight(75);
  301. }
  302. void Vector3Prop::setPropWidth(Number width) {
  303. xInput->Resize(width-PROP_PADDING-propContents->getPosition().x, xInput->getHeight());
  304. yInput->Resize(width-PROP_PADDING-propContents->getPosition().x, yInput->getHeight());
  305. zInput->Resize(width-PROP_PADDING-propContents->getPosition().x, zInput->getHeight());
  306. }
  307. void Vector3Prop::handleEvent(Event *event) {
  308. if(event->getDispatcher() == xInput || event->getDispatcher() == yInput || event->getDispatcher() == zInput) {
  309. if(event->getEventCode() == UIEvent::CHANGE_EVENT) {
  310. // if(xInput && yInput && zInput) {
  311. // lastData = currentData;
  312. // currentData = Vector2(atof(positionX->getText().c_str()), atof(positionY->getText().c_str()));
  313. // }
  314. if(!suppressChangeEvent) {
  315. dispatchEvent(new Event(), Event::CHANGE_EVENT);
  316. // dispatchEvent(new PropEvent(this, NULL, PropDataVector2(lastData), PropDataVector2(currentData)), PropEvent::EVENT_PROP_CHANGE);
  317. }
  318. }
  319. }
  320. }
  321. void Vector3Prop::setPropData(PolycodeEditorPropActionData* data) {
  322. // set(data->vector2Val);
  323. dispatchEvent(new Event(), Event::CHANGE_EVENT);
  324. }
  325. void Vector3Prop::set(const Vector3 &position) {
  326. suppressChangeEvent = true;
  327. xInput->setText(String::NumberToString(position.x, 5));
  328. yInput->setText(String::NumberToString(position.y, 5));
  329. zInput->setText(String::NumberToString(position.z, 5));
  330. suppressChangeEvent = false;
  331. }
  332. Vector3 Vector3Prop::get() const {
  333. return Vector3(atof(xInput->getText().c_str()), atof(yInput->getText().c_str()), atof(zInput->getText().c_str()));
  334. }
  335. Vector3Prop::~Vector3Prop() {
  336. }
  337. Vector2Prop::Vector2Prop(String caption) : PropProp(caption, "Vector2") {
  338. labelX = new UILabel("X:", 11);
  339. labelX->color.a = 1.0;
  340. propContents->addChild(labelX);
  341. labelX->setPosition(-20, 6);
  342. labelY = new UILabel("Y:", 11);
  343. labelY->color.a = 1.0;
  344. propContents->addChild(labelY);
  345. labelY->setPosition(60, 6);
  346. positionX = NULL;
  347. positionY = NULL;
  348. positionX = new UITextInput(false, 50, 12);
  349. positionX->addEventListener(this, UIEvent::CHANGE_EVENT);
  350. positionX->setText("0");
  351. positionX->setNumberOnly(true);
  352. propContents->addChild(positionX);
  353. positionX->setPosition(0, 0);
  354. positionY = new UITextInput(false, 50, 12);
  355. positionY->setText("0");
  356. positionY->addEventListener(this, UIEvent::CHANGE_EVENT);
  357. positionY->setNumberOnly(true);
  358. propContents->addChild(positionY);
  359. positionY->setPosition(80, 0);
  360. setHeight(25);
  361. }
  362. void Vector2Prop::setPropWidth(Number width) {
  363. labelX->setPosition(0, 6);
  364. labelY->setPosition(((width-propContents->getPosition().x-PROP_PADDING)/2.0), 6);
  365. positionX->setPositionX(labelX->getPosition().x + 20);
  366. positionX->Resize(floor(((width-propContents->getPosition().x-PROP_PADDING)/2.0)-25), positionX->getHeight());
  367. positionY->setPositionX(labelY->getPosition().x + 20);
  368. positionY->Resize(floor(((width-propContents->getPosition().x-PROP_PADDING)/2.0)-25), positionY->getHeight());
  369. }
  370. void Vector2Prop::handleEvent(Event *event) {
  371. if(event->getDispatcher() == positionX || event->getDispatcher() == positionY) {
  372. if(event->getEventType() == "UIEvent" && event->getEventCode() == UIEvent::CHANGE_EVENT) {
  373. if(positionX && positionY) {
  374. lastData = currentData;
  375. currentData = Vector2(atof(positionX->getText().c_str()), atof(positionY->getText().c_str()));
  376. }
  377. if(!suppressChangeEvent) {
  378. dispatchEvent(new Event(), Event::CHANGE_EVENT);
  379. dispatchEvent(new PropEvent(this, NULL, PropDataVector2(lastData), PropDataVector2(currentData)), PropEvent::EVENT_PROP_CHANGE);
  380. }
  381. }
  382. }
  383. }
  384. void Vector2Prop::setPropData(PolycodeEditorPropActionData* data) {
  385. set(data->vector2Val);
  386. dispatchEvent(new Event(), Event::CHANGE_EVENT);
  387. }
  388. void Vector2Prop::set(Vector2 position) {
  389. suppressChangeEvent = true;
  390. positionX->setText(String::NumberToString(position.x, 5));
  391. positionY->setText(String::NumberToString(position.y, 5));
  392. suppressChangeEvent = false;
  393. }
  394. Vector2 Vector2Prop::get() {
  395. return Vector2(atof(positionX->getText().c_str()), atof(positionY->getText().c_str()));
  396. }
  397. Vector2Prop::~Vector2Prop() {
  398. }
  399. CustomProp::CustomProp(String key, String value) : PropProp("", "Custom") {
  400. keyEntry = new UITextInput(false, 120, 12);
  401. keyEntry->setText(key);
  402. keyEntry->addEventListener(this, UIEvent::CHANGE_EVENT);
  403. propContents->addChild(keyEntry);
  404. keyEntry->setPosition(-90, 0);
  405. valueEntry = new UITextInput(false, 120, 12);
  406. valueEntry->setText(value);
  407. valueEntry->addEventListener(this, UIEvent::CHANGE_EVENT);
  408. propContents->addChild(valueEntry);
  409. valueEntry->setPosition(45, 0);
  410. removeButton = new UIImageButton("main/remove_icon.png", 1.0, 12, 12);
  411. removeButton->addEventListener(this, UIEvent::CLICK_EVENT);
  412. propContents->addChild(removeButton);
  413. removeButton->setPosition(-110, 6);
  414. setHeight(25);
  415. }
  416. CustomProp::~CustomProp() {
  417. keyEntry->removeAllHandlersForListener(this);
  418. valueEntry->removeAllHandlersForListener(this);
  419. removeButton->removeAllHandlersForListener(this);
  420. delete removeButton;
  421. delete keyEntry;
  422. delete valueEntry;
  423. }
  424. void CustomProp::handleEvent(Event *event) {
  425. if(event->getEventType() == "UIEvent") {
  426. if(event->getDispatcher() == keyEntry || event->getDispatcher() == valueEntry) {
  427. dispatchEvent(new Event(), Event::CHANGE_EVENT);
  428. }
  429. if(event->getDispatcher() == removeButton) {
  430. dispatchEvent(new Event(), Event::CANCEL_EVENT);
  431. }
  432. }
  433. }
  434. void CustomProp::set(String key, String val) {
  435. }
  436. String CustomProp::getValue() {
  437. return valueEntry->getText();
  438. }
  439. String CustomProp::getKey() {
  440. return keyEntry->getText();
  441. }
  442. StringProp::StringProp(String caption) : PropProp(caption, "String") {
  443. stringEntry = new UITextInput(false, 150, 12);
  444. stringEntry->addEventListener(this, UIEvent::CHANGE_EVENT);
  445. stringEntry->setText("");
  446. propContents->addChild(stringEntry);
  447. stringEntry->setPosition(0, 0);
  448. setHeight(25);
  449. }
  450. void StringProp::setPropWidth(Number width) {
  451. stringEntry->Resize(width-PROP_PADDING-propContents->getPosition().x, stringEntry->getHeight());
  452. stringEntry->setPosition(0.0, 2);
  453. }
  454. void StringProp::handleEvent(Event *event) {
  455. if(event->getDispatcher() == stringEntry) {
  456. if(event->getEventType() == "UIEvent" && event->getEventCode() == UIEvent::CHANGE_EVENT) {
  457. lastValue = currentValue;
  458. currentValue = stringEntry->getText();
  459. if(!suppressChangeEvent) {
  460. dispatchEvent(new Event(), Event::CHANGE_EVENT);
  461. dispatchEvent(new PropEvent(this, NULL, PropDataString(lastValue), PropDataString(currentValue)), PropEvent::EVENT_PROP_CHANGE);
  462. }
  463. }
  464. }
  465. }
  466. void StringProp::setPropData(PolycodeEditorPropActionData* data) {
  467. set(data->stringVal);
  468. dispatchEvent(new Event(), Event::CHANGE_EVENT);
  469. }
  470. void StringProp::set(String str) {
  471. suppressChangeEvent = true;
  472. stringEntry->setText(str);
  473. suppressChangeEvent = false;
  474. }
  475. String StringProp::get() {
  476. return currentValue;
  477. }
  478. StringProp::~StringProp() {
  479. }
  480. SliderProp::SliderProp(String caption, Number min, Number max) : PropProp(caption, "Slider") {
  481. slider = new UIHSlider(min, max, 100);
  482. slider->addEventListener(this, UIEvent::CHANGE_EVENT);
  483. slider->setPosition(0, 8);
  484. propContents->addChild(slider);
  485. valueLabel = new UILabel("0.0", 10);
  486. propContents->addChild(valueLabel);
  487. valueLabel->setPosition(120, 5);
  488. valueLabel->color.a = 1.0;
  489. setHeight(25);
  490. }
  491. void SliderProp::setPropWidth(Number width) {
  492. slider->Resize(width - propContents->getPosition().x - PROP_PADDING - 50, slider->getHeight());
  493. valueLabel->setPosition(width - propContents->getPosition().x - PROP_PADDING - 30, 5);
  494. }
  495. void SliderProp::handleEvent(Event *event) {
  496. if(event->getDispatcher() == slider) {
  497. if(event->getEventType() == "UIEvent" && event->getEventCode() == UIEvent::CHANGE_EVENT) {
  498. lastValue = currentValue;
  499. currentValue = slider->getSliderValue();
  500. if(!suppressChangeEvent) {
  501. dispatchEvent(new Event(), Event::CHANGE_EVENT);
  502. dispatchEvent(new PropEvent(this, NULL, PropDataNumber(lastValue), PropDataNumber(currentValue)), PropEvent::EVENT_PROP_CHANGE);
  503. }
  504. valueLabel->setText(String::NumberToString(slider->getSliderValue()));
  505. }
  506. }
  507. }
  508. void SliderProp::setPropData(PolycodeEditorPropActionData* data) {
  509. set(data->numVal);
  510. lastValue = currentValue;
  511. currentValue = slider->getSliderValue();
  512. dispatchEvent(new Event(), Event::CHANGE_EVENT);
  513. }
  514. void SliderProp::set(Number number) {
  515. suppressChangeEvent = true;
  516. slider->setSliderValue(number);
  517. lastValue = currentValue;
  518. currentValue = slider->getSliderValue();
  519. valueLabel->setText(String::NumberToString(slider->getSliderValue()));
  520. suppressChangeEvent = false;
  521. }
  522. Number SliderProp::get() {
  523. return currentValue;
  524. }
  525. SliderProp::~SliderProp() {
  526. }
  527. NumberProp::NumberProp(String caption) : PropProp(caption, "Number") {
  528. numberEntry = new UITextInput(false, 50, 20);
  529. numberEntry->addEventListener(this, UIEvent::CHANGE_EVENT);
  530. numberEntry->setText("0");
  531. numberEntry->setNumberOnly(true);
  532. propContents->addChild(numberEntry);
  533. numberEntry->setPosition(0, 2);
  534. setHeight(25);
  535. }
  536. void NumberProp::setPropWidth(Number width) {
  537. numberEntry->Resize(width-PROP_PADDING-propContents->getPosition().x, numberEntry->getHeight());
  538. numberEntry->setPosition(0.0, 2);
  539. }
  540. void NumberProp::setPropData(PolycodeEditorPropActionData* data) {
  541. set(data->numVal);
  542. dispatchEvent(new Event(), Event::CHANGE_EVENT);
  543. }
  544. void NumberProp::handleEvent(Event *event) {
  545. if(event->getDispatcher() == numberEntry) {
  546. if(event->getEventType() == "UIEvent" && event->getEventCode() == UIEvent::CHANGE_EVENT) {
  547. lastValue = currentValue;
  548. currentValue = atof(numberEntry->getText().c_str());
  549. if(!suppressChangeEvent) {
  550. dispatchEvent(new Event(), Event::CHANGE_EVENT);
  551. dispatchEvent(new PropEvent(this, NULL, PropDataNumber(lastValue), PropDataNumber(currentValue)), PropEvent::EVENT_PROP_CHANGE);
  552. }
  553. }
  554. }
  555. }
  556. void NumberProp::set(Number number) {
  557. suppressChangeEvent = true;
  558. numberEntry->setText(String::NumberToString(number), 5);
  559. suppressChangeEvent = false;
  560. }
  561. Number NumberProp::get() {
  562. return currentValue;
  563. }
  564. NumberProp::~NumberProp() {
  565. }
  566. ColorProp::ColorProp(String caption) : PropProp(caption, "Color") {
  567. colorEntry = new UIColorBox(globalColorPicker, Color(), 45, 25);
  568. colorEntry->addEventListener(this, UIEvent::CHANGE_EVENT);
  569. colorEntry->setPosition(-2, 0);
  570. propContents->addChild(colorEntry);
  571. setHeight(25);
  572. }
  573. void ColorProp::handleEvent(Event *event) {
  574. if(event->getDispatcher() == colorEntry) {
  575. if(event->getEventType() == "UIEvent" && event->getEventCode() == UIEvent::CHANGE_EVENT) {
  576. lastColor = currentColor;
  577. currentColor = colorEntry->getSelectedColor();
  578. if(!suppressChangeEvent) {
  579. dispatchEvent(new Event(), Event::CHANGE_EVENT);
  580. dispatchEvent(new PropEvent(this, NULL, PropDataColor(lastColor), PropDataColor(currentColor)), PropEvent::EVENT_PROP_CHANGE);
  581. }
  582. }
  583. }
  584. }
  585. void ColorProp::setPropData(PolycodeEditorPropActionData* data) {
  586. set(data->colorVal);
  587. dispatchEvent(new Event(), Event::CHANGE_EVENT);
  588. }
  589. void ColorProp::set(Color color) {
  590. suppressChangeEvent = true;
  591. colorEntry->setBoxColor(color);
  592. lastColor = currentColor;
  593. currentColor = colorEntry->getSelectedColor();
  594. suppressChangeEvent = false;
  595. }
  596. Color ColorProp::get() {
  597. return currentColor;
  598. }
  599. ColorProp::~ColorProp() {
  600. }
  601. ComboProp::ComboProp(String caption) : PropProp(caption, "Combo") {
  602. comboEntry = new UIComboBox(globalMenu, 150);
  603. comboEntry->addEventListener(this, UIEvent::CHANGE_EVENT);
  604. propContents->addChild(comboEntry);
  605. comboEntry->setPosition(-3, 0);
  606. setHeight(25);
  607. }
  608. void ComboProp::setPropWidth(Number width) {
  609. comboEntry->Resize(width - propContents->getPosition().x - PROP_PADDING, comboEntry->getHeight());
  610. }
  611. void ComboProp::setPropData(PolycodeEditorPropActionData* data) {
  612. set(data->intVal);
  613. dispatchEvent(new Event(), Event::CHANGE_EVENT);
  614. }
  615. void ComboProp::handleEvent(Event *event) {
  616. if(event->getDispatcher() == comboEntry) {
  617. if(event->getEventType() == "UIEvent" && event->getEventCode() == UIEvent::CHANGE_EVENT) {
  618. lastValue = currentValue;
  619. currentValue = comboEntry->getSelectedIndex();
  620. if(!suppressChangeEvent) {
  621. dispatchEvent(new Event(), Event::CHANGE_EVENT);
  622. dispatchEvent(new PropEvent(this, NULL, PropDataInt(lastValue), PropDataInt(currentValue)), PropEvent::EVENT_PROP_CHANGE);
  623. }
  624. }
  625. }
  626. }
  627. void ComboProp::set(unsigned int index) {
  628. suppressChangeEvent = true;
  629. comboEntry->setSelectedIndex(index);
  630. suppressChangeEvent = false;
  631. }
  632. unsigned int ComboProp::get() {
  633. return currentValue;
  634. }
  635. ComboProp::~ComboProp() {
  636. }
  637. BoolProp::BoolProp(String caption) : PropProp(caption, "Bool") {
  638. checkEntry = new UICheckBox("", false);
  639. checkEntry->addEventListener(this, UIEvent::CHANGE_EVENT);
  640. checkEntry->setPosition(0, 4);
  641. propContents->addChild(checkEntry);
  642. setHeight(25);
  643. }
  644. void BoolProp::setPropData(PolycodeEditorPropActionData* data) {
  645. set(data->boolVal);
  646. dispatchEvent(new Event(), Event::CHANGE_EVENT);
  647. }
  648. void BoolProp::handleEvent(Event *event) {
  649. if(event->getDispatcher() == checkEntry) {
  650. if(event->getEventType() == "UIEvent" && event->getEventCode() == UIEvent::CHANGE_EVENT) {
  651. lastData = currentData;
  652. currentData = checkEntry->isChecked();
  653. dispatchEvent(new Event(), Event::CHANGE_EVENT);
  654. dispatchEvent(new PropEvent(this, NULL, PropDataBool(lastData), PropDataBool(currentData)), PropEvent::EVENT_PROP_CHANGE);
  655. }
  656. }
  657. }
  658. void BoolProp::set(bool val) {
  659. checkEntry->setChecked(val);
  660. lastData = currentData;
  661. currentData = checkEntry->isChecked();
  662. }
  663. bool BoolProp::get() {
  664. return currentData;
  665. }
  666. BoolProp::~BoolProp() {
  667. }
  668. SoundProp::SoundProp(String caption) : PropProp(caption, "Sound"){
  669. soundFile = new UILabel("", 11);
  670. soundFile->setPosition(0, 5);
  671. propContents->addChild(soundFile);
  672. soundFile->color.a = 1.0;
  673. playButton = new UIButton("Play", 50);
  674. propContents->addChild(playButton);
  675. playButton->setPosition(0, 25);
  676. playButton->addEventListener(this, UIEvent::CLICK_EVENT);
  677. changeButton = new UIButton("Change", 80);
  678. propContents->addChild(changeButton);
  679. changeButton->setPosition(60, 25);
  680. changeButton->addEventListener(this, UIEvent::CLICK_EVENT);
  681. setHeight(70);
  682. previewSound = NULL;
  683. }
  684. SoundProp::~SoundProp() {
  685. }
  686. void SoundProp::handleEvent(Event *event) {
  687. if(event->getDispatcher() == globalFrame->assetBrowser && event->getEventType() == "UIEvent" && event->getEventCode() == UIEvent::OK_EVENT) {
  688. String newSoundPath = globalFrame->assetBrowser->getSelectedAssetPath();
  689. set(newSoundPath);
  690. globalFrame->assetBrowser->removeAllHandlersForListener(this);
  691. dispatchEvent(new Event(), Event::CHANGE_EVENT);
  692. dispatchEvent(new PropEvent(this, NULL, PropDataString(lastData), PropDataString(currentData)), PropEvent::EVENT_PROP_CHANGE);
  693. globalFrame->hideModal();
  694. }
  695. if(event->getDispatcher() == playButton && event->getEventType() == "UIEvent" && event->getEventCode() == UIEvent::CLICK_EVENT) {
  696. if(previewSound) {
  697. previewSound->Play();
  698. }
  699. }
  700. if(event->getDispatcher() == changeButton && event->getEventType() == "UIEvent" && event->getEventCode() == UIEvent::CLICK_EVENT) {
  701. globalFrame->assetBrowser->addEventListener(this, UIEvent::OK_EVENT);
  702. std::vector<String> extensions;
  703. extensions.push_back("wav");
  704. extensions.push_back("ogg");
  705. globalFrame->showAssetBrowser(extensions);
  706. }
  707. }
  708. void SoundProp::setPropData(PolycodeEditorPropActionData* data) {
  709. set(data->stringVal);
  710. dispatchEvent(new Event(), Event::CHANGE_EVENT);
  711. }
  712. void SoundProp::set(String soundPath) {
  713. if(previewSound) {
  714. delete previewSound;
  715. }
  716. lastData = currentData;
  717. currentData = soundPath;
  718. previewSound = new Sound(soundPath);
  719. soundFile->setText(soundPath);
  720. }
  721. String SoundProp::get() {
  722. if(previewSound) {
  723. return previewSound->getFileName();
  724. }
  725. return "";
  726. }
  727. BezierRGBACurveProp::BezierRGBACurveProp(String caption) : PropProp(caption, "BezierRGBA") {
  728. changeButton = new UIButton("Edit", 120);
  729. propContents->addChild(changeButton);
  730. changeButton->setPosition(0, 0);
  731. changeButton->addEventListener(this, UIEvent::CLICK_EVENT);
  732. setHeight(25);
  733. curveR = NULL;
  734. curveG = NULL;
  735. curveB = NULL;
  736. curveA = NULL;
  737. }
  738. BezierRGBACurveProp::~BezierRGBACurveProp() {
  739. }
  740. void BezierRGBACurveProp::handleEvent(Event *event) {
  741. if(event->getDispatcher() == changeButton && event->getEventType() == "UIEvent" && event->getEventCode() == UIEvent::CLICK_EVENT) {
  742. globalFrame->curveEditor->clearCurves();
  743. if(curveR && curveG && curveB && curveA) {
  744. globalFrame->curveEditor->addCurve("Red", curveR, Color(1.0, 0.0, 0.0, 1.0));
  745. globalFrame->curveEditor->addCurve("Green", curveG, Color(0.0, 1.0, 0.0, 1.0));
  746. globalFrame->curveEditor->addCurve("Blue", curveB, Color(0.0, 0.0, 1.0, 1.0));
  747. globalFrame->curveEditor->addCurve("Alpha", curveA, Color(1.0, 1.0, 1.0, 1.0));
  748. globalFrame->showCurveEditor();
  749. }
  750. }
  751. }
  752. BezierCurveProp::BezierCurveProp(String caption, String curveName) : PropProp(caption, "BezierCurve") {
  753. this->curveName = curveName;
  754. changeButton = new UIButton("Edit", 120);
  755. propContents->addChild(changeButton);
  756. changeButton->setPosition(0, 0);
  757. changeButton->addEventListener(this, UIEvent::CLICK_EVENT);
  758. setHeight(25);
  759. curve = NULL;
  760. }
  761. BezierCurveProp::~BezierCurveProp() {
  762. }
  763. void BezierCurveProp::handleEvent(Event *event) {
  764. if(event->getDispatcher() == changeButton && event->getEventType() == "UIEvent" && event->getEventCode() == UIEvent::CLICK_EVENT) {
  765. globalFrame->curveEditor->clearCurves();
  766. if(curve) {
  767. globalFrame->curveEditor->addCurve(curveName, curve, Color());
  768. globalFrame->showCurveEditor();
  769. }
  770. }
  771. }
  772. TextureProp::TextureProp(String caption) : PropProp(caption, "Texture"){
  773. previewShape = new UIRect(48, 48);
  774. previewShape->setAnchorPoint(-1.0, -1.0, 0.0);
  775. previewShape->setPosition(2, 1);
  776. propContents->addChild(previewShape);
  777. changeButton = new UIButton("Change", 80);
  778. propContents->addChild(changeButton);
  779. changeButton->setPosition(60, 5);
  780. changeButton->addEventListener(this, UIEvent::CLICK_EVENT);
  781. textureLabel = new UILabel("", 12, "sans");
  782. propContents->addChild(textureLabel);
  783. textureLabel->setPosition(-100, 32);
  784. textureLabel->color.a = 1.0;
  785. setHeight(60);
  786. }
  787. void TextureProp::setPropWidth(Number width) {
  788. changeButton->setPosition(width-changeButton->getWidth()-PROP_PADDING-100, 5);
  789. previewShape->setPosition(changeButton->getPosition().x-48-10, 1);
  790. }
  791. TextureProp::~TextureProp() {
  792. }
  793. void TextureProp::setPropData(PolycodeEditorPropActionData* data) {
  794. set(CoreServices::getInstance()->getMaterialManager()->createTextureFromFile(data->stringVal));
  795. dispatchEvent(new Event(), Event::CHANGE_EVENT);
  796. }
  797. void TextureProp::handleEvent(Event *event) {
  798. if(event->getDispatcher() == globalFrame->assetBrowser && event->getEventType() == "UIEvent" && event->getEventCode() == UIEvent::OK_EVENT) {
  799. String texturePath = globalFrame->assetBrowser->getSelectedAssetPath();
  800. set(CoreServices::getInstance()->getMaterialManager()->createTextureFromFile(texturePath));
  801. globalFrame->assetBrowser->removeAllHandlersForListener(this);
  802. dispatchEvent(new Event(), Event::CHANGE_EVENT);
  803. dispatchEvent(new PropEvent(this, NULL, PropDataString(lastData), PropDataString(currentData)), PropEvent::EVENT_PROP_CHANGE);
  804. globalFrame->hideModal();
  805. }
  806. if(event->getDispatcher() == changeButton && event->getEventType() == "UIEvent" && event->getEventCode() == UIEvent::CLICK_EVENT) {
  807. globalFrame->assetBrowser->addEventListener(this, UIEvent::OK_EVENT);
  808. std::vector<String> extensions;
  809. extensions.push_back("png");
  810. globalFrame->showAssetBrowser(extensions);
  811. }
  812. }
  813. void TextureProp::set(Texture *texture) {
  814. previewShape->setTexture(texture);
  815. lastData = currentData;
  816. currentData = texture->getResourcePath();
  817. OSFileEntry entry = OSFileEntry(texture->getResourcePath(), OSFileEntry::TYPE_FILE);
  818. textureLabel->setText(entry.name);
  819. }
  820. Texture* TextureProp::get() {
  821. return previewShape->getTexture();
  822. }
  823. SceneSpriteProp::SceneSpriteProp(String caption) : PropProp(caption, "SceneSprite"){
  824. previewSprite = new SceneSprite("default/default.sprite");
  825. previewSprite->setAnchorPoint(-1.0, -1.0, 0.0);
  826. previewSprite->setPosition(2, 1);
  827. previewSprite->setPrimitiveOptions(ScenePrimitive::TYPE_VPLANE, 48,48);
  828. propContents->addChild(previewSprite);
  829. changeButton = new UIButton("Change", 80);
  830. propContents->addChild(changeButton);
  831. changeButton->setPosition(60, 5);
  832. changeButton->addEventListener(this, UIEvent::CLICK_EVENT);
  833. setHeight(70);
  834. }
  835. SceneSpriteProp::~SceneSpriteProp() {
  836. }
  837. void SceneSpriteProp::handleEvent(Event *event) {
  838. if(event->getDispatcher() == globalFrame->assetBrowser && event->getEventType() == "UIEvent" && event->getEventCode() == UIEvent::OK_EVENT) {
  839. String filePath = globalFrame->assetBrowser->getSelectedAssetPath();
  840. set(filePath);
  841. globalFrame->assetBrowser->removeAllHandlersForListener(this);
  842. dispatchEvent(new Event(), Event::CHANGE_EVENT);
  843. dispatchEvent(new PropEvent(this, NULL, PropDataString(lastData), PropDataString(currentData)), PropEvent::EVENT_PROP_CHANGE);
  844. globalFrame->hideModal();
  845. }
  846. if(event->getDispatcher() == changeButton && event->getEventType() == "UIEvent" && event->getEventCode() == UIEvent::CLICK_EVENT) {
  847. globalFrame->assetBrowser->addEventListener(this, UIEvent::OK_EVENT);
  848. std::vector<String> extensions;
  849. extensions.push_back("sprite");
  850. globalFrame->showAssetBrowser(extensions);
  851. }
  852. }
  853. void SceneSpriteProp::setPropData(PolycodeEditorPropActionData* data) {
  854. set(data->stringVal);
  855. dispatchEvent(new Event(), Event::CHANGE_EVENT);
  856. }
  857. void SceneSpriteProp::set(String fileName) {
  858. if(fileName != previewSprite->getFileName()) {
  859. if(previewSprite) {
  860. propContents->removeChild(previewSprite);
  861. delete previewSprite;
  862. }
  863. lastData = currentData;
  864. currentData = fileName;
  865. previewSprite = new SceneSprite(fileName);
  866. previewSprite->setAnchorPoint(-1.0, -1.0, 0.0);
  867. previewSprite->setPosition(2, 1);
  868. previewSprite->setPrimitiveOptions(ScenePrimitive::TYPE_VPLANE, 48,48);
  869. propContents->addChild(previewSprite);
  870. }
  871. }
  872. String SceneSpriteProp::get() {
  873. return previewSprite->getFileName();
  874. }
  875. SceneEntityInstanceProp::SceneEntityInstanceProp(String caption) : PropProp(caption, "SceneEntityInstance"){
  876. previewInstance = new SceneEntityInstance("default/default.entity2d");
  877. previewInstance->setAnchorPoint(-1.0, -1.0, 0.0);
  878. previewInstance->setPosition(2, 1);
  879. propContents->addChild(previewInstance);
  880. changeButton = new UIButton("Change", 80);
  881. propContents->addChild(changeButton);
  882. changeButton->setPosition(60, 5);
  883. changeButton->addEventListener(this, UIEvent::CLICK_EVENT);
  884. setHeight(50);
  885. }
  886. SceneEntityInstanceProp::~SceneEntityInstanceProp() {
  887. }
  888. void SceneEntityInstanceProp::handleEvent(Event *event) {
  889. if(event->getDispatcher() == globalFrame->assetBrowser && event->getEventType() == "UIEvent" && event->getEventCode() == UIEvent::OK_EVENT) {
  890. String filePath = globalFrame->assetBrowser->getSelectedAssetPath();
  891. set(filePath);
  892. globalFrame->assetBrowser->removeAllHandlersForListener(this);
  893. dispatchEvent(new Event(), Event::CHANGE_EVENT);
  894. dispatchEvent(new PropEvent(this, NULL, PropDataString(lastData), PropDataString(currentData)), PropEvent::EVENT_PROP_CHANGE);
  895. globalFrame->hideModal();
  896. }
  897. if(event->getDispatcher() == changeButton && event->getEventType() == "UIEvent" && event->getEventCode() == UIEvent::CLICK_EVENT) {
  898. globalFrame->assetBrowser->addEventListener(this, UIEvent::OK_EVENT);
  899. std::vector<String> extensions;
  900. extensions.push_back("entity2d");
  901. globalFrame->showAssetBrowser(extensions);
  902. }
  903. }
  904. void SceneEntityInstanceProp::setPropData(PolycodeEditorPropActionData* data) {
  905. set(data->stringVal);
  906. dispatchEvent(new Event(), Event::CHANGE_EVENT);
  907. }
  908. void SceneEntityInstanceProp::set(String fileName) {
  909. if(fileName != previewInstance->getFileName()) {
  910. propContents->removeChild(previewInstance);
  911. delete previewInstance;
  912. previewInstance = new SceneEntityInstance(fileName);
  913. previewInstance->setAnchorPoint(-1.0, -1.0, 0.0);
  914. previewInstance->setPosition(2, 1);
  915. lastData = currentData;
  916. currentData = fileName;
  917. Number radius = previewInstance->getCompoundBBoxRadius();
  918. if(radius > 48) {
  919. previewInstance->setScale(48.0/(radius*2.0), 48.0/(radius*2.0));
  920. }
  921. propContents->addChild(previewInstance);
  922. }
  923. }
  924. String SceneEntityInstanceProp::get() {
  925. return previewInstance->getFileName();
  926. }
  927. ShaderPassProp::ShaderPassProp(Material *material, int shaderIndex) : PropProp("", "ShaderPassProp") {
  928. this->material = material;
  929. this->shader = material->getShader(shaderIndex);
  930. this->shaderIndex = shaderIndex;
  931. removeButton = new UIImageButton("main/remove_icon.png", 1.0, 12, 12);
  932. removeButton->addEventListener(this, UIEvent::CLICK_EVENT);
  933. propContents->addChild(removeButton);
  934. removeButton->setPosition(-110, 6);
  935. shaderComboBox = new UIComboBox(globalMenu, 100);
  936. shaderComboBox->addEventListener(this, UIEvent::CHANGE_EVENT);
  937. propContents->addChild(shaderComboBox);
  938. int index = 0;
  939. MaterialManager *materialManager = CoreServices::getInstance()->getMaterialManager();
  940. for(int i=0; i < materialManager->getNumShaders(); i++) {
  941. if(materialManager->getShaderByIndex(i)->screenShader) {
  942. shaderComboBox->addComboItem(materialManager->getShaderByIndex(i)->getName(), (void*)materialManager->getShaderByIndex(i));
  943. if(shader == materialManager->getShaderByIndex(i)) {
  944. shaderComboBox->setSelectedIndex(index);
  945. }
  946. index++;
  947. }
  948. }
  949. editButton = new UIButton("Options", 30);
  950. editButton->addEventListener(this, UIEvent::CLICK_EVENT);
  951. propContents->addChild(editButton);
  952. setHeight(25);
  953. }
  954. ShaderPassProp::~ShaderPassProp() {
  955. }
  956. void ShaderPassProp::handleEvent(Event *event) {
  957. if(event->getDispatcher() == removeButton && event->getEventCode() == UIEvent::CLICK_EVENT) {
  958. dispatchEvent(new Event(), Event::REMOVE_EVENT);
  959. } else if(event->getDispatcher() == editButton && event->getEventCode() == UIEvent::CLICK_EVENT) {
  960. dispatchEvent(new Event(), Event::SELECT_EVENT);
  961. } else if(event->getDispatcher() == shaderComboBox) {
  962. Shader *selectedShader = (Shader*)shaderComboBox->getSelectedItem()->data;
  963. if(selectedShader) {
  964. if(material->getShader(shaderIndex) != selectedShader) {
  965. material->removeShader(shaderIndex);
  966. ShaderBinding *newShaderBinding = selectedShader->createBinding();
  967. material->addShaderAtIndex(selectedShader, newShaderBinding, shaderIndex);
  968. dispatchEvent(new Event(), Event::CHANGE_EVENT);
  969. }
  970. }
  971. }
  972. }
  973. void ShaderPassProp::setPropWidth(Number width) {
  974. Number adjustedWidth = width-PROP_PADDING-5;
  975. shaderComboBox->setPosition(-90, 0);
  976. shaderComboBox->Resize(floor(adjustedWidth * 0.75), shaderComboBox->getHeight());
  977. editButton->setPosition(-90 + shaderComboBox->getWidth() + 5, 0);
  978. editButton->Resize(floor(adjustedWidth * 0.25), editButton->getHeight());
  979. }
  980. TargetBindingProp::TargetBindingProp(Shader *shader, Material *material, ShaderBinding *binding, RenderTargetBinding *targetBinding) : PropProp("", "TargetBindingProp") {
  981. this->targetBinding = targetBinding;
  982. this->material = material;
  983. this->shader = shader;
  984. this->binding = binding;
  985. removeButton = new UIImageButton("main/remove_icon.png", 1.0, 12, 12);
  986. removeButton->addEventListener(this, UIEvent::CLICK_EVENT);
  987. propContents->addChild(removeButton);
  988. removeButton->setPosition(-110, 6);
  989. typeComboBox = new UIComboBox(globalMenu, 100);
  990. typeComboBox->addComboItem("IN");
  991. typeComboBox->addComboItem("OUT");
  992. typeComboBox->addComboItem("COLOR");
  993. typeComboBox->addComboItem("DEPTH");
  994. typeComboBox->setSelectedIndex(targetBinding->mode);
  995. typeComboBox->addEventListener(this, UIEvent::CHANGE_EVENT);
  996. propContents->addChild(typeComboBox);
  997. targetComboBox = new UIComboBox(globalMenu, 100);
  998. for(int i=0; i < material->getNumShaderRenderTargets(); i++) {
  999. ShaderRenderTarget *target = material->getShaderRenderTarget(i);
  1000. targetComboBox->addComboItem(target->id, (void*) target);
  1001. if(targetBinding->texture == target->texture) {
  1002. targetComboBox->setSelectedIndex(i);
  1003. }
  1004. }
  1005. targetComboBox->addEventListener(this, UIEvent::CHANGE_EVENT);
  1006. propContents->addChild(targetComboBox);
  1007. textureComboBox = new UIComboBox(globalMenu, 100);
  1008. for(int i=0; i < shader->expectedTextures.size(); i++) {
  1009. textureComboBox->addComboItem(shader->expectedTextures[i]);
  1010. if(shader->expectedTextures[i] == targetBinding->name) {
  1011. textureComboBox->setSelectedIndex(i);
  1012. }
  1013. }
  1014. textureComboBox->addEventListener(this, UIEvent::CHANGE_EVENT);
  1015. propContents->addChild(textureComboBox);
  1016. setHeight(25);
  1017. if(typeComboBox->getSelectedIndex() == 1) {
  1018. textureComboBox->enabled = false;
  1019. textureComboBox->visible = false;
  1020. } else {
  1021. textureComboBox->enabled = true;
  1022. textureComboBox->visible = true;
  1023. }
  1024. if(typeComboBox->getSelectedIndex() == 2 || typeComboBox->getSelectedIndex() == 3) {
  1025. targetComboBox->enabled = false;
  1026. targetComboBox->visible = false;
  1027. } else {
  1028. targetComboBox->enabled = true;
  1029. targetComboBox->visible = true;
  1030. }
  1031. }
  1032. TargetBindingProp::~TargetBindingProp() {
  1033. }
  1034. void TargetBindingProp::handleEvent(Event *event) {
  1035. if(event->getDispatcher() == removeButton && event->getEventCode() == UIEvent::CLICK_EVENT) {
  1036. dispatchEvent(new Event(), Event::REMOVE_EVENT);
  1037. } else if(event->getDispatcher() == typeComboBox && event->getEventCode() == UIEvent::CHANGE_EVENT) {
  1038. binding->clearTexture(targetBinding->name);
  1039. if(typeComboBox->getSelectedIndex() == 1) {
  1040. textureComboBox->enabled = false;
  1041. textureComboBox->visible = false;
  1042. } else {
  1043. textureComboBox->enabled = true;
  1044. textureComboBox->visible = true;
  1045. binding->addTexture(targetBinding->name, targetBinding->texture);
  1046. }
  1047. if(typeComboBox->getSelectedIndex() == 2 || typeComboBox->getSelectedIndex() == 3) {
  1048. targetComboBox->enabled = false;
  1049. targetComboBox->visible = false;
  1050. } else {
  1051. targetComboBox->enabled = true;
  1052. targetComboBox->visible = true;
  1053. }
  1054. binding->removeRenderTargetBinding(targetBinding);
  1055. targetBinding->mode = typeComboBox->getSelectedIndex();
  1056. binding->addRenderTargetBinding(targetBinding);
  1057. dispatchEvent(new Event(), Event::CHANGE_EVENT);
  1058. } else if(event->getDispatcher() == targetComboBox && event->getEventCode() == UIEvent::CHANGE_EVENT) {
  1059. ShaderRenderTarget *target = (ShaderRenderTarget*)targetComboBox->getSelectedItem()->data;
  1060. targetBinding->texture = target->texture;
  1061. targetBinding->id = target->id;
  1062. binding->removeRenderTargetBinding(targetBinding);
  1063. binding->addRenderTargetBinding(targetBinding);
  1064. binding->clearTexture(targetBinding->name);
  1065. if(targetBinding->mode == RenderTargetBinding::MODE_IN) {
  1066. binding->addTexture(targetBinding->name, targetBinding->texture);
  1067. }
  1068. dispatchEvent(new Event(), Event::CHANGE_EVENT);
  1069. } else if(event->getDispatcher() == textureComboBox && event->getEventCode() == UIEvent::CHANGE_EVENT) {
  1070. targetBinding->name = textureComboBox->getSelectedItem()->label;
  1071. binding->removeRenderTargetBinding(targetBinding);
  1072. binding->addRenderTargetBinding(targetBinding);
  1073. binding->clearTexture(targetBinding->name);
  1074. binding->addTexture(targetBinding->name, targetBinding->texture);
  1075. dispatchEvent(new Event(), Event::CHANGE_EVENT);
  1076. }
  1077. }
  1078. void TargetBindingProp::setPropWidth(Number width) {
  1079. Number size = width-PROP_PADDING-85-15;
  1080. typeComboBox->setPosition(-90, 0);
  1081. typeComboBox->Resize(80, typeComboBox->getHeight());
  1082. targetComboBox->setPosition(-90 + 85, 0);
  1083. targetComboBox->Resize(floor(size*0.5), targetComboBox->getHeight());
  1084. textureComboBox->setPosition(-90 + 85 + targetComboBox->getWidth() + 5, 0);
  1085. textureComboBox->Resize(floor(size*0.5), textureComboBox->getHeight());
  1086. }
  1087. RenderTargetProp::RenderTargetProp(ShaderRenderTarget *renderTarget, Material *material) : PropProp("", "RenderTargetProp") {
  1088. this->material = material;
  1089. this->renderTarget = renderTarget;
  1090. removeButton = new UIImageButton("main/remove_icon.png", 1.0, 12, 12);
  1091. removeButton->addEventListener(this, UIEvent::CLICK_EVENT);
  1092. propContents->addChild(removeButton);
  1093. removeButton->setPosition(-110, 6);
  1094. nameInput = new UITextInput(false, 20, 12);
  1095. nameInput->addEventListener(this, UIEvent::CHANGE_EVENT);
  1096. propContents->addChild(nameInput);
  1097. nameInput->setText(renderTarget->id);
  1098. nameInput->setCaretPosition(0);
  1099. widthInput = new UITextInput(false, 20, 12);
  1100. widthInput->setNumberOnly(true);
  1101. widthInput->setText(String::NumberToString(renderTarget->width));
  1102. propContents->addChild(widthInput);
  1103. widthInput->setCaretPosition(0);
  1104. widthInput->addEventListener(this, UIEvent::CHANGE_EVENT);
  1105. heightInput = new UITextInput(false, 20, 12);
  1106. heightInput->setNumberOnly(true);
  1107. heightInput->setText(String::NumberToString(renderTarget->height));
  1108. propContents->addChild(heightInput);
  1109. heightInput->setCaretPosition(0);
  1110. heightInput->addEventListener(this, UIEvent::CHANGE_EVENT);
  1111. typeComboBox = new UIComboBox(globalMenu, 100);
  1112. typeComboBox->addComboItem("Pixels");
  1113. typeComboBox->addComboItem("Norm.");
  1114. typeComboBox->setSelectedIndex(renderTarget->sizeMode);
  1115. typeComboBox->addEventListener(this, UIEvent::CHANGE_EVENT);
  1116. propContents->addChild(typeComboBox);
  1117. setHeight(25);
  1118. }
  1119. void RenderTargetProp::setPropWidth(Number width) {
  1120. Number quarter = floor((width-PROP_PADDING- (5*3)) * 0.25);
  1121. nameInput->setPosition(-90, 0);
  1122. nameInput->Resize(floor(quarter * 1.8), nameInput->getHeight());
  1123. widthInput->setPosition(-90 + 5 + (quarter * 1.8), 0);
  1124. widthInput->Resize(floor(quarter*0.6), widthInput->getHeight());
  1125. heightInput->setPosition(-90 + 10 + (quarter * 2.4), 0);
  1126. heightInput->Resize(floor(quarter*0.6), heightInput->getHeight());
  1127. typeComboBox->setPosition(-90 + 15 + (quarter*3), 0);
  1128. typeComboBox->Resize(floor(quarter), typeComboBox->getHeight());
  1129. }
  1130. RenderTargetProp::~RenderTargetProp() {
  1131. }
  1132. void RenderTargetProp::recreateRenderTarget() {
  1133. material->recreateRenderTarget(renderTarget);
  1134. }
  1135. void RenderTargetProp::handleEvent(Event *event) {
  1136. if(event->getEventType() == "UIEvent") {
  1137. if(event->getDispatcher() == nameInput) {
  1138. renderTarget->id = nameInput->getText();
  1139. }
  1140. if(event->getDispatcher() == typeComboBox) {
  1141. renderTarget->sizeMode = typeComboBox->getSelectedIndex();
  1142. recreateRenderTarget();
  1143. }
  1144. if(event->getDispatcher() == typeComboBox) {
  1145. renderTarget->sizeMode = typeComboBox->getSelectedIndex();
  1146. recreateRenderTarget();
  1147. }
  1148. if(event->getDispatcher() == widthInput) {
  1149. renderTarget->width = atof(widthInput->getText().c_str());
  1150. recreateRenderTarget();
  1151. }
  1152. if(event->getDispatcher() == heightInput) {
  1153. renderTarget->height = atof(heightInput->getText().c_str());
  1154. recreateRenderTarget();
  1155. }
  1156. if(event->getDispatcher() == removeButton) {
  1157. dispatchEvent(new Event(), Event::CANCEL_EVENT);
  1158. }
  1159. }
  1160. PropProp::handleEvent(event);
  1161. }
  1162. ShaderPassesSheet::ShaderPassesSheet() : PropSheet("SHADER PASSES", "shaderPasses") {
  1163. propHeight = 70;
  1164. addButton = new UIButton("Add Shader Pass", 150);
  1165. addButton->addEventListener(this, UIEvent::CLICK_EVENT);
  1166. contents->addChild(addButton);
  1167. addButton->setPosition(15, 35);
  1168. customUndoHandler = true;
  1169. material = NULL;
  1170. binding = NULL;
  1171. selectedProp = NULL;
  1172. removeIndex = -1;
  1173. }
  1174. ShaderPassesSheet::~ShaderPassesSheet() {
  1175. }
  1176. void ShaderPassesSheet::setMaterial(Material *material) {
  1177. this->material = material;
  1178. refreshPasses();
  1179. }
  1180. void ShaderPassesSheet::refreshPasses() {
  1181. for(int i=0; i < props.size(); i++) {
  1182. contents->removeChild(props[i]);
  1183. props[i]->removeAllHandlersForListener(this);
  1184. delete props[i];
  1185. }
  1186. props.clear();
  1187. propHeight = 0;
  1188. if(!material) {
  1189. return;
  1190. }
  1191. for(int i=0; i < material->getNumShaders(); i++) {
  1192. ShaderPassProp *passProp = new ShaderPassProp(material, i);
  1193. passProp->addEventListener(this, Event::REMOVE_EVENT);
  1194. passProp->addEventListener(this, Event::CHANGE_EVENT);
  1195. passProp->addEventListener(this, Event::SELECT_EVENT);
  1196. addProp(passProp);
  1197. propHeight += 30;
  1198. }
  1199. addButton->setPosition(15, propHeight);
  1200. propHeight += 70;
  1201. dispatchEvent(new Event(), Event::COMPLETE_EVENT);
  1202. Resize(getWidth(), getHeight());
  1203. }
  1204. void ShaderPassesSheet::Update() {
  1205. if(removeIndex != -1) {
  1206. material->removeShader(removeIndex);
  1207. refreshPasses();
  1208. removeIndex = -1;
  1209. }
  1210. }
  1211. void ShaderPassesSheet::handleEvent(Event *event) {
  1212. if(event->getDispatcher() == addButton) {
  1213. Shader *defaultShader = (Shader*)CoreServices::getInstance()->getResourceManager()->getResource(Resource::RESOURCE_SHADER, "PassThrough");
  1214. if(defaultShader) {
  1215. ShaderBinding *newShaderBinding = defaultShader->createBinding();
  1216. material->addShader(defaultShader, newShaderBinding);
  1217. }
  1218. refreshPasses();
  1219. dispatchEvent(new Event(), Event::CHANGE_EVENT);
  1220. } else {
  1221. for(int i=0; i < props.size(); i++) {
  1222. if(event->getDispatcher() == props[i]) {
  1223. if(event->getEventCode() == Event::CHANGE_EVENT) {
  1224. dispatchEvent(new Event(), Event::CHANGE_EVENT);
  1225. selectedProp = (ShaderPassProp*)props[i];
  1226. dispatchEvent(new Event(), Event::SELECT_EVENT);
  1227. } else if(event->getEventCode() == Event::SELECT_EVENT) {
  1228. selectedProp = (ShaderPassProp*)props[i];
  1229. dispatchEvent(new Event(), Event::SELECT_EVENT);
  1230. } else if(event->getEventCode() == Event::REMOVE_EVENT) {
  1231. removeIndex = i;
  1232. dispatchEvent(new Event(), Event::REMOVE_EVENT);
  1233. }
  1234. }
  1235. }
  1236. }
  1237. PropSheet::handleEvent(event);
  1238. }
  1239. TargetBindingsSheet::TargetBindingsSheet() : PropSheet("TEXTURE BINDINGS", "targetBindings") {
  1240. propHeight = 70;
  1241. addButton = new UIButton("Add Render Target", 150);
  1242. addButton->addEventListener(this, UIEvent::CLICK_EVENT);
  1243. contents->addChild(addButton);
  1244. addButton->setPosition(15, 35);
  1245. customUndoHandler = true;
  1246. material = NULL;
  1247. binding = NULL;
  1248. bindingToRemove = NULL;
  1249. }
  1250. TargetBindingsSheet::~TargetBindingsSheet() {
  1251. }
  1252. void TargetBindingsSheet::setShader(Shader *shader, Material *material, ShaderBinding *binding) {
  1253. this->shader = shader;
  1254. this->material = material;
  1255. this->binding = binding;
  1256. refreshTargets();
  1257. }
  1258. void TargetBindingsSheet::Update() {
  1259. if(bindingToRemove) {
  1260. binding->removeRenderTargetBinding(bindingToRemove);
  1261. bindingToRemove = NULL;
  1262. refreshTargets();
  1263. }
  1264. }
  1265. void TargetBindingsSheet::refreshTargets() {
  1266. for(int i=0; i < props.size(); i++) {
  1267. contents->removeChild(props[i]);
  1268. props[i]->removeAllHandlersForListener(this);
  1269. delete props[i];
  1270. }
  1271. props.clear();
  1272. propHeight = 0;
  1273. if(!material) {
  1274. return;
  1275. }
  1276. for(int i=0; i < binding->getNumRenderTargetBindings(); i++) {
  1277. RenderTargetBinding *targetBinding = binding->getRenderTargetBinding(i);
  1278. TargetBindingProp *bindingProp = new TargetBindingProp(shader, material, binding, targetBinding);
  1279. bindingProp->addEventListener(this, Event::REMOVE_EVENT);
  1280. addProp(bindingProp);
  1281. propHeight += 30;
  1282. }
  1283. addButton->setPosition(15, propHeight);
  1284. propHeight += 70;
  1285. dispatchEvent(new Event(), Event::COMPLETE_EVENT);
  1286. Resize(getWidth(), getHeight());
  1287. }
  1288. void TargetBindingsSheet::handleEvent(Event *event) {
  1289. if(event->getDispatcher() == addButton) {
  1290. RenderTargetBinding* newBinding = new RenderTargetBinding();
  1291. newBinding->mode = RenderTargetBinding::MODE_COLOR;
  1292. newBinding->texture = NULL;
  1293. binding->addRenderTargetBinding(newBinding);
  1294. refreshTargets();
  1295. dispatchEvent(new Event(), Event::CHANGE_EVENT);
  1296. }
  1297. for(int i=0; i < props.size(); i++) {
  1298. if(event->getDispatcher() == props[i]) {
  1299. switch(event->getEventCode()) {
  1300. case Event::REMOVE_EVENT:
  1301. bindingToRemove = ((TargetBindingProp*)props[i])->targetBinding;
  1302. break;
  1303. case Event::CHANGE_EVENT:
  1304. dispatchEvent(new Event(), Event::CHANGE_EVENT);
  1305. break;
  1306. }
  1307. }
  1308. }
  1309. PropSheet::handleEvent(event);
  1310. }
  1311. RenderTargetsSheet::RenderTargetsSheet() : PropSheet("RENDER TARGETS", "renderTargets") {
  1312. propHeight = 70;
  1313. addButton = new UIButton("Add Render Target", 150);
  1314. addButton->addEventListener(this, UIEvent::CLICK_EVENT);
  1315. contents->addChild(addButton);
  1316. addButton->setPosition(15, 35);
  1317. customUndoHandler = true;
  1318. material = NULL;
  1319. binding = NULL;
  1320. removeIndex = -1;
  1321. }
  1322. RenderTargetsSheet::~RenderTargetsSheet() {
  1323. }
  1324. void RenderTargetsSheet::refreshTargets() {
  1325. for(int i=0; i < props.size(); i++) {
  1326. contents->removeChild(props[i]);
  1327. props[i]->removeAllHandlersForListener(this);
  1328. delete props[i];
  1329. }
  1330. props.clear();
  1331. propHeight = 0;
  1332. if(!material) {
  1333. return;
  1334. }
  1335. for(int i=0; i < material->getNumShaderRenderTargets(); i++) {
  1336. ShaderRenderTarget *renderTarget = material->getShaderRenderTarget(i);
  1337. RenderTargetProp *targetProp = new RenderTargetProp(renderTarget, material);
  1338. targetProp->addEventListener(this, Event::CANCEL_EVENT);
  1339. addProp(targetProp);
  1340. propHeight += 30;
  1341. }
  1342. addButton->setPosition(15, propHeight);
  1343. propHeight += 70;
  1344. dispatchEvent(new Event(), Event::COMPLETE_EVENT);
  1345. Resize(getWidth(), getHeight());
  1346. }
  1347. void RenderTargetsSheet::Update() {
  1348. if(material != lastMaterial) {
  1349. lastMaterial = material;
  1350. refreshTargets();
  1351. }
  1352. if(removeIndex != -1) {
  1353. material->removeShaderRenderTarget(removeIndex);
  1354. removeIndex = -1;
  1355. refreshTargets();
  1356. }
  1357. }
  1358. void RenderTargetsSheet::handleEvent(Event *event) {
  1359. if(!material)
  1360. return;
  1361. if(event->getDispatcher() == addButton) {
  1362. ShaderRenderTarget* newRenderTarget = new ShaderRenderTarget();
  1363. newRenderTarget->id = "render_target";
  1364. newRenderTarget->width = 1.0;
  1365. newRenderTarget->height = 1.0;
  1366. newRenderTarget->normalizedWidth = normTextureWidth;
  1367. newRenderTarget->normalizedHeight = normTextureHeight;
  1368. newRenderTarget->sizeMode = ShaderRenderTarget::SIZE_MODE_NORMALIZED;
  1369. material->addShaderRenderTarget(newRenderTarget);
  1370. refreshTargets();
  1371. }
  1372. for(int i=0; i < props.size(); i++) {
  1373. if(event->getDispatcher() == props[i] && event->getEventType() == "") {
  1374. switch(event->getEventCode()) {
  1375. case Event::CANCEL_EVENT:
  1376. removeIndex = i;
  1377. break;
  1378. case Event::CHANGE_EVENT:
  1379. break;
  1380. }
  1381. }
  1382. }
  1383. PropSheet::handleEvent(event);
  1384. }
  1385. EntityPropSheet::EntityPropSheet() : PropSheet("CUSTOM PROPERTIES", "entityProps"){
  1386. propHeight = 75;
  1387. addButton = new UIButton("Add Property", 150);
  1388. addButton->addEventListener(this, UIEvent::CLICK_EVENT);
  1389. contents->addChild(addButton);
  1390. addButton->setPosition(15, 35);
  1391. customUndoHandler = true;
  1392. entity = NULL;
  1393. lastEntity = NULL;
  1394. lastNumProps = 0;
  1395. removeIndex = -1;
  1396. }
  1397. void EntityPropSheet::applyPropActionData(PolycodeEditorPropActionData *data) {
  1398. if(!entity)
  1399. return;
  1400. entity->entityProps.clear();
  1401. for(int i=0; i < data->entity->entityProps.size(); i++) {
  1402. entity->entityProps.push_back(data->entity->entityProps[i]);
  1403. }
  1404. refreshProps();
  1405. }
  1406. void EntityPropSheet::handleEvent(Event *event) {
  1407. if(!entity)
  1408. return;
  1409. if(event->getDispatcher() == addButton && event->getEventType() == "UIEvent") {
  1410. PolycodeEditorPropActionData *beforeData = PropDataEntity(entity);
  1411. entity->entityProps.push_back(EntityProp());
  1412. refreshProps();
  1413. PolycodeEditorPropActionData *afterData = PropDataEntity(entity);
  1414. PropEvent *propEvent = new PropEvent(NULL, this, beforeData, afterData);
  1415. dispatchEvent(propEvent, PropEvent::EVENT_PROP_CHANGE);
  1416. }
  1417. for(int i=0; i < props.size(); i++) {
  1418. if(event->getDispatcher() == props[i] && event->getEventType() == "") {
  1419. switch(event->getEventCode()) {
  1420. case Event::CANCEL_EVENT:
  1421. removeIndex = i;
  1422. break;
  1423. case Event::CHANGE_EVENT:
  1424. PolycodeEditorPropActionData *beforeData = PropDataEntity(entity);
  1425. if(i < entity->entityProps.size()) {
  1426. entity->entityProps[i].propName = ((CustomProp*)props[i])->getKey();
  1427. entity->entityProps[i].propValue = ((CustomProp*)props[i])->getValue();
  1428. }
  1429. PolycodeEditorPropActionData *afterData = PropDataEntity(entity);
  1430. PropEvent *propEvent = new PropEvent(NULL, this, beforeData, afterData);
  1431. dispatchEvent(propEvent, PropEvent::EVENT_PROP_CHANGE);
  1432. break;
  1433. }
  1434. }
  1435. }
  1436. PropSheet::handleEvent(event);
  1437. }
  1438. void EntityPropSheet::refreshProps() {
  1439. for(int i=0; i < props.size(); i++) {
  1440. contents->removeChild(props[i]);
  1441. props[i]->removeAllHandlersForListener(this);
  1442. delete props[i];
  1443. }
  1444. props.clear();
  1445. propHeight = 0;
  1446. for(int i=0; i < entity->entityProps.size(); i++) {
  1447. EntityProp prop = entity->entityProps[i];
  1448. CustomProp *newProp = new CustomProp(prop.propName, prop.propValue);
  1449. newProp->addEventListener(this, Event::CANCEL_EVENT);
  1450. newProp->addEventListener(this, Event::CHANGE_EVENT);
  1451. addProp(newProp);
  1452. propHeight += 30;
  1453. }
  1454. addButton->setPosition(15, propHeight);
  1455. propHeight += 70;
  1456. if(lastNumProps != entity->entityProps.size()) {
  1457. dispatchEvent(new Event(), Event::COMPLETE_EVENT);
  1458. }
  1459. lastNumProps = entity->entityProps.size();
  1460. Resize(getWidth(), getHeight());
  1461. }
  1462. void EntityPropSheet::Update() {
  1463. if(entity) {
  1464. if(removeIndex != -1) {
  1465. PolycodeEditorPropActionData *beforeData = PropDataEntity(entity);
  1466. if(removeIndex < entity->entityProps.size()) {
  1467. entity->entityProps.erase(entity->entityProps.begin() + removeIndex);
  1468. }
  1469. removeIndex = -1;
  1470. refreshProps();
  1471. PolycodeEditorPropActionData *afterData = PropDataEntity(entity);
  1472. PropEvent *propEvent = new PropEvent(NULL, this, beforeData, afterData);
  1473. dispatchEvent(propEvent, PropEvent::EVENT_PROP_CHANGE);
  1474. }
  1475. enabled = true;
  1476. if(entity != lastEntity) {
  1477. refreshProps();
  1478. lastEntity = entity;
  1479. }
  1480. } else {
  1481. enabled = false;
  1482. }
  1483. }
  1484. ShaderOptionsSheet::ShaderOptionsSheet() : PropSheet("SHADER OPTIONS", "shader_options"){
  1485. shader = NULL;
  1486. propHeight = 40;
  1487. }
  1488. ShaderOptionsSheet::~ShaderOptionsSheet() {
  1489. }
  1490. void ShaderOptionsSheet::handleEvent(Event *event) {
  1491. if(event->getEventCode() == Event::CHANGE_EVENT) {
  1492. for(int i=0 ; i < props.size(); i++) {
  1493. if(event->getDispatcher() == props[i]) {
  1494. if(props[i]->propType == "Number") {
  1495. (*(Number*)binding->getLocalParamByName(props[i]->label->getText())->data) = ((NumberProp*)props[i])->get();
  1496. } else if(props[i]->propType == "Color") {
  1497. (*(Color*)binding->getLocalParamByName(props[i]->label->getText())->data) = ((ColorProp*)props[i])->get();
  1498. } else if(props[i]->propType == "Vector2") {
  1499. (*(Vector2*)binding->getLocalParamByName(props[i]->label->getText())->data) = ((Vector2Prop*)props[i])->get();
  1500. }
  1501. dispatchEvent(new Event(), Event::CHANGE_EVENT);
  1502. return;
  1503. }
  1504. }
  1505. }
  1506. PropSheet::handleEvent(event);
  1507. }
  1508. void ShaderOptionsSheet::Update() {
  1509. }
  1510. void ShaderOptionsSheet::clearShader() {
  1511. for(int i=0; i < props.size(); i++) {
  1512. contents->removeChild(props[i]);
  1513. props[i]->removeAllHandlersForListener(this);
  1514. delete props[i];
  1515. }
  1516. props.clear();
  1517. propHeight = 30;
  1518. }
  1519. void ShaderOptionsSheet::setOptionsFromParams(std::vector<ProgramParam> &params) {
  1520. for(int i=0; i < params.size(); i++) {
  1521. if(!CoreServices::getInstance()->getRenderer()->getDataPointerForName(params[i].name)) {
  1522. switch (params[i].type) {
  1523. case ProgramParam::PARAM_NUMBER:
  1524. {
  1525. String paramName = params[i].name;
  1526. NumberProp *numberProp = new NumberProp(paramName);
  1527. addProp(numberProp);
  1528. Number numberValue = (*(Number*)binding->getLocalParamByName(params[i].name)->data);
  1529. numberProp->set(numberValue);
  1530. propHeight += 30;
  1531. }
  1532. break;
  1533. case ProgramParam::PARAM_COLOR:
  1534. {
  1535. String paramName = params[i].name;
  1536. ColorProp *colorProp = new ColorProp(paramName);
  1537. addProp(colorProp);
  1538. Color colorValue = (*(Color*)binding->getLocalParamByName(params[i].name)->data);
  1539. colorProp->set(colorValue);
  1540. propHeight += 40;
  1541. }
  1542. break;
  1543. case ProgramParam::PARAM_VECTOR2:
  1544. {
  1545. String paramName = params[i].name;
  1546. Vector2Prop *vec2Prop = new Vector2Prop(paramName);;
  1547. addProp(vec2Prop);
  1548. Vector2 vec2val = (*(Vector2*)binding->getLocalParamByName(params[i].name)->data);
  1549. vec2Prop->set(vec2val);
  1550. propHeight += 30;
  1551. }
  1552. break;
  1553. }
  1554. }
  1555. }
  1556. }
  1557. void ShaderOptionsSheet::setShader(Shader *shader, Material *material, ShaderBinding *binding) {
  1558. clearShader();
  1559. this->shader = shader;
  1560. this->material = material;
  1561. if(!shader || !material)
  1562. return;
  1563. this->binding = binding;
  1564. setOptionsFromParams(shader->expectedParams);
  1565. dispatchEvent(new Event(), Event::COMPLETE_EVENT);
  1566. Resize(getWidth(), getHeight());
  1567. }
  1568. ShaderTexturesSheet::ShaderTexturesSheet() : PropSheet("SHADER TEXTURES", "shader_textures"){
  1569. shader = NULL;
  1570. propHeight = 40;
  1571. }
  1572. ShaderTexturesSheet::~ShaderTexturesSheet() {
  1573. }
  1574. void ShaderTexturesSheet::handleEvent(Event *event) {
  1575. if(event->getEventCode() == Event::CHANGE_EVENT) {
  1576. for(int i=0; i < textureProps.size(); i++) {
  1577. if(event->getDispatcher() == textureProps[i]) {
  1578. binding->clearTexture(textureProps[i]->label->getText());
  1579. binding->addTexture(textureProps[i]->label->getText(), textureProps[i]->get());
  1580. dispatchEvent(new Event(), Event::CHANGE_EVENT);
  1581. }
  1582. }
  1583. for(int i=0; i < cubemapProps.size(); i++) {
  1584. if(event->getDispatcher() == cubemapProps[i]) {
  1585. binding->clearCubemap(cubemapProps[i]->label->getText());
  1586. Cubemap *cubemap = (Cubemap*)cubemapProps[i]->comboEntry->getSelectedItem()->data;
  1587. binding->addCubemap(cubemapProps[i]->label->getText(), cubemap);
  1588. dispatchEvent(new Event(), Event::CHANGE_EVENT);
  1589. }
  1590. }
  1591. }
  1592. PropSheet::handleEvent(event);
  1593. }
  1594. void ShaderTexturesSheet::Update() {
  1595. }
  1596. void ShaderTexturesSheet::clearShader() {
  1597. for(int i=0; i < props.size(); i++) {
  1598. contents->removeChild(props[i]);
  1599. props[i]->removeAllHandlersForListener(this);
  1600. delete props[i];
  1601. }
  1602. props.clear();
  1603. cubemapProps.clear();
  1604. textureProps.clear();
  1605. propHeight = 30;
  1606. }
  1607. void ShaderTexturesSheet::setShader(Shader *shader, Material *material, ShaderBinding *binding) {
  1608. clearShader();
  1609. this->shader = shader;
  1610. this->material = material;
  1611. if(!shader || !material)
  1612. return;
  1613. this->binding = binding;
  1614. for(int i=0; i < shader->expectedCubemaps.size(); i++) {
  1615. ComboProp *comboProp = new ComboProp(shader->expectedCubemaps[i]);
  1616. std::vector<Resource*> cubemaps = CoreServices::getInstance()->getResourceManager()->getResources(Resource::RESOURCE_CUBEMAP);
  1617. for(int j=0; j < cubemaps.size(); j++) {
  1618. comboProp->comboEntry->addComboItem(cubemaps[j]->getResourceName(), (void*) cubemaps[j]);
  1619. if(material) {
  1620. if(material->getShaderBinding(0)) {
  1621. Cubemap *currentCubemap = material->getShaderBinding(0)->getCubemap(shader->expectedCubemaps[i]);
  1622. if(currentCubemap) {
  1623. if(currentCubemap->getResourceName() == cubemaps[j]->getResourceName()) {
  1624. comboProp->set(j);
  1625. }
  1626. }
  1627. }
  1628. }
  1629. }
  1630. addProp(comboProp);
  1631. cubemapProps.push_back(comboProp);
  1632. propHeight += 45;
  1633. }
  1634. for(int i=0; i < shader->expectedTextures.size(); i++) {
  1635. TextureProp *textureProp = new TextureProp(shader->expectedTextures[i]);
  1636. if(material) {
  1637. if(material->getShaderBinding(0)) {
  1638. Texture *currentTexture = material->getShaderBinding(0)->getTexture(shader->expectedTextures[i]);
  1639. if(currentTexture) {
  1640. textureProp->set(currentTexture);
  1641. }
  1642. }
  1643. }
  1644. addProp(textureProp);
  1645. textureProps.push_back(textureProp);
  1646. propHeight += 65;
  1647. }
  1648. dispatchEvent(new Event(), Event::COMPLETE_EVENT);
  1649. Resize(getWidth(), getHeight());
  1650. }
  1651. TransformSheet::TransformSheet() : PropSheet("TRANSFORM", "entity_transform") {
  1652. entity = NULL;
  1653. positionProp = new Vector3Prop("Position");
  1654. addProp(positionProp);
  1655. scaleProp = new Vector3Prop("Scale");
  1656. addProp(scaleProp);
  1657. rotationProp = new Vector3Prop("Rotation");
  1658. addProp(rotationProp);
  1659. propHeight = 275;
  1660. enabled = false;
  1661. }
  1662. TransformSheet::~TransformSheet() {
  1663. }
  1664. void TransformSheet::setEntity(Entity *entity) {
  1665. this->entity = entity;
  1666. if(entity) {
  1667. enabled = true;
  1668. } else {
  1669. enabled = false;
  1670. }
  1671. }
  1672. void TransformSheet::Update() {
  1673. if(!entity) {
  1674. return;
  1675. }
  1676. if(entity->getPosition() != lastPosition) {
  1677. positionProp->set(entity->getPosition());
  1678. lastPosition = entity->getPosition();
  1679. }
  1680. if(entity->getScale() != lastScale) {
  1681. scaleProp->set(entity->getScale());
  1682. lastScale = entity->getScale();
  1683. }
  1684. if(entity->getEulerRotation() != lastRotation) {
  1685. rotationProp->set(entity->getEulerRotation() * TODEGREES);
  1686. lastRotation = entity->getEulerRotation() * TODEGREES;
  1687. }
  1688. }
  1689. void TransformSheet::handleEvent(Event *event) {
  1690. if(event->getEventCode() == Event::CHANGE_EVENT) {
  1691. if(event->getDispatcher() == positionProp) {
  1692. lastPosition = positionProp->get();
  1693. entity->setPosition(lastPosition);
  1694. } else if(event->getDispatcher() == scaleProp) {
  1695. lastScale = scaleProp->get();
  1696. entity->setScale(lastScale);
  1697. } else if(event->getDispatcher() == rotationProp) {
  1698. lastRotation = rotationProp->get();
  1699. entity->setRotationEuler(lastRotation);
  1700. }
  1701. }
  1702. PropSheet::handleEvent(event);
  1703. }
  1704. SceneLightSheet::SceneLightSheet() : PropSheet("LIGHT", "scene_light") {
  1705. typeProp = new ComboProp("Type");
  1706. typeProp->comboEntry->addComboItem("Area");
  1707. typeProp->comboEntry->addComboItem("Spot");
  1708. addProp(typeProp);
  1709. lightColorProp = new ColorProp("Light color");
  1710. addProp(lightColorProp);
  1711. specularColorProp = new ColorProp("Specular color");
  1712. addProp(specularColorProp);
  1713. intensityProp = new NumberProp("Intensity");
  1714. addProp(intensityProp);
  1715. constantAttenuationProp = new SliderProp("Constant att.", 0.0, 1.0);
  1716. addProp(constantAttenuationProp);
  1717. linearAttenuationProp = new SliderProp("Linear att.", 0.0, 1.0);
  1718. addProp(linearAttenuationProp);
  1719. quadraticAttenuationProp = new SliderProp("Quadratic att.", 0.0, 1.0);
  1720. addProp(quadraticAttenuationProp);
  1721. spotlightCutoffProp = new NumberProp("Spot cutoff");
  1722. addProp(spotlightCutoffProp);
  1723. spotlightExponentProp = new SliderProp("Spot exponent", 0.0, 50.0);
  1724. addProp(spotlightExponentProp);
  1725. castShadowsProp = new BoolProp("Cast shadows");
  1726. addProp(castShadowsProp);
  1727. shadowMapFOVProp = new SliderProp("Shadow FOV", 1.0, 180.0);
  1728. addProp(shadowMapFOVProp);
  1729. shadowResolutionProp = new NumberProp("Shadowmap res.");
  1730. addProp(shadowResolutionProp);
  1731. propHeight = 365;
  1732. light = NULL;
  1733. enabled = false;
  1734. }
  1735. SceneLightSheet::~SceneLightSheet() {
  1736. }
  1737. void SceneLightSheet::setSceneLight(SceneLight *light) {
  1738. this->light = light;
  1739. if(light) {
  1740. light->enableDebugDraw(true);
  1741. typeProp->set(light->getLightType());
  1742. lightColorProp->set(light->lightColor);
  1743. specularColorProp->set(light->specularLightColor);
  1744. intensityProp->set(light->getIntensity());
  1745. constantAttenuationProp->set(light->getConstantAttenuation());
  1746. linearAttenuationProp->set(light->getLinearAttenuation());
  1747. quadraticAttenuationProp->set(light->getQuadraticAttenuation());
  1748. spotlightCutoffProp->set(light->getSpotlightCutoff());
  1749. spotlightExponentProp->set(light->getSpotlightExponent());
  1750. castShadowsProp->set(light->areShadowsEnabled());
  1751. shadowMapFOVProp->set(light->getShadowMapFOV());
  1752. shadowResolutionProp->set(light->getShadowMapResolution());
  1753. enabled = true;
  1754. } else {
  1755. enabled = false;
  1756. }
  1757. }
  1758. void SceneLightSheet::handleEvent(Event *event) {
  1759. if(!light) {
  1760. return;
  1761. }
  1762. if(event->getEventCode() == Event::CHANGE_EVENT) {
  1763. if(event->getDispatcher() == typeProp) {
  1764. light->setLightType(typeProp->get());
  1765. } else if(event->getDispatcher() == lightColorProp) {
  1766. light->lightColor = lightColorProp->get();
  1767. } else if(event->getDispatcher() == specularColorProp) {
  1768. light->specularLightColor = specularColorProp->get();
  1769. } else if(event->getDispatcher() == intensityProp) {
  1770. light->setIntensity(intensityProp->get());
  1771. } else if(event->getDispatcher() == constantAttenuationProp) {
  1772. light->setAttenuation(constantAttenuationProp->get(), light->getLinearAttenuation(), light->getQuadraticAttenuation());
  1773. } else if(event->getDispatcher() == linearAttenuationProp) {
  1774. light->setAttenuation(light->getConstantAttenuation(), linearAttenuationProp->get(), light->getQuadraticAttenuation());
  1775. } else if(event->getDispatcher() == quadraticAttenuationProp) {
  1776. light->setAttenuation(light->getConstantAttenuation(), light->getLinearAttenuation(), quadraticAttenuationProp->get());
  1777. } else if(event->getDispatcher() == castShadowsProp) {
  1778. light->enableShadows(castShadowsProp->get(), shadowResolutionProp->get());
  1779. } else if(event->getDispatcher() == shadowMapFOVProp) {
  1780. light->setShadowMapFOV(shadowMapFOVProp->get());
  1781. } else if(event->getDispatcher() == shadowResolutionProp) {
  1782. light->enableShadows(castShadowsProp->get(), shadowResolutionProp->get());
  1783. } else if(event->getDispatcher() == spotlightCutoffProp) {
  1784. light->setSpotlightProperties(spotlightCutoffProp->get(), light->getSpotlightExponent());
  1785. } else if(event->getDispatcher() == spotlightExponentProp) {
  1786. light->setSpotlightProperties(light->getSpotlightCutoff(), spotlightExponentProp->get());
  1787. }
  1788. }
  1789. PropSheet::handleEvent(event);
  1790. }
  1791. ScenePrimitiveSheet::ScenePrimitiveSheet() : PropSheet("PRIMITIVE", "scene_primitive") {
  1792. typeProp = new ComboProp("Type");
  1793. typeProp->comboEntry->addComboItem("Box");
  1794. typeProp->comboEntry->addComboItem("Plane");
  1795. typeProp->comboEntry->addComboItem("Vert. Plane");
  1796. typeProp->comboEntry->addComboItem("Cylinder");
  1797. typeProp->comboEntry->addComboItem("Uncapped Cylinder");
  1798. typeProp->comboEntry->addComboItem("Sphere");
  1799. typeProp->comboEntry->addComboItem("Torus");
  1800. typeProp->comboEntry->addComboItem("Cone");
  1801. typeProp->comboEntry->addComboItem("Circle");
  1802. addProp(typeProp);
  1803. option1Prop = new NumberProp("");
  1804. addProp(option1Prop);
  1805. option2Prop = new NumberProp("");
  1806. addProp(option2Prop);
  1807. option3Prop = new NumberProp("");
  1808. addProp(option3Prop);
  1809. option4Prop = new NumberProp("");
  1810. addProp(option4Prop);
  1811. option5Prop = new NumberProp("");
  1812. addProp(option5Prop);
  1813. propHeight = 240;
  1814. enabled = false;
  1815. primitive = NULL;
  1816. }
  1817. void ScenePrimitiveSheet::updatePrimitiveLabels() {
  1818. if(!primitive) {
  1819. return;
  1820. }
  1821. option1Prop->enabled = false;
  1822. option1Prop->visible = false;
  1823. option2Prop->enabled = false;
  1824. option2Prop->visible = false;
  1825. option3Prop->enabled = false;
  1826. option3Prop->visible = false;
  1827. option4Prop->enabled = false;
  1828. option4Prop->visible = false;
  1829. option5Prop->enabled = false;
  1830. option5Prop->visible = false;
  1831. switch(primitive->getPrimitiveType()) {
  1832. case ScenePrimitive::TYPE_BOX:
  1833. option1Prop->setPropName("Width");
  1834. option2Prop->setPropName("Height");
  1835. option3Prop->setPropName("Depth");
  1836. option1Prop->enabled = true;
  1837. option1Prop->visible = true;
  1838. option2Prop->enabled = true;
  1839. option2Prop->visible = true;
  1840. option3Prop->enabled = true;
  1841. option3Prop->visible = true;
  1842. propHeight = 45 + (45 * 3);
  1843. break;
  1844. case ScenePrimitive::TYPE_PLANE:
  1845. option1Prop->setPropName("Width");
  1846. option2Prop->setPropName("Height");
  1847. option1Prop->enabled = true;
  1848. option1Prop->visible = true;
  1849. option2Prop->enabled = true;
  1850. option2Prop->visible = true;
  1851. propHeight = 45 + (45 * 2);
  1852. break;
  1853. case ScenePrimitive::TYPE_VPLANE:
  1854. option1Prop->setPropName("Width");
  1855. option2Prop->setPropName("Height");
  1856. option1Prop->enabled = true;
  1857. option1Prop->visible = true;
  1858. option2Prop->enabled = true;
  1859. option2Prop->visible = true;
  1860. propHeight = 45 + (45 * 2);
  1861. break;
  1862. case ScenePrimitive::TYPE_CYLINDER:
  1863. option1Prop->setPropName("Length");
  1864. option2Prop->setPropName("Radius");
  1865. option3Prop->setPropName("Segments");
  1866. option1Prop->enabled = true;
  1867. option1Prop->visible = true;
  1868. option2Prop->enabled = true;
  1869. option2Prop->visible = true;
  1870. option3Prop->enabled = true;
  1871. option3Prop->visible = true;
  1872. propHeight = 45 + (45 * 3);
  1873. break;
  1874. case ScenePrimitive::TYPE_UNCAPPED_CYLINDER:
  1875. option1Prop->setPropName("Length");
  1876. option2Prop->setPropName("Radius");
  1877. option3Prop->setPropName("Segments");
  1878. option1Prop->enabled = true;
  1879. option1Prop->visible = true;
  1880. option2Prop->enabled = true;
  1881. option2Prop->visible = true;
  1882. option3Prop->enabled = true;
  1883. option3Prop->visible = true;
  1884. propHeight = 45 + (45 * 3);
  1885. break;
  1886. case ScenePrimitive::TYPE_SPHERE:
  1887. option1Prop->setPropName("Radius");
  1888. option2Prop->setPropName("Lat. segments");
  1889. option3Prop->setPropName("Long. segments");
  1890. option1Prop->enabled = true;
  1891. option1Prop->visible = true;
  1892. option2Prop->enabled = true;
  1893. option2Prop->visible = true;
  1894. option3Prop->enabled = true;
  1895. option3Prop->visible = true;
  1896. propHeight = 45 + (45 * 3);
  1897. break;
  1898. case ScenePrimitive::TYPE_TORUS:
  1899. option1Prop->setPropName("Torus radius");
  1900. option2Prop->setPropName("Pipe radius");
  1901. option3Prop->setPropName("Ring segments");
  1902. option4Prop->setPropName("Pipe segments");
  1903. option1Prop->enabled = true;
  1904. option1Prop->visible = true;
  1905. option2Prop->enabled = true;
  1906. option2Prop->visible = true;
  1907. option3Prop->enabled = true;
  1908. option3Prop->visible = true;
  1909. option4Prop->enabled = true;
  1910. option4Prop->visible = true;
  1911. propHeight = 45 + (45 * 4);
  1912. break;
  1913. case ScenePrimitive::TYPE_CONE:
  1914. option1Prop->setPropName("Length");
  1915. option2Prop->setPropName("Radius");
  1916. option3Prop->setPropName("Segments");
  1917. option1Prop->enabled = true;
  1918. option1Prop->visible = true;
  1919. option2Prop->enabled = true;
  1920. option2Prop->visible = true;
  1921. option3Prop->enabled = true;
  1922. option3Prop->visible = true;
  1923. propHeight = 45 + (45 * 3);
  1924. break;
  1925. case ScenePrimitive::TYPE_CIRCLE:
  1926. option1Prop->setPropName("Width");
  1927. option2Prop->setPropName("Height");
  1928. option3Prop->setPropName("Segments");
  1929. option1Prop->enabled = true;
  1930. option1Prop->visible = true;
  1931. option2Prop->enabled = true;
  1932. option2Prop->visible = true;
  1933. option3Prop->enabled = true;
  1934. option3Prop->visible = true;
  1935. propHeight = 45 + (45 * 3);
  1936. break;
  1937. }
  1938. dispatchEvent(new Event(), Event::COMPLETE_EVENT);
  1939. }
  1940. ScenePrimitiveSheet::~ScenePrimitiveSheet() {
  1941. }
  1942. void ScenePrimitiveSheet::setScenePrimitive(ScenePrimitive *primitive) {
  1943. this->primitive = primitive;
  1944. if(primitive) {
  1945. typeProp->set(primitive->getPrimitiveType());
  1946. option1Prop->set(primitive->getPrimitiveParameter1());
  1947. option2Prop->set(primitive->getPrimitiveParameter2());
  1948. option3Prop->set(primitive->getPrimitiveParameter3());
  1949. option4Prop->set(primitive->getPrimitiveParameter4());
  1950. option5Prop->set(primitive->getPrimitiveParameter5());
  1951. updatePrimitiveLabels();
  1952. enabled = true;
  1953. } else {
  1954. enabled = false;
  1955. }
  1956. }
  1957. void ScenePrimitiveSheet::handleEvent(Event *event) {
  1958. if(!primitive) {
  1959. return;
  1960. }
  1961. if(event->getEventCode() == Event::CHANGE_EVENT) {
  1962. primitive->setPrimitiveOptions(typeProp->get(), option1Prop->get(), option2Prop->get(), option3Prop->get(), option4Prop->get(), option5Prop->get());
  1963. if(event->getDispatcher() == typeProp) {
  1964. updatePrimitiveLabels();
  1965. }
  1966. }
  1967. PropSheet::handleEvent(event);
  1968. }
  1969. MaterialPropSheet::MaterialPropSheet() : PropSheet("MATERIAL", "material") {
  1970. materialProp = new ComboProp("Material");
  1971. addProp(materialProp);
  1972. propHeight = 70;
  1973. enabled = false;
  1974. }
  1975. MaterialPropSheet::~MaterialPropSheet() {
  1976. }
  1977. void MaterialPropSheet::setSceneMesh(SceneMesh *sceneMesh) {
  1978. this->sceneMesh = sceneMesh;
  1979. if(sceneMesh) {
  1980. enabled = true;
  1981. reloadMaterials();
  1982. } else {
  1983. enabled = false;
  1984. }
  1985. }
  1986. void MaterialPropSheet::reloadMaterials() {
  1987. Resource *selectedMaterial = NULL;
  1988. selectedMaterial = NULL;
  1989. if(sceneMesh) {
  1990. selectedMaterial = (Resource*)sceneMesh->getMaterial();
  1991. }
  1992. materialProp->comboEntry->clearItems();
  1993. std::vector<Resource*> materials = CoreServices::getInstance()->getResourceManager()->getResources(Resource::RESOURCE_MATERIAL);
  1994. for(int i=0; i < materials.size(); i++) {
  1995. if(((Material*)materials[i])->screenMaterial) {
  1996. continue;
  1997. }
  1998. materialProp->comboEntry->addComboItem(materials[i]->getResourceName(), (void*) materials[i]);
  1999. if(selectedMaterial == materials[i]) {
  2000. materialProp->comboEntry->setSelectedIndex(i);
  2001. }
  2002. }
  2003. }
  2004. void MaterialPropSheet::handleEvent(Event *event) {
  2005. if(!sceneMesh) {
  2006. PropSheet::handleEvent(event);
  2007. return;
  2008. }
  2009. if(event->getDispatcher() == materialProp && event->getEventCode() == Event::CHANGE_EVENT) {
  2010. Material *newMaterial = (Material*)materialProp->comboEntry->getSelectedItem()->data;
  2011. sceneMesh->setMaterial(newMaterial);
  2012. }
  2013. PropSheet::handleEvent(event);
  2014. }
  2015. EntitySheet::EntitySheet() : PropSheet("ENTITY", "entity"){
  2016. idProp = new StringProp("ID");
  2017. addProp(idProp);
  2018. tagProp = new StringProp("Tags (foo,bar)");
  2019. addProp(tagProp);
  2020. colorProp = new ColorProp("Color");
  2021. addProp(colorProp);
  2022. blendingProp = new ComboProp("Blend mode");
  2023. addProp(blendingProp);
  2024. blendingProp->comboEntry->addComboItem("None");
  2025. blendingProp->comboEntry->addComboItem("Normal");
  2026. blendingProp->comboEntry->addComboItem("Lighten");
  2027. blendingProp->comboEntry->addComboItem("Color");
  2028. blendingProp->comboEntry->addComboItem("Premultiplied");
  2029. blendingProp->comboEntry->addComboItem("Multiply");
  2030. propHeight = 160;
  2031. entity = NULL;
  2032. enabled = false;
  2033. }
  2034. EntitySheet::~EntitySheet() {
  2035. }
  2036. void EntitySheet::handleEvent(Event *event) {
  2037. if(!entity)
  2038. return;
  2039. if(event->getDispatcher() == blendingProp && event->getEventCode() == Event::CHANGE_EVENT) {
  2040. entity->blendingMode = blendingProp->get();
  2041. } else if(event->getDispatcher() == colorProp && event->getEventCode() == Event::CHANGE_EVENT) {
  2042. entity->color = colorProp->get();
  2043. }else if(event->getDispatcher() == idProp && event->getEventCode() == Event::CHANGE_EVENT) {
  2044. entity->id = idProp->get();
  2045. } else if(event->getDispatcher() == tagProp && event->getEventCode() == Event::CHANGE_EVENT) {
  2046. String tagString = "";
  2047. for(int i=0; i < entity->getNumTags(); i++) {
  2048. if(i != 0) {
  2049. tagString += ",";
  2050. }
  2051. tagString += entity->getTagAtIndex(i);
  2052. }
  2053. entity->clearTags();
  2054. String cleaned = tagProp->get().replace(" ", "");
  2055. std::vector<String> tags = cleaned.split(",");
  2056. for(int i=0; i < tags.size(); i++) {
  2057. entity->addTag(tags[i]);
  2058. }
  2059. }
  2060. PropSheet::handleEvent(event);
  2061. }
  2062. void EntitySheet::setEntity(Entity *entity) {
  2063. this->entity = entity;
  2064. if(entity) {
  2065. idProp->set(entity->id);
  2066. String tagString = "";
  2067. for(int i=0; i < entity->getNumTags(); i++) {
  2068. if(i != 0) {
  2069. tagString += ",";
  2070. }
  2071. tagString += entity->getTagAtIndex(i);
  2072. }
  2073. tagProp->set(tagString);
  2074. colorProp->set(entity->color);
  2075. blendingProp->set(entity->blendingMode);
  2076. enabled = true;
  2077. } else {
  2078. enabled = false;
  2079. }
  2080. }
  2081. SceneSpriteSheet::SceneSpriteSheet() : PropSheet("SCREEN SPRITE", "SceneSprite") {
  2082. sprite = NULL;
  2083. lastSprite = NULL;
  2084. spriteProp = new SceneSpriteProp("Sprite");
  2085. spriteProp->addEventListener(this, Event::CHANGE_EVENT);
  2086. addProp(spriteProp);
  2087. defaultAnimationProp = new ComboProp("Animation");
  2088. defaultAnimationProp->addEventListener(this, Event::CHANGE_EVENT);
  2089. addProp(defaultAnimationProp);
  2090. propHeight = 140;
  2091. }
  2092. SceneSpriteSheet::~SceneSpriteSheet() {
  2093. }
  2094. void SceneSpriteSheet::handleEvent(Event *event) {
  2095. if(!sprite)
  2096. return;
  2097. if(event->getDispatcher() == sprite->getResourceEntry()) {
  2098. spriteProp->previewSprite->reloadSprite();
  2099. sprite->getResourceEntry()->removeAllHandlersForListener(this);
  2100. lastSprite = NULL;
  2101. }
  2102. if(event->getDispatcher() == defaultAnimationProp) {
  2103. sprite->playAnimation(defaultAnimationProp->comboEntry->getSelectedItem()->label, 0, false);
  2104. spriteProp->previewSprite->playAnimation(defaultAnimationProp->comboEntry->getSelectedItem()->label, 0, false);
  2105. }
  2106. if(event->getDispatcher() == spriteProp) {
  2107. sprite->loadFromFile(spriteProp->get());
  2108. defaultAnimationProp->comboEntry->clearItems();
  2109. for(int i=0; i < sprite->getNumAnimations(); i++) {
  2110. defaultAnimationProp->comboEntry->addComboItem(sprite->getAnimationAtIndex(i)->name);
  2111. }
  2112. }
  2113. PropSheet::handleEvent(event);
  2114. }
  2115. void SceneSpriteSheet::Update() {
  2116. if(sprite) {
  2117. if(lastSprite != sprite) {
  2118. defaultAnimationProp->comboEntry->clearItems();
  2119. for(int i=0; i < sprite->getNumAnimations(); i++) {
  2120. defaultAnimationProp->comboEntry->addComboItem(sprite->getAnimationAtIndex(i)->name);
  2121. if(sprite->getCurrentAnimation()) {
  2122. if(sprite->getCurrentAnimation()->name == sprite->getAnimationAtIndex(i)->name) {
  2123. defaultAnimationProp->comboEntry->setSelectedIndex(i);
  2124. spriteProp->previewSprite->playAnimation(sprite->getCurrentAnimation()->name, 0, false);
  2125. }
  2126. }
  2127. }
  2128. lastSprite = sprite;
  2129. }
  2130. enabled = true;
  2131. spriteProp->set(sprite->getFileName());
  2132. sprite->getResourceEntry()->addEventListener(this, Event::RESOURCE_RELOAD_EVENT);
  2133. } else {
  2134. enabled = false;
  2135. }
  2136. }
  2137. SceneEntityInstanceSheet::SceneEntityInstanceSheet() : PropSheet("ENTITY INSTANCE", "SceneEntityInstance") {
  2138. instance = NULL;
  2139. instanceProp = new SceneEntityInstanceProp("Entity file");
  2140. instanceProp->addEventListener(this, Event::CHANGE_EVENT);
  2141. addProp(instanceProp);
  2142. propHeight = 100;
  2143. }
  2144. SceneEntityInstanceSheet::~SceneEntityInstanceSheet() {
  2145. }
  2146. void SceneEntityInstanceSheet::handleEvent(Event *event) {
  2147. if(!instance)
  2148. return;
  2149. if(event->getDispatcher() == instanceProp) {
  2150. instance->loadFromFile(instanceProp->get());
  2151. instance->getResourceEntry()->setResourcePath(instanceProp->get());
  2152. instance->getResourceEntry()->setResourceName(instanceProp->get());
  2153. dispatchEvent(new Event(), Event::CHANGE_EVENT);
  2154. }
  2155. PropSheet::handleEvent(event);
  2156. }
  2157. void SceneEntityInstanceSheet::Update() {
  2158. if(instance) {
  2159. enabled = true;
  2160. instanceProp->set(instance->getFileName());
  2161. } else {
  2162. enabled = false;
  2163. }
  2164. }
  2165. UILabelSheet::UILabelSheet() : PropSheet("SCREEN LABEL", "UILabel") {
  2166. label = NULL;
  2167. caption = new StringProp("Contents");
  2168. caption->addEventListener(this, Event::CHANGE_EVENT);
  2169. addProp(caption);
  2170. size = new NumberProp("Size (px)");
  2171. size->addEventListener(this, Event::CHANGE_EVENT);
  2172. addProp(size);
  2173. font = new ComboProp("Font");
  2174. font->addEventListener(this, Event::CHANGE_EVENT);
  2175. addProp(font);
  2176. enableAA = new BoolProp("Antialias");
  2177. enableAA->addEventListener(this, Event::CHANGE_EVENT);
  2178. addProp(enableAA);
  2179. lastSize = -1;
  2180. propHeight = 160;
  2181. refreshFonts();
  2182. }
  2183. void UILabelSheet::refreshFonts() {
  2184. FontManager *fontManager = CoreServices::getInstance()->getFontManager();
  2185. font->comboEntry->clearItems();
  2186. for(int i=0; i < fontManager->getNumFonts(); i++) {
  2187. FontEntry *entry = fontManager->getFontEntryByIndex(i);
  2188. if(entry->fontName != "section") {
  2189. font->comboEntry->addComboItem(entry->fontName);
  2190. }
  2191. }
  2192. }
  2193. UILabelSheet::~UILabelSheet() {
  2194. }
  2195. void UILabelSheet::handleEvent(Event *event) {
  2196. if(!label)
  2197. return;
  2198. if(event->getDispatcher() == caption) {
  2199. label->setText(caption->get());
  2200. dispatchEvent(new Event(), Event::CHANGE_EVENT);
  2201. }
  2202. if(event->getDispatcher() == font) {
  2203. String fontName = font->comboEntry->getSelectedItem()->label;
  2204. Font *font = CoreServices::getInstance()->getFontManager()->getFontByName(fontName);
  2205. label->getLabel()->setFont(font);
  2206. label->setText(caption->get());
  2207. lastFont = fontName;
  2208. dispatchEvent(new Event(), Event::CHANGE_EVENT);
  2209. }
  2210. if(event->getDispatcher() == size) {
  2211. int newSize= size->get();
  2212. if(newSize < 4)
  2213. newSize = 4;
  2214. lastSize = newSize;
  2215. label->getLabel()->setSize(newSize);
  2216. label->setText(caption->get());
  2217. dispatchEvent(new Event(), Event::CHANGE_EVENT);
  2218. }
  2219. if(event->getDispatcher() == enableAA) {
  2220. if(enableAA->get()) {
  2221. label->getLabel()->setAntialiasMode(Label::ANTIALIAS_FULL);
  2222. } else {
  2223. label->getLabel()->setAntialiasMode(Label::ANTIALIAS_NONE);
  2224. }
  2225. label->setText(caption->get());
  2226. dispatchEvent(new Event(), Event::CHANGE_EVENT);
  2227. }
  2228. PropSheet::handleEvent(event);
  2229. }
  2230. void UILabelSheet::Update() {
  2231. if(label) {
  2232. enabled = true;
  2233. if(label != lastLabel) {
  2234. lastLabel = label;
  2235. caption->set(label->getText());
  2236. enableAA->set(label->getLabel()->getAntialiasMode() == Label::ANTIALIAS_FULL);
  2237. size->set(label->getLabel()->getSize());
  2238. for(int i=0; i < font->comboEntry->getNumItems(); i++) {
  2239. String comboFont = font->comboEntry->getItemAtIndex(i)->label;
  2240. if(comboFont == label->getLabel()->getFont()->getFontName()) {
  2241. if(comboFont != lastFont) {
  2242. font->set(i);
  2243. lastFont = comboFont;
  2244. }
  2245. }
  2246. }
  2247. }
  2248. } else {
  2249. enabled = false;
  2250. }
  2251. }
  2252. SoundSheet::SoundSheet() : PropSheet("SCREEN SOUND", "Sound") {
  2253. sound = NULL;
  2254. soundProp = new SoundProp("Sound file");
  2255. soundProp->addEventListener(this, Event::CHANGE_EVENT);
  2256. addProp(soundProp);
  2257. referenceDistance = new NumberProp("Reference dist");
  2258. referenceDistance->addEventListener(this, Event::CHANGE_EVENT);
  2259. addProp(referenceDistance);
  2260. maxDistance = new NumberProp("Max dist");
  2261. maxDistance->addEventListener(this, Event::CHANGE_EVENT);
  2262. addProp(maxDistance);
  2263. volume = new NumberProp("Volume");
  2264. volume->addEventListener(this, Event::CHANGE_EVENT);
  2265. addProp(volume);
  2266. pitch = new NumberProp("Pitch");
  2267. pitch->addEventListener(this, Event::CHANGE_EVENT);
  2268. addProp(pitch);
  2269. lastReferenceDistance = 0.0;
  2270. lastMaxDistance = 0.0;
  2271. lastVolume = 0.0;
  2272. lastPitch = 0.0;
  2273. lastSoundPath = "";
  2274. propHeight = 230;
  2275. }
  2276. SoundSheet::~SoundSheet() {
  2277. }
  2278. void SoundSheet::handleEvent(Event *event) {
  2279. if(!sound)
  2280. return;
  2281. if(event->getDispatcher() == referenceDistance && event->getEventCode() == Event::CHANGE_EVENT) {
  2282. lastReferenceDistance = referenceDistance->get();
  2283. sound->getSound()->setReferenceDistance(lastReferenceDistance);
  2284. dispatchEvent(new Event(), Event::CHANGE_EVENT);
  2285. }
  2286. if(event->getDispatcher() == maxDistance && event->getEventCode() == Event::CHANGE_EVENT) {
  2287. lastMaxDistance = maxDistance->get();
  2288. sound->getSound()->setMaxDistance(lastMaxDistance);
  2289. dispatchEvent(new Event(), Event::CHANGE_EVENT);
  2290. }
  2291. if(event->getDispatcher() == volume && event->getEventCode() == Event::CHANGE_EVENT) {
  2292. lastVolume = volume->get();
  2293. sound->getSound()->setVolume(lastVolume);
  2294. }
  2295. if(event->getDispatcher() == pitch && event->getEventCode() == Event::CHANGE_EVENT) {
  2296. lastPitch = pitch->get();
  2297. sound->getSound()->setPitch(lastPitch);
  2298. }
  2299. if(event->getDispatcher() == soundProp && event->getEventCode() == Event::CHANGE_EVENT) {
  2300. lastSoundPath = soundProp->get();
  2301. sound->getSound()->loadFile(lastSoundPath, false);
  2302. }
  2303. PropSheet::handleEvent(event);
  2304. }
  2305. void SoundSheet::Update() {
  2306. if(sound) {
  2307. enabled = true;
  2308. if(sound->getSound()->getFileName() != lastSoundPath) {
  2309. lastSoundPath = sound->getSound()->getFileName();
  2310. soundProp->set(sound->getSound()->getFileName());
  2311. }
  2312. if(sound->getSound()->getReferenceDistance() != lastReferenceDistance) {
  2313. lastReferenceDistance = sound->getSound()->getReferenceDistance();
  2314. referenceDistance->set(sound->getSound()->getReferenceDistance());
  2315. }
  2316. if(sound->getSound()->getMaxDistance() != lastMaxDistance) {
  2317. lastMaxDistance = sound->getSound()->getMaxDistance();
  2318. maxDistance->set(sound->getSound()->getMaxDistance());
  2319. }
  2320. if(sound->getSound()->getVolume() != lastVolume) {
  2321. lastVolume = sound->getSound()->getVolume();
  2322. volume->set(sound->getSound()->getVolume());
  2323. }
  2324. if(sound->getSound()->getPitch() != lastPitch) {
  2325. lastPitch = sound->getSound()->getPitch();
  2326. pitch->set(sound->getSound()->getPitch());
  2327. }
  2328. } else {
  2329. enabled = false;
  2330. }
  2331. }