general_pool 에서 장수 선택 기능 추가

This commit is contained in:
2020-12-31 07:43:56 +09:00
parent 187db3d011
commit 3e35dec9fa
66 changed files with 5597 additions and 1319 deletions
+42
View File
@@ -372,4 +372,46 @@ function getNpcColor(npcType) {
return 'skyblue';
}
return null;
}
function initTooltip($obj) {
if ($obj === undefined) {
$obj = $('.obj_tooltip');
} else if (!$obj.hasClass('obj_tooltip')) {
$obj = $obj.find('.obj_tooltip');
}
console.log($obj);
$obj.each(function() {
$target = $(this);
if ($target.data('installHandler')) {
return true;
}
$target.data('installHandler', true);
$target.mouseover(function() {
var $objTooltip = $(this);
if ($objTooltip.data('setObjTooltip')) {
return true;
}
var tooltipClassText = $objTooltip.data('tooltip-class');
if (!tooltipClassText) {
tooltipClassText = '';
}
var template = '<div class="tooltip {0}" role="tooltip"><div class="arrow"></div><div class="tooltip-inner"></div></div>'
.format(tooltipClassText);
$objTooltip.tooltip({
title: function() {
return $.trim($(this).find('.tooltiptext').html());
},
template: template,
html: true
}).tooltip('show');
$objTooltip.data('setObjTooltip', true);
});
});
}
+74 -76
View File
@@ -1,4 +1,3 @@
/*
function showCityGeneral(cityIdx){
@@ -21,13 +20,13 @@ function loadScenarioPreview(scenarioIdx){
function loadScenarios(){
function loadScenarios() {
$.ajax({
method:'post',
url:'j_load_scenarios.php',
dataType:'json'
}).then(function(result){
if(!result.result){
method: 'post',
url: 'j_load_scenarios.php',
dataType: 'json'
}).then(function(result) {
if (!result.result) {
var deferred = $.Deferred();
deferred.reject('fail');
return deferred.promise();
@@ -37,18 +36,18 @@ function loadScenarios(){
var list = {};
$.each(result.scenario, function(idx, value){
$.each(result.scenario, function(idx, value) {
var title = value.title || "-";
var pat = /【(.*?)[0-9\-_\.a-zA-Z]*】/;
var category = pat.exec(title);
category = category?category[1]:'-';
category = category ? category[1] : '-';
value.title = title;
value.category = category;
value.idx = idx;
value.year = value.year || 180;
if(!(category in list)){
if (!(category in list)) {
list[category] = {};
}
@@ -56,12 +55,12 @@ function loadScenarios(){
});
var $select = $('#scenario_sel');
$.each(list, function(category, items){
$.each(list, function(category, items) {
var $optgroup = $('<optgroup>').attr('label', category);
$.each(items, function(idx, scenario){
$.each(items, function(idx, scenario) {
var $option = $('<option>')
.data('scenario',scenario)
.data('scenario', scenario)
.val(idx)
.html(scenario.title);
$optgroup.append($option);
@@ -75,7 +74,7 @@ function loadScenarios(){
});
}
function scenarioPreview(){
function scenarioPreview() {
var $select = $(this);
var $option = $select.find('option:selected');
@@ -89,125 +88,124 @@ function scenarioPreview(){
$year.html('{0}년'.format(scenario.year));
$npc.html('{0}명'.format(scenario.npc_cnt));
if(scenario.npcEx_cnt == 0){
if (scenario.npcEx_cnt == 0) {
$npcEx.html('');
}
else{
} else {
$npcEx.html('+{0}명'.format(scenario.npcEx_cnt));
}
$nation.html('');
$.each(scenario.nation, function(idx, nation){
$.each(scenario.nation, function(idx, nation) {
$nation.append('<span style="color:{0}">{1}</span> {2}명. {3}<br>'.format(
nation.color, nation.name, nation.generals, nation.cities.join(', ')
));
});
}
function formSetup(){
$.validator.addMethod("autorun_user", function(value,element){
function formSetup() {
$.validator.addMethod("autorun_user", function(value, element) {
var parent = $(element).parent('.input-group');
var checkCnt = parent.find('input:checked').length;
if(value <= 0){
if(checkCnt > 0){
if (value <= 0) {
if (checkCnt > 0) {
return false;
}
return true;
}
if(checkCnt == 0){
if (checkCnt == 0) {
return false;
}
return true;
}, "유효 시간과 옵션은 동시에 설정해야합니다.");
$('#game_form').validate({
rules:{
turnterm:"required",
sync:"required",
scenario:"required",
fiction:"required",
extend:"required",
npcmode:"required",
show_img_level:"required",
tournament_trig:"required",
join_mode:'required',
autorun_user_minutes:{required: true, autorun_user: true, min:0}
rules: {
turnterm: "required",
sync: "required",
scenario: "required",
fiction: "required",
extend: "required",
npcmode: "required",
show_img_level: "required",
tournament_trig: "required",
join_mode: 'required',
autorun_user_minutes: { required: true, autorun_user: true, min: 0 }
},
errorElement: "div",
errorPlacement: function ( error, element ) {
errorPlacement: function(error, element) {
// Add the `help-block` class to the error element
error.addClass( "invalid-feedback" );
error.addClass("invalid-feedback");
if ( element.prop( "type" ) === "checkbox" ) {
error.insertAfter( element.parent( "label" ) );
if (element.prop("type") === "checkbox") {
error.insertAfter(element.parent("label"));
} else {
error.insertAfter( element );
error.insertAfter(element);
}
},
highlight: function ( element, errorClass, validClass ) {
$( element ).addClass( "is-invalid" ).removeClass( "is-valid" );
highlight: function(element, errorClass, validClass) {
$(element).addClass("is-invalid").removeClass("is-valid");
},
unhighlight: function (element, errorClass, validClass) {
$( element ).addClass( "is-valid" ).removeClass( "is-invalid" );
unhighlight: function(element, errorClass, validClass) {
$(element).addClass("is-valid").removeClass("is-invalid");
}
});
$('#game_form').submit(function(e){
$('#game_form').submit(function(e) {
e.preventDefault();
if(!$("#game_form").valid()){
if (!$("#game_form").valid()) {
return;
}
var autorun_user_minutes = parseInt($('#autorun_user_minutes').val());
var autorun_user = [];
if(autorun_user_minutes > 0){
$('.autorun_user_chk:checked').each(function(){
if (autorun_user_minutes > 0) {
$('.autorun_user_chk:checked').each(function() {
autorun_user.push($(this).data('key'));
});
}
$.ajax({
cache:false,
type:'post',
url:'j_install.php',
dataType:'json',
data:{
turnterm:$('#turnterm input:radio:checked').val(),
sync:$('#sync input:radio:checked').val(),
scenario:$('#scenario_sel').val(),
fiction:$('#fiction input:radio:checked').val(),
extend:$('#extend input:radio:checked').val(),
npcmode:$('#npcmode input:radio:checked').val(),
show_img_level:$('#show_img_level input:radio:checked').val(),
tournament_trig:$('#tournament_trig input:radio:checked').val(),
reserve_open:$('#reserve_open').val(),
pre_reserve_open:$('#pre_reserve_open').val(),
join_mode:$('#join_mode input:radio:checked').val(),
autorun_user_minutes:autorun_user_minutes,
autorun_user:autorun_user
cache: false,
type: 'post',
url: 'j_install.php',
dataType: 'json',
data: {
turnterm: $('#turnterm input:radio:checked').val(),
sync: $('#sync input:radio:checked').val(),
scenario: $('#scenario_sel').val(),
fiction: $('#fiction input:radio:checked').val(),
extend: $('#extend input:radio:checked').val(),
block_general_create: $('#block_general_create input:radio:checked').val(),
npcmode: $('#npcmode input:radio:checked').val(),
show_img_level: $('#show_img_level input:radio:checked').val(),
tournament_trig: $('#tournament_trig input:radio:checked').val(),
reserve_open: $('#reserve_open').val(),
pre_reserve_open: $('#pre_reserve_open').val(),
join_mode: $('#join_mode input:radio:checked').val(),
autorun_user_minutes: autorun_user_minutes,
autorun_user: autorun_user
}
}).then(function(result){
}).then(function(result) {
var deferred = $.Deferred();
if(!result.result){
if (!result.result) {
alert(result.reason);
deferred.reject('fail');
}
else{
} else {
alert('게임이 리셋되었습니다.');
deferred.resolve();
}
return deferred.promise();
}).then(function(){
}).then(function() {
location.href = '..';
});
});
}
$(function(){
$(function() {
loadScenarios();
$('#scenario_sel').change(scenarioPreview);
formSetup();
})
})
+206
View File
@@ -0,0 +1,206 @@
var templateGeneralCard = '<div class="general_card">\
<h4 class="bg1 with_border"><%generalName%></h4>\
<h4><img src="<%iconPath%>" height=64 width=64></h4><p>\
<%if(leadership){%>\
<%leadership%> / <%strength%> / <%intel%><br>\
<%}%>\
<%if(personalText){%><%personalText%><br><%}%>\
<%if(specialDomesticText||specialWarText){%>\
<%specialDomesticText%> / <%specialWarText%><br>\
<%}%>\
<%if(dex){%><br>\
보병: <%parseInt(dex[0]/1000)%>K<br>\
궁병: <%parseInt(dex[1]/1000)%>K<br>\
기병: <%parseInt(dex[2]/1000)%>K<br>\
귀병: <%parseInt(dex[3]/1000)%>K<br>\
차병: <%parseInt(dex[4]/1000)%>K<br>\
<%}%>\
</p>\
<button type="subject" class="with_skin with_border select_btn" data-name="<%generalName%>" value="<%uniqueName%>" name="pick">선택하기</button>\
</div>';
var templateSpecial =
'<span class="obj_tooltip" data-toggle="tooltip" data-placement="top"><%text%>\
<span class="tooltiptext">\
<%info%>\
</span>\
</span>\
';
function pickGeneral() {
$btn = $(this);
if (hasGeneralID) {
if (!confirm('이 장수를 선택할까요? : {0}'.format($btn.data('name')))) {
return false;
}
$.post({
url: 'j_update_picked_general.php',
dataType: 'json',
data: {
pick: $btn.val()
}
}).then(function(result) {
if (!result.result) {
alert(result.reason);
location.refresh();
}
alert('선택한 장수로 변경했습니다.');
location.href = './';
});
return false;
}
currentGeneralInfo = cards[$btn.val()];
var $card = $btn.closest('.general_card');
var $leftPad = $('#left_pad');
$leftPad.empty();
$card.clone().appendTo($leftPad);
initTooltip($leftPad);
return false;
}
function buildGeneral() {
if (!currentGeneralInfo) {
alert('장수를 선택해주세요!');
return false;
}
if (!confirm('이 장수로 생성할까요?')) {
return false;
}
$.post({
url: 'j_select_picked_general.php',
dataType: 'json',
data: {
pick: currentGeneralInfo.uniqueName,
use_own_picture: $('#use_own_picture').is(':checked'),
leadership: parseInt($('#leadership').val()),
strength: parseInt($('#leadership').val()),
intel: parseInt($('#leadership').val()),
personal: $('#selChar').val()
}
}).then(function(result) {
if (!result.result) {
alert(result.reason);
location.refresh();
}
alert('선택한 장수로 생성했습니다.');
location.href = './';
});
return false;
}
function updateOutdateTimer() {
var $validUntilText = $('#valid_until_text');
var now = Date.now();
var validUntil = $validUntilText.data('until');
if (validUntil <= 0) {
return;
} else if (validUntil < now) {
$validUntilText.data('until', 0);
$('#valid_until').hide();
$('#outdate_token').show();
return;
} else if (validUntil - now <= 30000) {
$validUntilText.css('color', "rgb(255, {0}, {0})".format(255 * (validUntil - now) / 30000));
}
setTimeout(updateOutdateTimer, 1000);
}
function printGenerals(value) {
$('.card_holder').empty();
$('#valid_until').show();
$('#valid_until_text').html(value.validUntil).data('until', (new Date(value.validUntil)).getTime()).css('color', 'white');
$('#outdate_token').hide();
var pick = $.map(value.pick, function(value, key) {
return value;
});
var emptyCard = {
'leadership': null,
'strength': null,
'intel': null,
'personalText': null,
'specialDomesticText': null,
'specialWarText': null,
'dex': null
};
$.each(pick, function(idx, cardData) {
cardData.iconPath = getIconPath(cardData.imgsvr, cardData.picture);
if (cardData.specialDomestic !== undefined) {
cardData.specialDomesticText = TemplateEngine(templateSpecial, {
text: cardData.specialDomesticName,
info: cardData.specialDomesticInfo
});
cardData.specialWarText = '-';
}
if (cardData.specialWar !== undefined) {
cardData.specialWarText = TemplateEngine(templateSpecial, {
text: cardData.specialWarName,
info: cardData.specialWarInfo
});
if (cardData.specialDomesticText === undefined) {
cardData.specialDomesticText = '-';
}
}
//FIXME: ego로 적었던것 같음!
if (cardData.personal in characterInfo) {
cardData.personalText = TemplateEngine(templateSpecial, {
text: characterInfo[cardData.personal].name,
info: characterInfo[cardData.personal].info
});
} else {
cardData.personalText = cardData.personal;
}
cards[cardData.uniqueName] = cardData;
var $card = $(TemplateEngine(templateGeneralCard, $.extend({}, emptyCard, cardData)));
$('.card_holder').append($card);
$card.find('.select_btn').click(pickGeneral);
$card.find('.obj_tooltip').tooltip({
title: function() {
return $.trim($(this).find('.tooltiptext').html());
},
html: true
});
});
updateOutdateTimer();
}
$(function($) {
$.post('j_get_select_pool.php').then(function(value) {
if (!value.result) {
alert(value.reason);
return;
}
console.log(value);
printGenerals(value);
});
$('#build_general').on('click', buildGeneral);
$.each(validCustomOption, function(idx, value) {
if (value == 'picture') {
$('.custom_picture').show();
} else if (value == 'ego') {
$('.custom_personality').show();
} else if (value == 'stat') {
$('.custom_stat').show();
}
});
});