• R/O
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

密猟オンラインクライアントプログラム JAVAベース


Commit MetaInfo

Révision21 (tree)
l'heure2016-12-25 00:47:49
Auteurmanjihq

Message de Log

表示するユーザー名やアイテム名などをそれなりに全角判定して表示を調整するようにした

Change Summary

Modification

--- trunk/src/hunton/Hunt.java (revision 20)
+++ trunk/src/hunton/Hunt.java (revision 21)
@@ -132,6 +132,12 @@
132132 public static final byte MOVE_LEFT = 2;
133133 public static final byte MOVE_RIGHT = 3;
134134
135+ /* system parameter */
136+ public static final int WIDTH_VIEW_USERNAME = 16;
137+ public static final int WIDTH_VIEW_WEAPONNAME = 16;
138+ public static final int WIDTH_VIEW_ITEMNAME = 16;
139+ public static final int WIDTH_VIEW_ANIMALNAME = 16;
140+
135141 /* system variable */
136142 static String HostName;
137143 static String UserName;
@@ -193,6 +199,122 @@
193199 p[nidx + 3] = (byte) (n & 0xff);
194200 }
195201
202+ public static final boolean isSingleByte(int codepoint) {
203+ boolean result = false;
204+ if (Character.charCount(codepoint) == 1) {
205+ if (codepoint >= 0 && codepoint < 0x80) {
206+ result = true;
207+ }
208+ }
209+ return result;
210+ }
211+
212+ public static final int countStringWidth(String s) {
213+ int i;
214+ int nwidth = 0;
215+ for (i = 0; i < s.length(); i++) {
216+ int c;
217+ c = s.codePointAt(i);
218+ if (Character.charCount(c) == 2) {
219+ i++;
220+ }
221+ if (isSingleByte(c) == false) {
222+ nwidth += 2;
223+ } else {
224+ nwidth++;
225+ }
226+ }
227+ return nwidth;
228+ }
229+
230+ public static final String rightStringWidth(String s, int nlimit) {
231+ StringBuilder wkname = new StringBuilder();
232+ int i;
233+ int nwidth = 0;
234+ for (i = 0; i < s.length(); i++) {
235+ int c;
236+ c = s.codePointAt(i);
237+ if (Character.charCount(c) == 2) {
238+ i++;
239+ }
240+ if (isSingleByte(c) == false) {
241+ if (nwidth + 2 > nlimit) {
242+ break;
243+ }
244+ nwidth += 2;
245+ } else {
246+ if (nwidth + 1 > nlimit) {
247+ break;
248+ }
249+ nwidth++;
250+ }
251+ wkname.appendCodePoint(c);
252+ }
253+ if (nwidth < nlimit) {
254+ StringBuilder wkspace = new StringBuilder();
255+ for (; nwidth < nlimit; nwidth++) {
256+ wkspace.append(" ");
257+ }
258+ wkname.insert(0, wkspace);
259+ }
260+ return wkname.toString();
261+ }
262+
263+ public static final String trimStringWidth(String s, int nlimit) {
264+ StringBuilder wkname = new StringBuilder();
265+ int i;
266+ int nwidth = 0;
267+ for (i = 0; i < s.length(); i++) {
268+ int c;
269+ c = s.codePointAt(i);
270+ if (Character.charCount(c) == 2) {
271+ i++;
272+ }
273+ if (isSingleByte(c) == false) {
274+ if (nwidth + 2 > nlimit) {
275+ break;
276+ }
277+ nwidth += 2;
278+ } else {
279+ if (nwidth + 1 > nlimit) {
280+ break;
281+ }
282+ nwidth++;
283+ }
284+ wkname.appendCodePoint(c);
285+ }
286+ return wkname.toString();
287+ }
288+
289+ public static final String formatStringWidth(String s, int nview) {
290+ StringBuilder wkname = new StringBuilder();
291+ int i;
292+ int nwidth = 0;
293+ for (i = 0; i < s.length(); i++) {
294+ int c;
295+ c = s.codePointAt(i);
296+ if (Character.charCount(c) == 2) {
297+ i++;
298+ }
299+ if (isSingleByte(c) == false) {
300+ if (nwidth + 2 > nview) {
301+ break;
302+ }
303+ nwidth += 2;
304+ } else {
305+ if (nwidth + 1 > nview) {
306+ break;
307+ }
308+ nwidth++;
309+ }
310+ wkname.appendCodePoint(c);
311+ }
312+ for (; nwidth < nview; nwidth++) {
313+ wkname.append(" ");
314+ }
315+ return wkname.toString();
316+ }
317+
196318 public static final int getType() {
197319 return yourType;
198320 }
@@ -298,6 +420,7 @@
298420 }
299421 }
300422 nowWeapon[n] = new String(p, nidx, i + 1, SYSTEM_CHARSET);
423+ nowWeapon[n] = trimStringWidth(nowWeapon[n], WIDTH_VIEW_WEAPONNAME);
301424 } catch (UnsupportedEncodingException e) {
302425 nowWeapon[n] = "?"; //NOI18N
303426 }
@@ -312,6 +435,7 @@
312435 }
313436 }
314437 nowItem[n] = new String(p, nidx, i + 1, SYSTEM_CHARSET);
438+ nowItem[n] = trimStringWidth(nowItem[n], WIDTH_VIEW_ITEMNAME);
315439 } catch (UnsupportedEncodingException e) {
316440 nowItem[n] = "?"; //NOI18N
317441 }
@@ -464,6 +588,7 @@
464588 } else {
465589 UserName = s;
466590 }
591+ UserName = trimStringWidth(UserName, WIDTH_VIEW_USERNAME);
467592 }
468593
469594 public static void setPassWord(String s) {
@@ -800,7 +925,7 @@
800925 }
801926 work = ifile.readLine();
802927 if (work != null) {
803- UserName = work;
928+ UserName = trimStringWidth(work, WIDTH_VIEW_USERNAME);
804929 }
805930 mainWndBounds = load_rect(ifile);
806931 statusViewBounds = load_rect(ifile);
--- trunk/src/hunton/HuntLoginWnd.java (revision 20)
+++ trunk/src/hunton/HuntLoginWnd.java (revision 21)
@@ -62,7 +62,7 @@
6262 add(label);
6363
6464 gridbag.gridwidth = GridBagConstraints.REMAINDER;
65- username = new TextField(Hunt.getUserName(), Hunt.USERNAME_LEN);
65+ username = new TextField(Hunt.getUserName(), Hunt.WIDTH_VIEW_USERNAME);
6666 layout.setConstraints(username, gridbag);
6767 username.addActionListener(this);
6868 add(username);
--- trunk/src/hunton/MesgBox.java (revision 20)
+++ trunk/src/hunton/MesgBox.java (revision 21)
@@ -7,18 +7,29 @@
77
88 static void make_text_labels(Dialog dialog, String s) {
99 String wk;
10+ int nwidth;
1011 int ns = 0;
1112 int pos = s.indexOf('\n');
1213 Panel panel = new Panel(new GridLayout(0, 1));
1314 while (pos != -1) {
1415 wk = s.substring(ns, pos);
16+ nwidth = Hunt.countStringWidth(wk);
17+ if (nwidth < 20) {
18+ wk = Hunt.trimStringWidth(s, 20);
19+ }
1520 panel.add(new Label(wk));
1621 ns = pos + 1;
1722 pos = s.indexOf('\n', ns);
1823 }
1924 wk = s.substring(ns);
25+ nwidth = Hunt.countStringWidth(wk);
26+ if (nwidth < 20) {
27+ wk = Hunt.formatStringWidth(s, 20);
28+ }
2029 panel.add(new Label(wk));
2130 dialog.add(panel, BorderLayout.CENTER);
31+ dialog.add(new Panel(), BorderLayout.WEST);
32+ dialog.add(new Panel(), BorderLayout.EAST);
2233 }
2334
2435 public static boolean MessageBox(Frame w,
--- trunk/src/hunton/RecvTask.java (revision 20)
+++ trunk/src/hunton/RecvTask.java (revision 21)
@@ -125,10 +125,11 @@
125125 } else {
126126 work += Hunt.getBundle().getString("WHOLIST_HUNTER");
127127 }
128- work += username;
129- work += " "; //NOI18N
130- DecimalFormat form = new DecimalFormat("#########0"); //NOI18N
131- work += form.format(wk_score);
128+ work += "["; //NOI18N
129+ work += Hunt.trimStringWidth(username, Hunt.WIDTH_VIEW_USERNAME);
130+ work += "]"; //NOI18N
131+ DecimalFormat form = new DecimalFormat("#,##0;-#,##0"); //NOI18N
132+ work += Hunt.rightStringWidth(form.format(wk_score), 11);
132133 work += Hunt.getBundle().getString("LABEL_POINT");
133134 if (buffer[n] != 0) {
134135 work += Hunt.getBundle().getString("WHOLIST_ONLINE");