chuni: add userbox sub trophy, fix unlock challenge

This commit is contained in:
Dniel97
2025-08-31 19:49:06 +02:00
parent 3c7ac3ac58
commit 415bbc92b3
6 changed files with 73 additions and 19 deletions

View File

@@ -44,7 +44,25 @@
<tr><td>Nameplate:</td><td style="width: 80%;"><div id="name_nameplate"></div></td></tr>
<tr><td>Trophy:</td><td><div id="name_trophy">
<select name="trophy" id="trophy" onchange="changeTrophy()" style="width:100%;">
<select name="trophy" id="trophy" onclick="changeTrophy()" style="width:100%;">
{% for item in trophies.values() %}
<option value="{{ item["id"] }}" class="trophy-rank{{ item["rarity"] }}">{{ item["name"] }}</option>
{% endfor %}
</select>
</div></td></tr>
<tr><td>Trophy Sub 1:</td><td><div id="name_trophy">
<select name="trophy-sub-1" id="trophy-sub-1" onclick="changeTrophySub1()" style="width:100%;">
<option value="-1"></option>
{% for item in trophies.values() %}
<option value="{{ item["id"] }}" class="trophy-rank{{ item["rarity"] }}">{{ item["name"] }}</option>
{% endfor %}
</select>
</div></td></tr>
<tr><td>Trophy Sub 2:</td><td><div id="name_trophy">
<select name="trophy-sub-2" id="trophy-sub-2" onclick="changeTrophySub2()" style="width:100%;">
<option value="-1"></option>
{% for item in trophies.values() %}
<option value="{{ item["id"] }}" class="trophy-rank{{ item["rarity"] }}">{{ item["name"] }}</option>
{% endfor %}
@@ -124,7 +142,10 @@ userbox_components = {
};
types = Object.keys(userbox_components);
orig_trophy = curr_trophy = "{{ profile.trophyId }}";
orig_trophy_sub_1 = curr_trophy_sub_1 = "{{ profile.trophyIdSub1 }}";
orig_trophy_sub_2 = curr_trophy_sub_2 = "{{ profile.trophyIdSub2 }}";
curr_trophy_img = "";
curr_trophy_name = "";
function enableButtons(enabled) {
document.getElementById("reset-btn").disabled = !enabled;
@@ -169,6 +190,7 @@ function changeTrophy() {
var trophy_element = document.getElementById("trophy");
curr_trophy = trophy_element.value;
curr_trophy_name = trophy_element[trophy_element.selectedIndex].innerText
curr_trophy_img = getRankImage(trophy_element[trophy_element.selectedIndex]);
updatePreview();
if (curr_trophy != orig_trophy) {
@@ -176,12 +198,38 @@ function changeTrophy() {
}
}
function changeTrophySub1() {
var trophy_element = document.getElementById("trophy-sub-1");
curr_trophy_sub_1 = trophy_element.value;
curr_trophy_img = getRankImage(trophy_element[trophy_element.selectedIndex]);
curr_trophy_name = trophy_element[trophy_element.selectedIndex].innerText
updatePreview();
if (curr_trophy_sub_1 != orig_trophy_sub_1) {
enableButtons(true);
}
}
function changeTrophySub2() {
var trophy_element = document.getElementById("trophy-sub-2");
curr_trophy_sub_2 = trophy_element.value;
curr_trophy_img = getRankImage(trophy_element[trophy_element.selectedIndex]);
curr_trophy_name = trophy_element[trophy_element.selectedIndex].innerText
updatePreview();
if (curr_trophy_sub_2 != orig_trophy_sub_2) {
enableButtons(true);
}
}
function resetUserbox() {
for (const type of types) {
changeItem(type, userbox_components[type][orig_id], userbox_components[type][orig_name], userbox_components[type][orig_img]);
}
// reset trophy
document.getElementById("trophy").value = orig_trophy;
document.getElementById("trophy-sub-1").value = orig_trophy_sub_1;
document.getElementById("trophy-sub-2").value = orig_trophy_sub_2;
changeTrophy();
// disable the save/reset buttons until something changes
enableButtons(false);
@@ -193,12 +241,14 @@ function updatePreview() {
document.getElementById("name_" + type).innerHTML = userbox_components[type][curr_name];
}
document.getElementById("preview_trophy_rank").src = "img/rank/" + curr_trophy_img;
document.getElementById("preview_trophy_name").innerHTML = document.getElementById("trophy")[document.getElementById("trophy").selectedIndex].innerText;
document.getElementById("preview_trophy_name").innerHTML = curr_trophy_name;
}
function saveUserbox() {
$.post("/game/chuni/update.userbox", { nameplate: userbox_components["nameplate"][curr_id],
trophy: curr_trophy,
trophy: curr_trophy,
trophySub1: curr_trophy_sub_1,
trophySub2: curr_trophy_sub_2,
character: userbox_components["character"][curr_id] })
.done(function (data) {
// set the current as the original and disable buttons
@@ -207,7 +257,9 @@ function saveUserbox() {
userbox_components[type][orig_name] = userbox_components[type][orig_name];
userbox_components[type][orig_img] = userbox_components[type][curr_img];
}
orig_trophy = curr_trophy
orig_trophy = curr_trophy;
orig_trophy_sub_1 = curr_trophy_sub_1;
orig_trophy_sub_2 = curr_trophy_sub_2;
enableButtons(false);
})
.fail(function () {