Automatic groups added. Added support for click on selection icons.

This commit is contained in:
johns 2001-04-23 21:12:50 +00:00
parent 9d693d9b4c
commit 46f7e472fe
7 changed files with 124 additions and 19 deletions

View file

@ -621,6 +621,8 @@
<LI>Removed all %Zd in printf, not portable.
<LI>Fixed bug: Time for duration of spells is wrong.
<LI>Fixed bug: Wrong mana cost for rune spell.
<LI>Added support for mouse clicks on icons of selections.
<LI>Automatic groups added.
<LI>+++
</UL>
</UL>

View file

@ -257,10 +257,25 @@ freecraft [OPTIONS] [map.pud|map.pud.gz]
Load complete state.
<LI><KBD>ALT+M, F10</KBD><BR>
Enter game menu.
<LI><KBD>space</KBD><BR>
<LI><KBD>SPACE</KBD><BR>
Center on last message.
</UL>
<H3>Mouse commands</H3>
<H4>Clicking on minimap</H4>
<H4>Clicking on map</H4>
<UL>
<LI>Single click with left mouse button<BR>
<LI>SHIFT Single click with left mouse button<BR>
<LI>CTRL Single click with left mouse button<BR>
<LI>ALT Single click with left mouse button<BR>
<LI>Double click with left mouse button<BR>
<LI>Click & Hold with left mouse button<BR>
</UL>
<H2><A NAME="ccl">CCL: FreeCraft Configuration Language</A></H2>
The CCL is scheme. I use SIOD for this.

View file

@ -247,10 +247,9 @@ extern void UserInterfaceCclRegister(void); /// register ccl features
/// Called if the mouse is moved in Normal interface state
extern void UIHandleMouseMove(int x,int y);
/// Called if any mouse button is pressed down
extern void UIHandleButtonDown(int b);
extern void UIHandleButtonDown(unsigned button);
/// Called if any mouse button is released up
extern void UIHandleButtonUp(int b);
/// Called if the mouse is moved
extern void UIHandleButtonUp(unsigned button);
//@}

View file

@ -120,6 +120,9 @@ global void AddToGroup(Unit **units,int nunits,int num)
group=&Groups[num];
for( i=0; group->NumUnits<NUM_UNITS_PER_GROUP && i<nunits; i++ ) {
if( units[i]->GroupId!=-1 ) {
RemoveUnitFromGroup(units[i]);
}
group->Units[group->NumUnits++]=units[i];
units[i]->GroupId=num;

View file

@ -44,6 +44,8 @@ global Unit* Selected[MaxSelectable] = {
NoUnitP,NoUnitP,NoUnitP
}; /// All selected units
local int GroupId; /// Unique group id for automatic groups
/*----------------------------------------------------------------------------
-- Functions
----------------------------------------------------------------------------*/
@ -55,6 +57,9 @@ global void UnSelectAll(void)
{
Unit *unit;
while( !++GroupId ) {
}
while( NumSelected ) {
unit=Selected[--NumSelected];
Selected[NumSelected]=NoUnitP; // FIXME: only needed for old code
@ -80,6 +85,9 @@ global void ChangeSelectedUnits(Unit** units,int count)
for( i=0; i<count; i++ ) {
Selected[i]=u=units[i];
u->Selected=1;
if( count>1 ) {
u->LastGroup=GroupId;
}
CheckUnitToBeDrawn(u);
}
NumSelected=count;
@ -109,6 +117,9 @@ global int SelectUnit(Unit* unit)
Selected[NumSelected++]=unit;
unit->Selected=1;
if( NumSelected>1 ) {
Selected[0]->LastGroup=unit->LastGroup=GroupId;
}
CheckUnitToBeDrawn(unit);
return 1;
}
@ -144,6 +155,15 @@ global void UnSelectUnit(Unit* unit)
if( i<--NumSelected ) {
Selected[i]=Selected[NumSelected];
}
if( NumSelected>1 ) { // Assign new group to remaining units
while( !++GroupId ) {
}
for( i=0; i<NumSelected; ++i ) {
Selected[i]->LastGroup=GroupId;
}
}
Selected[NumSelected]=NoUnitP; // FIXME: only needed for old code
unit->Selected=0;
CheckUnitToBeDrawn(unit);
@ -236,6 +256,12 @@ global int SelectUnitsByType(Unit* base)
}
}
if( NumSelected>1 ) {
for( i=0; i<NumSelected; ++i ) {
Selected[i]->LastGroup=GroupId;
}
}
return NumSelected;
}
@ -271,10 +297,28 @@ global int SelectGroup(int group_number)
*/
global int SelectGroupFromUnit(Unit *unit)
{
int i;
unsigned group;
#if 0
if( unit->GroupId==-1 ) {
return 0;
}
return SelectGroup(unit->GroupId);
#endif
DebugLevel0Fn("%d\n",unit->LastGroup);
if( !(group=unit->LastGroup) ) { // belongs to no group
return 0;
}
UnSelectAll();
for( i=0; i<NumUnits; ++i ) {
if( Units[i]->LastGroup==group ) {
SelectUnit(Units[i]);
}
}
return NumSelected;
}
/**

View file

@ -913,6 +913,8 @@ global void InputMouseButtonPress(const EventCallback* callbacks,
global void InputMouseButtonRelease(const EventCallback* callbacks,
unsigned ticks,unsigned button)
{
unsigned mask;
//
// Same button before pressed.
//
@ -922,13 +924,21 @@ global void InputMouseButtonRelease(const EventCallback* callbacks,
LastMouseButton=0;
MouseState=InitialMouseState;
}
MouseButtons&=~(1<<button);
MouseButtons&=~(1<<button)<<MouseDoubleShift;
MouseButtons&=~(1<<button)<<MouseDragShift;
MouseButtons&=~(1<<button)<<MouseHoldShift;
LastMouseTicks=ticks;
callbacks->ButtonReleased(button);
mask=0;
if( MouseButtons&((1<<button)<<MouseDoubleShift) ) {
mask|=button<<MouseDoubleShift;
}
if( MouseButtons&((1<<button)<<MouseDragShift) ) {
mask|=button<<MouseDragShift;
}
if( MouseButtons&((1<<button)<<MouseHoldShift) ) {
mask|=button<<MouseHoldShift;
}
MouseButtons&=~(0x01010101<<button);
callbacks->ButtonReleased(button|mask);
}
/**

View file

@ -916,6 +916,35 @@ local void SendCommand(int x,int y)
//.............................................................................
/**
** Mouse button press on selection area.
**
** @param num Button number.
** @param button Mouse Button pressed.
*/
local void DoSelectionButtons(unsigned num,unsigned button)
{
Unit* unit;
if( num>=NumSelected || !(MouseButtons&LeftButton) ) {
return;
}
unit=Selected[num];
if( (KeyModifiers&ModifierControl)
|| ((MouseButtons&LeftButton)<<MouseDoubleShift)) {
SelectUnitsByType(unit);
} else if( KeyModifiers&ModifierAlt ) {
SelectGroupFromUnit(unit);
} else if( KeyModifiers&ModifierShift ) {
ToggleSelectUnit(unit);
} else {
SelectSingleUnit(unit);
}
}
//.............................................................................
/**
** Handle mouse button pressed in select state.
**
@ -988,9 +1017,9 @@ local void UISelectStateButtonDown(unsigned button)
/**
** Called if mouse button pressed down.
**
** @param b Button pressed down.
** @param button Button pressed down.
*/
global void UIHandleButtonDown(int b)
global void UIHandleButtonDown(unsigned button)
{
if( CursorState==CursorStateRectangle ) { // select mode
return;
@ -1000,7 +1029,7 @@ global void UIHandleButtonDown(int b)
// Selecting target. (Move,Attack,Patrol,... commands);
//
if( CursorState==CursorStateSelect ) {
UISelectStateButtonDown(b);
UISelectStateButtonDown(button);
return;
}
@ -1073,7 +1102,9 @@ global void UIHandleButtonDown(int b)
DoRightButton(Minimap2MapX(CursorX),Minimap2MapY(CursorY));
}
} else if( CursorOn==CursorOnButton ) {
if( (MouseButtons&LeftButton) ) {
if( NumSelected>1 && ButtonUnderCursor && ButtonUnderCursor<10 ) {
DoSelectionButtons(ButtonUnderCursor-1,button);
} else if( (MouseButtons&LeftButton) ) {
if( ButtonUnderCursor==0 && GameMenuButtonClicked==0 ) {
GameMenuButtonClicked = 1;
MustRedraw|=RedrawMenuButton;
@ -1089,7 +1120,6 @@ global void UIHandleButtonDown(int b)
,!(KeyModifiers&ModifierShift));
}
}
DebugLevel0("Button %d\n",ButtonUnderCursor);
} else if( ButtonUnderCursor>9 ) {
DoButtonButtonClicked(ButtonUnderCursor-10);
}
@ -1100,9 +1130,9 @@ global void UIHandleButtonDown(int b)
/**
** Called if mouse button released.
**
** @param b Button released.
** @param button Button released.
*/
global void UIHandleButtonUp(int b)
global void UIHandleButtonUp(unsigned button)
{
//
// Move map.
@ -1111,7 +1141,7 @@ global void UIHandleButtonUp(int b)
GameCursor=TheUI.Point.Cursor; // Reset
return;
}
if( (1<<b) == LeftButton && GameMenuButtonClicked == 1 ) {
if( (1<<button) == LeftButton && GameMenuButtonClicked == 1 ) {
GameMenuButtonClicked = 0;
MustRedraw|=RedrawMenuButton;
if( ButtonUnderCursor == 0 ) {
@ -1183,9 +1213,11 @@ global void UIHandleButtonUp(int b)
,CursorY-TheUI.MapY+MapY*TileSizeY);
}
if( unit ) {
if( KeyModifiers&ModifierControl ) {
// FIXME: Not nice coded, button number hardcoded!
if( (KeyModifiers&ModifierControl)
|| (button&(1<<MouseDoubleShift))) {
num=SelectUnitsByType(unit);
} else if( (KeyModifiers&ModifierAlt) && unit->GroupId!=-1 ) {
} else if( (KeyModifiers&ModifierAlt) && unit->LastGroup ) {
num=SelectGroupFromUnit(unit);
// Don't allow to select own and enemy units.