From bdb9275f8c428c4635014de8c30453ba13297ba2 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 25 Mar 2017 01:22:42 +0100 Subject: [PATCH] - made the mugshot accessible to ZScript. Note that there is no direct access, all this exposes is a single function to get the current face's texture which then can be drawn using the existing functions. --- src/g_statusbar/sbar.h | 1 + src/g_statusbar/shared_sbar.cpp | 21 +++++++++++++++++++ wadsrc/static/zscript/statusbar/statusbar.txt | 21 ++++++++++++++++++- 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/g_statusbar/sbar.h b/src/g_statusbar/sbar.h index 0b3f676ca..0079d5b71 100644 --- a/src/g_statusbar/sbar.h +++ b/src/g_statusbar/sbar.h @@ -443,6 +443,7 @@ public: double drawClip[4] = { 0,0,0,0 }; // defines a clipping rectangle (not used yet) bool fullscreenOffsets = false; // current screen is displayed with fullscreen behavior. DVector2 cleanScale; // factor for scaled fullscreen display. + FMugShot mugshot; private: bool RepositionCoords (int &x, int &y, int xo, int yo, const int w, const int h) const; diff --git a/src/g_statusbar/shared_sbar.cpp b/src/g_statusbar/shared_sbar.cpp index c3925cb51..51106914e 100644 --- a/src/g_statusbar/shared_sbar.cpp +++ b/src/g_statusbar/shared_sbar.cpp @@ -431,6 +431,7 @@ void DBaseStatusBar::CallTick() GlobalVMStack.Call(func, params, countof(params), nullptr, 0); } else Tick(); + mugshot.Tick(CPlayer); } //--------------------------------------------------------------------------- @@ -1023,6 +1024,7 @@ void DBaseStatusBar::SetMugShotState(const char *stateName, bool waitTillDone, b VMValue params[] = { (DObject*)this, &statestring, waitTillDone, reset }; GlobalVMStack.Call(func, params, countof(params), nullptr, 0); } + mugshot.SetState(stateName, waitTillDone, reset); } //--------------------------------------------------------------------------- @@ -1196,6 +1198,7 @@ void DBaseStatusBar::NewGame () VMValue params[] = { (DObject*)this }; GlobalVMStack.Call(func, params, countof(params), nullptr, 0); } + mugshot.Reset(); } void DBaseStatusBar::ShowPop(int pop) @@ -1776,3 +1779,21 @@ DEFINE_ACTION_FUNCTION(DBaseStatusBar, FormatNumber) else fmt.Format("%s%*d", prefix.GetChars(), minsize, number); ACTION_RETURN_STRING(fmt); } + +DEFINE_ACTION_FUNCTION(DBaseStatusBar, ReceivedWeapon) +{ + PARAM_SELF_PROLOGUE(DBaseStatusBar); + self->mugshot.Grin(); + return 0; +} + +DEFINE_ACTION_FUNCTION(DBaseStatusBar, GetMugshot) +{ + PARAM_SELF_PROLOGUE(DBaseStatusBar); + PARAM_POINTER(player, player_t); + PARAM_STRING(def_face); + PARAM_INT(accuracy); + PARAM_INT_DEF(stateflags); + auto tex = self->mugshot.GetFace(player, def_face, accuracy, (FMugShot::StateFlags)stateflags); + ACTION_RETURN_INT(tex ? tex->id.GetIndex() : -1); +} diff --git a/wadsrc/static/zscript/statusbar/statusbar.txt b/wadsrc/static/zscript/statusbar/statusbar.txt index 059c602fd..2a1b92492 100644 --- a/wadsrc/static/zscript/statusbar/statusbar.txt +++ b/wadsrc/static/zscript/statusbar/statusbar.txt @@ -1,4 +1,21 @@ +struct MugShot +{ + enum StateFlags + { + STANDARD = 0x0, + + XDEATHFACE = 0x1, + ANIMATEDGODMODE = 0x2, + DISABLEGRIN = 0x4, + DISABLEOUCH = 0x8, + DISABLEPAIN = 0x10, + DISABLERAMPAGE = 0x20, + CUSTOM = 0x40, + } +} + + class BaseStatusBar native ui { enum EPop @@ -156,17 +173,18 @@ class BaseStatusBar native ui native virtual void Tick (); native virtual void Draw (int state, double TicFrac); native virtual void ScreenSizeChanged (); + native virtual clearscope void ReceivedWeapon (Weapon weapn); virtual void FlashItem (class itemtype) {} virtual void AttachToPlayer (PlayerInfo player) { CPlayer = player; } virtual void FlashCrosshair () { CrosshairSize = XHAIRPICKUPSIZE; } virtual void NewGame () {} virtual void ShowPop (int popnum) { ShowLog = (popnum == POP_Log && !ShowLog); } - virtual clearscope void ReceivedWeapon (Weapon weapn) {} virtual bool MustDrawLog(int state) { return true; } virtual void SetMugShotState (String state_name, bool wait_till_done=false, bool reset=false) {} native void RefreshBackground () const; + native TextureID GetMugshot(PlayerInfo player, String default_face, int accuracy, int stateflags=MugShot.STANDARD); // These functions are kept native solely for performance reasons. They get called repeatedly and can drag down performance easily if they get too slow. native Inventory ValidateInvFirst (int numVisible) const; @@ -676,6 +694,7 @@ class BaseStatusBar native ui DrawTexture(texture, pos, animated, screenalign, alpha, boxsize, itemAlign, flags); } } + } //============================================================================