Ticket #2357: idle_worker_blink_v12.patch
File idle_worker_blink_v12.patch, 14.7 KB (added by , 10 years ago) |
---|
-
binaries/data/mods/public/gui/common/colorFades.js
217 217 return false; 218 218 } 219 219 220 //[END] of hero fade functions 221 No newline at end of file 220 //[END] of hero fade functions 221 //[START] idle workers icon 222 223 function colorFade_IdleWorker(data) 224 { 225 var rgb = data.rgb; 226 // init color 227 if (data.tickCounter == 0) 228 { 229 rgb.r = 255; 230 rgb.g = 255; 231 rgb.b = 255; 232 } 233 // hide it every tick 234 if (data.tickCounter % 2 == 0) 235 rgb.o = 0; 236 else 237 rgb.o = 100; 238 } 239 240 //[END] of idle workers icon functions 241 No newline at end of file -
binaries/data/mods/public/gui/session/input.js
2084 2084 lastIdleType = undefined; 2085 2085 } 2086 2086 2087 function findIdleUnit(classes) 2087 // selectionLimit [optional]: positive number greater than zero or false, if all should be selected 2088 function findIdleUnit(classes, selectionLimit) 2088 2089 { 2089 2090 var append = Engine.HotkeyIsPressed("selection.add"); 2090 var selectall = Engine.HotkeyIsPressed("selection.offscreen"); 2091 var selectall = Engine.HotkeyIsPressed("selection.offscreen") || selectionLimit === false; 2092 if (!selectionLimit || selectionLimit <= 0) 2093 selectionLimit = 1; 2091 2094 2092 2095 // Reset the last idle unit, etc., if the selection type has changed. 2093 2096 var type = classes.join(); … … 2101 2104 2102 2105 for (var i = 0; i < classes.length; ++i) 2103 2106 { 2104 var data = { idleClass: classes[currIdleClass], prevUnit: lastIdleUnit, limit: 1};2107 var data = { idleClass: classes[currIdleClass], prevUnit: lastIdleUnit, limit: selectionLimit }; 2105 2108 if (append) 2106 2109 data.excludeUnits = g_Selection.toList(); 2107 2110 -
binaries/data/mods/public/gui/session/session.js
56 56 // always through the list of all ongoing attacks... 57 57 var g_previousHeroHitPoints = undefined; 58 58 59 // cache idle worker button class names 60 var g_idleWorkerClasses = undefined; 61 59 62 function GetSimState() 60 63 { 61 64 if (!g_SimState) … … 148 151 { 149 152 g_Players = getPlayerData(null); 150 153 } 154 155 // cache worker class data 156 g_idleWorkerClasses = Engine.GuiInterfaceCall("GetIdleWorkerClasses"); 151 157 158 // set function to button 159 for (var n = 1; n <= 3; n++) 160 { 161 var idleWorkerButton = Engine.GetGUIObjectByName("idleWorkerButton[" + n + "]"); 162 if (idleWorkerButton) 163 { 164 idleWorkerButton.onpress = function() { findIdleUnit(g_idleWorkerClasses); }; 165 idleWorkerButton.onpressright = function() { findIdleUnit(g_idleWorkerClasses, false); }; 166 } 167 } 168 152 169 // Cache civ data 153 170 g_CivData = loadCivData(); 154 171 g_CivData["gaia"] = { "Code": "gaia", "Name": "Gaia" }; … … 490 507 updatePlayerDisplay(); 491 508 updateSelectionDetails(); 492 509 updateResearchDisplay(); 510 updateIdleWorkerButton(); 493 511 updateBuildingPlacementPreview(); 494 512 updateTimeElapsedCounter(); 495 513 updateTimeNotifications(); … … 502 520 } 503 521 504 522 /** 523 + * updates the idle worker button 524 + */ 525 function updateIdleWorkerButton() 526 { 527 var simState = GetSimState(); 528 var idleUnitsCounter = simState.players[Engine.GetPlayerID()].idleWorkerButtonCount; 529 // set color fade and label 530 if (idleUnitsCounter > 0) 531 { 532 startColorFade("idleWorkerColorOverlay", 750, 0, colorFade_IdleWorker, false); 533 var label = Engine.GetGUIObjectByName("idleWorkerLabel") 534 label.caption = idleUnitsCounter; 535 label.hidden = false; 536 } 537 else 538 { 539 stopColorFade("idleWorkerColorOverlay"); 540 var label = Engine.GetGUIObjectByName("idleWorkerLabel"); 541 label.hidden = true; 542 } 543 } 544 545 /** 505 546 * updates a status bar on the GUI 506 547 * nameOfBar: name of the bar 507 548 * points: points to show -
binaries/data/mods/public/gui/session/session.xml
949 949 950 950 <!-- Idle Worker Button --> 951 951 <object size="100%-36 100%-36 100%-5 100%-5"> 952 <!-- TODO: should highlight the button if there's non-zero idle workers -->953 952 <object name="idle-overlay" size="-85 -85 100% 100%" type="image" sprite="stretched:session/minimap-idle.png" ghost="true"/> 954 953 <!-- Since we don't support non-rectangular buttons, we approximate the area using 3 rectangles TODO: Make this cleaner --> 955 <object type="button" 954 <object type="button" name="idleWorkerButton[1]" 956 955 tooltip_style="sessionToolTip" 957 tooltip=" Find idle worker"956 tooltip="Click to find an idle worker, right-click to select all idle workers." 958 957 hotkey="selection.idleworker" 959 > 960 <action on="Press">findIdleUnit(["Female", "Trade", "FishingBoat", "CitizenSoldier", "Healer"]);</action> 961 </object> 962 <object type="button" 958 /> 959 <object type="button" name="idleWorkerButton[2]" 963 960 tooltip_style="sessionToolTip" 964 tooltip=" Find idle worker"961 tooltip="Click to find an idle worker, right-click to select all idle workers." 965 962 size="15 -15 100% 0" 966 > 967 <action on="Press">findIdleUnit(["Female", "Trade", "FishingBoat", "CitizenSoldier", "Healer"]);</action> 968 </object> 969 <object type="button" 963 /> 964 <object type="button" name="idleWorkerButton[3]" 970 965 tooltip_style="sessionToolTip" 971 tooltip=" Find idle worker"966 tooltip="Click to find an idle worker, right-click to select all idle workers." 972 967 size="-15 15 0 100%" 973 >974 <action on="Press">findIdleUnit(["Female", "Trade", "FishingBoat", "CitizenSoldier", "Healer"]);</action>975 < /object>968 /> 969 <object name="idleWorkerColorOverlay" type="image" size="-85 -85 100% 100%" addColorMask="session/minimap-idle-colorMask.png" ghost="true"/> 970 <object name="idleWorkerLabel" type="text" style="groupIconsText" size="0 0 100% 100%" ghost="true"/> 976 971 </object> 977 972 </object> 978 973 -
binaries/data/mods/public/simulation/components/GuiInterface.js
89 89 "team": cmpPlayer.GetTeam(), 90 90 "teamsLocked": cmpPlayer.GetLockTeams(), 91 91 "cheatsEnabled": cmpPlayer.GetCheatsEnabled(), 92 "idleWorkerButtonCount": cmpPlayer.GetIdleWorkerButtonCount(), 92 93 "phase": phase, 93 94 "isAlly": allies, 94 95 "isMutualAlly": mutualAllies, … … 727 728 }; 728 729 729 730 // Returns the battle state of the player. 731 GuiInterface.prototype.GetIdleWorkerClasses = function(player) 732 { 733 // try to get the data 734 var cmpPlayer = QueryPlayerIDInterface(player, IID_Player); 735 if (!cmpPlayer) 736 return []; 737 else 738 return cmpPlayer.GetIdleWorkerButtonClassesList(); 739 }; 740 741 // Returns the battle state of the player. 730 742 GuiInterface.prototype.GetBattleState = function(player) 731 743 { 732 744 var cmpBattleDetection = QueryPlayerIDInterface(player, IID_BattleDetection); … … 1976 1988 "SetWallPlacementPreview": 1, 1977 1989 "GetFoundationSnapData": 1, 1978 1990 "PlaySound": 1, 1991 "GetIdleWorkerClasses" :1, 1979 1992 "FindIdleUnits": 1, 1980 1993 "GetTradingRouteGain": 1, 1981 1994 "GetTradingDetails": 1, -
binaries/data/mods/public/simulation/components/Player.js
1 1 function Player() {} 2 2 3 3 Player.prototype.Schema = 4 "<a:component type='system'/><empty/>"; 5 4 "<element name='IdleWorkerButtonClasses' a:help='Classes of entities which are used for the idle worker button.'>" + 5 "<attribute name='datatype'>" + 6 "<value>tokens</value>" + 7 "</attribute>" + 8 "<text/>" + 9 "</element>"; 10 6 11 Player.prototype.Init = function() 7 12 { 8 13 this.playerID = undefined; … … 36 41 this.cheatsEnabled = false; 37 42 this.cheatTimeMultiplier = 1; 38 43 this.heroes = []; 44 this.idleWorkerButtonCount = 0; 45 this.idleWorkerButtonClasses = this.template.IdleWorkerButtonClasses._string ? this.template.IdleWorkerButtonClasses._string.split(/\s+/) : []; // classes used for the work idle button 39 46 Engine.QueryInterface(SYSTEM_ENTITY, IID_EndGameManager).CheckConquestCriticalEntities(); 40 47 }; 41 48 49 /** 50 * Returns an array of unit classes which are used for the idle worker button 51 */ 52 Player.prototype.GetIdleWorkerButtonClassesList = function() 53 { 54 return this.idleWorkerButtonClasses; 55 }; 56 42 57 Player.prototype.SetPlayerID = function(id) 43 58 { 44 59 this.playerID = id; … … 559 574 if (index >= 0) 560 575 this.heroes.splice(index, 1); 561 576 } 577 // check, if new idle worker is gone 578 var cmpUnitAI = Engine.QueryInterface(msg.entity, IID_UnitAI); 579 if (cmpUnitAI) 580 if (cmpUnitAI.IsIdle() && cmpUnitAI.IsUsedForIdleWorkerButton()) 581 this.DecreaseWorkerButtonCount(); 562 582 } 563 583 if (msg.to == this.playerID) 564 584 { … … 570 590 571 591 if (cmpIdentity && cmpIdentity.HasClass("Hero")) 572 592 this.heroes.push(msg.entity); 593 594 // check, if new idle worker is there 595 var cmpUnitAI = Engine.QueryInterface(msg.entity, IID_UnitAI); 596 if (cmpUnitAI) 597 if (cmpUnitAI.IsIdle() && cmpUnitAI.IsUsedForIdleWorkerButton()) 598 this.IncreaseWorkerButtonCount(); 573 599 } 574 600 }; 575 601 … … 664 690 cmpGUIInterface.PushNotification(notification); 665 691 }; 666 692 693 Player.prototype.GetIdleWorkerButtonCount = function() 694 { 695 return this.idleWorkerButtonCount; 696 }; 697 698 Player.prototype.IncreaseWorkerButtonCount = function() 699 { 700 this.idleWorkerButtonCount++; 701 }; 702 703 Player.prototype.DecreaseWorkerButtonCount = function() 704 { 705 this.idleWorkerButtonCount--; 706 if (this.idleWorkerButtonCount < 0) 707 { 708 this.idleWorkerButtonCount = 0; 709 error("Negative worker idle count for player '" + this.playerID + "'"); 710 } 711 }; 712 667 713 Engine.RegisterComponentType(IID_Player, "Player", Player); -
binaries/data/mods/public/simulation/components/UnitAI.js
169 169 "GuardedAttacked": function(msg) { 170 170 // ignore 171 171 }, 172 173 "UnitIdleChanged": function(msg) { 174 // do only if its not animal and is used for the idle worker button 175 if (!this.IsAnimal() && this.IsUsedForIdleWorkerButton()) 176 { 177 var cmpPlayer = QueryOwnerInterface(this.entity, IID_Player); 178 if (cmpPlayer) 179 { 180 if(msg.idle) 181 cmpPlayer.IncreaseWorkerButtonCount(); 182 else 183 cmpPlayer.DecreaseWorkerButtonCount(); 184 } 185 } 186 }, 172 187 173 188 // Formation handlers: 174 189 … … 1401 1416 return false; 1402 1417 }, 1403 1418 1404 "leave": function( ) {1419 "leave": function(msg) { 1405 1420 var rangeMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); 1406 1421 if (this.losRangeQuery) 1407 1422 rangeMan.DisableActiveQuery(this.losRangeQuery); … … 1409 1424 rangeMan.DisableActiveQuery(this.losHealRangeQuery); 1410 1425 1411 1426 this.StopTimer(); 1412 1413 if (this.isIdle )1427 // only change idle state, if next state is different from idle (happens in case of death of unit FormationIdle --> IndiviIdle) 1428 if (this.isIdle && !(msg.nextState && msg.nextState.length > 0 && msg.nextState[msg.nextState.length-1].indexOf(".IDLE") != -1)) 1414 1429 { 1415 1430 this.isIdle = false; 1416 1431 Engine.PostMessage(this.entity, MT_UnitIdleChanged, { "idle": this.isIdle }); … … 3059 3074 this.formationController = INVALID_ENTITY; // entity with IID_Formation that we belong to 3060 3075 this.isGarrisoned = false; 3061 3076 this.isIdle = false; 3077 this.isUsedForIdleWorkerButton = undefined; // will be initialised, if IsUsedForIdleWorkerButton() is called the first time 3062 3078 this.lastFormationTemplate = ""; 3063 3079 this.finishedOrder = false; // used to find if all formation members finished the order 3064 3080 … … 3143 3159 return Engine.QueryInterface(this.entity, IID_Heal); 3144 3160 }; 3145 3161 3162 UnitAI.prototype.IsUsedForIdleWorkerButton = function() 3163 { 3164 // return cached value, if some is stored 3165 if (this.isUsedForIdleWorkerButton !== undefined) 3166 return this.isUsedForIdleWorkerButton; 3167 3168 // calculate value 3169 this.isUsedForIdleWorkerButton = false; 3170 var cmpIdentity = Engine.QueryInterface(this.entity, IID_Identity); 3171 if (!cmpIdentity) 3172 return false; 3173 var cmpPlayer = QueryOwnerInterface(this.entity, IID_Player); 3174 if (!cmpPlayer) 3175 return false; 3176 // check idle class names 3177 for each(var className in cmpPlayer.GetIdleWorkerButtonClassesList()) 3178 if (cmpIdentity.HasClass(className)) { 3179 this.isUsedForIdleWorkerButton = true; 3180 break; 3181 } 3182 // return the value 3183 return this.isUsedForIdleWorkerButton; 3184 }; 3185 3146 3186 UnitAI.prototype.IsIdle = function() 3147 3187 { 3148 3188 return this.isIdle; … … 3791 3831 UnitFsm.ProcessMessage(this, {"type": "PackFinished", "packed": msg.packed}); 3792 3832 }; 3793 3833 3834 UnitAI.prototype.OnUnitIdleChanged = function(msg) 3835 { 3836 var cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership); 3837 if (!cmpOwnership) 3838 return; 3839 UnitFsm.ProcessMessage(this, {"type": "UnitIdleChanged", "idle": msg.idle, "player": cmpOwnership.GetOwner()}); 3840 } 3841 3794 3842 //// Helper functions to be called by the FSM //// 3795 3843 3796 3844 UnitAI.prototype.GetWalkSpeed = function() -
binaries/data/mods/public/simulation/helpers/FSM.js
359 359 if (leave) 360 360 { 361 361 obj.fsmStateName = fromState[i]; 362 if (leave.apply(obj ))362 if (leave.apply(obj, [{"nextState": toState}])) 363 363 { 364 364 obj.FsmStateNameChanged(obj.fsmStateName); 365 365 return; … … 373 373 if (enter) 374 374 { 375 375 obj.fsmStateName = toState[i]; 376 if (enter.apply(obj ))376 if (enter.apply(obj, [{"previousState": fromState}])) 377 377 { 378 378 obj.FsmStateNameChanged(obj.fsmStateName); 379 379 return; -
binaries/data/mods/public/simulation/templates/special/player.xml
39 39 </Pillar> 40 40 </LimitChangers> 41 41 </EntityLimits> 42 <Player/> 42 <Player> 43 <IdleWorkerButtonClasses datatype="tokens">Worker Trade FishingBoat</IdleWorkerButtonClasses> 44 </Player> 43 45 <StatisticsTracker/> 44 46 <TechnologyManager/> 45 47 </Entity>