Planet mining settings interface
* Modified owned planet view to include a field which indicates whether mining settings are specific to the planet or come from the empire; modified "simple" game components accordingly * Modified stored procedures to only allow planet-specific mining settings updates when the planet actually uses planet-specific settings, and added a stored procedure which toggles the source of a planet's settings * Added corresponding parts to mining settings DAO and resources controller * Added session commands and server command handlers that toggle the source of the settings and that upload the settings * Split planet page template into multiple files for clarity and added the mining priorities form to the natural resources tab
This commit is contained in:
parent
51b529a09f
commit
e64f847ec3
25 changed files with 1009 additions and 152 deletions
legacyworlds-web-main
Content/Raw/WEB-INF/fm
src/main/java/com/deepclone/lw/web/main/game
|
@ -376,55 +376,8 @@
|
|||
|
||||
</#if>
|
||||
|
||||
<#list data.own.resources as resource>
|
||||
<#if resource.resourceProvider?has_content>
|
||||
<#local showResources=true>
|
||||
<#break>
|
||||
</#if>
|
||||
</#list>
|
||||
|
||||
<#if showResources?has_content>
|
||||
<@tab id="natres" title="Natural resources">
|
||||
|
||||
<@listview>
|
||||
<@lv_line headers=true>
|
||||
<@lv_column width="x">Resource</@lv_column>
|
||||
<@lv_column width=100 right=true>Quantity </@lv_column>
|
||||
<@lv_column width=100> Capacity</@lv_column>
|
||||
<@lv_column width=100 centered=true>Extraction<br/>difficulty</@lv_column>
|
||||
<@lv_column width=100 centered=true>Priority</@lv_column>
|
||||
</@lv_line>
|
||||
|
||||
<#list data.own.resources as resource>
|
||||
<#if resource.resourceProvider?has_content>
|
||||
<#local resProv=resource.resourceProvider>
|
||||
|
||||
<@lv_line>
|
||||
<@lv_column>
|
||||
${resource.title?xhtml}
|
||||
<div class="auto-hide">${resource.description?xhtml}</div>
|
||||
</@lv_column>
|
||||
<@lv_column right=true>${resProv.quantity?string(",##0")} </@lv_column>
|
||||
<@lv_column>/ ${resProv.capacity?string(",##0")}</@lv_column>
|
||||
<@lv_column centered=true>${resProv.difficulty} %</@lv_column>
|
||||
<@lv_column centered=true>
|
||||
<#switch resProv.priority>
|
||||
<#case 0>lowest<#break>
|
||||
<#case 1>low<#break>
|
||||
<#case 2>normal<#break>
|
||||
<#case 3>high<#break>
|
||||
<#case 4>highest<#break>
|
||||
</#switch>
|
||||
</@lv_column>
|
||||
</@lv_line>
|
||||
|
||||
</#if>
|
||||
</#list>
|
||||
</@listview>
|
||||
|
||||
</@tab>
|
||||
</#if>
|
||||
|
||||
<#include "planet/natres.ftl" />
|
||||
<@RenderNaturalResources />
|
||||
</#if>
|
||||
|
||||
</@tabs>
|
||||
|
|
|
@ -0,0 +1,79 @@
|
|||
<#macro RenderNaturalResources>
|
||||
<#list data.own.resources as resource>
|
||||
<#if resource.resourceProvider?has_content>
|
||||
<#local showResources=true>
|
||||
<#break>
|
||||
</#if>
|
||||
</#list>
|
||||
|
||||
<#if showResources?has_content>
|
||||
<@tab id="natres" title="Natural resources">
|
||||
<form action="planet-${data.id}-update-mset.action" method="POST">
|
||||
|
||||
<@listview>
|
||||
<@lv_line headers=true>
|
||||
<@lv_column width="x">Resource</@lv_column>
|
||||
<@lv_column width=100 right=true>Quantity </@lv_column>
|
||||
<@lv_column width=100> Capacity</@lv_column>
|
||||
<@lv_column width=100 centered=true>Extraction<br/>difficulty</@lv_column>
|
||||
<@lv_column width=100 centered=true>Priority</@lv_column>
|
||||
</@lv_line>
|
||||
|
||||
<#list data.own.resources as resource>
|
||||
<#if resource.resourceProvider?has_content>
|
||||
<#local resProv=resource.resourceProvider>
|
||||
|
||||
<@lv_line>
|
||||
<@lv_column>
|
||||
${resource.title?xhtml}
|
||||
<div class="auto-hide">${resource.description?xhtml}</div>
|
||||
</@lv_column>
|
||||
<@lv_column right=true>${resProv.quantity?string(",##0")} </@lv_column>
|
||||
<@lv_column>/ ${resProv.capacity?string(",##0")}</@lv_column>
|
||||
<@lv_column centered=true>${resProv.difficulty} %</@lv_column>
|
||||
<@lv_column centered=true>
|
||||
<#if data.own.ownMiningSettings>
|
||||
<select name="pms-${resource.identifier?xhtml}" class="input">
|
||||
<option style="padding: 0 5px" value="0" <#if resProv.priority = 0>selected="selected"</#if>>lowest</option>
|
||||
<option style="padding: 0 5px" value="1" <#if resProv.priority = 1>selected="selected"</#if>>low</option>
|
||||
<option style="padding: 0 5px" value="2" <#if resProv.priority = 2>selected="selected"</#if>>normal</option>
|
||||
<option style="padding: 0 5px" value="3" <#if resProv.priority = 3>selected="selected"</#if>>high</option>
|
||||
<option style="padding: 0 5px" value="4" <#if resProv.priority = 4>selected="selected"</#if>>highest</option>
|
||||
</select>
|
||||
<#else>
|
||||
<#switch resProv.priority>
|
||||
<#case 0>lowest<#break>
|
||||
<#case 1>low<#break>
|
||||
<#case 2>normal<#break>
|
||||
<#case 3>high<#break>
|
||||
<#case 4>highest<#break>
|
||||
</#switch>
|
||||
</#if>
|
||||
</@lv_column>
|
||||
</@lv_line>
|
||||
|
||||
</#if>
|
||||
</#list>
|
||||
|
||||
<@lv_line headers=true>
|
||||
<@lv_column width="x" colspan=5> </@lv_column>
|
||||
</@lv_line>
|
||||
<@lv_line>
|
||||
<@lv_column right=true colspan=5>
|
||||
<#if data.own.ownMiningSettings>
|
||||
Using planet-specific settings
|
||||
<input type="submit" name="toggle-settings" value="Use empire settings" class="input" style="margin: 15px 0 0 0" />
|
||||
<input type="submit" name="update-pms" value="Update priorities" class="input" style="margin: 15px 0 0 0" />
|
||||
<#else>
|
||||
<input type="submit" name="toggle-settings" value="Use specific settings" class="input" style="margin: 15px 0 0 0" />
|
||||
</#if>
|
||||
</@lv_column>
|
||||
</@lv_line>
|
||||
|
||||
</@listview>
|
||||
|
||||
</form>
|
||||
|
||||
</@tab>
|
||||
</#if>
|
||||
</#macro>
|
|
@ -374,54 +374,8 @@
|
|||
</@tab>
|
||||
</#if>
|
||||
|
||||
<#list data.own.resources as resource>
|
||||
<#if resource.resourceProvider?has_content>
|
||||
<#local showResources=true>
|
||||
<#break>
|
||||
</#if>
|
||||
</#list>
|
||||
|
||||
<#if showResources?has_content>
|
||||
<@tab id="natres" title="Ressources naturelles">
|
||||
|
||||
<@listview>
|
||||
<@lv_line headers=true>
|
||||
<@lv_column width="x">Ressource</@lv_column>
|
||||
<@lv_column width=100 right=true>Quantité </@lv_column>
|
||||
<@lv_column width=100> Capacité</@lv_column>
|
||||
<@lv_column width=100 centered=true>Difficulté<br/>d'extraction</@lv_column>
|
||||
<@lv_column width=100 centered=true>Priorité</@lv_column>
|
||||
</@lv_line>
|
||||
|
||||
<#list data.own.resources as resource>
|
||||
<#if resource.resourceProvider?has_content>
|
||||
<#local resProv=resource.resourceProvider>
|
||||
|
||||
<@lv_line>
|
||||
<@lv_column>
|
||||
${resource.title?xhtml}
|
||||
<div class="auto-hide">${resource.description?xhtml}</div>
|
||||
</@lv_column>
|
||||
<@lv_column right=true>${resProv.quantity?string(",##0")} </@lv_column>
|
||||
<@lv_column>/ ${resProv.capacity?string(",##0")}</@lv_column>
|
||||
<@lv_column centered=true>${resProv.difficulty} %</@lv_column>
|
||||
<@lv_column centered=true>
|
||||
<#switch resProv.priority>
|
||||
<#case 0>très basse<#break>
|
||||
<#case 1>basse<#break>
|
||||
<#case 2>normale<#break>
|
||||
<#case 3>haute<#break>
|
||||
<#case 4>très haute<#break>
|
||||
</#switch>
|
||||
</@lv_column>
|
||||
</@lv_line>
|
||||
|
||||
</#if>
|
||||
</#list>
|
||||
</@listview>
|
||||
|
||||
</@tab>
|
||||
</#if>
|
||||
<#include "planet/natres.ftl" />
|
||||
<@RenderNaturalResources />
|
||||
|
||||
</#if>
|
||||
|
||||
|
|
|
@ -0,0 +1,80 @@
|
|||
<#macro RenderNaturalResources>
|
||||
<#list data.own.resources as resource>
|
||||
<#if resource.resourceProvider?has_content>
|
||||
<#local showResources=true>
|
||||
<#break>
|
||||
</#if>
|
||||
</#list>
|
||||
|
||||
<#if showResources?has_content>
|
||||
<@tab id="natres" title="Ressources naturelles">
|
||||
<form action="planet-${data.id}-update-mset.action" method="POST">
|
||||
|
||||
<@listview>
|
||||
<@lv_line headers=true>
|
||||
<@lv_column width="x">Ressource</@lv_column>
|
||||
<@lv_column width=100 right=true>Quantité </@lv_column>
|
||||
<@lv_column width=100> Capacité</@lv_column>
|
||||
<@lv_column width=100 centered=true>Difficulté<br/>d'extraction</@lv_column>
|
||||
<@lv_column width=100 centered=true>Priorité</@lv_column>
|
||||
</@lv_line>
|
||||
|
||||
<#list data.own.resources as resource>
|
||||
<#if resource.resourceProvider?has_content>
|
||||
<#local resProv=resource.resourceProvider>
|
||||
|
||||
<@lv_line>
|
||||
<@lv_column>
|
||||
${resource.title?xhtml}
|
||||
<div class="auto-hide">${resource.description?xhtml}</div>
|
||||
</@lv_column>
|
||||
<@lv_column right=true>${resProv.quantity?string(",##0")} </@lv_column>
|
||||
<@lv_column>/ ${resProv.capacity?string(",##0")}</@lv_column>
|
||||
<@lv_column centered=true>${resProv.difficulty} %</@lv_column>
|
||||
<@lv_column centered=true>
|
||||
<#if data.own.ownMiningSettings>
|
||||
<select name="pms-${resource.identifier?xhtml}" class="input">
|
||||
<option style="padding: 0 5px" value="0" <#if resProv.priority = 0>selected="selected"</#if>>très basse</option>
|
||||
<option style="padding: 0 5px" value="1" <#if resProv.priority = 1>selected="selected"</#if>>basse</option>
|
||||
<option style="padding: 0 5px" value="2" <#if resProv.priority = 2>selected="selected"</#if>>normale</option>
|
||||
<option style="padding: 0 5px" value="3" <#if resProv.priority = 3>selected="selected"</#if>>haute</option>
|
||||
<option style="padding: 0 5px" value="4" <#if resProv.priority = 4>selected="selected"</#if>>très haute</option>
|
||||
</select>
|
||||
<#else>
|
||||
<#switch resProv.priority>
|
||||
<#case 0>très basse<#break>
|
||||
<#case 1>basse<#break>
|
||||
<#case 2>normale<#break>
|
||||
<#case 3>haute<#break>
|
||||
<#case 4>très haute<#break>
|
||||
</#switch>
|
||||
</#if>
|
||||
</@lv_column>
|
||||
</@lv_line>
|
||||
|
||||
</#if>
|
||||
</#list>
|
||||
|
||||
<@lv_line headers=true>
|
||||
<@lv_column width="x" colspan=5> </@lv_column>
|
||||
</@lv_line>
|
||||
<@lv_line>
|
||||
<@lv_column right=true colspan=5>
|
||||
<#if data.own.ownMiningSettings>
|
||||
Cette planète utilise des priorités d'extraction qui lui sont spécifiques.
|
||||
<input type="submit" name="toggle-settings" value="Utiliser les priorités de l'empire" class="input" style="margin: 15px 0 0 0" />
|
||||
<input type="submit" name="update-pms" value="Mettre à jour les priorités" class="input" style="margin: 15px 0 0 0" />
|
||||
<#else>
|
||||
Cette planète utilise les priorités d'extraction de l'empire.
|
||||
<input type="submit" name="toggle-settings" value="Utiliser des priorités spécifiques" class="input" style="margin: 15px 0 0 0" />
|
||||
</#if>
|
||||
</@lv_column>
|
||||
</@lv_line>
|
||||
|
||||
</@listview>
|
||||
|
||||
</form>
|
||||
|
||||
</@tab>
|
||||
</#if>
|
||||
</#macro>
|
|
@ -1,6 +1,10 @@
|
|||
package com.deepclone.lw.web.main.game;
|
||||
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
@ -80,8 +84,8 @@ public class PlanetPage
|
|||
|
||||
|
||||
@RequestMapping( value = "/planet-{planetId}-cancel-abandon.action" , method = RequestMethod.POST )
|
||||
public String cancelAbandon( HttpServletRequest request , @ModelAttribute( "language" ) String language , Model model ,
|
||||
@PathVariable String planetId )
|
||||
public String cancelAbandon( HttpServletRequest request , @ModelAttribute( "language" ) String language ,
|
||||
Model model , @PathVariable String planetId )
|
||||
throws SessionException , SessionServerException , SessionMaintenanceException
|
||||
{
|
||||
int pId;
|
||||
|
@ -233,4 +237,108 @@ public class PlanetPage
|
|||
PlayerSession pSession = this.getSession( PlayerSession.class , request );
|
||||
return this.render( model , "game" , language , "planet" , pSession.flushQueue( pId , true ) );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handler for commands that modify planet mining settings
|
||||
*
|
||||
* <p>
|
||||
* This method handles all mining settings commands, including both switching between empire-
|
||||
* and planet-specific settings and updating all priorities.
|
||||
*
|
||||
* @param request
|
||||
* the HTTP request
|
||||
* @param model
|
||||
* the model
|
||||
* @param planetId
|
||||
* the planet's identifier string from the path
|
||||
* @param toggle
|
||||
* this parameter from the form's <code>toggle-settings</code> value will be set if
|
||||
* the "Switch to empire-wide/planet-specific settings" button was clicked.
|
||||
*
|
||||
* @return a redirect to the overview page if the planet identifier was invalid, or a redirect
|
||||
* to the planet page's natural resources tab otherwise.
|
||||
*
|
||||
* @throws SessionException
|
||||
* if some error occurs on the server
|
||||
* @throws SessionServerException
|
||||
* if the server is unreachable
|
||||
* @throws SessionMaintenanceException
|
||||
* if the game is under maintenance
|
||||
*/
|
||||
@RequestMapping( value = "/planet-{planetId}-update-mset.action" , method = RequestMethod.POST )
|
||||
public String updateMiningSettings( HttpServletRequest request , Model model , @PathVariable String planetId ,
|
||||
@RequestParam( value = "toggle-settings" , required = false ) String toggle )
|
||||
throws SessionException , SessionServerException , SessionMaintenanceException
|
||||
{
|
||||
int pId;
|
||||
try {
|
||||
pId = Integer.parseInt( planetId );
|
||||
} catch ( NumberFormatException e ) {
|
||||
return this.redirect( "overview" );
|
||||
}
|
||||
|
||||
PlayerSession session = this.getSession( PlayerSession.class , request );
|
||||
if ( toggle == null ) {
|
||||
Map< String , Integer > settings = this.getMiningSettings( request );
|
||||
if ( settings != null ) {
|
||||
session.updatePlanetMiningSettings( pId , settings );
|
||||
}
|
||||
} else {
|
||||
session.toggleMiningSettingsFor( pId );
|
||||
}
|
||||
|
||||
return this.redirect( "planet-" + Integer.toString( pId ) + "#natres" );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract mining priorities from the HTTP request
|
||||
*
|
||||
* <p>
|
||||
* Look for all submitted fields that begin with "pms-" then try to extract their values into a
|
||||
* map that associates resource identifiers to priorities.
|
||||
*
|
||||
* @param request
|
||||
* the HTTP request
|
||||
*
|
||||
* @return the map containing the submitted mining settings, or <code>null</code> if one of the
|
||||
* values was incorrect.
|
||||
*/
|
||||
private Map< String , Integer > getMiningSettings( HttpServletRequest request )
|
||||
{
|
||||
Map< String , Object > input = this.getInput( request );
|
||||
Map< String , Integer > miningSettings = new HashMap< String , Integer >( );
|
||||
for ( Entry< String , Object > entry : input.entrySet( ) ) {
|
||||
// Ignore items which are not mining settings
|
||||
String name = entry.getKey( );
|
||||
if ( !name.startsWith( "pms-" ) ) {
|
||||
continue;
|
||||
}
|
||||
name = name.substring( 4 );
|
||||
|
||||
// Get values
|
||||
if ( ! ( entry.getValue( ) instanceof String[] ) ) {
|
||||
continue;
|
||||
}
|
||||
String[] values = (String[]) entry.getValue( );
|
||||
if ( values.length < 1 ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Pre-validate them
|
||||
int value;
|
||||
try {
|
||||
value = Integer.parseInt( values[ 0 ] );
|
||||
} catch ( NumberFormatException e ) {
|
||||
value = -1;
|
||||
}
|
||||
if ( value < 0 || value > 4 ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
miningSettings.put( name , value );
|
||||
}
|
||||
return miningSettings;
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue