Skip to content

Commit

Permalink
Ask for chosing a speciality in a blocking pop-up
Browse files Browse the repository at this point in the history
  • Loading branch information
Nadawoo committed Dec 20, 2024
1 parent dcc8e9c commit 8bea5ac
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 68 deletions.
47 changes: 0 additions & 47 deletions core/view/HtmlLayout.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,53 +121,6 @@ function block_create_citizen()
}


/**
* Boutons pour choisir sa spécialité citoyenne
* (explorateur, fouineur, bâtisseur)
*
* @param array $specialities Les caractéristiques de chaque spécialité, issues de l'API
* (points d'action, temps de fouille..)
* @return string
*/
function block_speciality_choice($specialities)
{

$buttons = new HtmlButtons();

$html_specialities = '';
foreach($specialities as $alias=>$speciality) {

$html_specialities .= '
<li>'.$buttons->button('specialize_'.$alias, '', 'inline').'&nbsp;
[<abbr title="Les points d\'action vous permettent d\'explorer le désert, construire des bâtiments et d\'autres actions encore.">Points d\'action</abbr>&nbsp;:
'. $speciality['action_points'].'&nbsp; |&nbsp;
<abbr title="Plus votre sac est grand, plus vous pouvez transporter d\'objets en même temps.">Sac</abbr>&nbsp;:
'.plural($speciality['bag_size'], 'objet').']
<div style="margin-left:0.5em;margin-bottom:0.5em;font-style:italic">'.$speciality['descr_purpose'].'</div>
</li>';
}

return '
<p class="center">
<button class="redbutton" onclick="toggle(\'#specialities\');hide(\'#capacities\');return false">Changer ma spécialité</button>
<button class="redbutton" onclick="toggle(\'#capacities\');hide(\'#specialities\');return false">Améliorer une capacité</button>
</p>
<ul id="specialities" class="hidden">
'.$html_specialities.'
</ul>
<ul id="capacities" class="hidden">
<li>'.$buttons->button('upgrade_camouflage', '', 'inline').'<br>
&nbsp;&nbsp;&nbsp;Permet de vous dissimuler aux yeux des autres humains
</li>
<li>'.$buttons->button('upgrade_vision', '', 'inline').'<br>
&nbsp;&nbsp;&nbsp;Permet de percer le camouflage des humains et des bâtiments
</li>
</ul>';
}


/**
* Bar above the map showing the countdown before the next attack, the current day...
* @param int $map_id The ID of the map on which the player is
Expand Down
2 changes: 1 addition & 1 deletion core/view/HtmlPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class HtmlPage
// Increment those variables when you modify the CSS or JS files. This ensures
// that the users' browsers reload the up-to-date files, instead of using
// the obsolete ones stored in their cache.
private $css_js_version = 51.4;
private $css_js_version = 51.5;

/**
* Sets HTTP headers to secure the website
Expand Down
63 changes: 60 additions & 3 deletions core/view/HtmlPopup.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,30 @@ function __construct() {}
* @param int $map_id
* @param int $citizen_id
* @param array $configs_map
* @param array $specialities
* @param array $speciality_caracs
* @param array $healing_items
* @param bool $is_custom_popup_visible
*
* @return string HTML
*/
public function all_popups($msg_popup, $map_id, $citizen_id,
$configs_map, $speciality_caracs,
$healing_items, $is_custom_popup_visible) {
public function all_popups( $msg_popup,
$map_id,
$citizen_id,
$configs_map,
$specialities,
$speciality_caracs,
$healing_items,
$is_custom_popup_visible
) {

return $this->predefined('poppresentation', '')
. $this->predefined('poptasks', 'Objectifs')
. $this->predefined('popdoor', '&#8505;&#65039; La porte de la ville')
. $this->predefined('popdayclock', '', ['map_id'=>$map_id, 'current_cycle'=>$configs_map['current_cycle']])
. $this->predefined('popvault', '')
. $this->predefined('popitems', '')
. $this->predefined('popspecialize', 'Action du jour', $specialities)
. $this->predefined('popmycaracs', 'Mes caractéristiques', $speciality_caracs)
. $this->predefined('popwounded', '', ['citizen_id'=>$citizen_id, 'healing_items'=>$healing_items])
. $this->predefined('popcontrol', '&#8505;&#65039; Le contrôle de zone')
Expand Down Expand Up @@ -872,6 +880,55 @@ private function popdayclock($params) {
}


private function popspecialize($specialities) {

$buttons = new HtmlButtons();

$html_specialities = '';
foreach($specialities as $alias=>$speciality) {

$html_specialities .= '
<li>'.$buttons->button('specialize_'.$alias, '', 'inline').'&nbsp;
[<abbr title="Les points d\'action vous permettent d\'explorer le désert, construire des bâtiments et d\'autres actions encore.">Points d\'action</abbr>&nbsp;:
'. $speciality['action_points'].'&nbsp; |&nbsp;
<abbr title="Plus votre sac est grand, plus vous pouvez transporter d\'objets en même temps.">Sac</abbr>&nbsp;:
'.plural($speciality['bag_size'], 'objet').']
<div style="margin-left:0.5em;margin-bottom:0.5em;font-style:italic">'.$speciality['descr_purpose'].'</div>
</li>';
}

return '
<p>Choisissez la caractéristique à améliorer sur votre citoyen :</p>
<ul class="collapsible">
<li>
<div class="collapsible-header"><strong>Choisir ma spécialité</strong></div>
<div class="collapsible-body">
<ul id="specialities">
'.$html_specialities.'
</ul>
</div>
</li>
<!--
<li>
<div class="collapsible-header"><strong>Améliorer une capacité</strong></div>
<div class="collapsible-body">
<ul id="capacities">
<li>'.$buttons->button('upgrade_camouflage', '', 'inline').'<br>
&nbsp;&nbsp;&nbsp;Permet de vous dissimuler aux yeux des autres humains
</li>
<li>'.$buttons->button('upgrade_vision', '', 'inline').'<br>
&nbsp;&nbsp;&nbsp;Permet de percer le camouflage des humains et des bâtiments
</li>
</ul>
</div>
</li>
-->
</ul>';
}


/**
* Displays the in-game smartphone (which shows action points, radar, etc.)
*
Expand Down
28 changes: 11 additions & 17 deletions public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@

<?php
/**
* Start of the HTML page
* Beginning of the HTML page
*/
echo $layout->page_header($citizen['user_id'], $citizen['citizen_id'], $citizen['citizen_pseudo']);
echo $html['hidden_player_data'];
Expand All @@ -191,9 +191,15 @@
?>

<section id="popups">
<?php echo $popup->all_popups($msg_popup, $citizen['map_id'], $citizen['citizen_id'],
$configs['map'], $speciality_caracs,
$healing_items, $is_custom_popup_visible)
<?php echo $popup->all_popups( $msg_popup,
$citizen['map_id'],
$citizen['citizen_id'],
$configs['map'],
$specialities,
$speciality_caracs,
$healing_items,
$is_custom_popup_visible
);
?>
</section>

Expand All @@ -219,19 +225,7 @@
</div>
</template>
</section>

<?php
// Asks for chosing a citizen speciality (builder, digger...)
if ($citizen['citizen_id'] !== null and $citizen['last_specialization_cycle'] < $current_cycle) {
?>
<fieldset id="citizen_caracs">
<legend>Action du jour</legend>
<?php echo $layout->block_speciality_choice($specialities) ?>
</fieldset>
<?php
} ?>



<div id="game_container" data-section="game">

<?php
Expand Down
6 changes: 6 additions & 0 deletions public/resources/js/onPageLoad.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ if (document.getElementById('map') !== null) {
// Add the number of defenses required in the tasks list
let tasks = new Tasks();
tasks.populateTaskDefenses();

// Ask for chosing a citizen speciality (builder, digger...)
let citizenId = Number(document.querySelector("#citizenId").innerText);
if(Number(_citizens[citizenId]["last_specialization_cycle"]) < getCurrentCycle()) {
window.location.hash = "#popspecialize";
}
}, 1000);
} else {
document.querySelector("#views_bar").classList.add("hidden");
Expand Down

0 comments on commit 8bea5ac

Please sign in to comment.