memory plugin-newbie plugin dev. questions (1 Viewer)

newbie23

Portal Member
August 6, 2005
7
0
Hello everyone,

I'm a beginner programmer who is working on a small plugin for MediaPortal. The plugin allows you to play the game 'memory'. ( find a pair of matching cards.) I have worked through 'tutorial 1' and implemented the game logic. The list of cards are implemented with a thumbnailpanel. I have a small question concerning this plugin.

When a user selects his second card I want the image to be shown for a few seconds. Afterwards the cardimage should go back to a questionmark (when the user selected two different images) or disappear ( when the user selects two times the same image)

How can I implement this pause? At the moment I do the following:

I set the IconImageBig of the card to the correct image(image A), I let the thread sleep and then set the IconImageBig of the card back to the questionmark or to a blank image. This does not seem to work. The first
image A is never shown. Can I force the thumbnailpanel to update? (there is a DoUpdate()-procedure but that does not seem to do work).

Thanks in advance for any help
 

Smirnuff

Portal Pro
December 7, 2004
630
3
United Kingdom
Can I force the thumbnailpanel to update?

As you have discovered, DoUpdate calls the Update method whose default implementation does nothing.

What you can do it override either the Process or Render method of your GUIWindow class and have something like:


Code:
public override void Process()
{
	base.Process();

	if(_tickLastRevealed != 0 && Environment.TickCount - _tickLastDelta > _tickLastRevealed)
		_itemLastRevealed.IconImageBig = "foo.png";
}

in your OnAction override you'd need to have something like:

Code:
public override void OnAction(Action action)
{
	if(action.wID == Action.ActionType.ACTION_SELECT_ITEM)
	{
		_itemLastRevealed = _thumbnailPanel.SelectedListItem;
		_itemLastRevealed.IconImageBig = "foobar.png";
		_tickLastRevealed = Environment.TickCount;
	}

	...
	...
}

Set _tickLastDelta to the number of milliseconds you want the revealed image to appear for, for instance 2.5 seconds would be 2500.

*** edit ***

I've just realized that I've misread your post :(.
 

newbie23

Portal Member
August 6, 2005
7
0
GUI updating

Thank you for the responses to my question, but at the moment I have not yet succeeded in showing something for a few seconds and then showing something else. For example, the code that I use is similar to the code below. I set the label of a control to text A, I wait for 2.5 seconds and then update the label to text B. The result is that text A is never shown and that after 2.5 seconds, text B is immediately shown. So I expect that at the point marked by xxxxxxxxxx there must be some statement that forces the GUI to update itself. I tried things like DoUpdate(),Refresh(), Render(), GUIControl.RefreshControl,.. but none of them seems to actually do something (as explained in the first reply to my original question). What statement should be placed instead of the xxxxxxx's. Thanks in advance for any sugggestions? (without this the memory game is more or less useless, I have now solved it with an extra click from the user to explicitly change the images but this is rather annoying)


GUILabelControl Playerlabel=GetControl((int)Controls.CONTROL_PLAYERNAME) as GUILabelControl;

playerlabel.Label=”current player is player 1”;

xxxxxxxxxx

int start=Environment.TickCount;
int timepassed=0;

while(timepassed<2500){
timepassed=Environment.TickCount-start;
//System.Threading.Thread.Sleep(100);
}

playerlabel.Label=”current player is player 2”;
 

Smirnuff

Portal Pro
December 7, 2004
630
3
United Kingdom
Try GUIWindowManager.Process in place of the xxxxx, it may also be necessary to refresh the control manually via GUIControl.RefreshControl.

The purpose of this method is basically to yield time for other tasks in the current thread to be performed, such as rendering. It's advisable to try and avoid local wait loops such as the one in the previous example, during those 2.5 seconds if you don't yield then the UI will be unresponsive.

In the above code snippet you should also consider yielding during the while loop.

Let us know how you get on.
 

newbie23

Portal Member
August 6, 2005
7
0
Thanks Smirnoff, it was indeed GUIWindowManager.Process that was needed to update the images.
Most of the plugin work is finished, but many small details are still to do:
-adding setup screen (I have at the moment a small XML-document that is read to determine the number of players, their names and the images to use)
-adding sound
-testing
-computer opponent (don't know if this is funny, because its memory will be better than mine anyway)

A screenshot as requested:
Image1.jpg
 

Boris

Portal Pro
June 5, 2005
69
0
France
newbie23 said:
Can anyone test this beta?
Just to let me know if it works on other machines ?
Thanks in advance

Installation Instructions and downloads can be found at:

http://members.lycos.nl/mediaportal/

Work well here, in France :) Good job !
A one player version with the goal to do the less try could be cool...
And a 2 players, but against the computer...

In don't think that you need to put a back button. Right click with the mouse do it, the top bar do it, on remote you have a back key, etc...
 

Users who are viewing this thread

Top Bottom