OSDN Git Service

左上bのぱんの画像がスコアで変わるように
[h58pcdgame/GameScriptCoreLibrary.git] / www / corelib / classes / BreadItemWidgetClass.js
1 var BreadItemWidgetClass = function(manager, args)
2 {
3         BreadItemWidgetClass.base.apply(this, arguments);
4         this.manager = manager;
5         
6         this.size = new Point2D(320, 32);
7         this.origin = new Point2D(5, 37);
8         
9         this.updateInterval = 10;
10         this.updateCount = 999;
11         this.wBox = null;
12         
13         this.numberKeyPressed = [false, false, false, false, false, false, false, false, false, false];
14         
15 }.extend(WidgetClass, {
16         generateBreadImage(score){
17                 if(score <= 0)
18                 {
19                         return "burntbread.png";
20                 }
21                 if(score <=10)
22                 {
23                         return "KOPPE.png";
24                 }else if(score <=20)
25                 {
26                         return "bread.png";
27                 }else if(score <= 40)
28                 {
29                         return "curypan.png";
30                 }else
31                 {
32                         return "crosand.png";
33                 }
34         },
35         attach : function(){},
36         update: function(){
37                 if(this.wBox != null)
38                 {
39                         this.manager.mainArea.removeChild(this.wBox);
40                 }
41                 var element = document.createElement('div');
42                 with(element)
43                 {
44                         style.top = this.origin.y + "px";
45                         style.left = this.origin.x + "px";
46                         style.width = this.size.x + "px";
47                         style.height = this.size.y + "px";
48                         //style.overflow = "hidden";
49                         style.position = "absolute";
50                         style.zIndex = "500";
51                 }
52                 
53                 var maxItems = 10;
54                 var items = this.manager.userManager.breadList;
55                 
56                 var xloc = 0;
57                 for(var i = 0; i < maxItems && i < items.length; i++)
58                 {
59                         var img = document.createElement('img');
60                         with(img)
61                         {
62                                 style.position = "absolute";
63                                 style.top = "0px";
64                                 style.left = xloc + "px";
65                                 style.width = this.size.y + "px";
66                                 style.height = this.size.y + "px";
67                                 src = "images/" + BreadItemWidgetClass.prototype.generateBreadImage(items[i]);
68                                 //src = "images/012.png";
69                         }
70                         element.appendChild(img);
71                         var div = document.createElement('div');
72                         with(div)
73                         {
74                                 style.position = "absolute";
75                                 style.top = this.size.y + "px";
76                                 style.left = xloc + "px";
77                                 style.width = this.size.y + "px";
78                                 style.height = this.size.y + "px";
79                                 style.textAlign = "center";
80                         }
81                         div.innerText = i;
82                         element.appendChild(div);
83                         xloc += this.size.y;
84                 }
85
86                 this.manager.mainArea.appendChild(element);
87                 this.wBox = element;
88         },
89         detach : function()
90         {
91                 if(this.wBox != null)
92                 {
93                         this.manager.mainArea.removeChild(this.wBox);
94                 }
95         },
96         tick : function()
97         {
98                 this.updateCount++;
99                 if(this.updateCount > this.updateInterval)
100                 {
101                         this.update();
102                         this.updateCount = 0;
103                 }
104                 
105                 for(var i = 0; i < 10; i++)
106                 {
107                         if(this.manager.UIManager.keyState.numbers[i])
108                         {
109                                 if(this.numberKeyPressed[i])
110                                 {
111                                         this.keyPressed(this.manager.userManager.breadList[i]);
112                                 }
113                         }else
114                         {
115                                 this.numberKeyPressed[i] = false;
116                         }
117                 }
118                 
119                 return true;
120         },
121         keyPressed : function(breadId)
122         {
123         
124         }
125 });
126