- Added levellump, skillname, playerclass, playername, ammo1tag, ammo2tag, weapontag, inventorytag, globalvar <int>, and globalarray <int> to drawstring.

- String constants starting in '$' will cause drawstring to reference the language lump.
- Added pushup transition for strife popups.  This elulates the stats screen from hexen 2.  This behaves identical to slideinbottom if the primary statusbar has fullscreenoffsets set.

SVN r2299 (trunk)
This commit is contained in:
Braden Obrzut 2010-04-22 23:38:11 +00:00
parent 82af1640fd
commit bd40bba37c
3 changed files with 225 additions and 69 deletions

View file

@ -57,6 +57,7 @@
#include "g_level.h" #include "g_level.h"
#include "v_palette.h" #include "v_palette.h"
#include "p_acs.h" #include "p_acs.h"
#include "gstrings.h"
#define ADJUST_RELCENTER(x, y, outX, outY) \ #define ADJUST_RELCENTER(x, y, outX, outY) \
if(x.RelCenter()) \ if(x.RelCenter()) \
@ -615,6 +616,13 @@ void SBarInfo::ParseSBarInfo(int lump)
sc.MustGetToken(TK_IntConst); sc.MustGetToken(TK_IntConst);
popup.speed = sc.Number; popup.speed = sc.Number;
} }
else if(sc.Compare("pushup"))
{
popup.transition = Popup::TRANSITION_PUSHUP;
sc.MustGetToken(',');
sc.MustGetToken(TK_IntConst);
popup.speed = sc.Number;
}
else if(sc.Compare("fade")) else if(sc.Compare("fade"))
{ {
popup.transition = Popup::TRANSITION_FADE; popup.transition = Popup::TRANSITION_FADE;
@ -722,78 +730,79 @@ SBarInfo::~SBarInfo()
} }
//Popup //Popup
Popup::Popup() Popup::Popup() : transition(TRANSITION_NONE), opened(false), moving(false),
height(320), width(200), speed(0), speed2(0), alpha(FRACUNIT), x(320),
y(200), displacementX(0), displacementY(0)
{ {
transition = TRANSITION_NONE;
height = 320;
width = 200;
speed = 0;
x = 320;
y = 200;
alpha = FRACUNIT;
opened = false;
moving = false;
} }
void Popup::init() void Popup::init()
{ {
x = width; x = width;
y = height; y = height;
if(transition == TRANSITION_SLIDEINBOTTOM) switch(transition)
{ {
x = 0; case TRANSITION_SLIDEINBOTTOM:
} case TRANSITION_PUSHUP:
else if(transition == TRANSITION_FADE) x = 0;
{ break;
alpha = 0; case TRANSITION_FADE:
x = 0; alpha = 0;
y = 0; x = 0;
y = 0;
break;
default:
break;
} }
} }
void Popup::tick() void Popup::tick()
{ {
if(transition == TRANSITION_SLIDEINBOTTOM) switch(transition)
{ {
if(moving) case TRANSITION_SLIDEINBOTTOM:
{ case TRANSITION_PUSHUP:
if(opened) if(moving)
y -= clamp(height + (y - height), 1, speed); {
int oldY = y;
if(opened)
y -= clamp(height + (y - height), 1, speed);
else
y += clamp(height - y, 1, speed);
if(transition == TRANSITION_PUSHUP)
displacementY += y - oldY;
}
if(y != 0 && y != height)
moving = true;
else else
y += clamp(height - y, 1, speed); moving = false;
} break;
if(y != 0 && y != height) case TRANSITION_FADE:
moving = true; if(moving)
else {
moving = false; if(opened)
} alpha = clamp(alpha + speed, 0, FRACUNIT);
else if(transition == TRANSITION_FADE) else
{ alpha = clamp(alpha - speed2, 0, FRACUNIT);
if(moving) }
{ if(alpha == 0 || alpha == FRACUNIT)
if(opened) moving = false;
alpha = clamp(alpha + speed, 0, FRACUNIT);
else else
alpha = clamp(alpha - speed2, 0, FRACUNIT); moving = true;
} break;
if(alpha == 0 || alpha == FRACUNIT) default:
if(opened)
{
y = 0;
x = 0;
}
else
{
y = height;
x = width;
}
moving = false; moving = false;
else break;
moving = true;
}
else
{
if(opened)
{
y = 0;
x = 0;
}
else
{
y = height;
x = width;
}
moving = false;
} }
} }
@ -819,6 +828,16 @@ int Popup::getAlpha(int maxAlpha)
return fixed_t((a * b) * FRACUNIT); return fixed_t((a * b) * FRACUNIT);
} }
int Popup::getXDisplacement()
{
return displacementX;
}
int Popup::getYDisplacement()
{
return displacementY;
}
void Popup::open() void Popup::open()
{ {
opened = true; opened = true;
@ -914,8 +933,13 @@ public:
armor = CPlayer->mo->FindInventory<ABasicArmor>(); armor = CPlayer->mo->FindInventory<ABasicArmor>();
if(hud != lastHud) if(hud != lastHud)
script->huds[hud]->Tick(NULL, this, true); script->huds[hud]->Tick(NULL, this, true);
script->huds[hud]->Draw(NULL, this, 0, 0, FRACUNIT);
if(currentPopup != POP_None && !script->huds[hud]->FullScreenOffsets())
script->huds[hud]->Draw(NULL, this, script->popups[currentPopup-1].getXDisplacement(), script->popups[currentPopup-1].getYDisplacement(), FRACUNIT);
else
script->huds[hud]->Draw(NULL, this, 0, 0, FRACUNIT);
lastHud = hud; lastHud = hud;
if(CPlayer->inventorytics > 0 && !(level.flags & LEVEL_NOINVENTORYBAR) && (state == HUD_StatusBar || state == HUD_Fullscreen)) if(CPlayer->inventorytics > 0 && !(level.flags & LEVEL_NOINVENTORYBAR) && (state == HUD_StatusBar || state == HUD_Fullscreen))
{ {
SBarInfoMainBlock *inventoryBar = state == HUD_StatusBar ? script->huds[STBAR_INVENTORY] : script->huds[STBAR_INVENTORYFULLSCREEN]; SBarInfoMainBlock *inventoryBar = state == HUD_StatusBar ? script->huds[STBAR_INVENTORY] : script->huds[STBAR_INVENTORYFULLSCREEN];

View file

@ -52,6 +52,7 @@ struct Popup
{ {
TRANSITION_NONE, TRANSITION_NONE,
TRANSITION_SLIDEINBOTTOM, TRANSITION_SLIDEINBOTTOM,
TRANSITION_PUSHUP,
TRANSITION_FADE, TRANSITION_FADE,
}; };
@ -65,6 +66,8 @@ struct Popup
int alpha; int alpha;
int x; int x;
int y; int y;
int displacementX;
int displacementY;
Popup(); Popup();
void init(); void init();
@ -75,6 +78,8 @@ struct Popup
int getXOffset(); int getXOffset();
int getYOffset(); int getYOffset();
int getAlpha(int maxAlpha=FRACUNIT); int getAlpha(int maxAlpha=FRACUNIT);
int getXDisplacement();
int getYDisplacement();
}; };
struct SBarInfo struct SBarInfo

View file

@ -515,7 +515,7 @@ class CommandDrawString : public SBarInfoCommand
public: public:
CommandDrawString(SBarInfo *script) : SBarInfoCommand(script), CommandDrawString(SBarInfo *script) : SBarInfoCommand(script),
shadow(false), spacing(0), font(NULL), translation(CR_UNTRANSLATED), shadow(false), spacing(0), font(NULL), translation(CR_UNTRANSLATED),
value(CONSTANT), valueArg(0) cache(-1), strValue(CONSTANT), valueArgument(0)
{ {
} }
@ -535,18 +535,50 @@ class CommandDrawString : public SBarInfoCommand
if(sc.CheckToken(TK_Identifier)) if(sc.CheckToken(TK_Identifier))
{ {
if(sc.Compare("levelname")) if(sc.Compare("levelname"))
strValue = LEVELNAME;
else if(sc.Compare("levellump"))
strValue = LEVELLUMP;
else if(sc.Compare("skillname"))
strValue = SKILLNAME;
else if(sc.Compare("playerclass"))
strValue = PLAYERCLASS;
else if(sc.Compare("playername"))
strValue = PLAYERNAME;
else if(sc.Compare("ammo1tag"))
strValue = AMMO1TAG;
else if(sc.Compare("ammo2tag"))
strValue = AMMO2TAG;
else if(sc.Compare("weapontag"))
strValue = WEAPONTAG;
else if(sc.Compare("inventorytag"))
strValue = INVENTORYTAG;
else if(sc.Compare("globalvar"))
{ {
value = LEVELNAME; strValue = GLOBALVAR;
valueArg = -1; sc.MustGetToken(TK_IntConst);
if(sc.Number < 0 || sc.Number >= NUM_GLOBALVARS)
sc.ScriptError("Global variable number out of range: %d", sc.Number);
valueArgument = sc.Number;
}
else if(sc.Compare("globalarray"))
{
strValue = GLOBALARRAY;
sc.MustGetToken(TK_IntConst);
if(sc.Number < 0 || sc.Number >= NUM_GLOBALVARS)
sc.ScriptError("Global variable number out of range: %d", sc.Number);
valueArgument = sc.Number;
} }
else else
sc.ScriptError("Unknown string '%s'.", sc.String); sc.ScriptError("Unknown string '%s'.", sc.String);
} }
else else
{ {
value = CONSTANT; strValue = CONSTANT;
sc.MustGetToken(TK_StringConst); sc.MustGetToken(TK_StringConst);
str = sc.String; if(sc.String[0] == '$')
str = GStrings[sc.String+1];
else
str = sc.String;
} }
sc.MustGetToken(','); sc.MustGetToken(',');
GetCoordinates(sc, fullScreenOffsets, x, y); GetCoordinates(sc, fullScreenOffsets, x, y);
@ -562,25 +594,102 @@ class CommandDrawString : public SBarInfoCommand
else //monospaced, so just multiplay the character size else //monospaced, so just multiplay the character size
x -= static_cast<int> ((font->GetCharWidth((int) script->spacingCharacter) + spacing) * str.Len()); x -= static_cast<int> ((font->GetCharWidth((int) script->spacingCharacter) + spacing) * str.Len());
} }
void Reset()
{
switch(strValue)
{
case PLAYERCLASS:
// userinfo changes before the actual class change.
case SKILLNAME:
// Although it's not possible for the skill level to change
// midlevel, it is possible the level was restarted.
cache = -1;
break;
default:
break;
}
}
void Tick(const SBarInfoMainBlock *block, const DSBarInfo *statusBar, bool hudChanged) void Tick(const SBarInfoMainBlock *block, const DSBarInfo *statusBar, bool hudChanged)
{ {
switch(value) switch(strValue)
{ {
case LEVELNAME: case LEVELNAME:
if(level.lumpnum != valueArg) if(level.lumpnum != cache)
{ {
valueArg = level.lumpnum; cache = level.lumpnum;
str = level.LevelName; str = level.LevelName;
} }
break; break;
case LEVELLUMP:
if(level.lumpnum != cache)
{
cache = level.lumpnum;
str = level.mapname;
}
break;
case SKILLNAME:
if(level.lumpnum != cache) // Can only change skill between level.
{
cache = level.lumpnum;
str = G_SkillName();
}
break;
case PLAYERCLASS:
if(statusBar->CPlayer->userinfo.PlayerClass != cache)
{
cache = statusBar->CPlayer->userinfo.PlayerClass;
str = statusBar->CPlayer->cls->Meta.GetMetaString(APMETA_DisplayName);
}
break;
case AMMO1TAG:
SetStringToTag(statusBar->ammo1);
break;
case AMMO2TAG:
SetStringToTag(statusBar->ammo2);
break;
case WEAPONTAG:
SetStringToTag(statusBar->CPlayer->ReadyWeapon);
break;
case INVENTORYTAG:
SetStringToTag(statusBar->CPlayer->mo->InvSel);
break;
case PLAYERNAME:
// Can't think of a good way to detect changes to this, so
// I guess copying it every tick will have to do.
str = statusBar->CPlayer->userinfo.netname;
break;
case GLOBALVAR:
if(ACS_GlobalVars[valueArgument] != cache)
{
cache = ACS_GlobalVars[valueArgument];
str = FBehavior::StaticLookupString(ACS_GlobalVars[valueArgument]);
}
break;
case GLOBALARRAY:
if(ACS_GlobalArrays[valueArgument][consoleplayer] != cache)
{
cache = ACS_GlobalArrays[valueArgument][consoleplayer];
str = FBehavior::StaticLookupString(ACS_GlobalArrays[valueArgument][consoleplayer]);
}
break;
default: default:
break; break;
} }
} }
protected: protected:
enum ValueType enum StringValueType
{ {
LEVELNAME, LEVELNAME,
LEVELLUMP,
SKILLNAME,
PLAYERCLASS,
PLAYERNAME,
AMMO1TAG,
AMMO2TAG,
WEAPONTAG,
INVENTORYTAG,
GLOBALVAR,
GLOBALARRAY,
CONSTANT CONSTANT
}; };
@ -591,9 +700,28 @@ class CommandDrawString : public SBarInfoCommand
EColorRange translation; EColorRange translation;
SBarInfoCoordinate x; SBarInfoCoordinate x;
SBarInfoCoordinate y; SBarInfoCoordinate y;
ValueType value; int cache; /// General purpose cache.
int valueArg; StringValueType strValue;
int valueArgument;
FString str; FString str;
private:
void SetStringToTag(AActor *actor)
{
if(actor != NULL)
{
if(actor->GetClass()->ClassIndex != cache)
{
cache = actor->GetClass()->ClassIndex;
str = actor->GetTag();
}
}
else
{
cache = -1;
str = "";
}
}
}; };
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -604,7 +732,7 @@ class CommandDrawNumber : public CommandDrawString
CommandDrawNumber(SBarInfo *script) : CommandDrawString(script), CommandDrawNumber(SBarInfo *script) : CommandDrawString(script),
fillZeros(false), whenNotZero(false), interpolationSpeed(0), drawValue(0), fillZeros(false), whenNotZero(false), interpolationSpeed(0), drawValue(0),
length(3), lowValue(-1), lowTranslation(CR_UNTRANSLATED), highValue(-1), length(3), lowValue(-1), lowTranslation(CR_UNTRANSLATED), highValue(-1),
highTranslation(CR_UNTRANSLATED), value(CONSTANT), valueArgument(0), highTranslation(CR_UNTRANSLATED), value(CONSTANT),
inventoryItem(NULL) inventoryItem(NULL)
{ {
} }
@ -987,7 +1115,6 @@ class CommandDrawNumber : public CommandDrawString
EColorRange highTranslation; EColorRange highTranslation;
EColorRange normalTranslation; EColorRange normalTranslation;
ValueType value; ValueType value;
int valueArgument;
const PClass *inventoryItem; const PClass *inventoryItem;
SBarInfoCoordinate startX; SBarInfoCoordinate startX;