o0CCEditBox.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. var o0 = require('o0');
  2. var o0CC = require('o0CC');
  3. var o0Game = require('o0Game');
  4. cc.Class({
  5. extends: cc.EditBox,
  6. properties: {
  7. //background:null,
  8. label:null,
  9. },
  10. o0EditingDidBegan:function(){
  11. this.label.node.active = true;
  12. this.label.string = this.string;
  13. },
  14. o0TextChanged:function(){
  15. this.label.string = this.string;
  16. },
  17. o0EditingDidEnded:function(){
  18. this.label.node.active = false;
  19. },/** */
  20. // use this for initialization
  21. onLoad: function () {
  22. var self = this;
  23. cc.loader.loadRes('editbox', cc.SpriteFrame, function (err, spriteFrame) {
  24. self.backgroundImage = spriteFrame;
  25. });/** */
  26. //this.background = o0CC.addScriptNode(this.node,'cc.Graphics',0);
  27. //this.fontColor = cc.c4b(255,255,255,255)
  28. this.fontColor = new cc.color(255,255,255);
  29. this.label = o0CC.addScriptNode(this.node,'cc.Label',2);
  30. /*this.label.node.anchorX = 0;
  31. this.label.node.anchorY = 0;/** */
  32. //this.label.horizontalAlign = cc.Label.HorizontalAlign.CENTER;
  33. //this.label.verticalAlign = cc.Label.VerticalAlign.CENTER;
  34. //this.label.fontSize = 16;
  35. //this.label.lineHeight = 20;
  36. this.label.overflow = cc.Label.Overflow.SHRINK;
  37. this.label.color = new cc.Color(155,155,155);
  38. this.label.node.color = new cc.Color(155,155,155);
  39. this.label.enableWrapText = false;
  40. this.label.node.active = false;
  41. var o0EditingDidBeganHandler = new cc.Component.EventHandler();
  42. o0EditingDidBeganHandler.target = this.node;
  43. o0EditingDidBeganHandler.component = "o0CCEditBox";
  44. o0EditingDidBeganHandler.handler = "o0EditingDidBegan";
  45. o0EditingDidBeganHandler.emit([]);
  46. this.editingDidBegan.push(o0EditingDidBeganHandler);
  47. var o0TextChangedHandler = new cc.Component.EventHandler();
  48. o0TextChangedHandler.target = this.node;
  49. o0TextChangedHandler.component = "o0CCEditBox";
  50. o0TextChangedHandler.handler = "o0TextChanged";
  51. o0TextChangedHandler.emit([]);
  52. this.textChanged.push(o0TextChangedHandler);
  53. var o0editingDidEndedHandler = new cc.Component.EventHandler();
  54. o0editingDidEndedHandler.target = this.node;
  55. o0editingDidEndedHandler.component = "o0CCEditBox";
  56. o0editingDidEndedHandler.handler = "o0EditingDidEnded";
  57. o0editingDidEndedHandler.emit([]);
  58. this.editingDidEnded.push(o0editingDidEndedHandler);/** */
  59. //this.background.enabled = false;
  60. },
  61. // called every frame
  62. update: function (dt) {
  63. /*
  64. this.background.clear();
  65. this.background.roundRect(this.node.width*(-this.node.anchorX),this.node.height*(-this.node.anchorY), this.node.width, this.node.height,3);
  66. this.background.fillColor = new cc.Color(50,50,50,250);
  67. this.background.fill();
  68. this.background.roundRect(this.node.width*(-this.node.anchorX), this.node.height*(-this.node.anchorY), this.node.width, this.node.height,3);
  69. this.background.strokeColor = new cc.Color(255,255,255,155);
  70. this.background.stroke();/** */
  71. this.label.node.anchorX = this.node.anchorX;
  72. this.label.node.anchorY = this.node.anchorY;
  73. this.label.node.x = 0;
  74. this.label.node.y = 0;
  75. this.label.node.width = this.node.width - 5;
  76. this.label.node.height = this.node.height;
  77. this.label.fontSize = this.node.height - 15;
  78. }
  79. })