Files
chocomae/src/game/lib/text/ranking_text.js
T

192 lines
4.9 KiB
JavaScript

function RankingText(type, x, y, appID) {
this.type = type;
this.appID = appID;
this.playerID = -1;
this.textRanking = this.makeRankingText(x, y);
this.textRanking.anchor.x = 1;
this.textPlayerName = this.makePlayerNameText(x, y);
this.textPlayerName.anchor.x = 0;
this.textRecord = this.makeRecordText(x, y);
this.textRecord.anchor.x = 1;
};
RankingText.prototype.makeText = function(x, y, fontStyle) {
var text = game.add.text(x, y, "", fontStyle);
text.anchor.y = 0.5;
text.inputEnabled = false;
if(this.type == RankingText.PLACE_FOR_RANKING)
text.setShadow(3, 3, 'rgba(32, 32, 32, 1)', 2);
else
text.setShadow(1, 1, 'rgba(32, 32, 32, 1)', 2);
return text;
};
RankingText.prototype.makeRankingText = function(x, y) {
var fontStyle = null;
var offsetX = 0;
if(this.type == RankingText.PLACE_FOR_RANKING) {
fontStyle = RankingText.FONT_STYLE_FOR_RANKING;
offsetX = 40;
}
else {
fontStyle = RankingText.FONT_STYLE_FOR_RESULT;
offsetX = 30;
}
return this.makeText(x + offsetX, y, fontStyle);
};
RankingText.prototype.makePlayerNameText = function(x, y) {
var fontStyle = null;
var offsetX = 0;
if(this.type == RankingText.PLACE_FOR_RANKING) {
fontStyle = RankingText.FONT_STYLE_FOR_RANKING;
offsetX = 70;
}
else {
fontStyle = RankingText.FONT_STYLE_FOR_RESULT;
offsetX = 40;
}
return this.makeText(x + offsetX, y, fontStyle);
};
RankingText.prototype.makeRecordText = function(x, y) {
var fontStyle = null;
var offsetX = 0;
if(this.type == RankingText.PLACE_FOR_RANKING) {
fontStyle = RankingText.FONT_STYLE_FOR_RANKING;
offsetX = 340;
}
else {
fontStyle = RankingText.FONT_STYLE_FOR_RESULT;
offsetX = 200;
}
return this.makeText(x + offsetX, y, fontStyle);
};
RankingText.prototype.resetText = function(text) {
text.text = "";
text.fill = "#ffffff";
text.stroke = "#888888";
text.strokeThickness = 0;
};
RankingText.prototype.reset = function() {
this.playerID = -1;
this.resetText(this.textRanking);
this.resetText(this.textPlayerName);
this.resetText(this.textRecord);
};
RankingText.prototype.setTextRankingColor = function(text, ranking) {
var fillColor = "";
var strokeColor = "";
switch(ranking) {
case 1:
fillColor = "#ffd700"; // gold
strokeColor = "#cd853f";
break;
case 2:
fillColor = "#d0d0d0"; // silver
strokeColor = "#404040";
break;
case 3:
fillColor = "#d2691e"; // bronze
strokeColor = "#8b0000";
break;
}
text.fill = fillColor;
text.stroke = strokeColor;
text.strokeThickness = 6;
text.setShadow(2, 2, "#333333", 2, false, true);
};
RankingText.prototype.setTopRankingTextColor = function(ranking) {
if(ranking < 4) {
this.setTextRankingColor(this.textRanking, ranking);
this.setTextRankingColor(this.textPlayerName, ranking);
this.setTextRankingColor(this.textRecord, ranking);
}
};
RankingText.prototype.setMyRankingTextColor = function() {
if(sessionStorageManager.getPlayerID() != this.playerID)
return;
var fillColor = "#9acd32"; // yellowgreen
var strokeColor = "#2e8b57"; // seagreen
this.textRanking.fill = fillColor;
this.textRanking.stroke = strokeColor;
this.textRanking.strokeThickness = 2;
this.textPlayerName.fill = fillColor;
this.textPlayerName.stroke = strokeColor;
this.textPlayerName.strokeThickness = 2;
this.textRecord.fill = fillColor;
this.textRecord.stroke = strokeColor;
this.textRecord.strokeThickness = 2;
};
RankingText.prototype.setRankingMinusTextColor = function(ranking) {
// console.log(ranking);
if(ranking >= 0)
return;
var fillColor = "#ddaaaa"; // yellowgreen
// var strokeColor = "#2e8b57"; // seagreen
this.textRanking.fill = fillColor;
// this.textRanking.stroke = strokeColor;
// this.textRanking.strokeThickness = 2;
this.textPlayerName.fill = fillColor;
// this.textPlayerName.stroke = strokeColor;
// this.textPlayerName.strokeThickness = 2;
this.textRecord.fill = fillColor;
// this.textRecord.stroke = strokeColor;
// this.textRecord.strokeThickness = 2;
};
RankingText.prototype.setContents = function(playerID, ranking, playerName, record) {
this.reset();
this.playerID = playerID;
if(record >= 0)
this.textRanking.text = ranking + "등";
else
this.textRanking.text = "실격";
this.textPlayerName.text = playerName;
this.setRecord(record, this.appID);
this.setTopRankingTextColor(ranking);
this.setRankingMinusTextColor(ranking);
this.setMyRankingTextColor();
};
RankingText.prototype.setRecord = function(record, appID) {
// this.textRecord.text = RecordUtil.getRecordValueWithUnit(record, appID);
var recordValue = record >= 0 ? record : -1 * record;
var absRecordValue = RecordUtil.getRecordValueWithUnit(
recordValue,
sessionStorageManager.getPlayingAppID()
);
this.textRecord.text = absRecordValue;
};
RankingText.FONT_STYLE_FOR_RANKING = {
font: "32px Arial",
fill: "#fff"
};
RankingText.FONT_STYLE_FOR_RESULT = {
font: "19px Arial",
fill: "#fff"
};
RankingText.PLACE_FOR_RANKING = 0;
RankingText.PLACE_FOR_RESULT = 1;