[virtualcommons-svn] SF.net SVN: virtualcommons:[169] mentalmodels/trunk/flex/src/ customComponents
Status: Beta
Brought to you by:
alllee
From: <kj...@us...> - 2009-07-02 01:22:15
|
Revision: 169 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=169&view=rev Author: kjonas Date: 2009-07-02 00:13:07 +0000 (Thu, 02 Jul 2009) Log Message: ----------- Forecasting components now have update button, and all data must be entered day-by-day. DayByDayDecisionsQuestionC.mxml now has a component at the bottom to tally cumulative fishings and earnings for the player. Further components must be added when the program can talk to the server about other players. Modified Paths: -------------- mentalmodels/trunk/flex/src/customComponents/questions/DayByDayDecisionsQuestionC.mxml mentalmodels/trunk/flex/src/customComponents/questions/ForecastingFishQuestionC.mxml mentalmodels/trunk/flex/src/customComponents/questions/ForecastingPeopleQuestionC.mxml mentalmodels/trunk/flex/src/customComponents/questions/components/ForecastComponent.mxml mentalmodels/trunk/flex/src/customComponents/questions/components/OneDay.mxml Modified: mentalmodels/trunk/flex/src/customComponents/questions/DayByDayDecisionsQuestionC.mxml =================================================================== --- mentalmodels/trunk/flex/src/customComponents/questions/DayByDayDecisionsQuestionC.mxml 2009-06-30 02:02:32 UTC (rev 168) +++ mentalmodels/trunk/flex/src/customComponents/questions/DayByDayDecisionsQuestionC.mxml 2009-07-02 00:13:07 UTC (rev 169) @@ -3,13 +3,17 @@ <mx:String id="description"></mx:String> + <mx:Label id="txtPrompt" text="It's Day {currentDay}. Where will you go to fish, or will you stay in the harbor?"/> <mx:Label id="lblChosen" text="location chosen: {deciding}"/> <mx:HBox id="buttons"/> <mx:HBox id="labels" verticalAlign="middle"/> - <mx:VBox id="dayByDayContent" borderStyle="outset" minHeight="42" minWidth="655" verticalGap="0"/> + <mx:VBox id="dayByDayContent" borderStyle="outset" minWidth="655" verticalGap="0" + height="300" verticalScrollPolicy="on"/> + <mx:Label id="lblCumulative" text="So far, you have fished {getLbs(cumTotal)}, which is worth {getMoney(cumTotal,dollarPerLb)}."/> + <mx:Script> <![CDATA[ import mx.controls.Button; @@ -19,7 +23,9 @@ public var numBays:int = 3; [Bindable] public var deciding:int = 0; - public var cumTotal:Number = 0; + [Bindable] public var currentDay:int = 1; + [Bindable] public var cumTotal:Number = 0; + [Bindable] public var dollarPerLb:Number = 3.99; public function init():void { @@ -97,25 +103,32 @@ public function advance(event:MouseEvent=null):void { - try + if(currentDay == 30) { - var last:Object = dayByDayContent.getChildAt(dayByDayContent.numChildren - 1); - if(last is OneDay) - { - cumTotal = (last as OneDay).presentTotal; - } + return; } - catch(err:Error) - { - // silent failure - } var newDay:OneDay = new OneDay(); newDay.numBays = numBays; - newDay.previousTotal = cumTotal; newDay.initialize(); + newDay.day = currentDay++; + newDay.dollarPerLb = dollarPerLb; dayByDayContent.addChild(newDay.load(deciding)); + cumTotal += newDay.presentTotal; +// try +// { +// var last:Object = dayByDayContent.getChildAt(dayByDayContent.numChildren - 1); +// if(last is OneDay) +// { +// cumTotal += (last as OneDay).presentTotal; +// } +// } +// catch(err:Error) +// { +// // silent failure +// } + deciding = 0; } @@ -127,6 +140,32 @@ init(); } + public function getLbs(lbsFished:Number):String + { + lbsFished = Math.round(lbsFished * 10.0) / 10.0; + + var zeroDec:String = ""; + if(lbsFished as int == lbsFished) + { + zeroDec = ".0"; + } + var lbString:String = String(lbsFished).substr(0,5) + zeroDec + " lbs"; + return lbString; + } + public function getMoney(lbsFished:Number, dollarPerLb:Number):String + { + var moneyMade:Number = lbsFished * dollarPerLb; + moneyMade = Math.floor(moneyMade * 100.0) / 100.0; + + var zeroDec:String = ""; + if(moneyMade as int == moneyMade) + { + zeroDec = ".00"; + } + var moneyString:String = "$" + moneyMade + zeroDec; + return moneyString; + } + ]]> </mx:Script> Modified: mentalmodels/trunk/flex/src/customComponents/questions/ForecastingFishQuestionC.mxml =================================================================== --- mentalmodels/trunk/flex/src/customComponents/questions/ForecastingFishQuestionC.mxml 2009-06-30 02:02:32 UTC (rev 168) +++ mentalmodels/trunk/flex/src/customComponents/questions/ForecastingFishQuestionC.mxml 2009-07-02 00:13:07 UTC (rev 169) @@ -11,6 +11,14 @@ <components:ForecastComponent id="calculated" style="2" isEntry="false" numBays="{numBays}" numColumns="{numColumns}" initialize="false"/> + <mx:HBox> + <mx:Spacer width="160"/> + <mx:VBox> + <mx:Button id="btnUpdate" label="Update" click="fishEntry.updateNextColumn()"/> + <mx:Label id="lblError" text="{fishEntry.errorMessage}"/> + </mx:VBox> + </mx:HBox> + <mx:Script> <![CDATA[ import mx.controls.Alert; Modified: mentalmodels/trunk/flex/src/customComponents/questions/ForecastingPeopleQuestionC.mxml =================================================================== --- mentalmodels/trunk/flex/src/customComponents/questions/ForecastingPeopleQuestionC.mxml 2009-06-30 02:02:32 UTC (rev 168) +++ mentalmodels/trunk/flex/src/customComponents/questions/ForecastingPeopleQuestionC.mxml 2009-07-02 00:13:07 UTC (rev 169) @@ -6,6 +6,14 @@ <components:ForecastComponent id="peopleEntry" style="0" isEntry="true" numBays="{numBays}" numColumns="{numColumns}" initialize="false"/> + <mx:HBox> + <mx:Spacer width="160"/> + <mx:VBox> + <mx:Button id="btnUpdate" label="Update" click="peopleEntry.updateNextColumn()"/> + <mx:Label id="lblError" text="{peopleEntry.errorMessage}"/> + </mx:VBox> + </mx:HBox> + <mx:Script> <![CDATA[ import actionscript.ForecastingPeopleQuestion; Modified: mentalmodels/trunk/flex/src/customComponents/questions/components/ForecastComponent.mxml =================================================================== --- mentalmodels/trunk/flex/src/customComponents/questions/components/ForecastComponent.mxml 2009-06-30 02:02:32 UTC (rev 168) +++ mentalmodels/trunk/flex/src/customComponents/questions/components/ForecastComponent.mxml 2009-07-02 00:13:07 UTC (rev 169) @@ -20,6 +20,8 @@ [Bindable] public var updaterObject:Object = null; [Bindable] public var updater:Function = new Function(); + [Bindable] public var currentColumn:int = 0; + // Game Data [Bindable] public var style:int = 0; // 0:People, 1:Fish, 2:Calculated [Bindable] public var numBays:int = 3; @@ -144,12 +146,19 @@ newDataGridColumn.headerText = ""+(columnNumber+1); // 1, 2, 3, ... newDataGridColumn.dataField = "day"+(columnNumber+1); // day1, day2, day3, ... - newDataGridColumn.editable = (isEntry && ((style == 0) || (style == 1))); // 0:People, 1:Fish newDataGridColumn.draggable = false; newDataGridColumn.sortable = false; newDataGridColumn.resizable = false; newDataGridColumn.width = 30; + newDataGridColumn.editable = (isEntry + && ((style == 0) || (style == 1)) + && columnNumber == 0); // 0:People, 1:Fish + if(newDataGridColumn.editable) + { + newDataGridColumn.setStyle("backgroundColor", "#FFFF00"); + } + columnArray[columnNumber] = newDataGridColumn; } dataGrid.columns = columnArray; @@ -161,18 +170,11 @@ { dataProvider = new ArrayCollection(); + addLabel(" <b>Day</b>:",true); + var bayNumber:int = 0; if(style==0) // 0:People { - if(isEntry) - { - addLabel(" <b>Predict</b>:",true); - } - else - { - addLabel(" <b>You Predicted</b>:",true); - } - addLabel("# People in Harbor:"); addField(); @@ -184,15 +186,6 @@ } else if(style==1) { - if(isEntry) - { - addLabel(" <b>Predict</b>:",true); - } - else - { - addLabel(" <b>You Predicted</b>:",true); - } - for(bayNumber=0; bayNumber<numBays; bayNumber++) { addLabel("# Fish in Bay " + (bayNumber+1) + "(AM):"); @@ -201,8 +194,6 @@ } else if(style==2) { - addLabel(" <b>We calculate that:</b>",true); - addLabel("You will be in location #:"); addField(); addLabel("You will get USD:"); @@ -235,44 +226,46 @@ } } - private function errorCheck():void + private function errorCheck():Boolean { + if(currentColumn >= dataGrid.columnCount) + { + errorMessage = "Click 'Forward' to continue to the next page."; + return true; + } markNoError(); + errorMessage = "Click 'Update' to continue."; var error:Boolean = false; - for(var column:Number=0; column < numColumns && !error; column++) + var colSum:Number = 0; + for(var field:Number=0; field < numFields && !error; field++) { - var colSum:Number = 0; - for(var field:Number=0; field < numFields && !error; field++) + var value:Object = getItem(field, currentColumn); + if(!validNum(value)) { - var value:Object = getItem(field, column); - if(!validNum(value)) - { - errorMessage = "Enter a value between "+minValue+" and "+maxValue+"."; - error = true; - markError(field,column); - } - else if(!inBounds(value)) - { - errorMessage = "Value must be between "+minValue+" and "+maxValue+"."; - error = true; - markError(field,column); - } - else if(style == 0) // 0:People - { - colSum += Number(value); - } + errorMessage = "Enter a value between "+minValue+" and "+maxValue+"."; + error = true; } - - if(!error && style == 0 && colSum != groupSize-1) // 0:People + else if(!inBounds(value)) { - errorMessage = "Sum of all columns must be exactly "+(groupSize-1)+"."; + errorMessage = "Value must be between "+minValue+" and "+maxValue+"."; error = true; - markError(-1,column); } + else if(style == 0) // 0:People + { + colSum += Number(value); + } } + if(!error && style == 0 && colSum != groupSize-1) // 0:People + { + errorMessage = "Sum of all columns must be exactly "+(groupSize-1)+"."; + error = true; + } + + finished = !error; + return finished; } private function validNum(n:Object):Boolean @@ -286,20 +279,33 @@ { return Number(n) >= minValue && Number(n) <= maxValue; } - public function markError(field:Number, column:Number):void + private function markNoError():void { - if(! (isEntry && (style == 0 || style == 1)) ) return; // 0:People, 1:Fish - DataGridColumn(dataGrid.columns[column]).setStyle("backgroundColor", "#ee82ee"); - dataGrid.selectedIndex = field; +// for(var column:Number=0; column < numColumns; column++) +// { +// DataGridColumn(dataGrid.columns[column]).setStyle("backgroundColor", "#FFFFFF"); +// } + dataGrid.selectedIndex = -1; } - private function markNoError():void + + public function updateNextColumn():void { - for(var column:Number=0; column < numColumns; column++) + if(errorCheck()) { - DataGridColumn(dataGrid.columns[column]).setStyle("backgroundColor", "#FFFFFF"); + dataGrid.columns[currentColumn].setStyle("backgroundColor", "#FFFFFF"); + dataGrid.columns[currentColumn].editable = false; + currentColumn = fix(currentColumn+1,0,dataGrid.columnCount) as int; + if(currentColumn < dataGrid.columnCount) + { + dataGrid.columns[currentColumn].editable = true; + dataGrid.columns[currentColumn].setStyle("backgroundColor", "#FFFF00"); + } } - dataGrid.selectedIndex = -1; } + private function fix(n:Number,min:Number,max:Number):Number + { + return Math.max(Math.min(max,n),min); + } ]]> </mx:Script> Modified: mentalmodels/trunk/flex/src/customComponents/questions/components/OneDay.mxml =================================================================== --- mentalmodels/trunk/flex/src/customComponents/questions/components/OneDay.mxml 2009-06-30 02:02:32 UTC (rev 168) +++ mentalmodels/trunk/flex/src/customComponents/questions/components/OneDay.mxml 2009-07-02 00:13:07 UTC (rev 169) @@ -13,6 +13,7 @@ public var previousTotal:Number = 0; public var presentTotal:Number = 0; public var day:int = 1; + public var dollarPerLb:Number = 3.99; public function init():void { @@ -78,6 +79,7 @@ var totalObject:TotalDisplay = new TotalDisplay(); totalObject.lbsFished = presentTotal; + totalObject.dollarPerLb = dollarPerLb; totalObject.initialize(); addChild(totalObject.redraw()); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |