stratagus-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Stratagus-CVS] stratagus doc/ChangeLog.html doc/ccl/ui.html sr...


From: Martin Renold
Subject: [Stratagus-CVS] stratagus doc/ChangeLog.html doc/ccl/ui.html sr...
Date: Sun, 14 Sep 2003 07:51:33 -0400

CVSROOT:        /cvsroot/stratagus
Module name:    stratagus
Branch:         
Changes by:     Martin Renold <address@hidden>  03/09/14 07:51:33

Modified files:
        doc            : ChangeLog.html 
        doc/ccl        : ui.html 
        src/include    : interface.h 
        src/ui         : botpanel.c ccl_ui.c 

Log message:
        NEW_UI: can highlight buttons now to show unit action; added 
documentation

Patches:
Index: stratagus/doc/ChangeLog.html
diff -u stratagus/doc/ChangeLog.html:1.526 stratagus/doc/ChangeLog.html:1.527
--- stratagus/doc/ChangeLog.html:1.526  Sun Sep 14 02:53:07 2003
+++ stratagus/doc/ChangeLog.html        Sun Sep 14 07:51:32 2003
@@ -2,7 +2,7 @@
 <html>
 <head>
 <!--
-----   $Id: ChangeLog.html,v 1.526 2003/09/14 06:53:07 mr-russ Exp $
+----   $Id: ChangeLog.html,v 1.527 2003/09/14 11:51:32 martinxyz Exp $
 
 ----   (c) Copyright 1998-2003 by Lutz Sammer
 
@@ -36,6 +36,7 @@
 <li>Future 1.19 Release<p>
     <ul>
     <li>++
+    <li>NEW_UI: Can highlight buttons now to show actions (from Martin Renold).
     <li>Removed old pathfinder, A-Star is not an option now (from Russell 
Smith).
     <li>Added MinRange to Orders, Pathfinder finds correct paths for a ranged 
attack now (from Russell Smith).
     <li>Corrected calculation of MapDistanceBetweenUnits (from Russell Smith).
Index: stratagus/doc/ccl/ui.html
diff -u stratagus/doc/ccl/ui.html:1.15 stratagus/doc/ccl/ui.html:1.16
--- stratagus/doc/ccl/ui.html:1.15      Wed Sep 10 11:33:43 2003
+++ stratagus/doc/ccl/ui.html   Sun Sep 14 07:51:33 2003
@@ -47,7 +47,50 @@
 <a href="unittype.html">NEXT</a> 
 <a href="ccl-index.html">Index</a> 
 <hr>
-<a href="#define-button">define-button</a>
+<a href="#add-button">add-button</a>
+<a href="#set-selection-changed-hook">set-selection-changed-hook</a>
+<a href="#set-selected-unit-changed-hook">set-selected-unit-changed-hook</a>
+<a href="#set-choose-target-begin-hook">set-choose-target-begin-hook</a>
+<a href="#set-choose-target-finish-hook">set-choose-target-finish-hook</a>
+<a href="#add-button">add-button</a>
+<a href="#remove-button">remove-button</a>
+<a href="#remove-all-buttons">remove-all-buttons</a>
+
+<a href="#command-patrol">command-patrol</a>
+<a href="#command-harvest">command-harvest</a>
+<a href="#command-attack">command-attack</a>
+<a href="#command-cancel-upgrade">command-cancel-upgrade</a>
+<a href="#command-build">command-build</a>
+<a href="#command-train-unit">command-train-unit</a>
+<a href="#command-cast-spell">command-cast-spell</a>
+<a href="#command-move">command-move</a>
+<a href="#command-stop">command-stop</a>
+<a href="#command-research">command-research</a>
+<a href="#command-unload">command-unload</a>
+<a href="#command-upgrade-to">command-upgrade-to</a>
+<a href="#command-attack-ground">command-attack-ground</a>
+<a href="#command-return-goods">command-return-goods</a>
+<a href="#command-cancel">command-cancel</a>
+<a href="#command-cancel-building">command-cancel-building</a>
+<a href="#command-cancel-train-unit">command-cancel-train-unit</a>
+<a href="#command-repair">command-repair</a>
+<a href="#command-stand-ground">command-stand-ground</a>
+<a href="#command-demolish">command-demolish</a>
+
+<a href="#check-allowed">check-allowed</a>
+<a href="#get-cost-string">get-cost-string</a>
+
+<a href="#selected-is-building">selected-is-building</a>
+<a href="#selected-is-training">selected-is-training</a>
+<a href="#selected-is-upgrading">selected-is-upgrading</a>
+<a href="#selected-get-race">selected-get-race</a>
+<a href="#selected-get-speed">selected-get-speed</a>
+<a href="#selected-owned-by-player">selected-owned-by-player</a>
+<a href="#selected-mixed-units">selected-mixed-units</a>
+<a href="#selected-get-action">selected-get-action</a>
+<a href="#selected-resource-loaded">selected-resource-loaded</a>
+<a href="#selected-draw-buttons">selected-draw-buttons</a>
+
 <a href="#define-cursor">define-cursor</a>
 <a href="#define-font">define-font</a>
 <a href="#define-font-colors">define-font-colors</a>
@@ -64,46 +107,30 @@
 
 Everything around the user interface.
 <h2>Functions</h2>
-<a name="define-button"></a>
-<h3>(define-button 'tag1 value1 'tag2 value2 ...)</h3>
+<a name="add-button"></a>
+<h3>(add-button 'tag1 value1 'tag2 value2 ...)</h3>
 
-Define a button in the button panel show during the game. Possible tags:
+Add a button to the button panel during the game. This is usually
+called from the 'button-hook of the unittypes (FIXME link), or from
+the selection-changed-hook (FIXME link) directly.
+See also (remove-all-buttons) (FIXME link)<br>
+Possible tags:
 
 <dl>
-<dt>forunit</dt>
-<dd>List of units the button applies to, or '(*) for all units.
-</dd>
 <dt>pos</dt>
-<dd>Position number. 
+<dd>Position number. Currently buttons can be added only to the button
+panel.
 <pre>
 0 1 2
 3 4 5
 6 7 8
 </pre>
 </dd>
-<dt>level</dt>
-<dd>Visible when in this button level (0 default, 9 cancel-only)
-</dd>
 <dt>icon</dt>
 <dd>Name of the icon to display.
 </dd>
 <dt>action</dt>
-<dd>Action to perform when the button is clicked.  Can be any of the following:
-move, stop, attack, repair, harvest, button, build, train-unit, patrol,
-stand-ground, attack-ground, return-goods, demolish, cast-spell, research,
-upgrade-to, unload, cancel, cancel-upgrade, cancel-train-unit, cancel-build.
-</dd>
-<dt>value</dt>
-<dd>Optional value associated with the action.
-</dd>
-<dt>allowed</dt>
-<dd>Optional check to see if a button is allowed.  Can be any of the following:
-check-true, check-false, check-upgrade, check-units-or, check-units-and,
-check-network, check-no-work, check-no-research, check-attack,
-check-upgrade-to, check-research, check-single-research.
-</dd>
-<dt>allowarg</dt>
-<dd>Optional argument used by the allowed function.
+<dd>Script to eval when the button is pressed.
 </dd>
 <dt>key</dt>
 <dd>Shortcut key for the button.
@@ -111,17 +138,394 @@
 <dt>hint</dt>
 <dd>Hint to be displayed for the button.
 </dd>
+<dt>highlight</dt>
+<dd>If given and true, highlight the button by drawing an extra border
+(used for showing actions).
+</dd>
 </dl>
 
 <h4>Example</h4>
 <pre>
-    (define-button 'pos 9 'level 0 'icon 'icon-exorcism
-      'action 'cast-spell 'value 'spell-exorcism
-      'allowed 'check-upgrade 'allow-arg '(upgrade-exorcism)
-      'key "e" 'hint "~!EXORCISM"
-      'for-unit '(unit-paladin unit-knight-rider unit-man-of-light))
+    ;; add a patrol button
+    (add-button 'pos 4
+      'icon (string-append "icon-" (selected-get-race) "-patrol-land")
+      'key "p" 'hint "~!PATROL"
+      'action (lambda () (command-patrol)))
+</pre>
+
+<a name="remove-button"></a>
+<h3>(remove-button id)</h3>
+Remove button number id.
+<h4>Example</h4>
+    (remove-button 4)
+<pre>
+</pre>
+
+<a name="remove-all-buttons"></a>
+<h3>(remove-all-buttons)</h3>
+Removes all buttons from the button panel.
+
+<a name="set-selection-changed-hook"></a>
+<h3>(set-selection-changed-hook '(begin ...))</h3>
+Set the script that will be evaluated whenever the player selects an other set 
of units.
+You will probably want call things like <a 
href="#remove-all-buttons">remove-all-buttons</a>
+and <a href="#add-button">add-button</a> here, after examining the selection 
with other helper functions.
+<p>
+I suggest you define a helper function that rebuilds the buttons, and
+call it from both selection-changed-hook and 
+<a href="#set-selected-unit-changed-hook">selected-unit-changed-hook</a>.
+
+<h4>Example</h4>
+<pre>
+    ; (Those are extracts from the demogame ccls)
+
+    ; FIXME: this is most likely a very ugly hack to scheme
+    (define (set-global symbol value)
+      (set-symbol-value! symbol value nil))
+    (define (get-global symbol)
+      (symbol-value symbol nil))
+
+    (set-selection-changed-hook '(begin
+      (set-global 'button-level 0)
+      (rebuild-buttons)))
+
+    (set-selected-unit-changed-hook '(begin
+      (rebuild-buttons)))
+
+    ; Build all the command buttons from scratch.
+    (define (rebuild-buttons)
+      (remove-all-buttons)
+      (if (selected-owned-by-player) (begin
+        ; draw some generic buttons
+        (if (= (get-global 'button-level) 0) (begin
+          (if (> (selected-get-speed) 0) (begin
+            (generic-movement-buttons)
+            (if (selected-mixed-units) (begin
+              (generic-combat-buttons))
+              ; Uniform selection: draw the unit's own buttons
+              (selected-draw-buttons))))
+          (if (selected-is-building) (begin
+            ; there can be only one building selected
+            ; no common buttons should be here for now, 
+            ; "destroy building" or something could be added.
+            (add-button 'pos 7
+              'icon 'icon-move-peasant
+              'key "m" 'hint "SET ~!MOVE"
+              'action (lambda () (command-move)))
+            ;
+            ; Call the building's own button-draw hook
+            ;
+            (selected-draw-buttons)
+            ; FIXME: maybe non-buildings could be upgrading too
+            ; note: upgrade is both researching and changing unit type
+            (if (selected-is-upgrading) (begin
+              ; could be optimized by not calling (selected-draw-buttons)
+              (remove-all-buttons)
+              (add-button 'pos 9 'icon 'icon-cancel
+                'key "\033" 'hint "~<ESC~> CANCEL UPGRADE"
+                'action (lambda() (command-cancel-upgrade))))))))
+        (begin ; else: button level is not zero
+          ;
+          ; Generic cancel button to go back to button level 0
+          ;
+          (add-button 'pos 9 'icon 'icon-cancel
+            'key "\033" 'hint "~<ESC~> CANCEL"
+            'action (lambda()
+              (set-global 'button-level 0)
+              (rebuild-buttons)))
+          ;
+          ; Call the unit's own button-draw hook
+          ;
+          (selected-draw-buttons))))))
+    ; no command buttons for enemy units.
+</pre>
+
+<a name="set-selected-unit-changed-hook"></a>
+<h3>(set-selected-unit-changed-hook)</h3>
+
+Set the script that will be evaluated when one of the selected units
+experiences some kind of upgrade, or when a global research is
+completed (this is when you might want new buttons to appear, or old
+ones to remove, or button images to be changed). This is seperated
+from <a href="#set-selection-changed-hook">set-selection-changed-hook</a>
+because you probably don't want to break out of a subbutton (eg selecting
+the building to build) here.
+
+<h4>Example</h4>
+<pre>
+    (set-selected-unit-changed-hook '(begin
+      (writes nil "[debug] selected-unit-changed-hook called")
+      (rebuild-buttons)))
+</pre>
+
+<a name="set-choose-target-begin-hook"></a>
+<h3>(set-choose-target-begin-hook)</h3>
+
+Set the script that will be evaluated when the user is asked to select
+some target. You will want to change the buttons. FIXME: other hooks
+can interrupt the select-target process, so a global flag must be set
+
+<h4>Example</h4>
+<pre>
+    ; When doing a target selection, only draw a cancel button.
+    ; If you leave them both empty, you can choose another building while
+    ; setting the destination and similar things.
+    (set-choose-target-begin-hook '(begin
+      (set-global 'button-level 9)
+      (rebuild-buttons)))
+    (set-choose-target-finish-hook '(begin
+      (set-global 'button-level 0)
+      (rebuild-buttons)))
+</pre>
+
+<a name="set-choose-target-finish-hook"></a>
+<h3>(set-choose-target-finish-hook)</h3>
+Set the script that will be evaluated when the user has finished to
+select a target. See <a 
href="#set-choose-target-begin-hook">set-choose-target-begin-hook</a>
+for details.
+
+<a name="command-patrol"></a>
+<h3>(command-patrol)</h3>
+(While game is running) Let the player select a destination where the
+currently selected units will patrol to.
+
+<a name="command-harvest"></a>
+<h3>(command-harvest)</h3>
+(While game is running) Let the player select a destination where the
+currently selected units will harvest.
+
+<a name="command-attack"></a>
+<h3>(command-attack)</h3>
+(While game is running) Let the player select a destination where the
+currently selected units will attack.
+
+<a name="command-cancel-upgrade"></a>
+<h3>(command-cancel-upgrade)</h3>
+(While game is running) Cancel the upgrade the currently selected unit
+is doing.
+
+<a name="command-build"></a>
+<h3>(command-build unittype)</h3>
+(While game is running) Let the player select a destination where a
+building will be placed. Costs are checked.
+<h4>Example</h4>
+<pre>
+    (command-build 'unit-farm)
+</pre>
+
+<a name="command-train-unit"></a>
+<h3>(command-train-unit unittype)</h3>
+(While game is running) Let the current unit train another unit (I
+wonder whether this works with non-buildings, too?)
+<h4>Example</h4>
+<pre>
+    ; define a helper function to add training buttons
+    (define (train-button type pos key hint)
+      (if (check-allowed (string-append 'unit- type))
+        (add-button
+          'icon (string-append 'icon- type)
+          'hint (string-append hint "   " (get-cost-string (string-append 
'unit- type)))
+          'pos pos
+          'key key
+          'action (lambda ()
+            (writes nil "Train-command\n")
+            (command-train-unit  (string-append 'unit- type))))))
+</pre>
+
+<a name="command-cast-spell"></a>
+<h3>(command-cast-spell spellid)</h3>
+(While game is running) Let the current unit(selection) cast a spell.
+<br>FIXME: untested.
+
+<h4>Example</h4>
+<pre>
+    FIXME
 </pre>
 
+<a name="command-move"></a>
+<h3>(command-move)</h3>
+(While game is running) Let the player select a destination where the
+currently selected units will move to.
+
+<a name="command-stop"></a>
+<h3>(command-stop)</h3>
+(While game is running) stop the selected units.
+
+<a name="command-research"></a>
+<h3>(command-research upgrade)</h3>
+(While game is running) Command the selected unit to research the
+given upgrade.
+
+<a name="command-unload"></a>
+<h3>(command-unload)</h3>
+(While game is running) Let the player select a destination where the
+currently selected unit(s) will unload to.
+
+<a name="command-upgrade-to"></a>
+<h3>(command-upgrade-to unittype)</h3>
+(While game is running) Command the selected unit to upgrade to
+another unittype.
+
+<a name="command-attack-ground"></a>
+<h3>(command-attack-ground)</h3>
+(While game is running) Let the player select a destination where the
+currently selected unit(s) will attack a ground area.
+
+<a name="command-return-goods"></a>
+<h3>(command-return-goods)</h3>
+(While game is running) Let the currently selected units return their
+goods.
+
+<a name="command-cancel"></a>
+<h3>(command-cancel)</h3>
+(While game is running) This cancels selecting a
+destination. (FIXME: or is it used elsewhere too?)
+
+<a name="command-cancel-building"></a>
+<h3>(command-cancel-building)</h3>
+(While game is running) This cancels building.
+(FIXME: does it work?)
+
+<a name="command-cancel-train-unit"></a>
+<h3>(command-cancel-train-unit)</h3>
+(While game is running) Let the first selected unit remove one item
+from the training queue. 
+(FIXME: or does it rather empty the training queue completely?)
+
+<a name="command-repair"></a>
+<h3>(command-repair)</h3>
+(While game is running) Let the player select a destination that the
+currently selected units will repair.
+
+<a name="command-stand-ground"></a>
+<h3>(command-stand-ground)</h3>
+Command the selected units not to move. (FIXME: correct?)
+
+<a name="command-demolish"></a>
+<h3>(command-demolish)</h3>
+(While game is running) Let the player select a destination where the
+currently selected units go demolishing (explode there).
+
+<a name="check-allowed"></a>
+<h3>(check-allowed thing)</h3>
+Check whether thing is allowed. Thing can be an upgrade or an unit.
+<h4>Example</h4>
+<pre>
+    (if (check-allowed 'unit-keep)
+      (add-button 'pos 2
+      'icon 'icon-keep
+      'key "k" 
+      'hint (string-append "UPGRADE TO ~!KEEP   " (get-cost-string 'unit-keep))
+      'action (lambda () (command-upgrade-to 'unit-keep))))
+</pre>
+
+<a name="get-cost-string"></a>
+<h3>(get-cost-string thing)</h3>
+Returns a string with the costs of thing (unit or upgrade), useful to
+give as button hint.
+<br>
+The string contains the special characters like
+&quot;$1&quot; that will let a resource icon appear instead of the
+text.
+
+<h4>Example</h4>
+<pre>
+      'hint (string-append "UPGRADE TO ~!KEEP   " (get-cost-string 'unit-keep))
+</pre>
+
+<a name="selected-is-building"></a>
+<h3>(selected-is-building)</h3>
+Returns true if the selected unit is a building. FIXME: bad name
+
+<a name="selected-is-training"></a>
+<h3>(selected-is-training)</h3>
+Returns true if the selected unit is training.
+
+<a name="selected-is-upgrading"></a>
+<h3>(selected-is-upgrading)</h3>
+Returns true if the selected unit is upgrading.
+
+<a name="selected-get-race"></a>
+<h3>(selected-get-race)</h3>
+Returns the race of the selected unit.
+<h4>Example</h4>
+<pre>
+    ; not yet used, could be useful for something like
+    'icon (string-append "icon-" (selected-get-race) "shield1")
+    ; if the icons are named properly
+</pre>
+
+<a name="selected-get-speed"></a>
+<h3>(selected-get-speed)</h3>
+
+Gets the speed of the selected unit, as defined in the
+unittype. Useful to decide whether to draw a movement button. 
+<br>
+Note that the speed declared in the unittype is just to display something,
+the real unit speed is hidden in the animation script.
+
+<a name="selected-owned-by-player"></a>
+<h3>(selected-owned-by-player)</h3>
+
+Returns true if the selected unit(s) is owned by the current
+player.
+<br>
+Note that the player cannot select more than one enemy unit a
+a time.
+
+<a name="selected-mixed-units"></a>
+<h3>(selected-mixed-units)</h3>
+Returns true if the selection contains more than one unittype.
+<h4>Example</h4>
+<pre>
+    (if (selected-mixed-units) (begin
+      ; attack/stand/patrol buttons for mixed selections
+        (generic-combat-buttons))
+      ; Uniform selection: draw the unit's own buttons
+        (selected-draw-buttons))
+</pre>
+
+<a name="selected-get-action"></a>
+<h3>(selected-get-action)</h3>
+Returns the name of the current action as a string. Possible values are:
+<p>
+Invalid (No unit selected), Mixed (multiple units selected, and they
+are doing different things), None, Still, StandGround, Follow, Move,
+Attack, AttackGround, Die, SpellCast, Train, Train, UpgradeTo,
+Research, Builded, Board, Unload, Patrol, Build, Repair, Resource,
+ReturnGoods, Demolish.
+<p>
+Note that those are case-sensitive.
+
+<h4>Example</h4>
+<pre>
+    (add-button 'pos 3
+      'icon (string-append "icon-sword1")
+      'key "a" 'hint "~!ATTACK"
+      'highlight (= (strcmp (selected-get-action) 'Attack) 0)
+      'action (lambda () (command-attack))))
+</pre>
+
+<a name="selected-resource-loaded"></a>
+<h3>(selected-resource-loaded)</h3>
+Returns the name of the resource the selected units have loaded, 
+'mixed if there are different resources loaded, or nil (false) if
+there are no resources loaded.
+<h4>Example</h4>
+<pre>
+    (if (selected-resource-loaded) (begin
+      (writes nil (string-append "[debug] Selected unit has loaded " 
(selected-resource-loaded) " resources.\n"))
+      (add-button 'pos 6 
+        ; could build icon string from the resource name :)
+        'icon 'icon-return-goods-peasant
+        'key "g" 'hint "RETURN WITH ~!GOODS"
+        'action (lambda () (command-return-goods)))))
+</pre>
+
+<a name="selected-draw-buttons"></a>
+<h3>(selected-draw-buttons)</h3>
+Run the 'add-buttons hook from the first selected unittype.
+
 <a name="define-cursor"></a>
 <h3>(define-cursor 'ident 'race 'tag1 value1 'tag2 value2 ...)</h3>
 
@@ -888,7 +1292,7 @@
 <h4>Not Used</h4>
 
 <hr>
-Last changed: $Id: ui.html,v 1.15 2003/09/10 15:33:43 martinxyz Exp $<br>
+Last changed: $Id: ui.html,v 1.16 2003/09/14 11:51:33 martinxyz Exp $<br>
 All trademarks and copyrights on this page are owned by their respective 
owners.
 <address>(c) 2002-2003 by <a href="http://stratagus.org";>
 The Stratagus Project</a></address></body></html>
Index: stratagus/src/include/interface.h
diff -u stratagus/src/include/interface.h:1.81 
stratagus/src/include/interface.h:1.82
--- stratagus/src/include/interface.h:1.81      Sun Aug 17 11:57:07 2003
+++ stratagus/src/include/interface.h   Sun Sep 14 07:51:33 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: interface.h,v 1.81 2003/08/17 15:57:07 n0body Exp $
+//     $Id: interface.h,v 1.82 2003/09/14 11:51:33 martinxyz Exp $
 
 #ifndef __INTERFACE_H__
 #define __INTERFACE_H__
@@ -95,6 +95,7 @@
     char*      UnitMask;               /// for which units is it available
 #else
     SCM        Action;                 /// script on button press
+    int         Highlight;             /// whether to draw a border
 #endif
     IconConfig Icon;                   /// icon to display
     int                Key;                    /// alternative on keyboard
@@ -316,7 +317,7 @@
        int key,const char* hint,const char* umask);
 #else
     /// Add a new button to the command panel
-extern void AddButton(int pos, char *icon_ident, SCM action, int key, char 
*hint);
+extern void AddButton(int pos, char *icon_ident, SCM action, int key, char 
*hint, int highlight);
     /// Remove a single button from the panel
 global void RemoveButton(int pos);
 #endif
Index: stratagus/src/ui/botpanel.c
diff -u stratagus/src/ui/botpanel.c:1.86 stratagus/src/ui/botpanel.c:1.87
--- stratagus/src/ui/botpanel.c:1.86    Fri Sep  5 14:10:56 2003
+++ stratagus/src/ui/botpanel.c Sun Sep 14 07:51:33 2003
@@ -27,7 +27,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: botpanel.c,v 1.86 2003/09/05 18:10:56 n0body Exp $
+//     $Id: botpanel.c,v 1.87 2003/09/14 11:51:33 martinxyz Exp $
 
 //@{
 
@@ -114,7 +114,7 @@
 #endif
 
     CLprintf(file,"\n;;; -----------------------------------------\n");
-    CLprintf(file,";;; MODULE: buttons $Id: botpanel.c,v 1.86 2003/09/05 
18:10:56 n0body Exp $\n\n");
+    CLprintf(file,";;; MODULE: buttons $Id: botpanel.c,v 1.87 2003/09/14 
11:51:33 martinxyz Exp $\n\n");
 
 #ifndef NEW_UI
     for( i=0; i<NumUnitButtons; ++i ) {
@@ -318,7 +318,7 @@
        enum _button_cmd_ action, const char *value, const ButtonCheckFunc func,
        const void *allow, int key, const char *hint, const char *umask)
 #else
-global void AddButton(int pos, char *icon_ident, SCM action, int key, char 
*hint)
+global void AddButton(int pos, char *icon_ident, SCM action, int key, char 
*hint, int highlight)
 #endif
 {
 #ifndef NEW_UI
@@ -410,6 +410,7 @@
     ba->Hint = hint;
     MustRedraw|=RedrawButtonPanel;
     ba->Key = key;
+    ba->Highlight = highlight;
 #endif
 }
 
@@ -480,9 +481,7 @@
     const ButtonAction* buttons;
     char buf[8];
 #else
-    //const UnitStats* stats;
     const ButtonAction* ba;
-    //char buf[8];
 #endif
 
     //
@@ -513,8 +512,6 @@
     for( i=0; i<9; ++i ) {
        ba = CurrentButtons + i;
        if( ba->Icon.Icon != NoIcon ) {
-           //int j;
-           //int action;
 #endif
 
            // cursor is on that button
@@ -619,6 +616,10 @@
                    default:
                        break;
                }
+           }
+#else
+           if( ba->Highlight ) {
+               v|=IconSelected;
            }
 #endif
 
Index: stratagus/src/ui/ccl_ui.c
diff -u stratagus/src/ui/ccl_ui.c:1.123 stratagus/src/ui/ccl_ui.c:1.124
--- stratagus/src/ui/ccl_ui.c:1.123     Thu Sep 11 02:49:06 2003
+++ stratagus/src/ui/ccl_ui.c   Sun Sep 14 07:51:33 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: ccl_ui.c,v 1.123 2003/09/11 06:49:06 mr-russ Exp $
+//     $Id: ccl_ui.c,v 1.124 2003/09/14 11:51:33 martinxyz Exp $
 
 //@{
 
@@ -497,6 +497,21 @@
 }
 
 /**
+**     Whether the selected unit is repairing.
+*/
+local SCM CclSelectedIsRepairing(void)
+{
+    if( NumSelected == 0) {
+       return SCM_UNSPECIFIED;
+    }
+    if( Selected[0]->Orders[0].Action==UnitActionTrain ) {
+       return SCM_BOOL_T;
+    } else {
+       return SCM_BOOL_F;
+    }
+}
+
+/**
 **     FIXME: docu
 */
 local SCM CclSelectedIsTraining(void)
@@ -567,6 +582,33 @@
 }
 
 /**
+**     Return the name of the resource type that is loaded.
+*/
+local SCM CclSelectedResourceLoaded(void)
+{
+    int i;
+    int type;
+    Unit * unit;
+    type = -1;
+    for ( i=0; i<NumSelected; i++ ) {
+       unit = Selected[i];
+       if( unit->CurrentResource && unit->Value && 
+           (!unit->Type->ResInfo[unit->CurrentResource]->LoseResources || 
+            unit->Value >= 
unit->Type->ResInfo[unit->CurrentResource]->ResourceCapacity) ) {
+           if( type == -1 ) {
+               type = unit->CurrentResource;
+           } else if( type != unit->CurrentResource ) {
+               return gh_str02scm("mixed");
+           }
+       }
+    }
+    if( type == -1 ) {
+       return SCM_UNSPECIFIED;
+    }
+    return gh_str02scm(DefaultResourceNames[type]);
+}
+
+/**
 **     FIXME: docu
 */
 local SCM CclSelectedMixedUnits(void)
@@ -589,6 +631,52 @@
 /**
 **     FIXME: docu
 */
+local SCM CclSelectedGetAction(void)
+{
+    int j;
+    UnitAction action;
+
+    if( NumSelected == 0 ) {
+       return gh_str02scm("Invalid");
+    }
+    action = Selected[0]->Orders[0].Action;
+    for( j=1; j<NumSelected; ++j ) {
+       if( Selected[j]->Orders[0].Action!=action ) {
+           return gh_str02scm("Mixed");
+       }
+    }
+
+    switch (action) {
+    case UnitActionNone: return gh_str02scm("None");
+    case UnitActionStill: return gh_str02scm("Still"); break;
+    case UnitActionStandGround: return gh_str02scm("StandGround"); break;
+    case UnitActionFollow: return gh_str02scm("Follow"); break;
+    case UnitActionMove: return gh_str02scm("Move"); break;
+    case UnitActionAttack: return gh_str02scm("Attack"); break;
+    case UnitActionAttackGround: return gh_str02scm("AttackGround"); break;
+    case UnitActionDie: return gh_str02scm("Die"); break;
+    case UnitActionSpellCast: return gh_str02scm("SpellCast"); break;
+    case UnitActionTrain: return gh_str02scm("Train"); break;
+    case UnitActionUpgradeTo: return gh_str02scm("UpgradeTo"); break;
+    case UnitActionResearch: return gh_str02scm("Research"); break;
+    case UnitActionBuilded: return gh_str02scm("Builded"); break;
+    case UnitActionBoard: return gh_str02scm("Board"); break;
+    case UnitActionUnload: return gh_str02scm("Unload"); break;
+    case UnitActionPatrol: return gh_str02scm("Patrol"); break;
+    case UnitActionBuild: return gh_str02scm("Build"); break;
+    case UnitActionRepair: return gh_str02scm("Repair"); break;
+    case UnitActionResource: return gh_str02scm("Resource"); break;
+    case UnitActionReturnGoods: return gh_str02scm("ReturnGoods"); break;
+    case UnitActionDemolish: return gh_str02scm("Demolish"); break;
+    default:
+       DebugLevel0Fn("FIXME: invalid action id %d\n" _C_ action);
+       return gh_str02scm("invalid");
+    }
+}
+
+/**
+**     FIXME: docu
+*/
 local SCM CclSelectedDrawButtons(void)
 {
     if( NumSelected > 0 ) {
@@ -3149,6 +3237,10 @@
            s1=gh_scm2newstr(value,NULL);
            ba.Key=*s1;
            free(s1);
+       } else if( gh_eq_p(value,gh_symbol2scm("highlight")) ) {
+           value=gh_car(list);
+           list=gh_cdr(list);
+           ba.Highlight=gh_scm2bool(value);
        } else if( gh_eq_p(value,gh_symbol2scm("hint")) ) {
            value=gh_car(list);
            list=gh_cdr(list);
@@ -3162,7 +3254,7 @@
 
 
     // maxy: allocated memory goes into currentButtons[], must not be freed
-    AddButton(pos,ba.Icon.Name,ba.Action,ba.Key,ba.Hint);
+    AddButton(pos,ba.Icon.Name,ba.Action,ba.Key,ba.Hint,ba.Highlight);
 
     return SCM_UNSPECIFIED;
 }
@@ -3721,6 +3813,8 @@
     gh_new_procedure0_0("selected-get-speed",CclSelectedGetSpeed);
     gh_new_procedure0_0("selected-owned-by-player",CclSelectedOwnedByPlayer);
     gh_new_procedure0_0("selected-mixed-units",CclSelectedMixedUnits);
+    gh_new_procedure0_0("selected-get-action",CclSelectedGetAction);
+    gh_new_procedure0_0("selected-resource-loaded",CclSelectedResourceLoaded);
     gh_new_procedure0_0("selected-draw-buttons",CclSelectedDrawButtons);
 
 #endif




reply via email to

[Prev in Thread] Current Thread [Next in Thread]