From aa2e3a3c274b598e2e68298db78eb4c6aab311a5 Mon Sep 17 00:00:00 2001 From: Ketmar Dark Date: Mon, 4 Apr 2016 23:14:28 +0300 Subject: [PATCH] HUD drawing script --- d2dsprite.d | 12 ++++++-- data/scripts/api/hud.dacs | 26 ++++++++++++++++++ data/scripts/d2dhud.dacs | 70 +++++++++++++++++++++++++++++++++++++++++++++++ data/scripts/dacsmain.txt | 1 + dengapi.d | 66 +++++++++++++++++++++++++++++++++----------- render.d | 9 ++++++ 6 files changed, 165 insertions(+), 19 deletions(-) create mode 100644 data/scripts/api/hud.dacs create mode 100644 data/scripts/d2dhud.dacs diff --git a/d2dsprite.d b/d2dsprite.d index 9090953..c42fd8a 100644 --- a/d2dsprite.d +++ b/d2dsprite.d @@ -135,7 +135,7 @@ public final class ImgSpriteMirrored : ImgSprite { // ////////////////////////////////////////////////////////////////////////// // -ImgSprite loadSpriteIntr (string spfilename, bool checkMirror) { +ImgSprite loadSpriteIntr (string spfilename, bool checkMirror, bool updateAtlas) { if (spfilename.length == 0) return null; ImgSprite im; if (auto imm = spfilename in sprImages) { @@ -149,7 +149,12 @@ ImgSprite loadSpriteIntr (string spfilename, bool checkMirror) { if (checkMirror && spnameReal.endsWith("_mirrored.vga")) { // for mirrored, load normal sprite and create mirrored one spnameReal = spnameReal[0..$-13]~".vga"; - if (auto imm = spnameReal in sprImages) im = *imm; else im = loadSpriteIntr(spnameReal, false); + if (auto imm = spnameReal in sprImages) { + im = *imm; + } else { + im = loadSpriteIntr(spnameReal, false, updateAtlas); + if (im !is null && updateAtlas) realiseSpriteAtlases(); + } if (im is null) return null; im = new ImgSpriteMirrored(im); assert(im.mirrored); @@ -160,6 +165,7 @@ ImgSprite loadSpriteIntr (string spfilename, bool checkMirror) { //conwriteln("loading sprite '", spfilename, "'"); im.vga = new D2DImage(spfilename); im.putToAtlas(); + if (updateAtlas) realiseSpriteAtlases(); } sprImages[spfilename] = im; } @@ -167,4 +173,4 @@ ImgSprite loadSpriteIntr (string spfilename, bool checkMirror) { } -public ImgSprite loadSprite (string spfilename) { return loadSpriteIntr(spfilename, true); } +public ImgSprite loadSprite (string spfilename, bool updateAtlas=false) { return loadSpriteIntr(spfilename, true, updateAtlas); } diff --git a/data/scripts/api/hud.dacs b/data/scripts/api/hud.dacs new file mode 100644 index 0000000..cb6dc91 --- /dev/null +++ b/data/scripts/api/hud.dacs @@ -0,0 +1,26 @@ +/* DooM2D: Midnight on the Firing Line + * coded by Ketmar // Invisible Vector + * Understanding is not required. Only obedience. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * 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. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +module apiHud; + +public extern int viewportHeight () pure; +public extern int viewportWidth () pure; + +public extern int spriteWidth (string spfile); +public extern int spriteHeight (string spfile); + +public extern void drawSpriteAt (string spfile, int x, int y); diff --git a/data/scripts/d2dhud.dacs b/data/scripts/d2dhud.dacs new file mode 100644 index 0000000..4ac7d73 --- /dev/null +++ b/data/scripts/d2dhud.dacs @@ -0,0 +1,70 @@ +/* DooM2D: Midnight on the Firing Line + * coded by Ketmar // Invisible Vector + * Understanding is not required. Only obedience. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * 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. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +module d2dhud is "engine" "hud"; + +import apiActor; +import apiMap; +import apiMove; +import apiHud; +import stdlib; + +import d2dplayer; // for some actor fields + + +const KeyFrameBase = 0; + + +// precache sprites +/* +public void initializeAnim () { + animClearFrames("engine", "hud", "sleep"); + // keys + animAddFrame("engine", "hud", "sleep", ACTOR_DIR_LEFT, "sprites/items/keyra0.vga"); + animAddFrame("engine", "hud", "sleep", ACTOR_DIR_LEFT, "sprites/items/keyga0.vga"); + animAddFrame("engine", "hud", "sleep", ACTOR_DIR_LEFT, "sprites/items/keyba0.vga"); +} +*/ + + +public void drawHud () { + auto pl = getPlayerActor(1); + //writeln("pl.classname: ", pl.classname); + if (pl.dead || !pl.isPlayer) return; + // draw keys + // WARNING: keep in sync with INV_ITEM_KEY_xxx + //writeln("HUD"); + auto inv = pl.invitems; + for (int kn = 0; kn < 3; ++kn) { + if (inv&(1<