New research and technology page
* Added legacyworlds-server-beans-technologies Maven module, including the player-level DAO and controller. * Added session classes to carry technology information, modified web client session façade accordingly * Various changes to common UI elements (forms, lists, etc...) so the start and end of some element can be drawn separately * Added controller, templates and JavaScript for research page
This commit is contained in:
parent
154f215e24
commit
6dcd59d7bc
45 changed files with 2314 additions and 178 deletions
legacyworlds-web-main/src/main/java/com/deepclone/lw/web/main/game
|
@ -10,7 +10,6 @@ import javax.servlet.http.HttpServletRequest;
|
|||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.SessionAttributes;
|
||||
|
@ -73,21 +72,15 @@ public class OverviewPage
|
|||
|
||||
|
||||
/**
|
||||
* "Implement technology" command
|
||||
* Empire-wide mining settings update command
|
||||
*
|
||||
* <p>
|
||||
* This method is mapped to the technology implementation command URL.
|
||||
* This method is called when a command to update empire-wide mining settings is received.
|
||||
*
|
||||
* @param request
|
||||
* the HTTP request
|
||||
* @param language
|
||||
* the language from the session
|
||||
* @param model
|
||||
* the model
|
||||
* @param tech
|
||||
* the technology identifier
|
||||
*
|
||||
* @return the overview page rendering order
|
||||
* @return a redirection to the overview page's "economy" tab
|
||||
*
|
||||
* @throws SessionException
|
||||
* if some error occurs on the server
|
||||
|
@ -96,26 +89,8 @@ public class OverviewPage
|
|||
* @throws SessionMaintenanceException
|
||||
* if the game is under maintenance
|
||||
*/
|
||||
@RequestMapping( value = "/implement-{tech}.action" , method = RequestMethod.POST )
|
||||
public String implement( HttpServletRequest request , @ModelAttribute( "language" ) String language , Model model ,
|
||||
@PathVariable String tech )
|
||||
throws SessionException , SessionServerException , SessionMaintenanceException
|
||||
{
|
||||
int techId;
|
||||
try {
|
||||
techId = Integer.parseInt( tech );
|
||||
} catch ( NumberFormatException e ) {
|
||||
return this.redirect( "overview" );
|
||||
}
|
||||
|
||||
PlayerSession pSession = this.getSession( PlayerSession.class , request );
|
||||
return this.render( model , "game" , language , "overview" , pSession.implementTechnology( techId ) );
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping( value = "/update-mining-settings.action" , method = RequestMethod.POST )
|
||||
public String updateMiningSettings( HttpServletRequest request , @ModelAttribute( "language" ) String language ,
|
||||
Model model )
|
||||
public String updateMiningSettings( HttpServletRequest request )
|
||||
throws SessionException , SessionServerException , SessionMaintenanceException
|
||||
{
|
||||
Map< String , Integer > miningSettings = this.getMiningSettings( request );
|
||||
|
|
|
@ -0,0 +1,186 @@
|
|||
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;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.SessionAttributes;
|
||||
|
||||
import com.deepclone.lw.session.SessionException;
|
||||
import com.deepclone.lw.web.beans.intercept.SessionRequirement;
|
||||
import com.deepclone.lw.web.beans.session.SessionMaintenanceException;
|
||||
import com.deepclone.lw.web.beans.session.SessionServerException;
|
||||
import com.deepclone.lw.web.beans.view.PageControllerBase;
|
||||
import com.deepclone.lw.web.csess.PlayerSession;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Controller for the Research page
|
||||
*
|
||||
* <p>
|
||||
* This controller contains all URL handlers associated with the research page: viewing research
|
||||
* state, setting research priorities, and implementing technologies.
|
||||
*
|
||||
* @author <a href="mailto:tseeker@legacyworlds.com">E. Benoît</a>
|
||||
*/
|
||||
@Controller
|
||||
@SessionRequirement( value = true , redirectTo = "player-session" , subType = "game" )
|
||||
@SessionAttributes( "language" )
|
||||
public class ResearchPage
|
||||
extends PageControllerBase
|
||||
{
|
||||
|
||||
/**
|
||||
* Research page view
|
||||
*
|
||||
* <p>
|
||||
* This method fetches all research information from the game server then requests the page
|
||||
* rendering.
|
||||
*
|
||||
* @param request
|
||||
* the HTTP request
|
||||
* @param language
|
||||
* the language from the session
|
||||
* @param model
|
||||
* the model
|
||||
*
|
||||
* @return the research page rendering information
|
||||
*
|
||||
* @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( "/research" )
|
||||
public String view( HttpServletRequest request , @ModelAttribute( "language" ) String language , Model model )
|
||||
throws SessionException , SessionServerException , SessionMaintenanceException
|
||||
{
|
||||
PlayerSession pSession = this.getSession( PlayerSession.class , request );
|
||||
return this.render( model , "game" , language , "research" , pSession.getResearch( ) );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Research priorities update command
|
||||
*
|
||||
* <p>
|
||||
* This method handles the research priorities update command, which is triggered when the
|
||||
* "Update" button is clicked on the "In progress" tab of the research page.
|
||||
*
|
||||
* @param request
|
||||
* the HTTP request
|
||||
*
|
||||
* @return a redirection to the research page's "in progress" tab
|
||||
*
|
||||
* @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 = "/research-set-priorities.action" , method = RequestMethod.POST )
|
||||
public String setPriorities( HttpServletRequest request )
|
||||
throws SessionException , SessionServerException , SessionMaintenanceException
|
||||
{
|
||||
Map< String , Integer > priorities = this.getPriorities( request );
|
||||
if ( priorities != null ) {
|
||||
this.getSession( PlayerSession.class , request ).updateResearchPriorities( priorities );
|
||||
}
|
||||
return this.redirect( "research#research" );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract research priorities from the HTTP request
|
||||
*
|
||||
* <p>
|
||||
* Look for all submitted fields that begin with "rp-" then try to extract their values into a
|
||||
* map that associates technology identifiers to priorities.
|
||||
*
|
||||
* @param request
|
||||
* the HTTP request
|
||||
*
|
||||
* @return the map containing the submitted priorities, or <code>null</code> if one of the
|
||||
* values was incorrect.
|
||||
*/
|
||||
private Map< String , Integer > getPriorities( HttpServletRequest request )
|
||||
{
|
||||
Map< String , Object > input = this.getInput( request );
|
||||
Map< String , Integer > priorities = new HashMap< String , Integer >( );
|
||||
for ( Entry< String , Object > entry : input.entrySet( ) ) {
|
||||
// Ignore items which are not priorities
|
||||
String name = entry.getKey( );
|
||||
if ( !name.startsWith( "rp-" ) ) {
|
||||
continue;
|
||||
}
|
||||
name = name.substring( 3 );
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
priorities.put( name , value );
|
||||
}
|
||||
return priorities;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Technology implementation command
|
||||
*
|
||||
* <p>
|
||||
* This method handles the technology implementation command, which is triggered when the
|
||||
* "Implement" button is clicked on the "Pending" tab of the research page.
|
||||
*
|
||||
* @param request
|
||||
* the HTTP request
|
||||
* @param tech
|
||||
* the identifier of the technology
|
||||
*
|
||||
* @return a redirection to the research page's "Implemented" tab
|
||||
*
|
||||
* @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 = "/research-implement.action" , method = RequestMethod.POST )
|
||||
public String implement( HttpServletRequest request , @RequestParam( "technology" ) String technology )
|
||||
throws SessionException , SessionServerException , SessionMaintenanceException
|
||||
{
|
||||
this.getSession( PlayerSession.class , request ).implementTechnology( technology );
|
||||
return this.redirect( "research#implemented" );
|
||||
}
|
||||
|
||||
}
|
Reference in a new issue