Skip to content

Commit

Permalink
Merge pull request #384 from Chameleonhider/master
Browse files Browse the repository at this point in the history
Configure-able player name drawing
  • Loading branch information
yvt committed Mar 5, 2016
2 parents 7d9ee6f + 39a7c74 commit 355d1f2
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 28 deletions.
2 changes: 2 additions & 0 deletions Sources/Client/ChatWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ namespace spades {
return w ? ConvertColor(w->GetTeam(2).color) : MakeVector4( 1, 1, 0, 1 );
case MsgColorRed:
return MakeVector4(1,0,0,1);
case MsgColorBlack:
return MakeVector4(0,0,0,1);
case MsgColorSysInfo:
return MakeVector4(0,1,0,1);
default:
Expand Down
1 change: 1 addition & 0 deletions Sources/Client/ChatWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ namespace spades {
static const char MsgColorSysInfo = MsgColorGreen;
static const char MsgColorRestore = 6;
static const char MsgImage = 7;
static const char MsgColorBlack = 8;
static const char MsgColorMax = 9;

class ChatWindow {
Expand Down
19 changes: 16 additions & 3 deletions Sources/Client/Client_Draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ SPADES_SETTING(cg_keyReloadWeapon, "");
SPADES_SETTING(cg_screenshotFormat, "jpeg");
SPADES_SETTING(cg_stats, "0");
SPADES_SETTING(cg_hideHud, "0");
SPADES_SETTING(cg_playerNames, "2");
SPADES_SETTING(cg_playerNameX, "0");
SPADES_SETTING(cg_playerNameY, "0");

namespace spades {
namespace client {
Expand Down Expand Up @@ -300,17 +303,27 @@ namespace spades {
void Client::DrawHottrackedPlayerName() {
SPADES_MARK_FUNCTION();

if ((int)cg_playerNames == 0)
return;

Player *p = GetWorld()->GetLocalPlayer();

hitTag_t tag = hit_None;
Player *hottracked = HotTrackedPlayer( &tag );
if(hottracked){
Vector3 posxyz = Project(hottracked->GetEye());
Vector2 pos = {posxyz.x, posxyz.y};
float dist = (hottracked->GetEye() - p->GetEye()).GetLength();
int idist = (int)floorf(dist + .5f);
char buf[64];
sprintf(buf, "%s [%d%s]", hottracked->GetName().c_str(), idist, (idist == 1) ? "block":"blocks");
if ((int)cg_playerNames == 1){
float dist = (hottracked->GetEye() - p->GetEye()).GetLength();
int idist = (int)floorf(dist + .5f);
sprintf(buf, "%s [%d%s]", hottracked->GetName().c_str(), idist, (idist == 1) ? "block" : "blocks");
}
else
sprintf(buf, "%s", hottracked->GetName().c_str());

pos.y += (int)cg_playerNameY;
pos.x += (int)cg_playerNameX;

IFont *font = textFont;
Vector2 size = font->Measure(buf);
Expand Down
13 changes: 2 additions & 11 deletions Sources/Client/Client_Input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,11 +377,6 @@ namespace spades {
playerInput.crouch = down;
}else if(CheckKey(cg_keySprint, name)){
playerInput.sprint = down;
if(down){
if(world->GetLocalPlayer()->IsToolWeapon()){
weapInput.secondary = false;
}
}
}else if(CheckKey(cg_keySneak, name)){
playerInput.sneak = down;
}else if(CheckKey(cg_keyJump, name)){
Expand All @@ -394,15 +389,11 @@ namespace spades {
}else if(CheckKey(cg_keyAltAttack, name)){
auto lastVal = weapInput.secondary;
if(world->GetLocalPlayer()->IsToolWeapon() && (!cg_holdAimDownSight)){
if(down && !playerInput.sprint && !world->GetLocalPlayer()->GetWeapon()->IsReloading()){
if(down && !world->GetLocalPlayer()->GetWeapon()->IsReloading()){
weapInput.secondary = !weapInput.secondary;
}
}else{
if(!playerInput.sprint){
weapInput.secondary = down;
}else{
weapInput.secondary = down;
}
weapInput.secondary = down;
}
if(world->GetLocalPlayer()->IsToolWeapon() && weapInput.secondary && !lastVal &&
world->GetLocalPlayer()->IsReadyToUseTool() &&
Expand Down
31 changes: 19 additions & 12 deletions Sources/Client/Client_NetHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include "Client.h"
#include <cstdlib>
#include <Core/Strings.h>
#include <Core/Settings.h>
#include <Core/Strings.h>

#include "IAudioDevice.h"
#include "IAudioChunk.h"
Expand All @@ -38,6 +40,8 @@

#include "NetClient.h"

SPADES_SETTING(cg_centerMessage, "1");

namespace spades {
namespace client {

Expand Down Expand Up @@ -87,16 +91,19 @@ namespace spades {
}
chatWindow->AddMessage(msg);

teamName = world->GetTeam(teamId).name;
if(old < 2){
std::string otherTeam = world->GetTeam(old).name;
msg = _Tr("Client", "{0} captured {1}'s Territory", teamName, otherTeam);
}else{
msg = _Tr("Client", "{0} captured an Neutral Territory", teamName);
if ((int)cg_centerMessage != 0){
teamName = world->GetTeam(teamId).name;
if (old < 2){
std::string otherTeam = world->GetTeam(old).name;
msg = _Tr("Client", "{0} captured {1}'s Territory", teamName, otherTeam);
}
else{
msg = _Tr("Client", "{0} captured an Neutral Territory", teamName);
}
NetLog("%s", msg.c_str());
centerMessageView->AddMessage(msg);
}
NetLog("%s", msg.c_str());
centerMessageView->AddMessage(msg);


if(world->GetLocalPlayer() && !IsMuted()){
if(teamId == world->GetLocalPlayer()->GetTeamId()){
Handle<IAudioChunk> chunk = audioDevice->RegisterSound("Sounds/Feedback/TC/YourTeamCaptured.wav");
Expand All @@ -120,7 +127,7 @@ namespace spades {
chatWindow->AddMessage(msg);
}

{
if ((int)cg_centerMessage != 0){
std::string holderName = p->GetName();
std::string otherTeamName = world->GetTeam(1 - p->GetTeamId()).name;
msg = _Tr("Client", "{0} captured {1}'s Intel.", holderName, otherTeamName);
Expand Down Expand Up @@ -149,7 +156,7 @@ namespace spades {
chatWindow->AddMessage(msg);
}

{
if ((int)cg_centerMessage != 0){
std::string holderName = p->GetName();
std::string otherTeamName = world->GetTeam(1 - p->GetTeamId()).name;
msg = _Tr("Client", "{0} picked up {1}'s Intel.", holderName, otherTeamName);
Expand All @@ -173,7 +180,7 @@ namespace spades {
chatWindow->AddMessage(msg);
}

{
if ((int)cg_centerMessage != 0){
std::string holderName = p->GetName();
std::string otherTeamName = world->GetTeam(1 - p->GetTeamId()).name;
msg = _Tr("Client", "{0} dropped {1}'s Intel", holderName, otherTeamName);
Expand Down
5 changes: 4 additions & 1 deletion Sources/Client/Client_Update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ SPADES_SETTING(cg_blood, "1");
SPADES_SETTING(cg_ejectBrass, "1");

SPADES_SETTING(cg_alerts, "");
SPADES_SETTING(cg_centerMessage, "");


namespace spades {
Expand Down Expand Up @@ -876,6 +877,8 @@ namespace spades {

if(ff)
s += ChatWindow::ColoredMessage(cause, MsgColorRed);
else if (killer == world->GetLocalPlayer() || victim == world->GetLocalPlayer())
s += ChatWindow::ColoredMessage(cause, MsgColorBlack);
else
s += cause;

Expand Down Expand Up @@ -906,7 +909,7 @@ namespace spades {
if(killer == local || victim == local){
std::string msg;
if( killer == local ) {
msg = _Tr("Client", "You have killed {0}", victim->GetName());
if ((int)cg_centerMessage == 2) msg = _Tr("Client", "You have killed {0}", victim->GetName());
} else {
msg = _Tr("Client", "You were killed by {0}", killer->GetName());
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Client/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ namespace spades {
if(!IsAlive())
return;

if(input.sprint){
if(input.sprint && !input.crouch && (input.moveBackward || input.moveForward || input.moveLeft || input.moveRight)){
newInput.primary = false;
newInput.secondary = false;
}
Expand Down

0 comments on commit 355d1f2

Please sign in to comment.