Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * This file is part of the Haven & Hearth game client.
- * Copyright (C) 2009 Fredrik Tolf <[email protected]>, and
- * Björn Johannessen <[email protected]>
- *
- * Redistribution and/or modification of this file is subject to the
- * terms of the GNU Lesser General Public License, version 3, as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * Other parts of this source tree adhere to other copying
- * rights. Please see the file `COPYING' in the root directory of the
- * source tree for details.
- *
- * A copy the GNU Lesser General Public License is distributed along
- * with the source tree of which this file is a part in the file
- * `doc/LPGL-3'. If it is missing for any reason, please see the Free
- * Software Foundation's website at <http://www.fsf.org/>, or write
- * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
- * Boston, MA 02111-1307 USA
- */
- package haven;
- import java.io.BufferedReader;
- import java.io.DataInputStream;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import femmod.AccountsPanel;
- import femmod.AccountsPanel.AccountAddPanel;
- import femmod.AccountsPanel.AccountData;
- import femmod.ServerStatusWnd;
- public class LoginScreen extends Widget {
- public static LoginScreen Instance;
- public Text error;
- IButton btn;
- static Text.Foundry textf, textfs;
- Tex bg = Resource.loadtex("gfx/loginscr");
- Tex logo = Resource.loadtex("gfx/logo");
- Text progress = null;
- // multilogin windows
- AccountsPanel accountsWidget = null;
- AccountAddPanel accountsAddWidget = null;
- static {
- textf = new Text.Foundry(new java.awt.Font("Sans", java.awt.Font.PLAIN, 16));
- textfs = new Text.Foundry(new java.awt.Font("Sans", java.awt.Font.PLAIN, 14));
- }
- public LoginScreen(Widget parent) {
- super(Coord.z, new Coord(800, 600), parent);
- setfocustab(true);
- parent.setfocus(this);
- new Img(Coord.z, bg, this);
- new Img(new Coord(420, 215).add(logo.sz().div(2).inv()), logo, this);
- new ServerStatusWnd(this);
- // show changelog on first run after update;
- // boolean same = Config.currentVersion.equals(MainFrame.VERSION);
- // if (!same) {
- // Config.currentVersion = MainFrame.VERSION;
- // Config.saveOptions();
- // showChangelog();
- // }
- Instance = this;
- }
- @SuppressWarnings("unused")
- private void showChangelog() {
- Window wnd = new Window(new Coord(100, 50), new Coord(50, 50), ui.root, "Changelog");
- wnd.justclose = true;
- Textlog txt = new Textlog(Coord.z, new Coord(350, 500), wnd);
- int maxlines = txt.maxLines = 200;
- wnd.pack();
- try {
- FileInputStream fstream;
- fstream = new FileInputStream("changelog.txt");
- DataInputStream in = new DataInputStream(fstream);
- BufferedReader br = new BufferedReader(new InputStreamReader(in, "UTF-8"));
- String strLine;
- int count = 0;
- while ((count < maxlines) && (strLine = br.readLine()) != null) {
- txt.append(strLine);
- count++;
- }
- br.close();
- in.close();
- fstream.close();
- } catch (FileNotFoundException e) {
- } catch (IOException e) {
- }
- txt.setprog(0);
- }
- private void mklogin() {
- synchronized (ui) {
- progress(null);
- }
- }
- public void error(String error) {
- synchronized (ui) {
- if (this.error != null)
- this.error = null;
- if (error != null)
- this.error = textf.render(error, java.awt.Color.RED);
- }
- }
- private void progress(String p) {
- synchronized (ui) {
- if (progress != null)
- progress = null;
- if (p != null)
- progress = textf.render(p, java.awt.Color.WHITE);
- }
- }
- public void clear() {
- synchronized (ui) {
- if (accountsWidget != null) {
- ui.destroy(accountsWidget);
- accountsWidget = null;
- }
- if (accountsAddWidget != null) {
- ui.destroy(accountsAddWidget);
- accountsAddWidget = null;
- }
- try {
- throw new Exception();
- } catch (Exception e) {
- e.printStackTrace();
- }
- accountsWidget = new AccountsPanel(new Coord(50, 70), new Coord(300, 600), this);
- accountsAddWidget = accountsWidget.new AccountAddPanel(new Coord(35, 10), new Coord(300, 100), this);
- mklogin();
- }
- }
- // ////////////////////////////////////////////////////////////////////
- // Widget methods
- public void wdgmsg(Widget sender, String msg, Object... args) {
- if (sender == accountsWidget) {
- if (msg == "accountLogin") {
- AccountData account = (AccountData) args[0];
- if (account != null)
- super.wdgmsg("login", new Object[] { account.Name, account.Pass, false });
- }
- } else if (sender == accountsAddWidget)
- accountsWidget.wdgmsg(sender, msg, args);
- else
- super.wdgmsg(sender, msg, args);
- }
- public void uimsg(String msg, Object... args) {
- synchronized (ui) {
- if (msg == "passwd") {
- clear();
- } else if (msg == "token") {
- super.wdgmsg("forget");
- } else if (msg == "error") {
- error((String) args[0]);
- } else if (msg == "prg") {
- error(null);
- clear();
- progress((String) args[0]);
- }
- }
- }
- public void draw(GOut g) {
- c = MainFrame.getCenterPoint().sub(400, 300);
- super.draw(g);
- if (error != null)
- g.image(error.tex(), new Coord(420 - (error.sz().x / 2), 500));
- if (progress != null)
- g.image(progress.tex(), new Coord(420 - (progress.sz().x / 2), 350));
- }
- public boolean type(char k, java.awt.event.KeyEvent ev) {
- // if( k == 10 )
- // {
- // if( ( accountsWidget != null ) && accountsWidget.enter() ) wdgmsg(
- // "login", new Object[] { account.Name, account.Pass } );
- // return ( true );
- // }
- return (super.type(k, ev));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment