Rev 245 | Rev 258 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
206 | ligi | 1 | /******************************************************** |
2 | * |
||
3 | * class to handle Editing of MK Params via MIDP / J2ME |
||
4 | * |
||
5 | * Author: Marcus -LiGi- Bueschleb |
||
6 | * |
||
7 | ********************************************************/ |
||
8 | |||
9 | import javax.microedition.lcdui.*; |
||
10 | |||
11 | public class MKParamsEditor |
||
255 | ligi | 12 | implements org.ligi.ufo.MKParamDefinitions, org.ligi.ufo.DUBwiseLangDefs |
206 | ligi | 13 | { |
14 | |||
220 | ligi | 15 | public byte nextstate; |
206 | ligi | 16 | |
17 | private int act_tab=0; |
||
220 | ligi | 18 | public int act_y=1; |
206 | ligi | 19 | private int act_lcd_lines=10; |
20 | |||
21 | DUBwiseCanvas canvas; |
||
22 | |||
220 | ligi | 23 | public String[] lcd_lines; |
206 | ligi | 24 | |
220 | ligi | 25 | public String[] menu_items; |
206 | ligi | 26 | |
220 | ligi | 27 | org.ligi.ufo.ParamsClass edit_source; |
206 | ligi | 28 | |
220 | ligi | 29 | |
30 | public MKParamsEditor(DUBwiseCanvas _canvas,org.ligi.ufo.ParamsClass _edit_source,byte _nextstate) |
||
206 | ligi | 31 | { |
220 | ligi | 32 | nextstate=_nextstate; |
33 | edit_source=_edit_source; |
||
34 | |||
206 | ligi | 35 | canvas=_canvas; |
36 | lcd_lines=new String[40]; |
||
37 | // refresh_lcd(); |
||
38 | } |
||
39 | |||
220 | ligi | 40 | |
41 | boolean select_mode=true; |
||
42 | |||
43 | |||
206 | ligi | 44 | public void paint ( Graphics g) |
45 | { |
||
220 | ligi | 46 | if (select_mode) |
47 | { |
||
255 | ligi | 48 | if (canvas.menu_items[0]!=canvas.l(edit_source.tab_stringids[0])) // usefull? |
220 | ligi | 49 | { |
50 | act_y=1; |
||
255 | ligi | 51 | menu_items=new String[edit_source.tab_stringids.length+1]; |
52 | for(int p=0;p<edit_source.tab_stringids.length;p++) |
||
53 | menu_items[p]=canvas.l(edit_source.tab_stringids[p]); |
||
54 | menu_items[edit_source.tab_stringids.length]=canvas.l(STRINGID_BACK); |
||
220 | ligi | 55 | canvas.setup_menu(menu_items,null); |
56 | } |
||
57 | canvas.paint_menu(g); |
||
58 | } |
||
59 | |||
60 | else |
||
61 | { |
||
62 | refresh_lcd(); |
||
63 | // canvas.paint_lcd(g,false); |
||
221 | ligi | 64 | canvas.paint_lcd(g); |
220 | ligi | 65 | } |
206 | ligi | 66 | } |
67 | |||
68 | |||
69 | public void refresh_lcd() |
||
70 | { |
||
71 | |||
220 | ligi | 72 | try { |
73 | act_lcd_lines=edit_source.field_names[act_tab].length*2+2; |
||
74 | |||
75 | for ( int i=0;i<act_lcd_lines;i++) |
||
76 | lcd_lines[i]=""; |
||
77 | |||
78 | |||
79 | |||
255 | ligi | 80 | // lcd_lines[0]=(act_tab==0?" ":"< ") + edit_source.tab_stringids[act_tab] + (act_tab==(edit_source.tab_stringids.length-1)?" ":" >"); |
220 | ligi | 81 | |
82 | for (int i=0;i<edit_source.field_names[act_tab].length;i++) |
||
83 | { |
||
84 | lcd_lines[2*i]=edit_source.field_names[act_tab][i]; |
||
85 | |||
86 | switch(edit_source.field_types[act_tab][i]) |
||
87 | { |
||
88 | case PARAMTYPE_BITSWITCH: |
||
223 | ligi | 89 | lcd_lines[1+2*i]=" " + (((edit_source.get_field_from_act(edit_source.field_positions[act_tab][i]/8)&(1<<edit_source.field_positions[act_tab][i]%8))==0)?"off":"on" ) ; |
220 | ligi | 90 | break; |
245 | ligi | 91 | |
220 | ligi | 92 | case PARAMTYPE_BYTE: |
223 | ligi | 93 | lcd_lines[1+2*i]=" "+edit_source.get_field_from_act(edit_source.field_positions[act_tab][i]); |
245 | ligi | 94 | |
95 | break; |
||
96 | |||
97 | case PARAMTYPE_BITMASK: |
||
98 | lcd_lines[1+2*i]=" "+edit_source.get_field_from_act(edit_source.field_positions[act_tab][i]); |
||
220 | ligi | 99 | if ((edit_source.get_field_from_act(edit_source.field_positions[act_tab][i])>250)&&(edit_source.get_field_from_act(edit_source.field_positions[act_tab][i])<256)) |
245 | ligi | 100 | lcd_lines[1+2*i]+="[Poti"+(edit_source.get_field_from_act(edit_source.field_positions[act_tab][i])-250) +"]"; |
101 | else |
||
102 | { |
||
103 | lcd_lines[1+2*i]+=" ["; |
||
104 | for (int bit=0;bit<8;bit++) |
||
105 | lcd_lines[1+2*i]+=((edit_source.get_field_from_act(edit_source.field_positions[act_tab][i]) & ( 1<<bit)) !=0)?"+":"-"; |
||
106 | lcd_lines[1+2*i]+="]"; |
||
107 | } |
||
108 | |||
109 | break; |
||
206 | ligi | 110 | |
245 | ligi | 111 | case PARAMTYPE_MKBYTE: |
112 | lcd_lines[1+2*i]=" "+edit_source.get_field_from_act(edit_source.field_positions[act_tab][i]); |
||
113 | if ((edit_source.get_field_from_act(edit_source.field_positions[act_tab][i])>250)&&(edit_source.get_field_from_act(edit_source.field_positions[act_tab][i])<256)) |
||
114 | lcd_lines[1+2*i]+=" [Poti"+(edit_source.get_field_from_act(edit_source.field_positions[act_tab][i])-250) +"]"; |
||
115 | break; |
||
206 | ligi | 116 | |
245 | ligi | 117 | |
220 | ligi | 118 | case PARAMTYPE_KEY: |
221 | ligi | 119 | if (edit_source.get_field_from_act(edit_source.field_positions[act_tab][i])==-4242) |
120 | lcd_lines[1+2*i]="none"; |
||
121 | else |
||
223 | ligi | 122 | lcd_lines[1+2*i]=" "+edit_source.get_field_from_act(edit_source.field_positions[act_tab][i]); |
221 | ligi | 123 | break; |
220 | ligi | 124 | case PARAMTYPE_STICK: |
223 | ligi | 125 | lcd_lines[1+2*i]=" "+edit_source.get_field_from_act(edit_source.field_positions[act_tab][i]); |
220 | ligi | 126 | break; |
127 | |||
128 | default: |
||
223 | ligi | 129 | lcd_lines[1+2*i]=" "+edit_source.choice_strings[edit_source.field_types[act_tab][i]-PARAMTYPE_CHOICE][edit_source.get_field_from_act(edit_source.field_positions[act_tab][i])]; |
220 | ligi | 130 | } |
131 | |||
132 | } |
||
133 | |||
255 | ligi | 134 | lcd_lines[act_lcd_lines-1]=canvas.l(STRINGID_BACK); |
220 | ligi | 135 | |
136 | canvas.lcd_lines=new String[act_lcd_lines]; |
||
137 | for ( int i=0;i<act_lcd_lines;i++) |
||
138 | { |
||
139 | lcd_lines[i]=(act_y==i?"#":" ")+lcd_lines[i]; |
||
140 | while(lcd_lines[i].length()<20) |
||
141 | lcd_lines[i]+=" "; |
||
206 | ligi | 142 | |
220 | ligi | 143 | canvas.lcd_lines[i]=lcd_lines[i]; |
144 | } |
||
206 | ligi | 145 | |
220 | ligi | 146 | } |
206 | ligi | 147 | |
220 | ligi | 148 | catch (Exception e){} |
149 | |||
150 | // for(int i=0;i<act_lcd_lines;i++) |
||
206 | ligi | 151 | |
220 | ligi | 152 | /* |
206 | ligi | 153 | } |
154 | else |
||
155 | { |
||
156 | canvas.lcd_lines=new String[1]; |
||
157 | canvas.lcd_lines[0]="reading params"; |
||
158 | } |
||
220 | ligi | 159 | */ |
206 | ligi | 160 | } |
161 | |||
162 | |||
163 | public final static int KEYCODE_CLEAR=-8; |
||
164 | |||
165 | public boolean editing_number=false; |
||
166 | |||
242 | ligi | 167 | public void pointer_press(int x,int row) |
168 | { |
||
169 | if (select_mode) |
||
170 | { |
||
171 | canvas.act_menu_select=row; |
||
172 | keypress (-4242,Canvas.FIRE); |
||
173 | |||
174 | } |
||
175 | else |
||
176 | { |
||
177 | if ((row%2)==0) |
||
178 | act_y=row+1; |
||
179 | else |
||
180 | { |
||
181 | act_y=row; |
||
182 | |||
183 | if (act_y==(canvas.lcd_lines.length-1)) |
||
184 | keypress (-4242,Canvas.FIRE); |
||
185 | else |
||
186 | { |
||
187 | if (x<(canvas.canvas_width/2)) |
||
188 | keypress (-4242,Canvas.LEFT); |
||
189 | else |
||
190 | keypress (-4242,Canvas.RIGHT); |
||
191 | } |
||
192 | } |
||
193 | } |
||
194 | } |
||
195 | |||
196 | |||
206 | ligi | 197 | public void keypress (int keyCode,int action) |
198 | { |
||
199 | |||
220 | ligi | 200 | if (select_mode) |
206 | ligi | 201 | { |
220 | ligi | 202 | if (action== Canvas.FIRE) |
206 | ligi | 203 | { |
220 | ligi | 204 | |
205 | if (canvas.act_menu_select==(menu_items.length-1)) |
||
206 | canvas.chg_state(nextstate); |
||
207 | else |
||
208 | |||
206 | ligi | 209 | { |
220 | ligi | 210 | act_tab=canvas.act_menu_select; |
211 | select_mode=false; |
||
212 | act_y=1; |
||
206 | ligi | 213 | } |
214 | } |
||
220 | ligi | 215 | else |
216 | canvas.menu_keypress(keyCode); |
||
206 | ligi | 217 | } |
220 | ligi | 218 | else |
206 | ligi | 219 | { |
220 | |||
221 | |||
220 | ligi | 222 | if ((act_y!=(act_lcd_lines-1))&&(((keyCode >= Canvas.KEY_NUM0) && (keyCode <= Canvas.KEY_NUM9))|| ( keyCode==KEYCODE_CLEAR))) |
223 | { |
||
224 | int act_pos=act_y/2; |
||
245 | ligi | 225 | if((edit_source.field_types[act_tab][act_pos]==edit_source.PARAMTYPE_BYTE)||(edit_source.field_types[act_tab][act_pos]==edit_source.PARAMTYPE_MKBYTE) ||(edit_source.field_types[act_tab][act_pos]==edit_source.PARAMTYPE_BITMASK)) |
220 | ligi | 226 | { |
227 | if ((keyCode >= Canvas.KEY_NUM0) && (keyCode <= Canvas.KEY_NUM9)) |
||
228 | { |
||
229 | if((editing_number)&&( Math.abs(edit_source.get_field_from_act(edit_source.field_positions[act_tab][act_pos]))*10+(keyCode - Canvas.KEY_NUM0)<1000)) |
||
230 | edit_source.set_field_from_act(edit_source.field_positions[act_tab][act_pos] , Math.abs(edit_source.get_field_from_act(edit_source.field_positions[act_tab][act_pos]))*10+(keyCode - Canvas.KEY_NUM0)); |
||
231 | else |
||
232 | edit_source.set_field_from_act(edit_source.field_positions[act_tab][act_pos] , (keyCode - Canvas.KEY_NUM0)); |
||
233 | editing_number=true; |
||
234 | return; |
||
235 | } |
||
236 | else |
||
237 | if ( keyCode==KEYCODE_CLEAR) |
||
238 | edit_source.set_field_from_act(edit_source.field_positions[act_tab][act_pos],0); |
||
239 | } |
||
240 | editing_number=false; |
||
241 | |||
242 | } |
||
206 | ligi | 243 | |
220 | ligi | 244 | switch (action) |
245 | { |
||
246 | |||
247 | case Canvas.DOWN: |
||
248 | if (act_y<(act_lcd_lines-2)) act_y+=2; |
||
249 | else act_y=1; |
||
250 | break; |
||
251 | |||
252 | case Canvas.UP: |
||
253 | if (act_y!=1) act_y-=2; |
||
254 | else act_y=act_lcd_lines-1; |
||
255 | break; |
||
256 | |||
257 | default: |
||
206 | ligi | 258 | |
259 | |||
220 | ligi | 260 | |
261 | if (act_y!=(act_lcd_lines-1)) |
||
262 | { |
||
263 | |||
264 | // |
||
265 | |||
266 | int act_pos=act_y/2; |
||
267 | |||
268 | if((edit_source.field_types[act_tab][act_pos]==edit_source.PARAMTYPE_KEY)) |
||
269 | edit_source.set_field_from_act(edit_source.field_positions[act_tab][act_pos],keyCode); |
||
270 | |||
271 | switch (action) |
||
272 | { |
||
273 | |||
274 | case Canvas.RIGHT: |
||
275 | switch(edit_source.field_types[act_tab][act_pos]) |
||
276 | { |
||
277 | case PARAMTYPE_BITSWITCH: |
||
278 | |||
279 | edit_source.field_from_act_xor((edit_source.field_positions[act_tab][act_pos]/8),1<<(edit_source.field_positions[act_tab][act_pos]%8)); |
||
280 | break; |
||
281 | |||
245 | ligi | 282 | case PARAMTYPE_BITMASK: |
283 | case PARAMTYPE_MKBYTE: |
||
220 | ligi | 284 | case PARAMTYPE_BYTE: |
245 | ligi | 285 | |
220 | ligi | 286 | |
245 | ligi | 287 | edit_source.field_from_act_add_min_max(edit_source.field_positions[act_tab][act_pos],1,0,255); |
220 | ligi | 288 | break; |
245 | ligi | 289 | case PARAMTYPE_STICK: |
290 | edit_source.field_from_act_add_min_max(edit_source.field_positions[act_tab][act_pos],1,0,10); |
||
291 | break; |
||
220 | ligi | 292 | |
293 | default: |
||
294 | edit_source.field_from_act_add_mod(edit_source.field_positions[act_tab][act_pos],1,edit_source.choice_strings[edit_source.field_types[act_tab][act_pos]-PARAMTYPE_CHOICE].length); |
||
295 | break; |
||
296 | } |
||
297 | break; |
||
298 | |||
299 | case Canvas.LEFT: |
||
300 | switch(edit_source.field_types[act_tab][act_pos]) |
||
301 | { |
||
302 | case PARAMTYPE_BITSWITCH: |
||
303 | edit_source.field_from_act_xor((edit_source.field_positions[act_tab][act_pos]/8),1<<(edit_source.field_positions[act_tab][act_pos]%8)); |
||
304 | |||
305 | break; |
||
245 | ligi | 306 | case PARAMTYPE_BITMASK: |
307 | case PARAMTYPE_MKBYTE: |
||
220 | ligi | 308 | case PARAMTYPE_BYTE: |
245 | ligi | 309 | edit_source.field_from_act_add_min_max(edit_source.field_positions[act_tab][act_pos],-1,0,255); |
310 | break; |
||
220 | ligi | 311 | case PARAMTYPE_STICK: |
245 | ligi | 312 | edit_source.field_from_act_add_min_max(edit_source.field_positions[act_tab][act_pos],-1,0,10); |
220 | ligi | 313 | break; |
314 | default: |
||
315 | edit_source.field_from_act_add_mod(edit_source.field_positions[act_tab][act_pos],1,edit_source.choice_strings[edit_source.field_types[act_tab][act_pos]-PARAMTYPE_CHOICE].length); |
||
316 | break; |
||
317 | } |
||
318 | |||
319 | |||
320 | break; |
||
321 | } |
||
322 | |||
323 | } |
||
324 | else |
||
325 | if (action== Canvas.FIRE) |
||
326 | { |
||
327 | act_y=1; |
||
242 | ligi | 328 | // canvas.act_menu_select=0; |
220 | ligi | 329 | canvas.menu_items[0]=""; |
330 | select_mode=true; |
||
331 | |||
332 | } |
||
333 | } |
||
334 | |||
335 | |||
336 | // if (!select_mode)refresh_lcd(); |
||
337 | |||
338 | } |
||
339 | } // keypress |
||
206 | ligi | 340 | } |
341 |