/* * This file is part of the Haven & Hearth game client. * Copyright (C) 2009 Fredrik Tolf <fredrik@dolda2000.com>, and * Björn Johannessen <johannessen.bjorn@gmail.com> * * 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 haven.ItemInfo.Name; import java.awt.Color; import java.util.Collections; import java.util.List; public class GItem extends AWidget implements ItemInfo.ResOwner { public static volatile long infoUpdated; static ItemFilter filter = null; private static long lastFilter = 0; public Indir<Resource> res; public int meter = 0; public int num = -1; private Object[] rawinfo; private List<ItemInfo> info = Collections.emptyList(); public boolean sendttupdate = false; public boolean matched = false; private long filtered = 0; public boolean drop = false; private double dropTimer = 0; public static void setFilter(ItemFilter filter) { GItem.filter = filter; lastFilter = System.currentTimeMillis(); } @RName("item") public static class $_ implements Factory { public Widget create(Coord c, Widget parent, Object[] args) { int res = (Integer)args[0]; return(new GItem(c, parent, parent.ui.sess.getres(res))); } } public interface ColorInfo { public Color olcol(); } public interface NumberInfo { public int itemnum(); } public class Amount extends ItemInfo implements NumberInfo { private final int num; public Amount(int num) { super(GItem.this); this.num = num; } public int itemnum() { return(num); } } public GItem(Widget parent, Indir<Resource> res) { this(Coord.z, parent, res); } public GItem(Coord c, Widget parent, Indir<Resource> res) { super(parent); this.c = c; this.res = res; } public Glob glob() { return(ui.sess.glob); } public List<ItemInfo> info() { if(info == null) info = ItemInfo.buildinfo(this, rawinfo); return(info); } public Resource resource() { return(res.get()); } public String resname(){ Resource res = resource(); if(res != null){ return res.name; } return ""; } public String name() { if(info != null) { Name name = ItemInfo.find(Name.class, info); return name != null ? name.str.text : null; } return null; } public void testMatch() { if(filtered < lastFilter){ matched = filter != null && filter.matches(info()); filtered = lastFilter; } } @Override public void tick(double dt) { super.tick(dt); if(drop) { dropTimer += dt; if (dropTimer > 0.1) { dropTimer = 0; wdgmsg("take", Coord.z); ui.message("Dropping bat!", GameUI.MsgType.BAD); } } } public void uimsg(String name, Object... args) { if(name == "num") { num = (Integer)args[0]; } else if(name == "chres") { res = ui.sess.getres((Integer)args[0]); } else if(name == "tt") { info = null; rawinfo = args; filtered = 0; if(sendttupdate){wdgmsg("ttupdate");} } else if(name == "meter") { meter = (Integer)args[0]; } } }