Guest User

Untitled

a guest
May 22nd, 2013
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.86 KB | None | 0 0
  1. /*
  2.  *  This file is part of the Haven & Hearth game client.
  3.  *  Copyright (C) 2009 Fredrik Tolf <[email protected]>, and
  4.  *                     Björn Johannessen <[email protected]>
  5.  *
  6.  *  Redistribution and/or modification of this file is subject to the
  7.  *  terms of the GNU Lesser General Public License, version 3, as
  8.  *  published by the Free Software Foundation.
  9.  *
  10.  *  This program is distributed in the hope that it will be useful,
  11.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  *  GNU General Public License for more details.
  14.  *
  15.  *  Other parts of this source tree adhere to other copying
  16.  *  rights. Please see the file `COPYING' in the root directory of the
  17.  *  source tree for details.
  18.  *
  19.  *  A copy the GNU Lesser General Public License is distributed along
  20.  *  with the source tree of which this file is a part in the file
  21.  *  `doc/LPGL-3'. If it is missing for any reason, please see the Free
  22.  *  Software Foundation's website at <http://www.fsf.org/>, or write
  23.  *  to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  24.  *  Boston, MA 02111-1307 USA
  25.  */
  26.  
  27. package haven;
  28.  
  29. import java.io.BufferedReader;
  30. import java.io.DataInputStream;
  31. import java.io.FileInputStream;
  32. import java.io.FileNotFoundException;
  33. import java.io.IOException;
  34. import java.io.InputStreamReader;
  35.  
  36. import femmod.AccountsPanel;
  37. import femmod.AccountsPanel.AccountAddPanel;
  38. import femmod.AccountsPanel.AccountData;
  39. import femmod.ServerStatusWnd;
  40.  
  41. public class LoginScreen extends Widget {
  42.     public static LoginScreen Instance;
  43.     public Text error;
  44.     IButton btn;
  45.     static Text.Foundry textf, textfs;
  46.     Tex bg = Resource.loadtex("gfx/loginscr");
  47.     Tex logo = Resource.loadtex("gfx/logo");
  48.     Text progress = null;
  49.  
  50.     // multilogin windows
  51.     AccountsPanel accountsWidget = null;
  52.     AccountAddPanel accountsAddWidget = null;
  53.  
  54.     static {
  55.         textf = new Text.Foundry(new java.awt.Font("Sans", java.awt.Font.PLAIN, 16));
  56.         textfs = new Text.Foundry(new java.awt.Font("Sans", java.awt.Font.PLAIN, 14));
  57.     }
  58.  
  59.     public LoginScreen(Widget parent) {
  60.         super(Coord.z, new Coord(800, 600), parent);
  61.  
  62.         setfocustab(true);
  63.         parent.setfocus(this);
  64.         new Img(Coord.z, bg, this);
  65.         new Img(new Coord(420, 215).add(logo.sz().div(2).inv()), logo, this);
  66.  
  67.         new ServerStatusWnd(this);
  68.         // show changelog on first run after update;
  69.         // boolean same = Config.currentVersion.equals(MainFrame.VERSION);
  70.         // if (!same) {
  71.         // Config.currentVersion = MainFrame.VERSION;
  72.         // Config.saveOptions();
  73.         // showChangelog();
  74.         // }
  75.  
  76.         Instance = this;
  77.     }
  78.  
  79.     @SuppressWarnings("unused")
  80.     private void showChangelog() {
  81.         Window wnd = new Window(new Coord(100, 50), new Coord(50, 50), ui.root, "Changelog");
  82.         wnd.justclose = true;
  83.         Textlog txt = new Textlog(Coord.z, new Coord(350, 500), wnd);
  84.         int maxlines = txt.maxLines = 200;
  85.         wnd.pack();
  86.         try {
  87.             FileInputStream fstream;
  88.             fstream = new FileInputStream("changelog.txt");
  89.             DataInputStream in = new DataInputStream(fstream);
  90.             BufferedReader br = new BufferedReader(new InputStreamReader(in, "UTF-8"));
  91.             String strLine;
  92.             int count = 0;
  93.             while ((count < maxlines) && (strLine = br.readLine()) != null) {
  94.                 txt.append(strLine);
  95.                 count++;
  96.             }
  97.             br.close();
  98.             in.close();
  99.             fstream.close();
  100.         } catch (FileNotFoundException e) {
  101.         } catch (IOException e) {
  102.         }
  103.         txt.setprog(0);
  104.     }
  105.  
  106.     private void mklogin() {
  107.         synchronized (ui) {
  108.             progress(null);
  109.         }
  110.     }
  111.  
  112.     public void error(String error) {
  113.         synchronized (ui) {
  114.             if (this.error != null)
  115.                 this.error = null;
  116.             if (error != null)
  117.                 this.error = textf.render(error, java.awt.Color.RED);
  118.         }
  119.     }
  120.  
  121.     private void progress(String p) {
  122.         synchronized (ui) {
  123.             if (progress != null)
  124.                 progress = null;
  125.             if (p != null)
  126.                 progress = textf.render(p, java.awt.Color.WHITE);
  127.         }
  128.     }
  129.  
  130.     public void clear() {
  131.         synchronized (ui) {
  132.             if (accountsWidget != null) {
  133.                 ui.destroy(accountsWidget);
  134.                 accountsWidget = null;
  135.             }
  136.             if (accountsAddWidget != null) {
  137.                 ui.destroy(accountsAddWidget);
  138.                 accountsAddWidget = null;
  139.             }
  140.  
  141.             try {
  142.                 throw new Exception();
  143.             } catch (Exception e) {
  144.                 e.printStackTrace();
  145.             }
  146.  
  147.             accountsWidget = new AccountsPanel(new Coord(50, 70), new Coord(300, 600), this);
  148.             accountsAddWidget = accountsWidget.new AccountAddPanel(new Coord(35, 10), new Coord(300, 100), this);
  149.             mklogin();
  150.         }
  151.     }
  152.  
  153.     // ////////////////////////////////////////////////////////////////////
  154.     // Widget methods
  155.     public void wdgmsg(Widget sender, String msg, Object... args) {
  156.         if (sender == accountsWidget) {
  157.             if (msg == "accountLogin") {
  158.                 AccountData account = (AccountData) args[0];
  159.  
  160.                 if (account != null)
  161.                     super.wdgmsg("login", new Object[] { account.Name, account.Pass, false });
  162.             }
  163.         } else if (sender == accountsAddWidget)
  164.             accountsWidget.wdgmsg(sender, msg, args);
  165.         else
  166.             super.wdgmsg(sender, msg, args);
  167.     }
  168.  
  169.     public void uimsg(String msg, Object... args) {
  170.         synchronized (ui) {
  171.             if (msg == "passwd") {
  172.                 clear();
  173.             } else if (msg == "token") {
  174.                 super.wdgmsg("forget");
  175.             } else if (msg == "error") {
  176.                 error((String) args[0]);
  177.             } else if (msg == "prg") {
  178.                 error(null);
  179.                 clear();
  180.                 progress((String) args[0]);
  181.             }
  182.         }
  183.     }
  184.  
  185.     public void draw(GOut g) {
  186.         c = MainFrame.getCenterPoint().sub(400, 300);
  187.         super.draw(g);
  188.         if (error != null)
  189.             g.image(error.tex(), new Coord(420 - (error.sz().x / 2), 500));
  190.         if (progress != null)
  191.             g.image(progress.tex(), new Coord(420 - (progress.sz().x / 2), 350));
  192.     }
  193.  
  194.     public boolean type(char k, java.awt.event.KeyEvent ev) {
  195.         // if( k == 10 )
  196.         // {
  197.         // if( ( accountsWidget != null ) && accountsWidget.enter() ) wdgmsg(
  198.         // "login", new Object[] { account.Name, account.Pass } );
  199.         // return ( true );
  200.         // }
  201.         return (super.type(k, ev));
  202.     }
  203. }
Advertisement
Add Comment
Please, Sign In to add comment