입력창 준비

This commit is contained in:
2020-05-13 00:45:38 +09:00
parent 800c85dd03
commit 2e9b87f0bc
8 changed files with 429 additions and 113 deletions
+3 -3
View File
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+6 -6
View File
File diff suppressed because one or more lines are too long
+28
View File
@@ -0,0 +1,28 @@
/**
* @author Script47 (https://github.com/Script47/Toast)
* @description Toast - A Bootstrap 4.2+ jQuery plugin for the toast component
* @version 0.7.1
**/
.toast-container {
position: sticky;
z-index: 1055;
top: 0
}
.toast-wrapper {
position: absolute;
z-index: 1055;
top: 0;
right: 0;
margin: 5px
}
.toast-container>.toast-wrapper>.toast {
min-width: 150px;
background-color: rgb(50, 50, 50);
border-top: none;
}
.toast-container>.toast-wrapper>.toast>.toast-header strong {
padding-right: 20px;
}
+136
View File
@@ -0,0 +1,136 @@
/**
* @author Script47 (https://github.com/Script47/Toast)
* @description Toast - A Bootstrap 4.2+ jQuery plugin for the toast component
* @version 0.7.1
**/
(function ($) {
var TOAST_CONTAINER_HTML = '<div class="toast-container" aria-live="polite" aria-atomic="true"></div>';
var TOAST_WRAPPER_HTML = '<div class="toast-wrapper"></div>';
$.toast = function (opts) {
// If container is not set in opts use body
var general_container = $('body');
if (opts.container && opts.container.length === 1)
general_container = opts.container;
// if toast container and wrapper are not present in container create them
if (!general_container.children('.toast-container').length) {
general_container.prepend(TOAST_CONTAINER_HTML);
general_container.children('.toast-container').append(TOAST_WRAPPER_HTML);
general_container.on('hidden.bs.toast', '.toast', function () {
$(this).remove();
});
}
var toast_wrapper = general_container.children('.toast-container').children('.toast-wrapper');
var id = 'toast-' + ($('.toast').length + 1),
html = '',
bg_header_class = '',
fg_header_class = '',
fg_subtitle_class = 'text-muted',
fg_dismiss_class = '',
title = opts.title || 'Notice!',
subtitle = opts.subtitle || '',
content = opts.content || '',
type = opts.type || 'info',
delay = opts.delay || -1,
img = opts.img,
pause_on_hover = opts.pause_on_hover || false,
pause = false,
delay_or_autohide = '';
switch (type) {
case 'info':
bg_header_class = 'bg-info';
fg_header_class = 'text-white';
fg_subtitle_class = 'text-white';
fg_dismiss_class = 'text-white';
break;
case 'success':
bg_header_class = 'bg-success';
fg_header_class = 'text-white';
fg_subtitle_class = 'text-white';
fg_dismiss_class = 'text-white';
break;
case 'warning':
case 'warn':
bg_header_class = 'bg-warning';
fg_header_class = 'text-white';
fg_subtitle_class = 'text-white';
fg_dismiss_class = 'text-white';
break;
case 'error':
case 'danger':
bg_header_class = 'bg-danger';
fg_header_class = 'text-white';
fg_subtitle_class = 'text-white';
fg_dismiss_class = 'text-white';
break;
}
if (pause_on_hover !== false) {
var hide_timestamp = Math.floor(Date.now() / 1000) + (delay / 1000);
delay_or_autohide = 'data-autohide="false"';
pause_on_hover = 'data-hide-timestamp="' + hide_timestamp + '"';
} else {
if (delay === -1) {
delay_or_autohide = 'data-autohide="false"';
} else {
delay_or_autohide = 'data-delay="' + delay + '"';
}
}
html = '<div id="' + id + '" class="toast" role="alert" aria-live="assertive" aria-atomic="true" ' + delay_or_autohide + ' ' + pause_on_hover + '>';
html += '<div class="toast-header ' + bg_header_class + ' ' + fg_header_class + '">';
if (typeof img !== 'undefined') {
html += '<img src="' + img.src + '" class="' + (img.class || '') + ' mr-2" alt="' + (img.alt || 'Image') + '" ' + (typeof img.title !== 'undefined' ? 'data-toggle="tooltip" title="' + img.title + '"' : '') + '>';
}
html += '<strong class="mr-auto">' + title + '</strong>';
html += '<small class="' + fg_subtitle_class + '">' + subtitle + '</small>';
html += '<button type="button" class="ml-2 mb-1 close" data-dismiss="toast" aria-label="Close">';
html += '<span aria-hidden="true" class="' + fg_dismiss_class + '">&times;</span>';
html += '</button>';
html += '</div>';
if (content !== '') {
html += '<div class="toast-body">'
html += content
html += '</div>';
}
html += '</div>';
toast_wrapper.append(html);
toast_wrapper.find('.toast:last').toast('show');
if (pause_on_hover !== false) {
setTimeout(function () {
if (!pause) {
$('#' + id).toast('hide');
}
}, delay);
$(document).on('mouseover', '#' + id, function () {
pause = true;
});
$(document).on('mouseleave', '#' + id, function () {
var current = Math.floor(Date.now() / 1000),
future = parseInt($(this).data('hide-timestamp'));
pause = false;
if (current >= future) {
$(this).toast('hide');
}
});
}
}
}(jQuery));
+39 -42
View File
@@ -76,20 +76,20 @@ $currentGeneralActionPriority = $rawNationGeneralPolicy['priority'] ?? $defaultG
var availableNationPriorityItems = <?= Json::encode(AutorunNationPolicy::$defaultPriority) ?>;
var defaultGeneralActionPriority = <?= Json::encode($defaultGeneralActionPriority) ?>;
/*var currentGeneralActionPriority = <?= Json::encode($currentGeneralActionPriority) ?>;*/
var currentGeneralActionPriority = ["NPC사망대비", "귀환", "금쌀구매", "출병", "긴급내정", "전투준비", "전방워프", "NPC헌납", "징병", "후방워프", "전쟁내정", "소집해제", "내정워프"];
var currentGeneralActionPriority = <?= Json::encode($currentGeneralActionPriority) ?>;
var availableGeneralActionPriorityItems = <?= Json::encode(AutorunGeneralPolicy::$default_priority) ?>;
</script>
<?= WebUtil::printJS('../e_lib/jquery-3.3.1.min.js') ?>
<?= WebUtil::printJS('../e_lib/Sortable.min.js') ?>
<?= WebUtil::printJS('../e_lib/jquery-sortable.js') ?>
<?= WebUtil::printJS('../e_lib/bootstrap.bundle.min.js') ?>
<?= WebUtil::printJS('../e_lib/jquery_toast/toast.js') ?>
<?= WebUtil::printJS('../d_shared/common_path.js') ?>
<?= WebUtil::printJS('js/common.js') ?>
<?= WebUtil::printJS('js/npc_control.js') ?>
<?= WebUtil::printCSS('../e_lib/bootstrap.min.css') ?>
<?= WebUtil::printCSS('../e_lib/summernote/summernote-bs4.css') ?>
<?= WebUtil::printCSS('../e_lib/jquery_toast/toast.css') ?>
<?= WebUtil::printCSS('../d_shared/common.css') ?>
<?= WebUtil::printCSS('css/common.css') ?>
<?= WebUtil::printCSS('css/npc_control.css') ?>
@@ -107,7 +107,7 @@ $currentGeneralActionPriority = $rawNationGeneralPolicy['priority'] ?? $defaultG
<div class="row">
<label for="reqNationGold" class="col-sm-6 col-form-label">국가 권장 금</label>
<div class="col-sm-6">
<input type="number" class="form-control" id="reqNationGold" min="0" value="0">
<input type="number" class="form-control" data-type="integer" id="reqNationGold" min="0" value="0">
</div>
</div>
<div style='text-align:right;'><small class="form-text text-muted">이 보다 많으면 포상, 적으면 몰수합니다.(긴급포상 제외)</small></div>
@@ -115,73 +115,73 @@ $currentGeneralActionPriority = $rawNationGeneralPolicy['priority'] ?? $defaultG
<label for="reqNationRice" class="col-sm-3 col-form-label">국가 권장 쌀</label>
<div class="col-sm-3">
<input type="number" class="form-control" id="reqNationRice" min="0" value="0">
<input type="number" class="form-control" data-type="integer" id="reqNationRice" min="0" value="0">
</div>
</div>
<div class="form-group row">
<label for="reqHumanWarUrgentGold" class="col-sm-3 col-form-label">전투유저장 긴급포상 금</label>
<div class="col-sm-3">
<input type="number" class="form-control" id="reqHumanWarUrgentGold" min="0" value="0">
<input type="number" class="form-control" data-type="integer" id="reqHumanWarUrgentGold" min="0" value="0">
</div>
<label for="reqHumanWarUrgentRice" class="col-sm-3 col-form-label">전투유저장 긴급포상 쌀</label>
<div class="col-sm-3">
<input type="number" class="form-control" id="reqHumanWarUrgentRice" min="0" value="0">
<input type="number" class="form-control" data-type="integer" id="reqHumanWarUrgentRice" min="0" value="0">
</div>
</div>
<div class="form-group row">
<label for="reqHumanWarRecommandGold" class="col-sm-3 col-form-label">전투유저장 권장 금</label>
<div class="col-sm-3">
<input type="number" class="form-control" id="reqHumanWarRecommandGold" min="0" value="0">
<input type="number" class="form-control" data-type="integer" id="reqHumanWarRecommandGold" min="0" value="0">
</div>
<label for="reqHumanWarRecommandRice" class="col-sm-3 col-form-label">전투유저장 권장 쌀</label>
<div class="col-sm-3">
<input type="number" class="form-control" id="reqHumanWarRecommandRice" min="0" value="0">
<input type="number" class="form-control" data-type="integer" id="reqHumanWarRecommandRice" min="0" value="0">
</div>
</div>
<div class="form-group row">
<label for="reqHumanDevelGold" class="col-sm-3 col-form-label">내정유저장 권장 금</label>
<div class="col-sm-3">
<input type="number" class="form-control" id="reqHumanDevelGold" min="0" value="0">
<input type="number" class="form-control" data-type="integer" id="reqHumanDevelGold" min="0" value="0">
</div>
<label for="reqHumanDevelRice" class="col-sm-3 col-form-label">내정유저장 권장 쌀</label>
<div class="col-sm-3">
<input type="number" class="form-control" id="reqHumanDevelRice" min="0" value="0">
<input type="number" class="form-control" data-type="integer" id="reqHumanDevelRice" min="0" value="0">
</div>
</div>
<div class="form-group row">
<label for="reqNPCWarGold" class="col-sm-3 col-form-label">전투NPC 권장 금</label>
<div class="col-sm-3">
<input type="number" class="form-control" id="reqNPCWarGold" min="0" value="0">
<input type="number" class="form-control" data-type="integer" id="reqNPCWarGold" min="0" value="0">
</div>
<label for="reqNPCWarRice" class="col-sm-3 col-form-label">전투NPC 권장 쌀</label>
<div class="col-sm-3">
<input type="number" class="form-control" id="reqNPCWarRice" min="0" value="0">
<input type="number" class="form-control" data-type="integer" id="reqNPCWarRice" min="0" value="0">
</div>
</div>
<div class="form-group row">
<label for="reqNPCDevelGold" class="col-sm-3 col-form-label">내정NPC 권장 금</label>
<div class="col-sm-3">
<input type="number" class="form-control" id="reqNPCDevelGold" min="0" value="0">
<input type="number" class="form-control" data-type="integer" id="reqNPCDevelGold" min="0" value="0">
</div>
<label for="reqNPCDevelRice" class="col-sm-3 col-form-label">내정NPC 권장 쌀</label>
<div class="col-sm-3">
<input type="number" class="form-control" id="reqNPCDevelRice" min="0" value="0">
<input type="number" class="form-control" data-type="integer" id="reqNPCDevelRice" min="0" value="0">
</div>
</div>
<div class="form-group row">
<label for="minimumResourceActionAmount" class="col-sm-3 col-form-label">포상/몰수/헌납/삼/팜 최소 단위</label>
<div class="col-sm-3">
<input type="number" class="form-control" id="minimumResourceActionAmount" min="0" value="0">
<input type="number" class="form-control" data-type="integer" id="minimumResourceActionAmount" min="0" value="0">
</div>
<label for="minWarCrew" class="col-sm-3 col-form-label">최소 전투 가능 병력 수</label>
<div class="col-sm-3">
<input type="number" class="form-control" id="minWarCrew" min="0" value="0">
<input type="number" class="form-control" data-type="integer" id="minWarCrew" min="0" value="0">
</div>
</div>
<div class="form-group row">
<label for="minNPCRecruitCityPopulation" class="col-sm-3 col-form-label">NPC 최소 징병 가능 인구 수</label>
<div class="col-sm-3">
<input type="number" class="form-control" id="minNPCRecruitCityPopulation" min="0" value="0">
<input type="number" class="form-control" data-type="integer" id="minNPCRecruitCityPopulation" min="0" value="0">
</div>
<label for="safeRecruitCityPopulationRatio" class="col-sm-3 col-form-label">제자리 징병 허용 인구율(%)</label>
<div class="col-sm-3">
@@ -191,24 +191,27 @@ $currentGeneralActionPriority = $rawNationGeneralPolicy['priority'] ?? $defaultG
<div class="form-group row">
<label for="minNPCWarLeadership" class="col-sm-3 col-form-label">NPC 전투 참여 통솔 기준</label>
<div class="col-sm-3">
<input type="number" class="form-control" id="minNPCWarLeadership" min="0" value="0">
<input type="number" class="form-control" data-type="integer" id="minNPCWarLeadership" min="0" value="0">
</div>
<label for="properWarTrainAtmos" class="col-sm-3 col-form-label">훈련/사기진작 목표치</label>
<div class="col-sm-3">
<input type="number" class="form-control" id="properWarTrainAtmos" min="0" max="100" value="0">
<input type="number" class="form-control" data-type="integer" id="properWarTrainAtmos" min="0" max="100" value="0">
</div>
</div>
<div class="alert alert-secondary">
전투 부대는 작업중입니다(json양식: {부대번호:[시작도시번호(아국),도착도시번호(적군)],...})<br>
후방 징병 부대는 작업중입니다(json양식: [부대번호,...])<br>
내정 부대는 작업중입니다(json양식: [부대번호,...])
<input type="hidden" value="{}" id="CombatForce">
<input type="hidden" value="[]" id="SupportForce">
<input type="hidden" value="[]" id="DevelopForce">
<input type="hidden" value="true" id="allowNpcAttackCity">
<input type="hidden" value="{}" data-type="json" id="CombatForce">
<input type="hidden" value="[]" data-type="json" id="SupportForce">
<input type="hidden" value="[]" data-type="json" id="DevelopForce">
<input type="hidden" value="true" data-type="json" id="allowNpcAttackCity"><!--allowNpcAttackCity는 현재 게임 내 비활성-->
</div>
<div class='control_bar'>
<button type="button" class="btn btn-dark reset_btn" data-type="nation_policy">초기값으로</button><button type="button" class="btn btn-primary submit_btn" data-type="nation_policy">설정</button>
<div class='control_bar' data-type="nationPolicy">
<div class="btn-group" role="group">
<button type="button" class="btn btn-dark reset_btn">초기값으로</button>
<button type="button" class="btn btn-secondary revert_btn">이전값으로</button>
</div><button type="button" class="btn btn-primary submit_btn">설정</button>
</div>
</div>
<div class="row">
@@ -219,22 +222,19 @@ $currentGeneralActionPriority = $rawNationGeneralPolicy['priority'] ?? $defaultG
<div class="col-sm-6">
<div class="bg2 sub_bar">비활성</div>
<div id="nationPriorityDisabled" class="list-group col" data-type="list">
<div class="list-group-item">비활성화1</div>
<div class="list-group-item">비활성화2</div>
</div>
</div>
<div class="col-sm-6">
<div class="bg2 sub_bar">활성</div>
<div id="nationPriority" class="list-group col" data-type="list">
<div class="list-group-item">활성화1</div>
<div class="list-group-item">활성화2</div>
<div class="list-group-item">활성화3</div>
<div class="list-group-item">활성화4</div>
</div>
</div>
</div>
<div class='control_bar'>
<button type="button" class="btn btn-dark reset_btn" data-type="nation_priority">초기값으로</button><button type="button" class="btn btn-primary submit_btn" data-type="nation_priority">설정</button>
<div class='control_bar' data-type="nationPriority">
<div class="btn-group" role="group">
<button type="button" class="btn btn-dark reset_btn">초기값으로</button>
<button type="button" class="btn btn-secondary revert_btn">이전값으로</button>
</div><button type="button" class="btn btn-primary submit_btn">설정</button>
</div>
</div>
</div>
@@ -245,22 +245,19 @@ $currentGeneralActionPriority = $rawNationGeneralPolicy['priority'] ?? $defaultG
<div class="col-sm-6">
<div class="bg2 sub_bar">비활성</div>
<div id="generalPriorityDisabled" class="list-group col" data-type="list">
<div class="list-group-item">비활성화1</div>
<div class="list-group-item">비활성화2</div>
</div>
</div>
<div class="col-sm-6">
<div class="bg2 sub_bar">활성</div>
<div id="generalPriority" class="list-group col" data-type="list">
<div class="list-group-item">활성화1</div>
<div class="list-group-item">활성화2</div>
<div class="list-group-item">활성화3</div>
<div class="list-group-item">활성화4</div>
</div>
</div>
</div>
<div class='control_bar'>
<button type="button" class="btn btn-dark reset_btn" data-type="general_priority">초기값으로</button><button type="button" class="btn btn-primary submit_btn" data-type="general_priority">설정</button>
<div class='control_bar' data-type="generalPriority">
<div class="btn-group" role="group">
<button type="button" class="btn btn-dark reset_btn">초기값으로</button>
<button type="button" class="btn btn-secondary revert_btn">이전값으로</button>
</div><button type="button" class="btn btn-primary submit_btn">설정</button>
</div>
</div>
</div>
+9
View File
@@ -311,6 +311,15 @@ function errUnknown(){
alert('작업을 실패했습니다.');
}
function errUnknownToast(){
$.toast({
title: '에러!',
content: '작업을 실패했습니다.',
type: 'danger',
delay: 5000
});
}
function quickReject(errMsg){
if(errMsg === undefined){
errMsg = '작업을 실패했습니다.';
+207 -61
View File
@@ -1,69 +1,215 @@
jQuery(function($){
jQuery(function ($) {
function initPriority(priorityKey, currentPriority, availablePriority){
var $disabledList = $('#{0}Disabled'.format(priorityKey));
var $enabledList = $('#{0}'.format(priorityKey));
function initPriority(priorityKey, currentPriority, availablePriority) {
var $disabledList = $('#{0}Disabled'.format(priorityKey));
var $enabledList = $('#{0}'.format(priorityKey));
$disabledList.empty();
$enabledList.empty();
$disabledList.empty();
$enabledList.empty();
var usedKey = {};
var itemFrame = '<div class="list-group-item" data-value="{0}">{0}</div>';
$.each(currentPriority, function(key, val){
var $item = $(itemFrame.format(val));
usedKey[val] = true;
$enabledList.append($item);
})
var $disabled = $(itemFrame.format('&lt;비활성화 항목들&gt;')).addClass('filtered');
$disabledList.append($disabled);
var usedKey = {};
var itemFrame = '<div class="list-group-item" data-value="{0}">{0}</div>';
$.each(currentPriority, function (key, val) {
var $item = $(itemFrame.format(val));
usedKey[val] = true;
$enabledList.append($item);
})
$.each(availablePriority, function(key, val){
if(val in usedKey){
return true;
var $disabled = $(itemFrame.format('&lt;비활성화 항목들&gt;')).addClass('filtered');
$disabledList.append($disabled);
$.each(availablePriority, function (key, val) {
if (val in usedKey) {
return true;
}
var $item = $(itemFrame.format(val));
$disabledList.append($item);
})
$disabledList.sortable({
group: priorityKey,
filter: '.filtered',
animation: 150
});
$enabledList.sortable({
group: priorityKey,
filter: '.filtered',
animation: 150
});
}
function initNationPolicy() {
$.each(currentNationPolicy, function (key, val) {
var $obj = $('#{0}'.format(key));
if (!$obj.length) {
console.log('{0}가 없대!'.format(key));
return true;
}
var type = $obj.data('type');
if (!$obj.is('input')) {
console.log('아니라고?');
return true;
}
if (type == 'percent') {
$obj.val(val * 100);
}
else if (type == 'json') {
$obj.val(JSON.stringify(val));
}
else {
$obj.val(val);
}
});
}
initPriority('generalPriority', currentGeneralActionPriority, availableGeneralActionPriorityItems);
initPriority('nationPriority', currentNationPriority, availableNationPriorityItems);
initNationPolicy();
$('.reset_btn').click(function () {
var $this = $(this);
if (!confirm('서버 초기 설정으로 되돌릴까요?')) {
return false;
}
var $item = $(itemFrame.format(val));
$disabledList.append($item);
var type = $this.parents('.control_bar').data('type');
if (type === 'nationPolicy') {
window.currentNationPolicy = window.defaultNationPolicy;
initNationPolicy();
}
else if (type === 'generalPriority') {
window.currentGeneralActionPriority = window.defaultGeneralActionPriority;
initPriority('generalPriority', currentGeneralActionPriority, availableGeneralActionPriorityItems);
}
else if (type === 'nationPriority') {
window.currentNationPriority = window.defaultNationPriority;
initPriority('nationPriority', currentNationPriority, availableNationPriorityItems);
}
$.toast({
title: '초기화 완료',
content: '서버 초기값을 적용했습니다. 설정 버튼을 누르면 반영됩니다.',
type: 'info',
delay: 5000
});
return false;
});
$('.revert_btn').click(function () {
var $this = $(this);
if (!confirm('이전 설정으로 되돌릴까요?')) {
return false;
}
var type = $this.parents('.control_bar').data('type');
if (type === 'nationPolicy') {
initNationPolicy();
}
if (type === 'generalPriority') {
initPriority('generalPriority', currentGeneralActionPriority, availableGeneralActionPriorityItems);
}
if (type === 'nationPriority') {
initPriority('nationPriority', currentNationPriority, availableNationPriorityItems);
}
$.toast({
title: '되돌리기 완료',
content: '이전 설정으로 되돌렸습니다.',
type: 'success',
delay: 5000
});
});
var collectPriority = function (priorityKey) {
var $list = $('#{0}'.format(priorityKey));
var result = [];
$list.find('.list-group-item').each(function(){
var $item = $(this);
result.push($item.data('value'));
});
return result;
}
var collectNationPolicy = function () {
var src = window.currentNationPolicy;
var result = {};
$.each(src, function (key, val) {
var $item = $('#{0}'.format(key));
var val = $item.val();
var dataType = $item.data('type');
if (dataType === 'percent') {
val /= 100;
}
else if (dataType === 'json') {
val = JSON.parse(val);
}
else if (dataType === 'integer') {
val = parseInt(val);
}
result[key] = val;
});
return result;
}
window.collectNationPolicy = collectNationPolicy;
$('.submit_btn').click(function () {
var $this = $(this);
if (!confirm('저장할까요?')) {
return false;
}
var type = $this.parents('.control_bar').data('type');
var data;
if (type === 'nationPolicy') {
data = collectNationPolicy();
}
else if (type === 'nationPriority') {
data = collectPriority(type);
}
else if (type === 'generalPriority') {
data = collectPriority(type);
}
else {
alert('올바르지 않은 type : {0}'.type);
return false;
}
console.log(data);
$.post({
url: 'j_set_npc_control.php',
dataType: 'json',
data: {
type: type,
data: JSON.stringify(data)
}
}).then(function (data) {
if (!data) {
return quickReject('설정하지 못했습니다.');
}
if (!data.result) {
return quickReject('설정하지 못했습니다. : ' + data.reason);
}
}, errUnknownToast)
.fail(function (reason) {
$.toast({
title: '에러!',
content: reason,
type: 'danger',
delay: 5000
});
});
})
$disabledList.sortable({
group: priorityKey,
filter: '.filtered',
animation: 150
});
$enabledList.sortable({
group: priorityKey,
filter: '.filtered',
animation: 150
});
}
initPriority('generalPriority', currentGeneralActionPriority, availableGeneralActionPriorityItems);
initPriority('nationPriority', currentNationPriority, availableNationPriorityItems);
$.each(currentNationPolicy, function(key, val){
var $obj = $('#{0}'.format(key));
if(!$obj.length){
console.log('{0}가 없대!'.format(key));
return true;
}
var type=$obj.data('type');
if(!$obj.is('input')){
console.log('아니라고?');
return true;
}
if(type =='percent'){
$obj.val(val*100);
}
else{
$obj.val(val);
}
});
});