Пример #1
0
public class Window extends Widget implements DTarget {
  private static final Tex tleft = Resource.loadtex("gfx/hud/wnd/tleft");
  private static final Tex tmain = Resource.loadtex("gfx/hud/wnd/tmain");
  private static final Tex tright = Resource.loadtex("gfx/hud/wnd/tright");
  public static final BufferedImage[] cbtni =
      new BufferedImage[] {
        Resource.loadimg("gfx/hud/wnd/cbtn"),
        Resource.loadimg("gfx/hud/wnd/cbtnd"),
        Resource.loadimg("gfx/hud/wnd/cbtnh")
      };
  public static final BufferedImage[] lbtni =
      new BufferedImage[] {
        Resource.loadimg("gfx/hud/wnd/lbtn"),
        Resource.loadimg("gfx/hud/wnd/lbtnd"),
        Resource.loadimg("gfx/hud/wnd/lbtnh")
      };
  public static final BufferedImage[] rbtni =
      new BufferedImage[] {
        Resource.loadimg("gfx/hud/wnd/rbtn"),
        Resource.loadimg("gfx/hud/wnd/rbtnd"),
        Resource.loadimg("gfx/hud/wnd/rbtnh")
      };
  public static final Color cc = new Color(248, 230, 190);
  public static final Text.Furnace cf =
      new Text.Imager(new Text.Foundry(new Font("Serif", Font.BOLD, 15), cc).aa(true)) {
        protected BufferedImage proc(Text text) {
          return (rasterimg(blurmask2(text.img.getRaster(), 1, 1, Color.BLACK)));
        }
      };
  public static final IBox fbox =
      new IBox("gfx/hud", "ftl", "ftr", "fbl", "fbr", "fl", "fr", "ft", "fb");
  public static final IBox swbox =
      new IBox("gfx/hud", "stl", "str", "sbl", "sbr", "sl", "sr", "st", "sb");
  public static final IBox wbox =
      new IBox("gfx/hud/wnd", "tl", "tr", "bl", "br", "vl", "vr", "ht", "hb");
  private static final IBox topless =
      new IBox(Tex.empty, Tex.empty, wbox.cbl, wbox.cbr, wbox.bl, wbox.br, Tex.empty, wbox.bb);
  private static final int th = tleft.sz().y, tdh = th - tmain.sz().y, tc = tdh + 18;
  private static final Coord capc = new Coord(20, th - 3);
  public Coord mrgn = new Coord(5, 5);
  protected Text cap;
  private boolean dt = false;
  protected boolean dm = false;
  public Coord ctl, csz, atl, asz, ac;
  protected Coord doff;
  protected final IButton cbtn;
  private final Collection<Widget> twdgs = new LinkedList<Widget>();

  // ******************************
  private static final String OPT_POS = "_pos";
  //    static Tex bg = Resource.loadtex("gfx/hud/bgtex");
  //    static Tex cl = Resource.loadtex("gfx/hud/cleft");
  //    static Tex cm = Resource.loadtex("gfx/hud/cmain");
  //    static Tex cr = Resource.loadtex("gfx/hud/cright");
  public Coord tlo, rbo;
  public boolean justclose = false;
  protected final String name;

  @RName("wnd")
  public static class $_ implements Factory {
    public Widget create(Coord c, Widget parent, Object[] args) {
      if (args.length < 2) return (new Window(c, (Coord) args[0], parent, null));
      else return (new Window(c, (Coord) args[0], parent, (String) args[1]));
    }
  }

  public Window(Coord c, Coord sz, Widget parent, String cap) {
    super(c, new Coord(0, 0), parent);
    if (cap != null) {
      this.cap = cf.render(cap);
      name = cap;
    } else {
      this.cap = null;
      name = null;
    }
    resize(sz);
    setfocustab(true);
    parent.setfocus(this);
    cbtn = new IButton(Coord.z, this, cbtni[0], cbtni[1], cbtni[2]);
    cbtn.recthit = true;
    addtwdg(cbtn);
    loadOpts();
  }

  public Coord contentsz() {
    Coord max = new Coord(0, 0);
    for (Widget wdg = child; wdg != null; wdg = wdg.next) {
      if (twdgs.contains(wdg)) continue;
      if (!wdg.visible) continue;
      Coord br = wdg.c.add(wdg.sz);
      if (br.x > max.x) max.x = br.x;
      if (br.y > max.y) max.y = br.y;
    }
    return (max.sub(1, 1));
  }

  protected void placetwdgs() {
    int x = sz.x - 5;
    for (Widget ch : twdgs) ch.c = xlate(new Coord(x -= ch.sz.x + 5, tc - (ch.sz.y / 2)), false);
  }

  public void addtwdg(Widget wdg) {
    twdgs.add(wdg);
    placetwdgs();
  }

  public void resize(Coord sz) {
    IBox box;
    int th;
    if (cap == null) {
      box = wbox;
      th = 0;
    } else {
      box = topless;
      th = Window.th;
    }
    sz = sz.add(box.bisz()).add(0, th).add(mrgn.mul(2));
    this.sz = sz;
    ctl = box.btloff().add(0, th);
    csz = sz.sub(box.bisz()).sub(0, th);
    atl = ctl.add(mrgn);
    asz = csz.sub(mrgn.mul(2));
    ac = new Coord();
    // ac = tlo.add(wbox.btloff()).add(mrgn);
    placetwdgs();
    for (Widget ch = child; ch != null; ch = ch.next) ch.presize();
  }

  public Coord xlate(Coord c, boolean in) {
    if (in) return (c.add(atl));
    else return (c.sub(atl));
  }

  public void cdraw(GOut g) {}

  public void draw(GOut g) {
    g.chcolor(0, 0, 0, 160);
    if (ctl == null || csz == null) {
      return;
    }
    g.frect(ctl, csz);
    g.chcolor();
    cdraw(g.reclip(xlate(Coord.z, true), asz));
    if (cap != null) {
      topless.draw(g, new Coord(0, th), sz.sub(0, th));
      g.image(tleft, Coord.z);
      Coord tmul = new Coord(tleft.sz().x, tdh);
      Coord tmbr = new Coord(sz.x - tright.sz().x, th);
      for (int x = tmul.x; x < tmbr.x; x += tmain.sz().x) {
        g.image(tmain, new Coord(x, tdh), tmul, tmbr);
      }
      g.image(tright, new Coord(sz.x - tright.sz().x, tdh));
      g.image(cap.tex(), capc.sub(0, cap.sz().y));
    } else {
      wbox.draw(g, Coord.z, sz);
    }
    /*
    if(cap != null) {
        GOut cg = og.reclip(new Coord(0, -7), sz.add(0, 7));
        int w = cap.tex().sz().x;
        cg.image(cl, new Coord((sz.x / 2) - (w / 2) - cl.sz().x, 0));
        cg.image(cm, new Coord((sz.x / 2) - (w / 2), 0), new Coord(w, cm.sz().y));
        cg.image(cr, new Coord((sz.x / 2) + (w / 2), 0));
        cg.image(cap.tex(), new Coord((sz.x / 2) - (w / 2), 0));
    }
    */
    super.draw(g);
  }

  public void uimsg(String msg, Object... args) {
    if (msg == "pack") {
      pack();
    } else if (msg == "dt") {
      dt = (Integer) args[0] != 0;
    } else {
      super.uimsg(msg, args);
    }
  }

  public boolean mousedown(Coord c, int button) {
    parent.setfocus(this);
    raise();
    if (super.mousedown(c, button)) return (true);
    if (c.y < tdh && cap != null) return (false);
    if (button == 1) {
      ui.grabmouse(this);
      dm = true;
      doff = c;
    }
    return (true);
  }

  public boolean mouseup(Coord c, int button) {
    if (dm) {
      canceldm();
      storeOpt(OPT_POS, this.c);
    } else {
      super.mouseup(c, button);
    }
    return (true);
  }

  public void canceldm() {
    if (dm) ui.grabmouse(null);
    dm = false;
  }

  public void mousemove(Coord c) {
    if (dm) {
      this.c = this.c.add(c.add(doff.inv()));
    } else {
      super.mousemove(c);
    }
  }

  public void wdgmsg(Widget sender, String msg, Object... args) {
    if (sender == cbtn) {
      if (justclose) ui.destroy(this);
      else wdgmsg("close");
    } else {
      super.wdgmsg(sender, msg, args);
    }
  }

  public boolean type(char key, java.awt.event.KeyEvent ev) {
    if (super.type(key, ev)) return (true);
    if (key == 27) {
      if (justclose) ui.destroy(this);
      else wdgmsg("close");
      return (true);
    }
    return (false);
  }

  public boolean drop(Coord cc, Coord ul) {
    if (dt) {
      wdgmsg("drop", cc);
      return (true);
    }
    return (false);
  }

  public boolean iteminteract(Coord cc, Coord ul) {
    return (false);
  }

  public Object tooltip(Coord c, Widget prev) {
    Object ret = super.tooltip(c, prev);
    if (ret != null) return (ret);
    else return ("");
  }

  protected void storeOpt(String opt, String value) {
    if (name == null) {
      return;
    }
    Config.setWindowOpt(name + opt, value);
  }

  protected void storeOpt(String opt, Coord value) {
    storeOpt(opt, value.toString());
  }

  protected void storeOpt(String opt, boolean value) {
    if (name == null) {
      return;
    }
    Config.setWindowOpt(name + opt, value);
  }

  protected Coord getOptCoord(String opt, Coord def) {
    synchronized (Config.window_props) {
      try {
        return new Coord(Config.window_props.getProperty(name + opt, def.toString()));
      } catch (Exception e) {
        return def;
      }
    }
  }

  protected boolean getOptBool(String opt, boolean def) {
    synchronized (Config.window_props) {
      try {
        return Config.window_props.getProperty(name + opt, null).equals("true");
      } catch (Exception e) {
        return def;
      }
    }
  }

  protected void loadOpts() {
    if (name == null) {
      return;
    }
    c = getOptCoord(OPT_POS, c);
  }
}
Пример #2
0
public class Gobble extends SIWidget {
  public static final BufferedImage bg = Resource.loadimg("gfx/hud/tempers/gbg");
  static Text.Foundry tnf =
      new Text.Foundry(new java.awt.Font("serif", java.awt.Font.BOLD, 16)).aa(true);
  public int[] lev = new int[4];
  public List<TypeMod> mods = new ArrayList<TypeMod>();
  static final Color loc = new Color(0, 128, 255);
  static final Color hic = new Color(0, 128, 64);
  static final BufferedImage[] lobars, hibars;
  private boolean updt = true;
  private TypeList typelist;
  private int[] lmax = new int[4];
  private int max;
  private Tex lvlmask;
  private long lvltime;
  private Tex levels;

  static {
    int n = bars.length;
    BufferedImage[] l = new BufferedImage[n];
    BufferedImage[] h = new BufferedImage[n];
    for (int i = 0; i < n; i++) {
      l[i] = monochromize(bars[i], loc);
      h[i] = monochromize(bars[i], hic);
    }
    lobars = l;
    hibars = h;
  }

  public static class TypeMod {
    public final Indir<Resource> t;
    public double a;
    private Tex rn, rh, ra;

    public TypeMod(Indir<Resource> t, double a) {
      this.t = t;
      this.a = a;
    }
  }

  private class TypeList extends Widget {
    private int nw;

    private TypeList(Coord c, Widget parent) {
      super(c, Coord.z, parent);
    }

    public void tick(double dt) {
      if (updt) {
        nw = 0;
        int aw = 0;
        for (TypeMod m : mods) {
          if (m.rn == null) {
            try {
              BufferedImage img = m.t.get().layer(Resource.imgc).img;
              String nm = m.t.get().layer(Resource.tooltip).t;
              Text rt = tnf.render(nm);
              int h = Inventory.sqsz.y;
              BufferedImage buf = TexI.mkbuf(new Coord(img.getWidth() + 10 + rt.sz().x, h));
              Graphics g = buf.getGraphics();
              g.drawImage(img, 0, (h - img.getHeight()) / 2, null);
              g.drawImage(rt.img, img.getWidth() + 10, (h - rt.sz().y) / 2, null);
              g.dispose();
              m.rn = new TexI(rasterimg(blurmask2(buf.getRaster(), 2, 1, new Color(32, 0, 0))));
              m.rh = new TexI(rasterimg(blurmask2(buf.getRaster(), 2, 1, new Color(192, 128, 0))));
            } catch (Loading l) {
            }
          }
          if (m.ra == null) {
            Text rt =
                tnf.render(
                    (int) Math.round(m.a * 100) + "%",
                    new Color(255, (int) (255 * m.a), (int) (255 * m.a)));
            m.ra = new TexI(rasterimg(blurmask2(rt.img.getRaster(), 2, 1, new Color(0, 0, 0))));
          }
          nw = Math.max(nw, m.rn.sz().x);
          aw = Math.max(aw, m.ra.sz().x);
        }
        int h = (Inventory.sqsz.y + 5) * mods.size();
        h += levels.sz().y + 20;
        resize(new Coord(Math.max(nw + 20 + aw, boxsz.x), h));
        this.c = Gobble.this.parentpos(parent).add(boxc).add(0, boxsz.y + 5);
        updt = false;
      }
    }

    public void draw(GOut g) {
      int tn = 0;
      int y = 0;
      int h = Inventory.sqsz.y;
      boolean[] hl = new boolean[mods.size()];
      if (lfood != null) {
        for (int t : lfood.types) hl[t] = true;
      }
      g.aimage(levels, new Coord(sz.x / 2, y), 0.5, 0);
      y += levels.sz().y + 20;
      for (TypeMod m : mods) {
        if (m.rn != null) g.image(hl[tn] ? m.rh : m.rn, new Coord(0, y));
        if (m.ra != null) g.image(m.ra, new Coord(nw + 20, y + ((h - m.ra.sz().y) / 2)));
        tn++;
        y += h + 5;
      }
    }
  }

  public Gobble(Coord c, Widget parent) {
    super(c, Utils.imgsz(Tempers.bg), parent);
    lcount(0, Color.WHITE);
    typelist = new TypeList(Coord.z, getparent(GameUI.class));
  }

  public void destroy() {
    typelist.destroy();
    super.destroy();
  }

  private GobbleInfo lfood;

  public void tick(double dt) {
    int max = 0;
    int[] lmax = new int[4];
    for (int i = 0; i < 4; i++) {
      lmax[i] = ui.sess.glob.cattr.get(Tempers.anm[i]).base;
      if (lmax[i] == 0) return;
      if (lmax[i] != this.lmax[i]) redraw();
      max = Math.max(max, lmax[i]);
    }
    this.lmax = lmax;
    this.max = max;

    GobbleInfo food = null;
    Alchemy ch = null;
    if (ui.lasttip instanceof WItem.ItemTip) {
      try {
        food = ItemInfo.find(GobbleInfo.class, ((WItem.ItemTip) ui.lasttip).item().info());
        ch = ItemInfo.find(Alchemy.class, ((WItem.ItemTip) ui.lasttip).item().info());
      } catch (Loading e) {
      }
    }
    if (lfood != food) {
      lfood = food;
      redraw();
    }
  }

  private double foodeff(GobbleInfo food) {
    double ret = 1.0;
    for (int t : lfood.types) ret *= mods.get(t).a;
    return (ret);
  }

  private WritableRaster rgmeter(GobbleInfo food, double e, int t) {
    return (alphablit(
        rmeter(hibars[t].getRaster(), lev[t] + (int) (e * food.h[t]), max),
        rmeter(lobars[t].getRaster(), lev[t] + (int) (e * food.l[t]), max),
        Coord.z));
  }

  private WritableRaster lgmeter(GobbleInfo food, double e, int t) {
    return (alphablit(
        lmeter(hibars[t].getRaster(), lev[t] + (int) (e * food.h[t]), max),
        lmeter(lobars[t].getRaster(), lev[t] + (int) (e * food.l[t]), max),
        Coord.z));
  }

  public void draw(BufferedImage buf) {
    WritableRaster dst = buf.getRaster();
    blit(dst, bg.getRaster(), Coord.z);

    alphablit(dst, rmeter(sbars[0].getRaster(), lmax[0], max), mc[0]);
    alphablit(
        dst, lmeter(sbars[1].getRaster(), lmax[1], max), mc[1].sub(bars[1].getWidth() - 1, 0));
    alphablit(
        dst, lmeter(sbars[2].getRaster(), lmax[2], max), mc[2].sub(bars[2].getWidth() - 1, 0));
    alphablit(dst, rmeter(sbars[3].getRaster(), lmax[3], max), mc[3]);

    if (lfood != null) {
      double e = foodeff(lfood);
      alphablit(dst, rgmeter(lfood, e, 0), mc[0]);
      alphablit(dst, lgmeter(lfood, e, 1), mc[1].sub(bars[1].getWidth() - 1, 0));
      alphablit(dst, lgmeter(lfood, e, 2), mc[2].sub(bars[1].getWidth() - 1, 0));
      alphablit(dst, rgmeter(lfood, e, 3), mc[3]);
    }

    alphablit(dst, rmeter(bars[0].getRaster(), lev[0], max), mc[0]);
    alphablit(dst, lmeter(bars[1].getRaster(), lev[1], max), mc[1].sub(bars[1].getWidth() - 1, 0));
    alphablit(dst, lmeter(bars[2].getRaster(), lev[2], max), mc[2].sub(bars[2].getWidth() - 1, 0));
    alphablit(dst, rmeter(bars[3].getRaster(), lev[3], max), mc[3]);

    StringBuilder tbuf = new StringBuilder();
    for (int i = 0; i < 4; i++)
      tbuf.append(
          String.format(
              "%s: %s/%s\n", rnm[i], Utils.fpformat(lev[i], 3, 1), Utils.fpformat(lmax[i], 3, 1)));
    tooltip = RichText.render(tbuf.toString(), 0).tex();
  }

  public void draw(GOut g) {
    super.draw(g);
    if (lvlmask != null) {
      long now = System.currentTimeMillis();
      if (now - lvltime > 1000) {
        lvlmask.dispose();
        lvlmask = null;
      } else {
        g.chcolor(255, 255, 255, 255 - (int) ((255 * (now - lvltime)) / 1000));
        g.image(lvlmask, Coord.z);
      }
    }
  }

  public void updt(int[] n) {
    this.lev = n;
    redraw();
  }

  public void lvlup(int a) {
    WritableRaster buf = imgraster(imgsz(bg));
    if ((a == 0) || (a == 3)) alphablit(buf, rmeter(bars[a].getRaster(), 1, 1), mc[a]);
    else alphablit(buf, lmeter(bars[a].getRaster(), 1, 1), mc[a].sub(bars[a].getWidth() - 1, 0));
    imgblur(buf, 2, 2);
    lvlmask = new TexI(rasterimg(buf));
    lvltime = System.currentTimeMillis();
  }

  public void lcount(int n, Color c) {
    Text rt = tnf.render(String.format("Gobble Points: %d", n), c);
    levels = new TexI(rasterimg(blurmask2(rt.img.getRaster(), 2, 1, new Color(0, 0, 0))));
  }

  public void typemod(Indir<Resource> t, double a) {
    updt = true;
    for (TypeMod m : mods) {
      if (m.t == t) {
        m.a = a;
        m.ra = null;
        return;
      }
    }
    mods.add(new TypeMod(t, a));
  }

  public Object tooltip(Coord c, Widget prev) {
    if (!c.isect(boxc, boxsz)) return (null);
    return (super.tooltip(c, prev));
  }
}
Пример #3
0
  RootWindow(Container container, Screen screen, Format[] format, Client c) {
    super(screen.rootId);
    rootwindow = container;
    client = c;
    screen.setRoot((Window) this);
    this.width = (short) (screen.width);
    this.height = (short) (screen.height);
    this.screen = screen;
    depth = screen.rootDepth;
    id = screen.rootId;
    type = DRAWABLE_WINDOW;
    x = y = 0;
    origin.x = 0;
    origin.y = 0;
    clss = (byte) InputOutput;
    for (int i = 0; i < format.length; i++) {
      if (format[i].depth == screen.rootDepth) {
        this.bitsPerPixel = format[i].bpp;
      }
    }
    setVisual(screen.rootVisual);
    setBackgroundIsPixel();
    background.pixel = screen.white;

    setBorderIsPixel();
    border.pixel = screen.black;
    borderWidth = 0;
    Resource.add(this);
    makeOptional();
    attr &= ~(1 << 3); // cursorIsNone

    optional.cursor = Cursor.rootCursor;
    setColormap(screen.defaultColormap);

    //  if(rootwindow instanceof JFrame){
    //    rootwindow.setSize(this.width+10, this.height+30); // ??
    //  }
    //  else{
    rootwindow.setSize(this.width, this.height);
    //  }

    try {
      ddxwindow = (DDXWindow) (Window.dDXWindow.newInstance());
    } catch (Exception e) {
      System.err.println(e);
      /*ddxwindow=new DDXWindowImp();*/
    }

    ddxwindow.init(this);
    ddxwindow.setLocation(0, 0);

    if (rootwindow instanceof Frame) {
      // ((Frame)rootwindow).setLayout(null);
      ((Frame) rootwindow).setResizable(false);
      ((Frame) rootwindow).setMenuBar(null);
      ((Frame) rootwindow).add((java.awt.Component) ddxwindow);
    } else if (rootwindow instanceof Applet) {
      ((Applet) rootwindow).add((java.awt.Component) ddxwindow);
    }
    /*
        else if(rootwindow instanceof JFrame){
          ((JFrame)rootwindow).getContentPane().setLayout(null);
          ((JFrame)rootwindow).setResizable(false);
          ((JFrame)rootwindow).setJMenuBar(null);
          ((JFrame)rootwindow).getContentPane().add((java.awt.Component)ddxwindow);
        }
        else if(rootwindow instanceof JWindow){
          ((JWindow)rootwindow).getContentPane().setLayout(null);
          ((JWindow)rootwindow).getContentPane().add((java.awt.Component)ddxwindow);
        }
        else if (rootwindow instanceof JApplet){
          ((JApplet)rootwindow).setJMenuBar(null);
          ((JApplet)rootwindow).getContentPane().add((java.awt.Component)ddxwindow);
        }
    */
    else {
      rootwindow.add((java.awt.Component) ddxwindow);
    }

    if (screen.windowmode != WeirdX.InBrowser) {
      rootwindow.addNotify();
    } else {
      rootwindow.setVisible(true);
    }
    ddxwindow.setVisible(true);

    {
      rootwindow.validate();
      Insets insets = rootwindow.getInsets();
      rootwindow.setSize(
          this.width + insets.left + insets.right, this.height + insets.top + insets.bottom);
      ddxwindow.setLocation(insets.left, insets.top);
      rootwindow.validate();
    }

    ddxwindow.requestFocus();
    Window.focus.win = id;

    Window.LOCK = rootwindow.getTreeLock();
    Client.LOCK = rootwindow.getTreeLock();
    Resource.LOCK = rootwindow.getTreeLock();

    spriteTrace[0] = this;
    sprite.win = this;
  }