Compare commits
5 commits
master
...
questtypes
Author | SHA1 | Date | |
---|---|---|---|
|
a3bac2e744 | ||
|
8c79cb617e | ||
|
fc9c4d9ea1 | ||
|
6e96556b0e | ||
|
852eab42f7 |
8 changed files with 687 additions and 46 deletions
|
@ -82,20 +82,25 @@
|
|||
* @param array $index Names of parameter to validate and to validate against
|
||||
* @return mixed True or the parameter with settings the validation failed on
|
||||
*/
|
||||
public function validateParam($params, $index)
|
||||
public function validateParam($params, $index, $config=null)
|
||||
{
|
||||
// Check onfig
|
||||
if(is_null($config)) {
|
||||
$config = $this->config;
|
||||
}
|
||||
|
||||
// Check parameter
|
||||
if(!array_key_exists($index, $params)) {
|
||||
throw new \nre\exceptions\ParamsNotValidException($index);
|
||||
}
|
||||
// Check settings
|
||||
if(!array_key_exists($index, $this->config)) {
|
||||
if(!array_key_exists($index, $config)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// Validate parameter and return result
|
||||
return $this->validate($params[$index], $this->config[$index]);
|
||||
return $this->validate($params[$index], $config[$index]);
|
||||
}
|
||||
|
||||
|
||||
|
@ -106,12 +111,12 @@
|
|||
* @param array $indices Names of parameters to validate and to validate against
|
||||
* @return mixed True or the parameters with settings the validation failed on
|
||||
*/
|
||||
public function validateParams($params, $indices)
|
||||
public function validateParams($params, $indices, $config=null)
|
||||
{
|
||||
// Validate parameters
|
||||
$validation = true;
|
||||
foreach($indices as $index) {
|
||||
$validation = $this->addValidationResults($validation, $index, $this->validateParam($params, $index));
|
||||
$validation = $this->addValidationResults($validation, $index, $this->validateParam($params, $index, $config));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -25,6 +25,27 @@
|
|||
* @var array
|
||||
*/
|
||||
public $models = array('media');
|
||||
/**
|
||||
* Required components
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $components = array('validation');
|
||||
|
||||
private $validationSettings = array(
|
||||
'bossname' => array(
|
||||
'minlength' => 1,
|
||||
'maxlength' => 32
|
||||
),
|
||||
'lives_boss' => array(
|
||||
'minlength' => 1,
|
||||
'regex' => '/^(\d*)$/'
|
||||
),
|
||||
'lives_character' => array(
|
||||
'minlength' => 1,
|
||||
'regex' => '/^(\d*)$/'
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
@ -227,23 +248,199 @@
|
|||
*/
|
||||
public function edittask($seminary, $questgroup, $quest)
|
||||
{
|
||||
// Get Fight
|
||||
$fight = $this->Bossfight->getBossFight($quest['id']);
|
||||
/*
|
||||
if(!is_null($fight['boss_seminarymedia_id'])) {
|
||||
$fight['bossmedia'] = $this->Media->getSeminaryMediaById($fight['boss_seminarymedia_id']);
|
||||
}
|
||||
*/
|
||||
|
||||
// Get stages
|
||||
$stage = $this->Bossfight->getFirstStage($quest['id']);
|
||||
$stage['childs'] = $this->getChildStages($stage['id']);
|
||||
// Get Character
|
||||
$character = $this->Characters->getCharacterForUserAndSeminary($this->Auth->getUserId(), $seminary['id']);
|
||||
|
||||
// Create (pseudo) tree
|
||||
$tree = $this->createStageTree($fight['lives_character'], $fight['lives_boss']);
|
||||
$this->attachStages($quest['id'], $tree);
|
||||
|
||||
// TODO Test
|
||||
print_r($this->createStageTree2($quest['id'], $fight['lives_character'], $fight['lives_boss']));
|
||||
|
||||
// Get allowed mimetypes
|
||||
$mimetypes = \nre\configs\AppConfig::$mimetypes['questtypes'];
|
||||
|
||||
// Values
|
||||
$step = 1;
|
||||
$steps = 1;
|
||||
$bossname = $fight['bossname'];
|
||||
$livesCharacter = $fight['lives_character'];
|
||||
$livesBoss = $fight['lives_boss'];
|
||||
$fields = array('bossname', 'lives_boss', 'lives_character');
|
||||
$validation = true;
|
||||
|
||||
// Save submitted data
|
||||
if($this->request->getRequestMethod() == 'POST')
|
||||
{
|
||||
// Get current step
|
||||
$step = max(0, min($steps, intval($this->request->getPostParam('step'))));
|
||||
|
||||
// Bossfight
|
||||
if($step == 0)
|
||||
{
|
||||
// Get params and validate them
|
||||
$validation = $this->Validation->validateParams($this->request->getPostParams(), $fields, $this->validationSettings);
|
||||
$bossname = $this->request->getPostParam('bossname');
|
||||
$livesCharacter = $this->request->getPostParam('lives_character');
|
||||
$livesBoss = $this->request->getPostParam('lives_boss');
|
||||
|
||||
// Validate image
|
||||
$bossimage = null;
|
||||
if(!empty($_FILES) && array_key_exists('bossimage', $_FILES) && $_FILES['bossimage']['error'] != UPLOAD_ERR_NO_FILE)
|
||||
{
|
||||
$bossimage = $_FILES['bossimage'];
|
||||
|
||||
// Check error
|
||||
if($bossimage['error'] !== UPLOAD_ERR_OK) {
|
||||
$validation = $this->Validation->addValidationResult($validation, 'bossimage', 'error', $bossimage['error']);
|
||||
}
|
||||
|
||||
// Check mimetype
|
||||
$bossimageMimetype = null;
|
||||
$bossimage['mimetype'] = \hhu\z\Utils::getMimetype($bossimage['tmp_name'], $bossimage['type']);
|
||||
foreach($mimetypes as &$mimetype)
|
||||
{
|
||||
if($mimetype['mimetype'] == $bossimage['mimetype']) {
|
||||
$bossimageMimetype = $mimetype;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(is_null($bossimageMimetype)) {
|
||||
$validation = $this->Validation->addValidationResult($validation, 'bossimage', 'mimetype', $bossimage['mimetype']);
|
||||
}
|
||||
elseif($bossimage['size'] > $bossimageMimetype['size']) {
|
||||
$validation = $this->Validation->addValidationResult($validation, 'bossimage', 'size', $bossimageMimetype['size']);
|
||||
}
|
||||
}
|
||||
|
||||
// Set Bossfight data
|
||||
if($validation === true)
|
||||
{
|
||||
// Upload boss image
|
||||
$mediaId = $this->Media->createQuestMedia(
|
||||
$this->Auth->getUserId(),
|
||||
$seminary['id'],
|
||||
sprintf('quest-bossfight-%s', $quest['url']),
|
||||
'',
|
||||
$bossimage['mimetype'],
|
||||
$bossimage['tmp_name']
|
||||
);
|
||||
|
||||
// Save data
|
||||
if(!is_null($fight))
|
||||
{
|
||||
// Edit Bossfight
|
||||
$this->Bossfight->editBossFight(
|
||||
$quest['id'],
|
||||
$bossname,
|
||||
($mediaId !== false ? $mediaId : $fight['boss_seminarymedia_id']),
|
||||
$livesCharacter,
|
||||
$livesBoss
|
||||
);
|
||||
|
||||
// TODO Delete needless stages
|
||||
}
|
||||
elseif($mediaId !== false)
|
||||
{
|
||||
// Create new Bossfight
|
||||
$this->Bossfight-createBossFight(
|
||||
$this->Auth->getUserId(),
|
||||
$quest['id'],
|
||||
$bossname,
|
||||
$mediaId,
|
||||
$livesCharacter,
|
||||
$livesBoss
|
||||
);
|
||||
}
|
||||
|
||||
// Reload fight
|
||||
$fight = $this->Bossfight->getBossFight($quest['id']);
|
||||
if(!is_null($fight['boss_seminarymedia_id'])) {
|
||||
$fight['bossmedia'] = $this->Media->getSeminaryMediaById($fight['boss_seminarymedia_id']);
|
||||
}
|
||||
$tree = $this->createStageTree($fight['lives_character'], $fight['lives_boss']);
|
||||
$this->attachStages($quest['id'], $tree);
|
||||
}
|
||||
}
|
||||
// Stages
|
||||
elseif($step == 1)
|
||||
{
|
||||
// Get stages
|
||||
$stages = $this->request->getPostParam('stages');
|
||||
|
||||
// Save stages
|
||||
foreach($tree as $i => &$v)
|
||||
{
|
||||
if(array_key_exists($i, $stages))
|
||||
{
|
||||
foreach($v as $j => &$h)
|
||||
{
|
||||
if(array_key_exists($j, $stages[$i]))
|
||||
{
|
||||
/*
|
||||
$text = $stages[$i][$j]['text'];
|
||||
$question = $stages[$i][$j]['question'];
|
||||
if(array_key_exists('stage', $h) && !empty($h['stage']))
|
||||
{
|
||||
// TODO Edit stage
|
||||
$stageId = $h['stage']['id'];
|
||||
var_dump($stageId);
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO Create new stage
|
||||
var_dump('create stage');
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Go to next/previous step
|
||||
// Go to next/previous step
|
||||
if($validation === true)
|
||||
{
|
||||
if(!is_null($this->request->getPostParam('prev'))) {
|
||||
$step--;
|
||||
}
|
||||
else {
|
||||
$step++;
|
||||
}
|
||||
if($step > $steps) {
|
||||
// TODO Redirect
|
||||
//$this->redirect($this->linker->link(array('quest', $seminary['url'], $questgroup['url'], $quest['url']), 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Get validation settings
|
||||
$validationSettings = array();
|
||||
foreach($fields as &$field) {
|
||||
$validationSettings[$field] = $this->validationSettings[$field];
|
||||
}
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('seminary', $seminary);
|
||||
$this->set('character', $character);
|
||||
$this->set('fight', $fight);
|
||||
$this->set('stages', $stage);
|
||||
//print_r($stage);
|
||||
$this->set('step', $step);
|
||||
$this->set('tree', $tree);
|
||||
$this->set('bossname', $bossname);
|
||||
$this->set('livesCharacter', $livesCharacter);
|
||||
$this->set('livesBoss', $livesBoss);
|
||||
$this->set('mimetypes', $mimetypes);
|
||||
$this->set('validation', $validation);
|
||||
$this->set('validationSettings', $validationSettings);
|
||||
}
|
||||
|
||||
|
||||
|
@ -287,6 +484,118 @@
|
|||
return $childStages;
|
||||
}
|
||||
|
||||
|
||||
private function createStageTree($livesCharacter, $livesBoss)
|
||||
{
|
||||
$c = max($livesCharacter, $livesBoss) * 2;
|
||||
$tree = array();
|
||||
|
||||
$tree[0] = array(
|
||||
array(
|
||||
'lives_character' => $livesCharacter,
|
||||
'lives_boss' => $livesBoss
|
||||
)
|
||||
);
|
||||
for($i=1; $i<$c; $i++ )
|
||||
{
|
||||
$treeitem = array();
|
||||
$n = pow(2, $i);
|
||||
for($j=0; $j<$n/2; $j++)
|
||||
{
|
||||
if(array_key_exists($j, $tree[$i-1]))
|
||||
{
|
||||
if($tree[$i-1][$j]['lives_character'] > 0 && $tree[$i-1][$j]['lives_boss'] > 0 && $tree[$i-1][$j]['lives_boss'] - 1 >= 0)
|
||||
{
|
||||
$treeitem[$j*2] = array(
|
||||
'lives_character' => $tree[$i-1][$j]['lives_character'],
|
||||
'lives_boss' => $tree[$i-1][$j]['lives_boss'] - 1,
|
||||
);
|
||||
}
|
||||
if($tree[$i-1][$j]['lives_character'] > 0 && $tree[$i-1][$j]['lives_boss'] > 0 && $tree[$i-1][$j]['lives_character'] - 1 >= 0)
|
||||
{
|
||||
$treeitem[$j*2+1] = array(
|
||||
'lives_character' => $tree[$i-1][$j]['lives_character'] - 1,
|
||||
'lives_boss' => $tree[$i-1][$j]['lives_boss'],
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$tree[] = $treeitem;
|
||||
}
|
||||
|
||||
|
||||
return $tree;
|
||||
}
|
||||
|
||||
|
||||
private function createStageTree2($questId, $livesCharacter, $livesBoss)
|
||||
{
|
||||
// Create tree root
|
||||
$tree = array();
|
||||
$tree[0] = array(
|
||||
'lives_character' => $livesCharacter,
|
||||
'lives_boss' => $livesBoss
|
||||
);
|
||||
|
||||
// Get first stage
|
||||
$stage = $this->Bossfight->getFirstStage($questId);
|
||||
$tree[0]['stage'] = $stage;
|
||||
|
||||
// Start recursion
|
||||
$this->createStageTreeRec($questId, $stage, $tree);
|
||||
|
||||
|
||||
// Return tree
|
||||
return $tree;
|
||||
}
|
||||
|
||||
|
||||
private function createStageTreeRec($questId, $stage, &$tree)
|
||||
{
|
||||
// Get child stages
|
||||
$childStages = $this->Bossfight->getChildStages($stage['id']);
|
||||
foreach($childStages as $childStage)
|
||||
{
|
||||
$this->createStageTreeRec($questId, $childStage, $tree);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private function attachStages($questId, &$tree)
|
||||
{
|
||||
foreach($tree as $i => &$v)
|
||||
{
|
||||
if($i == 0) {
|
||||
$v[0]['stage'] = $this->Bossfight->getFirstStage($questId);
|
||||
}
|
||||
else
|
||||
{
|
||||
$childStages = null;
|
||||
foreach($v as $j => &$h)
|
||||
{
|
||||
if(is_null($childStages))
|
||||
{
|
||||
$childStages = range(0, 1);
|
||||
if(array_key_exists('stage', $tree[$i-1][floor($j/2)]) && !empty($tree[$i-1][floor($j/2)]['stage']))
|
||||
{
|
||||
$stages = $this->Bossfight->getChildStages($tree[$i-1][floor($j/2)]['stage']['id']);
|
||||
if(!empty($stages)) {
|
||||
$childStages = $stages;
|
||||
}
|
||||
}
|
||||
$tree[$i-1][floor($j/2)]['childstages'] = $childStages;
|
||||
$h['stage'] = (count($childStages) > 0) ? $childStages[0] : array();
|
||||
}
|
||||
else {
|
||||
$h['stage'] = (count($childStages) > 1) ? $childStages[1] : array();
|
||||
$childStages = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -91,6 +91,35 @@
|
|||
}
|
||||
|
||||
|
||||
public function createBossFight($userId, $questId, $bossname, $bossmediaId, $livesCharacter, $livesBoss)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO questtypes_bossfight '.
|
||||
'(quest_id, created_user_id, bossname, boss_seminarymedia_id, lives_character, lives_boss) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?, ?, ?, ?)',
|
||||
'iisiii',
|
||||
$questId, $userId, $bossname, $bossmediaId, $livesCharacter, $livesBoss
|
||||
);
|
||||
|
||||
|
||||
return $this->db->getInsertId();
|
||||
}
|
||||
|
||||
|
||||
public function editBossFight($questId, $bossname, $bossmediaId, $livesCharacter, $livesBoss)
|
||||
{
|
||||
$this->db->query(
|
||||
'UPDATE questtypes_bossfight '.
|
||||
'SET bossname = ?, boss_seminarymedia_id = ?, lives_character = ?, lives_boss = ? '.
|
||||
'WHERE quest_id = ?',
|
||||
'siiii',
|
||||
$bossname, $bossmediaId, $livesCharacter, $livesBoss,
|
||||
$questId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the first Stage to begin the Boss-Fight with.
|
||||
*
|
||||
|
|
|
@ -1,41 +1,201 @@
|
|||
<?php if($validation !== true && !empty($validation)) : ?>
|
||||
<ul class="validation">
|
||||
<?php foreach($validation as $field => &$settings) : ?>
|
||||
<li>
|
||||
<ul>
|
||||
<?php foreach($settings as $setting => $value) : ?>
|
||||
<li>
|
||||
<?php switch($field) {
|
||||
case 'bossname':
|
||||
switch($setting) {
|
||||
case 'minlength': printf(_('Name is too short (min. %d chars)'), $value);
|
||||
break;
|
||||
case 'maxlength': printf(_('Name is too long (max. %d chars)'), $value);
|
||||
break;
|
||||
case 'regex': echo _('Name contains illegal characters');
|
||||
break;
|
||||
default: echo _('Name invalid');
|
||||
}
|
||||
break;
|
||||
case 'bossimage':
|
||||
switch($setting) {
|
||||
case 'error': printf(_('Error during file upload: %s'), $value);
|
||||
break;
|
||||
case 'mimetype': printf(_('File has wrong type “%s”'), $value);
|
||||
break;
|
||||
case 'size': echo _('File exceeds size maximum');
|
||||
break;
|
||||
default: echo _('File invalid');
|
||||
}
|
||||
break;
|
||||
} ?>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
</ul>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
</ul>
|
||||
<?php endif ?>
|
||||
<form method="post" enctype="multipart/form-data">
|
||||
<?php if($step == 0) : ?>
|
||||
<fieldset>
|
||||
<legend><?=_('Boss-Fight')?></legend>
|
||||
<legend><?=sprintf(_('Step %d'), 1)?>: <?=_('Boss-Fight')?></legend>
|
||||
<label><?=_('Boss name')?></label>
|
||||
<input type="text" name="bossname" value="<?=$fight['bossname']?>" /><br />
|
||||
<input type="text" name="bossname" value="<?=$bossname?>" maxlength="<?=$validationSettings['bossname']['maxlength']?>" <?=($validation !== true && array_key_exists('bossname', $validation)) ? 'class="invalid"' : null ?> /><br />
|
||||
<label><?=_('Boss image')?></label>
|
||||
<input type="file" name="bossimage" /><br />
|
||||
<label><?=_('Boss lives')?></label>
|
||||
<input type="number" name="lives_boss" value="<?=$fight['lives_boss']?>" /><br />
|
||||
<p><?=_('Allowed file types')?>:</p>
|
||||
<ul>
|
||||
<?php foreach($mimetypes as &$mimetype) : ?>
|
||||
<li><?=sprintf(_('%s-files'), strtoupper(explode('/',$mimetype['mimetype'])[1]))?> <?php if($mimetype['size'] > 0) : ?>(<?=_('max.')?> <?=round($mimetype['size']/(1024*1024),2)?> MiB)<?php endif ?></li>
|
||||
<?php endforeach ?>
|
||||
</ul>
|
||||
<label><?=_('Character lives')?></label>
|
||||
<input type="number" name="lives_character" value="<?=$fight['lives_character']?>" />
|
||||
<input type="number" name="lives_character" value="<?=$livesCharacter?>" <?=($validation !== true && array_key_exists('lives_character', $validation)) ? 'class="invalid"' : null ?> /><br />
|
||||
<label><?=_('Boss lives')?></label>
|
||||
<input type="number" name="lives_boss" value="<?=$livesBoss?>" <?=($validation !== true && array_key_exists('lives_boss', $validation)) ? 'class="invalid"' : null ?> />
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<legend><?=_('Stages')?></legend>
|
||||
<?php renderStage($stages, $fight['lives_boss'], $fight['lives_character']); ?>
|
||||
<input type="submit" name="next" value="<?=_('next step')?>" />
|
||||
<?php elseif($step == 1) : ?>
|
||||
<fieldset id="bosstree">
|
||||
<legend><?=sprintf(_('Step %d'), 2)?>: <?=_('Stages')?></legend>
|
||||
<?php foreach($tree as $i => $v) : ?>
|
||||
<div class="bosstreerow">
|
||||
<?php foreach($v as $j => $h) : ?>
|
||||
<div id="bti-<?=$i?>-<?=$j?>" class="bosstreeitem" style=" width:<?=sprintf('%.3F', 100/count($v))?>%">
|
||||
<span class="bosstreelabel">
|
||||
<?php if($h['lives_character'] > 0) : ?>
|
||||
<?php foreach(range(1,$h['lives_character']) as $l) : ?>
|
||||
<i class="fa fa-heart fa-fw char"></i>
|
||||
<?php endforeach ?>
|
||||
<?php endif ?>
|
||||
<?php if($h['lives_boss'] > 0) : ?>
|
||||
<?php foreach(range(1,$h['lives_boss']) as $l) : ?>
|
||||
<i class="fa fa-heart fa-fw boss"></i>
|
||||
<?php endforeach ?>
|
||||
<?php endif ?>
|
||||
</span>
|
||||
<div id="line-<?=$i?>-<?=$j?>" class="bosstreeline"></div>
|
||||
</div>
|
||||
<?php endforeach ?>
|
||||
</div>
|
||||
<?php endforeach ?>
|
||||
</fieldset>
|
||||
<input type="submit" name="save" value="<?=_('save')?>" />
|
||||
<fieldset id="stages">
|
||||
<legend><?=_('Selected stage')?></legend>
|
||||
<?php foreach($tree as $i => $v) : ?>
|
||||
<?php foreach($v as $j => $h) : ?>
|
||||
<div id="stage-<?=$i?>-<?=$j?>" class="bossstage">
|
||||
<div class="cf">
|
||||
<section class="opponent">
|
||||
<p class="fwb"><?=$character['name']?></p>
|
||||
<p class="portrait"><img src="<?=$linker->link(array('media','avatar',$seminary['url'],$character['charactertype_url'],$character['xplevel']))?>" class="hero" /></p>
|
||||
<p>
|
||||
<?php if($h['lives_character'] > 0) : ?>
|
||||
<?php foreach(range(1,$h['lives_character']) as $l) : ?>
|
||||
<i class="fa fa-heart fa-fw char"></i>
|
||||
<?php endforeach ?>
|
||||
<?php else : ?>
|
||||
<?=_('lost')?>
|
||||
<?php endif ?>
|
||||
</p>
|
||||
</section>
|
||||
<section class="opponent">
|
||||
<p class="fwb"><?=$fight['bossname']?></p>
|
||||
<p class="portrait"><img src="<?=$linker->link(array('media','seminary',$seminary['url'],$fight['bossmedia']['url']))?>" class="boss" /></p>
|
||||
<p>
|
||||
<?php if($h['lives_boss'] > 0) : ?>
|
||||
<?php foreach(range(1,$h['lives_boss']) as $l) : ?>
|
||||
<i class="fa fa-heart fa-fw boss"></i>
|
||||
<?php endforeach ?>
|
||||
<?php else : ?>
|
||||
<b><?=_('lost')?></b>
|
||||
<?php endif ?>
|
||||
</p>
|
||||
</section>
|
||||
</div>
|
||||
<textarea name="stages[<?=$i?>][<?=$j?>][question]"><?=$h['stage']['text']?></textarea>
|
||||
<?php if(array_key_exists('childstages', $h)) : ?>
|
||||
<ul class="bossfight cf">
|
||||
<?php foreach($h['childstages'] as &$childStage) : ?>
|
||||
<li class="option">
|
||||
<textarea name="stages[<?=$i?>][<?=$j?>]"><?php if(!empty($childStage)) : ?><?=\hhu\z\Utils::t($childStage['question'])?><?php endif ?></textarea>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
</ul>
|
||||
<?php endif ?>
|
||||
</div>
|
||||
<?php endforeach ?>
|
||||
<?php endforeach ?>
|
||||
</fieldset>
|
||||
<input type="submit" name="prev" value="<?=_('previous step')?>" />
|
||||
<input type="submit" name="next" value="<?=_('save')?>" />
|
||||
<input type="hidden" name="step" value="<?=$step?>" />
|
||||
<?php endif ?>
|
||||
</form>
|
||||
|
||||
<?php function renderStage($stage, $livesBoss, $livesCharacter, $level=0, $indices=array()) { ?>
|
||||
<div style="margin-left:<?=$level?>em">
|
||||
<h2><?=implode('.', $indices)?></h2>
|
||||
<?php if(!empty($stage['question'])) : ?>
|
||||
<p><?=$stage['question']?></p>
|
||||
<script>
|
||||
function drawLine(targetItemId, sourceItemId, lineId)
|
||||
{
|
||||
var sourceItem = $('#'+sourceItemId);
|
||||
var targetItem = $('#'+targetItemId);
|
||||
var sourcePoint = sourceItem.position();
|
||||
sourcePoint.left = sourcePoint.left + sourceItem.width()/2;
|
||||
sourcePoint.top = sourcePoint.top + sourceItem.height();
|
||||
var targetPoint = targetItem.position();
|
||||
targetPoint.left = targetPoint.left + targetItem.width()/2;
|
||||
var line = $('#'+lineId);
|
||||
|
||||
var length = Math.sqrt(
|
||||
Math.pow(targetPoint.left - sourcePoint.left, 2) +
|
||||
Math.pow(targetPoint.top - sourcePoint.top, 2)
|
||||
);
|
||||
var angle = 180 / Math.PI * Math.acos((targetPoint.left - sourcePoint.left) / length);
|
||||
|
||||
line.css('width', Math.floor(length)+'px');
|
||||
line.css('left', sourcePoint.left+'px');
|
||||
line.css('top', sourcePoint.top+'px');
|
||||
line.css('transform-origin', 'top left');
|
||||
line.css('transform', 'rotate('+angle+'deg)');
|
||||
}
|
||||
|
||||
function drawLines()
|
||||
{
|
||||
<?php foreach($tree as $i => $v) : ?>
|
||||
<?php foreach($v as $j => $h) : ?>
|
||||
<?php if($i > 0) : ?>
|
||||
drawLine('bti-<?=$i?>-<?=$j?>', 'bti-<?=$i-1?>-<?=floor($j/2)?>', 'line-<?=$i?>-<?=$j?>');
|
||||
<?php endif ?>
|
||||
<p><?=_('Character')?> <?=$livesCharacter?> vs. <?=$livesBoss?> <?=_('Boss')?></p>
|
||||
<p><?=$stage['text']?></p>
|
||||
<?php foreach($stage['childs'] as $index => &$childStage) : ?>
|
||||
<?php $childIndices = $indices; ?>
|
||||
<?php $childIndices[] = $index+1; ?>
|
||||
<?php renderStage($childStage, $livesBoss+$childStage['livedrain_boss'], $livesCharacter+$childStage['livedrain_character'], $level+1, $childIndices); ?>
|
||||
<?php endforeach ?>
|
||||
<?php if($livesBoss == 0 && $livesCharacter == 0) : ?>
|
||||
Bedie verloren
|
||||
<?php elseif($livesBoss == 0) : ?>
|
||||
Boss verloren, Character gewonnen
|
||||
<?php elseif($livesCharacter == 0) : ?>
|
||||
Boss gewonnen, Character verloren
|
||||
<?php endif ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<?php endforeach ?>
|
||||
}
|
||||
|
||||
function showSelectedStage()
|
||||
{
|
||||
$("#bosstree span.ui-selected").each(function(index) {
|
||||
var id = 'stage-' + $(this).parent().attr('id').substr(4);
|
||||
// hide current stage
|
||||
$("#stages div.bossstage").css('display', 'none');
|
||||
// show new stage
|
||||
$("#"+id).css('display', 'block');
|
||||
});
|
||||
}
|
||||
|
||||
var resizeTimer;
|
||||
$(function()
|
||||
{
|
||||
$(window).resize(function() {
|
||||
clearTimeout(resizeTimer);
|
||||
resizeTimer = setTimeout(drawLines, 100);
|
||||
});
|
||||
drawLines();
|
||||
$('#bosstree').selectable({
|
||||
filter: " span.bosstreelabel",
|
||||
selected: function(event, ui) {
|
||||
showSelectedStage();
|
||||
}
|
||||
});
|
||||
$("#bti-0-0 span.bosstreelabel").addClass('ui-selected');
|
||||
showSelectedStage();
|
||||
});
|
||||
</script>
|
||||
|
|
|
@ -373,6 +373,84 @@
|
|||
*/
|
||||
public function edittask($seminary, $questgroup, $quest)
|
||||
{
|
||||
// Get words
|
||||
$words = $this->Crossword->getWordsForQuest($quest['id']);
|
||||
|
||||
// Create 2D-matrix
|
||||
$matrix = array();
|
||||
$maxX = 0;
|
||||
$maxY = 0;
|
||||
foreach($words as $index => &$word)
|
||||
{
|
||||
// Insert word
|
||||
if($word['vertical'])
|
||||
{
|
||||
$x = $word['pos_x'];
|
||||
$startY = $word['pos_y'];
|
||||
$endY = $startY + mb_strlen($word['word'], 'UTF-8') - 1;
|
||||
|
||||
$matrix = array_pad($matrix, $x+1, array());
|
||||
$matrix[$x] = array_pad($matrix[$x], $endY+1, null);
|
||||
$maxX = max($maxX, $x);
|
||||
$maxY = max($maxY, $endY);
|
||||
|
||||
foreach(range($startY, $endY) as $y)
|
||||
{
|
||||
$matrix[$x][$y] = array(
|
||||
'char' => mb_substr($word['word'], $y-$startY, 1, 'UTF-8'),
|
||||
'indices' => (array_key_exists($x, $matrix) && array_key_exists($y, $matrix[$x]) && !is_null($matrix[$x][$y]) && array_key_exists('indices', $matrix[$x][$y])) ? $matrix[$x][$y]['indices'] : array()
|
||||
);
|
||||
if($y == $startY) {
|
||||
$matrix[$x][$y]['indices'][] = $index;
|
||||
}
|
||||
if(array_key_exists('answer', $word))
|
||||
{
|
||||
$answer = mb_substr($word['answer'], $y-$startY, 1, 'UTF-8');
|
||||
if($answer != ' ') {
|
||||
$matrix[$x][$y]['answer'] = $answer;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$startX = $word['pos_x'];
|
||||
$endX = $startX + mb_strlen($word['word'], 'UTF-8') - 1;
|
||||
$y = $word['pos_y'];
|
||||
|
||||
$matrix = array_pad($matrix, $endX+1, array());
|
||||
$maxX = max($maxX, $endX);
|
||||
$maxY = max($maxY, $y);
|
||||
|
||||
foreach(range($startX, $endX) as $x)
|
||||
{
|
||||
$matrix[$x] = array_pad($matrix[$x], $y+1, null);
|
||||
|
||||
$matrix[$x][$y] = array(
|
||||
'char' => mb_substr($word['word'], $x-$startX, 1, 'UTF-8'),
|
||||
'indices' => (array_key_exists($x, $matrix) && array_key_exists($y, $matrix[$x]) && !is_null($matrix[$x][$y]) && array_key_exists('indices', $matrix[$x][$y])) ? $matrix[$x][$y]['indices'] : array(),
|
||||
'answer' => null
|
||||
);
|
||||
if($x == $startX) {
|
||||
$matrix[$x][$y]['indices'][] = $index;
|
||||
}
|
||||
if(array_key_exists('answer', $word))
|
||||
{
|
||||
$answer = mb_substr($word['answer'], $x-$startX, 1, 'UTF-8');
|
||||
if($answer != ' ') {
|
||||
$matrix[$x][$y]['answer'] = $answer;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('words', $words);
|
||||
$this->set('maxX', $maxX);
|
||||
$this->set('maxY', $maxY);
|
||||
$this->set('matrix', $matrix);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1 +1,48 @@
|
|||
<p>TODO</p>
|
||||
<form method="post" class="crossword">
|
||||
<fieldset>
|
||||
<legend><?=_('Preview')?></legend>
|
||||
<table id="matrix">
|
||||
<tbody>
|
||||
<?php foreach(range(0, $maxY) as $y) : ?>
|
||||
<tr>
|
||||
<?php foreach(range(0, $maxX) as $x) : ?>
|
||||
<td>
|
||||
<?php if(array_key_exists($x, $matrix) && array_key_exists($y, $matrix[$x]) && !is_null($matrix[$x][$y])) : ?>
|
||||
<?php if(count($matrix[$x][$y]['indices']) > 0) : ?><span class="index"><?=implode('/',array_map(function($e) { return $e+1; }, $matrix[$x][$y]['indices']))?></span><?php endif ?>
|
||||
<input type="text" maxlength="1" size="1" disabled="disabled" value="<?=$matrix[$x][$y]['char']?>" />
|
||||
<?php endif ?>
|
||||
</td>
|
||||
<?php endforeach ?>
|
||||
</tr>
|
||||
<?php endforeach ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</fieldset>
|
||||
<fieldset class="dev">
|
||||
<legend><?=_('Questions')?></legend>
|
||||
<ol>
|
||||
<?php foreach($words as &$word) : ?>
|
||||
<li>
|
||||
<?=_('Position')?>:
|
||||
<input type="number" value="<?=$word['pos_x']+1?>" />
|
||||
<input type="number" value="<?=$word['pos_y']+1?>" />
|
||||
<select>
|
||||
<option <?php if(!$word['vertical']) : ?>selected="selected"<?php endif ?>><?=_('horizontal')?></option>
|
||||
<option <?php if($word['vertical']) : ?>selected="selected"<?php endif ?>><?=_('vertical')?></option>
|
||||
</select>
|
||||
<br />
|
||||
<?=_('Question')?>:<br />
|
||||
<textarea><?=$word['question']?></textarea><br />
|
||||
<?=_('Answer')?>:<br />
|
||||
<input type="text" value="<?=$word['word']?>" />
|
||||
<br />
|
||||
<input type="button" class="remove-question" value="−" />
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
<li>
|
||||
<input type="button" class="add-question" value="+" />
|
||||
</li>
|
||||
</ol>
|
||||
</fieldset>
|
||||
<input type="submit" name="save" value="<?=_('save')?>" />
|
||||
</form>
|
||||
|
|
|
@ -172,6 +172,7 @@ input[type="submit"][disabled]{text-shadow:1px 2px #d48c4e;background:#f9ac69;bo
|
|||
.notify p.announce{color:#0f373c;font-weight:700;font-size:.875em;margin-top:5px}
|
||||
.notify .fa{padding-right:5px}
|
||||
.notify .fa-times{float:right;padding:0;margin:-12px -10px 0 0;color:#d4d2ce}
|
||||
#notify-sound{display:none}
|
||||
|
||||
|
||||
/** Login, Registration & Filter **/
|
||||
|
@ -326,6 +327,8 @@ input[type="submit"][disabled]{text-shadow:1px 2px #d48c4e;background:#f9ac69;bo
|
|||
.success,.error{margin:15px 0;padding:5px 15px;border:1px solid #4F8A10;background:#DFF2BF;color:#4F8A10;border-radius:3px}
|
||||
.error{border:1px solid #850000;background:#ebd3d3;color:#850000}
|
||||
.success p,.error p{margin-bottom:5px}
|
||||
.dev textarea{width:99%;height:150px}
|
||||
.dev input[type="text"]{width:99%;max-width:99%;text-align:left}
|
||||
|
||||
.solvdmsg{margin-top:20px}
|
||||
|
||||
|
@ -342,7 +345,7 @@ input[type="submit"][disabled]{text-shadow:1px 2px #d48c4e;background:#f9ac69;bo
|
|||
|
||||
.crossword table{border-spacing:2px;border-collapse:separate}
|
||||
.crossword td{background:#d7d4cf;padding:1px;border:0}
|
||||
.crossword input[type=text]{text-align:center;height:26px;width:100%;min-width:8px;max-width:40px;margin:0;padding:0;border:none;text-transform:uppercase}
|
||||
.crossword table input[type=text]{text-align:center;height:26px;width:100%;min-width:8px;max-width:40px;margin:0;padding:0;border:none;text-transform:uppercase}
|
||||
.crossword ol{list-style-type:decimal;margin-left:25px}
|
||||
.crossword li{margin-top:20px}
|
||||
.crossword .index{position:absolute;font-size:0.625em;margin:-2px 0 0 2px}
|
||||
|
@ -354,6 +357,16 @@ input[type="submit"][disabled]{text-shadow:1px 2px #d48c4e;background:#f9ac69;bo
|
|||
.opponent p{text-align:center}
|
||||
.opponent .fa{font-size:1.25em;color:#c7135b;padding-right:0}
|
||||
.bossfight .option{background:#fff;margin-bottom:10px;padding:15px 15px 5px;border-radius:3px}
|
||||
#bosstree span.ui-selected{background-color:white}
|
||||
.bosstreerow{display:block;height:2em;margin:2em 0;text-align:center}
|
||||
.bosstreerow div{white-space:nowrap}
|
||||
.bosstreerow .fa{display:inline;font-size:1.25em;padding-right:0}
|
||||
.bosstreerow .char{color:#c7135b}
|
||||
.bosstreeitem{float:left}
|
||||
.bosstreelabel{display:block;margin-top:0.5em;cursor:pointer}
|
||||
.bosstreeline{position:absolute;width:0;height:1px;background-color:black}
|
||||
.bossstage{display:none}
|
||||
.bossstage textarea{width:100%;height:150px}
|
||||
|
||||
#dropZone.dev div{text-align:center;background-color:rgba(255,255,0,0.6)}
|
||||
#dropZone.dev i.move{cursor:grab}
|
||||
|
|
6
www/js/jquery-ui.min.js
vendored
6
www/js/jquery-ui.min.js
vendored
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue