From: Stefan F. <ste...@us...> - 2010-04-15 21:46:36
|
Update of /cvsroot/rails/18xx/rails/ui/swing In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv14783/rails/ui/swing Modified Files: ORUIManager.java ORPanel.java Log Message: RevenueCalculation feeds into ORPanel implementation Index: ORUIManager.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/ui/swing/ORUIManager.java,v retrieving revision 1.65 retrieving revision 1.66 diff -C2 -d -r1.65 -r1.66 *** ORUIManager.java 11 Apr 2010 15:49:47 -0000 1.65 --- ORUIManager.java 15 Apr 2010 21:46:28 -0000 1.66 *************** *** 1364,1368 **** } ! orPanel.initORCompanyTurn(orCompIndex); privatesCanBeBoughtNow = possibleActions.contains(BuyPrivate.class); --- 1364,1368 ---- } ! orPanel.initORCompanyTurn(orComp, orCompIndex); privatesCanBeBoughtNow = possibleActions.contains(BuyPrivate.class); Index: ORPanel.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/ui/swing/ORPanel.java,v retrieving revision 1.54 retrieving revision 1.55 diff -C2 -d -r1.54 -r1.55 *** ORPanel.java 15 Apr 2010 19:49:50 -0000 1.54 --- ORPanel.java 15 Apr 2010 21:46:28 -0000 1.55 *************** *** 21,25 **** public class ORPanel extends GridPanel ! implements ActionListener, KeyListener { private static final long serialVersionUID = 1L; --- 21,25 ---- public class ORPanel extends GridPanel ! implements ActionListener, KeyListener, RevenueListener { private static final long serialVersionUID = 1L; *************** *** 737,742 **** } ! public void initORCompanyTurn(int orCompIndex) { this.orCompIndex = orCompIndex; president[orCompIndex].setHighlight(true); --- 737,743 ---- } ! public void initORCompanyTurn(PublicCompanyI orComp, int orCompIndex) { + this.orComp = orComp; this.orCompIndex = orCompIndex; president[orCompIndex].setHighlight(true); *************** *** 771,774 **** --- 772,776 ---- revenueCaption.setHighlight(true); revenueSelect[orCompIndex].setValue(action.getPresetRevenue()); + setSelect(revenue[orCompIndex], revenueSelect[orCompIndex], true); *************** *** 779,784 **** --- 781,834 ---- button1.setEnabled(true); button1.setVisible(true); + + + // initialize and start the revenue adapter + RevenueAdapter ra = initRevenueCalculation(orComp); + + new Thread(ra).start(); } + private RevenueAdapter initRevenueCalculation(PublicCompanyI company){ + + GameManagerI gm = orUIManager.getGameUIManager().getGameManager(); + MapManager mapManager = gm.getMapManager(); + + NetworkGraphBuilder nwGraph = new NetworkGraphBuilder(); + nwGraph.generateGraph(mapManager.getHexesAsList()); + Graph<NetworkVertex, NetworkEdge> mapGraph = nwGraph.getMapGraph(); + + mapGraph = NetworkGraphBuilder.optimizeGraph(mapGraph); + + // revenue calculation example + mapGraph = NetworkGraphBuilder.optimizeGraph(mapGraph); + RevenueAdapter ra = new RevenueAdapter(mapGraph); + + // set tokens + List<TokenI> tokens = company.getTokens(); + for (TokenI token:tokens){ + NetworkVertex vertex = nwGraph.getVertex(token); + if (vertex != null) ra.addStartVertex(vertex); + } + + // run on railroad graph, does not work so far, thus use map graph + // RevenueAdapter ra = new RevenueAdapter(graph); + + // get trains + company.getPortfolio().getTrainList(); + for (TrainI train:company.getPortfolio().getTrainList()) { + ra.addTrain(train); + } + + ra.populateRevenueCalculator(company, gm.getCurrentPhase()); + ra.activateRevenuePrediction(); + ra.addRevenueListener(this); + + return ra; + } + + public void revenueUpdate(int revenue, boolean finalResult) { + revenueSelect[orCompIndex].setValue(revenue); + } + public void initPayoutStep(int orCompIndex, SetDividend action, boolean withhold, boolean split, boolean payout) { *************** *** 952,954 **** --- 1002,1005 ---- } + } |