Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
212 | ligi | 1 | /************************************************** |
2 | * |
||
3 | * class to handle Editing of MK Params |
||
4 | * |
||
5 | * Author: Marcus -LiGi- Bueschleb |
||
6 | * |
||
7 | * see README for further Infos |
||
8 | * |
||
9 | *************************************************/ |
||
10 | |||
11 | package org.ligi.android; |
||
12 | |||
13 | import android.view.*; |
||
14 | |||
15 | import org.ligi.ufo.*; |
||
16 | |||
17 | public class MKParamEditor |
||
18 | implements MKParamDefinitions |
||
19 | { |
||
20 | |||
21 | |||
22 | private int act_tab=0; |
||
23 | private int act_y=0; |
||
24 | private int act_lcd_lines=10; |
||
25 | |||
26 | DUBwise root; |
||
27 | |||
28 | public String[] lcd_lines; |
||
29 | |||
30 | public String[] public_lcd_lines; |
||
31 | |||
32 | public MKParamEditor(DUBwise _root) |
||
33 | { |
||
34 | root=_root; |
||
35 | lcd_lines=new String[40]; |
||
36 | // refresh_lcd(); |
||
37 | } |
||
38 | |||
39 | /* |
||
40 | public void paint ( Graphics g) |
||
41 | { |
||
42 | refresh_lcd(); |
||
43 | canvas.paint_lcd(g,false); |
||
44 | } |
||
45 | */ |
||
46 | |||
47 | public void refresh_lcd() |
||
48 | { |
||
49 | // try |
||
50 | { |
||
51 | |||
52 | if (root.mk!=null) |
||
53 | { |
||
54 | act_lcd_lines=root.mk.params.field_names[act_tab].length*2+1; |
||
55 | for ( int i=0;i<act_lcd_lines;i++) |
||
56 | lcd_lines[i]=""; |
||
57 | |||
58 | |||
59 | try |
||
60 | { |
||
61 | |||
62 | lcd_lines[0]=(act_tab==0?" ":"< ") + root.mk.params.tab_names[act_tab] + (act_tab==(root.mk.params.tab_names.length-1)?" ":" >"); |
||
63 | |||
64 | for (int i=0;i<root.mk.params.field_names[act_tab].length;i++) |
||
65 | { |
||
66 | lcd_lines[1+2*i]=root.mk.params.field_names[act_tab][i]; |
||
67 | if (root.mk.params.field_types[act_tab][i]== root.mk.params.PARAMTYPE_BITSWITCH) |
||
68 | lcd_lines[2+2*i]=(((root.mk.params.get_field_from_act(root.mk.params.field_positions[act_tab][i]/8)&(1<<root.mk.params.field_positions[act_tab][i]%8))==0)?"off":"on" ) ; |
||
69 | if (root.mk.params.field_types[act_tab][i]== root.mk.params.PARAMTYPE_BYTE) |
||
70 | { |
||
71 | lcd_lines[2+2*i]=""+root.mk.params.get_field_from_act(root.mk.params.field_positions[act_tab][i]); |
||
72 | if ((root.mk.params.get_field_from_act(root.mk.params.field_positions[act_tab][i])>250)&&(root.mk.params.get_field_from_act(root.mk.params.field_positions[act_tab][i])<256)) |
||
73 | lcd_lines[2+2*i]+="[Poti"+(root.mk.params.get_field_from_act(root.mk.params.field_positions[act_tab][i])-250) +"]"; |
||
74 | } |
||
75 | |||
76 | if (root.mk.params.field_types[act_tab][i]== root.mk.params.PARAMTYPE_STICK) |
||
77 | { |
||
78 | lcd_lines[2+2*i]=""+root.mk.params.get_field_from_act(root.mk.params.field_positions[act_tab][i]); |
||
79 | } |
||
80 | |||
81 | |||
82 | |||
83 | } |
||
84 | |||
85 | for (int i=0;i<act_lcd_lines;i++) |
||
86 | { |
||
87 | lcd_lines[i]=(act_y==i?"#":" ")+lcd_lines[i]; |
||
88 | } |
||
89 | |||
90 | for ( int i=0;i<act_lcd_lines;i++) |
||
91 | while(lcd_lines[i].length()<20) |
||
92 | { |
||
93 | lcd_lines[i]+=" "; |
||
94 | } |
||
95 | } |
||
96 | catch (Exception e){} |
||
97 | public_lcd_lines=new String[act_lcd_lines]; |
||
98 | for(int i=0;i<act_lcd_lines;i++) |
||
99 | public_lcd_lines[i]=lcd_lines[i]; |
||
100 | |||
101 | } |
||
102 | else |
||
103 | { |
||
104 | public_lcd_lines=new String[1]; |
||
105 | public_lcd_lines[0]="reading params"; |
||
106 | } |
||
107 | |||
108 | } |
||
109 | // catch (Exception e){} |
||
110 | } |
||
111 | |||
112 | |||
113 | public final static int KEYCODE_CLEAR=-8; |
||
114 | |||
115 | public boolean editing_number=false; |
||
116 | |||
117 | public void keypress (int keyCode,int action) |
||
118 | { |
||
119 | if (act_y==0) switch (action) |
||
120 | { |
||
121 | case KeyEvent.KEYCODE_DPAD_RIGHT: |
||
122 | if (act_tab<root.mk.params.tab_names.length-1) act_tab++; |
||
123 | break; |
||
124 | |||
125 | case KeyEvent.KEYCODE_DPAD_LEFT: |
||
126 | if (act_tab!=0) act_tab--; |
||
127 | break; |
||
128 | } |
||
129 | else |
||
130 | { |
||
131 | if(root.mk.params.field_types[act_tab][act_y/2-1]==root.mk.params.PARAMTYPE_BYTE) |
||
132 | { |
||
133 | if ((keyCode >=KeyEvent.KEYCODE_0) && (keyCode <=KeyEvent.KEYCODE_9)) |
||
134 | { |
||
135 | if((editing_number)&&( Math.abs(root.mk.params.get_field_from_act(root.mk.params.field_positions[act_tab][act_y/2-1]))*10+(keyCode -KeyEvent.KEYCODE_0)<1000)) |
||
136 | root.mk.params.set_field_from_act(root.mk.params.field_positions[act_tab][act_y/2-1] , Math.abs(root.mk.params.get_field_from_act(root.mk.params.field_positions[act_tab][act_y/2-1]))*10+(keyCode -KeyEvent.KEYCODE_0)); |
||
137 | else |
||
138 | root.mk.params.set_field_from_act(root.mk.params.field_positions[act_tab][act_y/2-1] , (keyCode -KeyEvent.KEYCODE_0)); |
||
139 | editing_number=true; |
||
140 | return; |
||
141 | } |
||
142 | else |
||
143 | if ( keyCode==KEYCODE_CLEAR) |
||
144 | root.mk.params.set_field_from_act(root.mk.params.field_positions[act_tab][act_y/2-1],0); |
||
145 | } |
||
146 | editing_number=false; |
||
147 | |||
148 | switch (action) |
||
149 | { |
||
150 | |||
151 | case KeyEvent.KEYCODE_DPAD_RIGHT: |
||
152 | switch(root.mk.params.field_types[act_tab][act_y/2-1]) |
||
153 | { |
||
154 | case PARAMTYPE_BITSWITCH: |
||
155 | |||
156 | root.mk.params.field_from_act_xor((root.mk.params.field_positions[act_tab][act_y/2-1]/8),1<<(root.mk.params.field_positions[act_tab][act_y/2-1]%8)); |
||
157 | break; |
||
158 | case PARAMTYPE_BYTE: |
||
159 | case PARAMTYPE_STICK: |
||
160 | |||
161 | root.mk.params.field_from_act_add(root.mk.params.field_positions[act_tab][act_y/2-1],1); |
||
162 | break; |
||
163 | } |
||
164 | break; |
||
165 | |||
166 | case KeyEvent.KEYCODE_DPAD_LEFT: |
||
167 | switch(root.mk.params.field_types[act_tab][act_y/2-1]) |
||
168 | { |
||
169 | case PARAMTYPE_BITSWITCH: |
||
170 | root.mk.params.field_from_act_xor((root.mk.params.field_positions[act_tab][act_y/2-1]/8),1<<(root.mk.params.field_positions[act_tab][act_y/2-1]%8)); |
||
171 | |||
172 | break; |
||
173 | case PARAMTYPE_BYTE: |
||
174 | case PARAMTYPE_STICK: |
||
175 | root.mk.params.field_from_act_add(root.mk.params.field_positions[act_tab][act_y/2-1],-1); |
||
176 | break; |
||
177 | } |
||
178 | |||
179 | |||
180 | break; |
||
181 | } |
||
182 | |||
183 | } |
||
184 | |||
185 | switch (action) |
||
186 | { |
||
187 | |||
188 | case KeyEvent.KEYCODE_DPAD_DOWN: |
||
189 | if (act_y<(act_lcd_lines-2)) act_y+=2; |
||
190 | else act_y=0; |
||
191 | break; |
||
192 | |||
193 | case KeyEvent.KEYCODE_DPAD_UP : |
||
194 | if (act_y!=0) act_y-=2; |
||
195 | else act_y=act_lcd_lines-1; |
||
196 | break; |
||
197 | |||
198 | } |
||
199 | |||
200 | refresh_lcd(); |
||
201 | |||
202 | |||
203 | } |
||
204 | } |
||
205 |