Icon Buttons

Wargus is a Warcraft 2 mod that allows you to play Warcraft 2 with the Stratagus engine.
User avatar
DinkyDyeAussie
Posts: 260
Joined: Fri Feb 10, 2012 10:39 am
Location: Australia

Icon Buttons

Post by DinkyDyeAussie »

In the original warcraft 2, and in freecraft, all the icons depressed when you clicked them:

So from this:
icon-normal.png
icon-normal.png (3.36 KiB) Viewed 7185 times
to this:
icon-pressed.png
icon-pressed.png (4.05 KiB) Viewed 7185 times
But in stratagus, this doesn't exist. I'd like to request the small features like this, and the highlighting of all the game menu button's text when you hover the mouse/click the mouse on them be put back in the game. Subtleties like this make a good game better.

I'm being a nag I feel, but I like these features to be in the game. :)
User avatar
Andrettin
Posts: 433
Joined: Sun Jun 30, 2013 9:58 pm
Location: Vienna, Austria
Contact:

Re: Icon Buttons

Post by Andrettin »

That would indeed be nice, and if the code was already in freecraft and we have the source code for the version which had the feature, then it shouldn't be too hard to reimplement it.
User avatar
DinkyDyeAussie
Posts: 260
Joined: Fri Feb 10, 2012 10:39 am
Location: Australia

Re: Icon Buttons

Post by DinkyDyeAussie »

I've been looking through the old freecraft 1.18 source and trying to figure out how to port it accross to the newest source in stratagus. Fun times, but having a few pointers as to how to would be good.

Where are Cyber and Jarod when you need them? This room service sucks! :P :P :P :P :P
User avatar
DinkyDyeAussie
Posts: 260
Joined: Fri Feb 10, 2012 10:39 am
Location: Australia

Re: Icon Buttons

Post by DinkyDyeAussie »

Still looking through stratagus code. To be honest, I feel the icons should be treated more like buttons than static images that you click. The code for the normal buttons (MenuButton and GameMenuButton) reflect this - with parameters for default, hover, and click, with the click activating the code to show the button has been clicked by changing the image.

Icons really don't have different images for the same icon, and as such it will be more of a code hack that makes it look as though the icon is depressed when clicked, like it is in freecraft. The code is there also in stratagus, but only for the tile button in the map editor, and even then it doesn't look depressed when clicked like the icons do in freecraft.

Here's the code from freecraft that (I think) shows the icon depressed:

Code: Select all

global void DrawUnitIcon(const Player* player, Icon* icon, unsigned flags, int x, int y)
{
    int color;
    int width;
    int height;

    DebugCheck(!icon);

    //
    //	Black border around icon with gray border if active.
    //
    color = (flags & IconActive) ? ColorGray : ColorBlack;

    width = icon->Width;
    height = icon->Height;
    VideoDrawRectangleClip(color, x, y, width + 7, height + 7);
    VideoDrawRectangleClip(ColorBlack, x + 1, y + 1, width + 5, height + 5);

    // _|	Shadow
    VideoDrawVLine(ColorGray, x + width + 4, y + 5, height - 1);
    VideoDrawVLine(ColorGray, x + width + 5, y + 5, height - 1);
    VideoDrawHLine(ColorGray, x + 5, y + height + 4, width + 1);
    VideoDrawHLine(ColorGray, x + 5, y + height + 5, width + 1);

    // |~	Light
    color = (flags & IconClicked) ? ColorGray : ColorWhite;
    VideoDrawHLine(color, x + 5, y + 3, width + 1);
    VideoDrawHLine(color, x + 5, y + 4, width + 1);
    VideoDrawVLine(color, x + 3, y + 3, height + 3);
    VideoDrawVLine(color, x + 4, y + 3, height + 3);

    if (flags & IconClicked) {
		  x += 5;
		  y += 5;
    } else {
		  x += 4;
		  y += 4;
    }

    DrawIcon(player, icon, x, y);

    if (flags & IconSelected) {
	     VideoDrawRectangleClip(ColorGreen, x, y, width, height);
    } else if (flags & IconAutoCast) {
	     VideoDrawRectangleClip(ColorBlue, x, y, width, height);
    }
}
...and the code from "editloop.cpp" in the stratagus code:

Code: Select all

static void DrawTileIcon(unsigned tilenum, unsigned x, unsigned y, unsigned flags)
{
	Uint32 color = (flags & IconActive) ? ColorGray : ColorBlack;

	Video.DrawRectangleClip(color, x, y, PixelTileSize.x + 7, PixelTileSize.y + 7);
	Video.DrawRectangleClip(ColorBlack, x + 1, y + 1, PixelTileSize.x + 5, PixelTileSize.y + 5);

	// Icon Shadow Edge
	Video.DrawVLine(ColorGray, x + PixelTileSize.x + 4, y + 5, PixelTileSize.y - 1); // _|
	Video.DrawVLine(ColorGray, x + PixelTileSize.x + 5, y + 5, PixelTileSize.y - 1);
	Video.DrawHLine(ColorGray, x + 5, y + PixelTileSize.y + 4, PixelTileSize.x + 1);
	Video.DrawHLine(ColorGray, x + 5, y + PixelTileSize.y + 5, PixelTileSize.x + 1);

	// Icon Light Edge
	color = (flags & IconClicked) ? ColorGray : ColorWhite;
	Video.DrawHLine(color, x + 5, y + 3, PixelTileSize.x + 1);
	Video.DrawHLine(color, x + 5, y + 4, PixelTileSize.x + 1);
	Video.DrawVLine(color, x + 3, y + 3, PixelTileSize.y + 3);
	Video.DrawVLine(color, x + 4, y + 3, PixelTileSize.y + 3);

	if (flags & IconClicked) 
	{
		 x += 5;
		 y += 5;		
	} else {
		 x += 4;
		 y += 4;
	}

	Map.TileGraphic->DrawFrameClip(Map.Tileset->tiles[tilenum].tile, x + 1, y + 1);

	if (flags & IconSelected) {
		 Video.DrawRectangleClip(ColorGreen, x, y, PixelTileSize.x + 1, PixelTileSize.y + 1);
	} else if (flags & IconAutoCast) {
		 Video.DrawRectangleClip(ColorBlue, x, y, PixelTileSize.x + 1, PixelTileSize.y + 1);
	}
}
Pretty much exactly the same code, but it's exclusive to editloop.cpp and not available to icons.cpp to use for all the other icons - of course we could just rename, adjust and add this variable to icons.h, and both editloop and icons.cpp could use it then.

Also I find that whenever you click a button, the action isn't passed until you release the mouse button, where as with the icons the action is passed as soon as you click it. Again, Warcraft 2 icons behaved like the buttons do, and didn't pass the action until mouse release on the icon, and if you had clicked the icon, but then release OFF the icon, the action wouldn't be passed, just like the buttons.

This could be an LUA switch as well so if people wanted to have the old school "press the icon, and the icon looks pressed then the action is passed", or the newer "press the icon, action passed straight away with no pressed look", it would keep everyone happy. And this could be used by anyone, for any game being made with the stratagus engine.

Just a few ideas for you :)
User avatar
DinkyDyeAussie
Posts: 260
Joined: Fri Feb 10, 2012 10:39 am
Location: Australia

Re: Icon Buttons

Post by DinkyDyeAussie »

Also what's the go with this code:

Code: Select all

void DrawUserDefinedButtons()
{
	for (size_t i = 0; i < UI.UserButtons.size(); ++i) {
		const CUIUserButton &button = UI.UserButtons[i];

		if (button.Button.X != -1) {
			DrawUIButton(button.Button.Style,
						 (ButtonAreaUnderCursor == ButtonAreaUser
						  && size_t(ButtonUnderCursor) == i ? MI_FLAGS_ACTIVE : 0) |
						 (button.Clicked ? MI_FLAGS_CLICKED : 0),
						 button.Button.X, button.Button.Y,
						 button.Button.Text);
		}
	}
}
It's just below this code:

Code: Select all

static void DrawMenuButtonArea_noNetwork()
{
	if (UI.MenuButton.X != -1) {
		DrawUIButton(UI.MenuButton.Style,
					 (ButtonAreaUnderCursor == ButtonAreaMenu
					  && ButtonUnderCursor == ButtonUnderMenu ? MI_FLAGS_ACTIVE : 0) |
					 (GameMenuButtonClicked ? MI_FLAGS_CLICKED : 0),
					 UI.MenuButton.X, UI.MenuButton.Y,
					 UI.MenuButton.Text);
	}
}
which defines the menu button. So technically speaking, we should be able to define any button we want to use right? If so, can we use it to define a clickable icon?
User avatar
jarod42
Posts: 101
Joined: Fri Jan 20, 2012 7:43 pm

Re: Icon Buttons

Post by jarod42 »

DinkyDyeAussie wrote:Where are Cyber and Jarod when you need them? This room service sucks! :P :P :P :P :P
I'm sorry, but I'm no longer active on stratagus...
User avatar
Andrettin
Posts: 433
Joined: Sun Jun 30, 2013 9:58 pm
Location: Vienna, Austria
Contact:

Re: Icon Buttons

Post by Andrettin »

jarod42 wrote: I'm sorry, but I'm no longer active on stratagus...
That's sad, but I'm very thankful for all the work you've put into the engine, merci!
User avatar
DinkyDyeAussie
Posts: 260
Joined: Fri Feb 10, 2012 10:39 am
Location: Australia

Re: Icon Buttons

Post by DinkyDyeAussie »

It's ok man, Will miss your contributions but you have helped alot with your knowledge of the engine too :) Are you still active in BOSWars?
User avatar
jarod42
Posts: 101
Joined: Fri Jan 20, 2012 7:43 pm

Re: Icon Buttons

Post by jarod42 »

DinkyDyeAussie wrote:It's ok man, Will miss your contributions but you have helped alot with your knowledge of the engine too :) Are you still active in BOSWars?
I'm no longer active on stratagus engine and games, sorry. (Anyway, I wasn't active on Bos, but on War*gus).
I'm now active on MaxR (a clone of Interplay Max).
User avatar
DinkyDyeAussie
Posts: 260
Joined: Fri Feb 10, 2012 10:39 am
Location: Australia

Re: Icon Buttons

Post by DinkyDyeAussie »

I had a look at MaxR yesterday. Looks alright :) Never played the original though.
Post Reply