Skip to content

Commit

Permalink
phex - changed the way names are drawn, maybe this fixes a bug
Browse files Browse the repository at this point in the history
  • Loading branch information
hetuw committed Jul 17, 2020
1 parent f79a47b commit efc31f7
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 20 deletions.
3 changes: 0 additions & 3 deletions gameSource/LivingLifePage.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

#include "TextField.h"

#include <string>

#define NUM_HUNGER_BOX_SPRITES 20

Expand Down Expand Up @@ -311,8 +310,6 @@ typedef struct LiveObject {
char shouldDrawPathMarks;
double pathMarkFade;

std::string phexHash;

// messages that arrive while we're still showing our current
// movement animation
SimpleVector<char*> pendingReceivedMessages;
Expand Down
11 changes: 7 additions & 4 deletions gameSource/hetuwmod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2781,8 +2781,9 @@ void HetuwMod::drawPlayerNames( LiveObject* player ) {
getRelationNameColor( player->relationName, playerNameColor );

setDrawColor( 0.0, 0.0, 0.0, 0.8 );
if ( itsTimeToDrawPhexName() && player->phexHash.length() > 0) {
std::string* name = Phex::getUserDisplayName(Phex::users[player->phexHash]);
if (itsTimeToDrawPhexName() &&
Phex::playerIdToHash.find(player->id) != Phex::playerIdToHash.end()) {
std::string* name = Phex::getUserDisplayName(Phex::playerIdToHash[player->id]);
float textWidth = customFont->measureString( name->c_str() );
drawRect( playerNamePos, textWidth/2 + 6, 16 );
setDrawColor( playerNameColor[0], playerNameColor[1], playerNameColor[2], 1 );
Expand Down Expand Up @@ -2825,10 +2826,12 @@ void HetuwMod::drawHighlightedPlayer() {
livingLifePage->hetuwDrawScaledHandwritingFont( player->curseName, playerNamePos, guiScale, alignCenter );
playerNamePos.y -= 32*guiScale;
}
if ( itsTimeToDrawPhexName() && player->phexHash.length() > 0) {
if (itsTimeToDrawPhexName() &&
Phex::playerIdToHash.find(player->id) != Phex::playerIdToHash.end()) {

double scale = customFont->hetuwGetScaleFactor();
customFont->hetuwSetScaleFactor(scale * guiScale);
std::string* name = Phex::getUserDisplayName(Phex::users[player->phexHash]);
std::string* name = Phex::getUserDisplayName(Phex::playerIdToHash[player->id]);
textWidth = customFont->measureString( name->c_str() );
setDrawColor( 0.0, 0.0, 0.0, 0.8 );
drawRect( playerNamePos, textWidth/2 + 6*guiScale, 16*guiScale );
Expand Down
24 changes: 13 additions & 11 deletions gameSource/phex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ std::string Phex::strCmdChar;

std::string Phex::publicHash = "";
std::unordered_map<std::string, Phex::User> Phex::users;
std::unordered_map<int, std::string> Phex::playerIdToHash;

bool Phex::hasFocus = false;
bool Phex::isMinimized = false;
Expand Down Expand Up @@ -351,7 +352,7 @@ void Phex::serverCmdSAY(std::vector<std::string> input) {
chatElement.text = joinStr(input, " ", 4);

createUser(chatElement.hash);
chatElement.name = string(*getUserDisplayName(users[chatElement.hash]));
chatElement.name = string(*getUserDisplayName(chatElement.hash));

chatElement.textToDraw = colorCodeNamesInChat+chatElement.name+": "+colorCodeWhite+chatElement.text;
mainChatWindow.addElement(chatElement);
Expand Down Expand Up @@ -448,8 +449,8 @@ void Phex::serverCmdHASH_SERVER_LIFE(std::vector<std::string> input) {
printf("Phex cant find player with id: %d\n", playerID);
return;
}
player->phexHash = string(input[1]);
createUser(input[1]);
playerIdToHash[playerID] = input[1];
users[input[1]].inGameServerPlayerID = playerID;
} catch(std::exception const & ex) {
printf("Phex EXCEPTION when receiving HASH_SERVER_LIFE command\n");
Expand Down Expand Up @@ -702,20 +703,21 @@ void Phex::Text::draw() {
HetuwMod::hDrawRecFromPercent(drawRec);
}

void Phex::createUser(std::string hash) {
void Phex::createUser(std::string &hash) {
users[hash].hash = hash;
//if (users.find(hash) == users.end()) return;
}

std::string* Phex::getUserDisplayName(User &user) {
if (user.displayName.length() > 0) return &user.displayName;
user.displayName = string(user.name);
if (user.displayName.length() < 1) {
user.displayName = user.hash;
if (user.displayName.length() > ChatElement::maxHashDisplayLength)
user.displayName = user.displayName.substr(0, ChatElement::maxHashDisplayLength);
std::string* Phex::getUserDisplayName(std::string &hash) {
createUser(hash);
if (users[hash].displayName.length() > 0) return &users[hash].displayName;
users[hash].displayName = string(users[hash].name);
if (users[hash].displayName.length() < 1) {
users[hash].displayName = users[hash].hash;
if (users[hash].displayName.length() > ChatElement::maxHashDisplayLength)
users[hash].displayName = users[hash].displayName.substr(0, ChatElement::maxHashDisplayLength);
}
return &user.displayName;
return &users[hash].displayName;
}

time_t Phex::strToTimeT(std::string str) {
Expand Down
5 changes: 3 additions & 2 deletions gameSource/phex.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ class Phex {

static std::string publicHash;
static std::unordered_map<std::string, User> users;
static std::unordered_map<int, std::string> playerIdToHash;

static bool hasFocus;
static bool isMinimized;
Expand Down Expand Up @@ -340,8 +341,8 @@ class Phex {
static double getLineHeight(HetuwFont *font);
static void drawString(std::string str, doublePair startPos);

static void createUser(std::string hash);
static std::string* getUserDisplayName(User &user);
static void createUser(std::string &hash);
static std::string* getUserDisplayName(std::string &hash);

static time_t strToTimeT(std::string str);
static void addCmdMessageToChatWindow(std::string msg, int type = 1);
Expand Down

0 comments on commit efc31f7

Please sign in to comment.