From 32c4db6c75342f77c6c65a348dc426b939c58b70 Mon Sep 17 00:00:00 2001 From: rylon Date: Thu, 6 Nov 2014 14:25:56 +0100 Subject: [PATCH] updated skilltree --- mojotrollz/api/char/js/skilltree.js | 185 +++++++++++++++++++-- mojotrollz/api/char/skilltree.php | 16 +- mojotrollz/api/char/tpl/skilltree_icon.tpl | 2 +- 3 files changed, 181 insertions(+), 22 deletions(-) diff --git a/mojotrollz/api/char/js/skilltree.js b/mojotrollz/api/char/js/skilltree.js index 0c55843..70ac59f 100644 --- a/mojotrollz/api/char/js/skilltree.js +++ b/mojotrollz/api/char/js/skilltree.js @@ -11,42 +11,136 @@ function skilltree(){ var id_img = '#'+this.id +'i'; switch (event.which) { case 1: - if(!is_point_max() && !is_icon_max(id_count)){ - write_icon_cur(id_count,id_img,1);} + if(is_icon_skillable(id) && !is_point_max() && !is_icon_max(id_count)){ + write_icon_cur(id,id_count,id_img,1);} break; case 2: //alert('Middle Mouse button pressed.'); break; case 3: - if(!is_icon_min(id_count)){ - write_icon_cur(id_count,id_img,-1);} + if(is_icon_deskillable(id) && !is_icon_min(id_count)){ + write_icon_cur(id,id_count,id_img,-1);} break; default: //alert('You have a strange Mouse!'); } }); } +function write_points(){ + $('#treeheader1 .stdText').html(' - '+points_spent_t1+' Points'); + $('#treeheader2 .stdText').html(' - '+points_spent_t2+' Points'); + $('#treeheader3 .stdText').html(' - '+points_spent_t3+' Points'); +} +function is_icon_skillable(id){ + tree = parseInt($(id).attr('t')); + row = parseInt($(id).attr('r')); + column = parseInt($(id).attr('r')); + count = 0; + + $('#tree'+tree+' .icon').each(function(){ + if($(this).attr('r') < row){ + count += parseInt($('#'+this.id+'c').attr('cur'));} + }); + + if(count < 5*(row-1)){ + return false;} + + if( $('#'+this.id+'i').hasClass('icon_border_grey_inc_left') || + $('#'+this.id+'i').hasClass('icon_border_green_inc_left') || + $('#'+this.id+'i').hasClass('icon_border_yellow_inc_left')){ + alert("abc"); + } + + if( $('#'+this.id+'i').hasClass('icon_border_grey_inc') || + $('#'+this.id+'i').hasClass('icon_border_green_inc') || + $('#'+this.id+'i').hasClass('icon_border_yellow_inc')){ + alert("abc2"); + } + + return true; + +} +function is_icon_deskillable(id){ + tree = parseInt($(id).attr('t')); + row = parseInt($(id).attr('r')); + count = 0; + $('#tree'+tree+' .icon').each(function(){ + if($(this).attr('r') > row){ + count += parseInt($('#'+this.id+'c').attr('cur'));} + }); + if(count > 0){ + return false;} + return true; +} function is_point_max(){ return points_max <= points_spent_t1 + points_spent_t2 +points_spent_t3;} function is_icon_max(id){ return $(id).attr('max') <= $(id).attr('cur');} function is_icon_min(id){ return 0 >= $(id).attr('cur');} -function write_icon_cur(id,id_img,amount){ - current = $(id).attr('cur'); +function write_icon_cur(id,id_count,id_img,amount){ + current = $(id_count).attr('cur'); current = parseInt(current)+amount; - $(id).attr('cur',current); - $(id).html(current+'/'+$(id).attr('max')); - if(is_icon_max(id)){ - write_icon_yellow(id,id_img); + $(id_count).attr('cur',current); + $(id_count).html(current+'/'+$(id_count).attr('max')); + if(is_icon_max(id_count)){ + write_icon_yellow(id,id_count,id_img); } else { - write_icon_green(id,id_img); + write_icon_green(id,id_count,id_img);} + + tree = parseInt($(id).attr('t')); + row = parseInt($(id).attr('r')); + + switch(tree){ + case 1: + points_spent_t1 += amount; + break; + case 2: + points_spent_t2 += amount; + break; + case 3: + points_spent_t3 += amount; + break; + } + write_points(); + + count = 0; + $('#tree'+tree+' .icon').each(function(){ + if($(this).attr('r') <= row){ + count += parseInt($('#'+this.id+'c').attr('cur'));} + }); + if(count >= 5*(row)){ + $('#tree'+tree+' .icon').each(function(){ + if(parseInt($('#'+this.id).attr('r')) == row+1){ + if(!$('#'+this.id+'i').hasClass('talent_arrow')){ + current = parseInt($('#'+this.id+'c').attr('cur')); + $('#'+this.id+'c').html(current+'/'+$('#'+this.id+'c').attr('max')); + } + if(is_icon_max('#'+this.id+'c')){ + write_icon_yellow('#'+this.id,'#'+this.id+'c','#'+this.id+'i'); + } else { + write_icon_green('#'+this.id,'#'+this.id+'c','#'+this.id+'i'); + } + } + }); + } else { + $('#tree'+tree+' .icon').each(function(){ + if(parseInt($('#'+this.id).attr('r')) > row){ + $('#'+this.id+'c').html(''); + write_icon_grey('#'+this.id,'#'+this.id+'c','#'+this.id+'i'); + } + }); } } -function write_icon_green(id,id_img){ - $(id).removeClass('icon_text_yellow'); - $(id).addClass('icon_text_green'); +function write_icon_green(id,id_count,id_img){ + if($(id_img).hasClass('icon_empty')){ + return;} + + $(id_count).removeClass('icon_text_yellow'); + $(id_count).addClass('icon_text_green'); + + $(id).attr('style','background: url(./api.php?call=files&cat=skilltree_skills&id='+$(id).attr('icon')+') 50% 50% no-repeat;'); if( $(id_img).hasClass('icon_border_grey') || $(id_img).hasClass('icon_border_yellow')){ @@ -90,9 +184,14 @@ function write_icon_green(id,id_img){ $(id_img).removeClass('icon_border_yellow_left'); $(id_img).addClass('icon_border_green_left');} } -function write_icon_yellow(id,id_img){ - $(id).removeClass('icon_text_green'); - $(id).addClass('icon_text_yellow'); +function write_icon_yellow(id,id_count,id_img){ + if($(id_img).hasClass('icon_empty')){ + return;} + + $(id_count).removeClass('icon_text_green'); + $(id_count).addClass('icon_text_yellow'); + + $(id).attr('style','background: url(./api.php?call=files&cat=skilltree_skills&id='+$(id).attr('icon')+') 50% 50% no-repeat;'); if( $(id_img).hasClass('icon_border_grey') || $(id_img).hasClass('icon_border_green')){ @@ -135,4 +234,56 @@ function write_icon_yellow(id,id_img){ $(id_img).removeClass('icon_border_grey_left'); $(id_img).removeClass('icon_border_green_left'); $(id_img).addClass('icon_border_yellow_left');} +} + +function write_icon_grey(id,id_count,id_img){ + if($(id_img).hasClass('icon_empty')){ + return;} + + $(id_count).removeClass('icon_text_green'); + $(id_count).removeClass('icon_text_yellow'); + + $(id).attr('style','background: url(./api.php?call=files&cat=skilltree_skills_grey&id='+$(id).attr('icon')+') 50% 50% no-repeat;'); + + if( $(id_img).hasClass('icon_border_yellow') || + $(id_img).hasClass('icon_border_green')){ + $(id_img).removeClass('icon_border_yellow'); + $(id_img).removeClass('icon_border_green'); + $(id_img).addClass('icon_border_grey');} + + if( $(id_img).hasClass('icon_border_yellow_down') || + $(id_img).hasClass('icon_border_green_down')){ + $(id_img).removeClass('icon_border_yellow_down'); + $(id_img).removeClass('icon_border_green_down'); + $(id_img).addClass('icon_border_grey_down');} + + if( $(id_img).hasClass('icon_border_yellow_down_right') || + $(id_img).hasClass('icon_border_green_down_right')){ + $(id_img).removeClass('icon_border_yellow_down_right'); + $(id_img).removeClass('icon_border_green_down_right'); + $(id_img).addClass('icon_border_grey_down_right');} + + if( $(id_img).hasClass('icon_border_yellow_right') || + $(id_img).hasClass('icon_border_green_right')){ + $(id_img).removeClass('icon_border_yellow_right'); + $(id_img).removeClass('icon_border_green_right'); + $(id_img).addClass('icon_border_grey_right');} + + if( $(id_img).hasClass('icon_border_yellow_inc') || + $(id_img).hasClass('icon_border_green_inc')){ + $(id_img).removeClass('icon_border_yellow_inc'); + $(id_img).removeClass('icon_border_green_inc'); + $(id_img).addClass('icon_border_grey_inc');} + + if( $(id_img).hasClass('icon_border_yellow_inc_left') || + $(id_img).hasClass('icon_border_green_inc_left')){ + $(id_img).removeClass('icon_border_yellow_inc_left'); + $(id_img).removeClass('icon_border_green_inc_left'); + $(id_img).addClass('icon_border_grey_inc_left');} + + if( $(id_img).hasClass('icon_border_yellow_left') || + $(id_img).hasClass('icon_border_green_left')){ + $(id_img).removeClass('icon_border_yellow_left'); + $(id_img).removeClass('icon_border_green_left'); + $(id_img).addClass('icon_border_grey_left');} } \ No newline at end of file diff --git a/mojotrollz/api/char/skilltree.php b/mojotrollz/api/char/skilltree.php index 54896cb..c751575 100644 --- a/mojotrollz/api/char/skilltree.php +++ b/mojotrollz/api/char/skilltree.php @@ -12,7 +12,7 @@ class skilltree{ $tree = 'tree'.$t; if($c == 1){ - $vars[$tree] .= '
';} + $vars[$tree] .= '
';} if( count($res) > $count && $res[$count]['tree'] == $t && @@ -38,7 +38,11 @@ class skilltree{ 'border' => $res[$count]['border'], 'text_color' => $text_color, 'max_text' => $max_text, - 'max' => $res[$count]['max'])); + 'max' => $res[$count]['max'], + 'tree' => $t, + 'row' => $r, + 'column' => $c, + 'icon' => $res[$count]['icon'])); $count++; } else { @@ -46,11 +50,15 @@ class skilltree{ $vars[$tree] .= \SYSTEM\PAGE\replace::replaceFile(SYSTEM\SERVERPATH(new PAPI(),'char/tpl/skilltree_icon.tpl'), array( 'id' => $id, 'style' => 'visibility:hidden;', - 'type' => 'talent_icon', + 'type' => 'talent_icon icon_empty', 'border' => '', 'text_color' => '', 'max_text' => '', - 'max' => 0)); + 'max' => 0, + 'tree' => $t, + 'row' => $r, + 'column' => $c, + 'icon' => '')); } if($c == 4){ diff --git a/mojotrollz/api/char/tpl/skilltree_icon.tpl b/mojotrollz/api/char/tpl/skilltree_icon.tpl index 18255f8..b52eac4 100644 --- a/mojotrollz/api/char/tpl/skilltree_icon.tpl +++ b/mojotrollz/api/char/tpl/skilltree_icon.tpl @@ -1,4 +1,4 @@ -
+
${max_text}
\ No newline at end of file