NextPVR Forums
  • ______
  • Home
  • New Posts
  • Wiki
  • Members
  • Help
  • Search
  • Register
  • Login
  • Home
  • Wiki
  • Members
  • Help
  • Search
NextPVR Forums Public Developers v
« Previous 1 … 26 27 28 29 30 … 93 Next »
Newbie Dev Question

 
  • 0 Vote(s) - 0 Average
Newbie Dev Question
Sentient
Offline

Member

Posts: 51
Threads: 11
Joined: Jan 2007
#1
2009-01-01, 01:06 PM
I am having a little play with creating plugins and stumbled across something I can't figure out which I'm sure must be rather simple.

I wanted to create a simple board game - until I realised I don't know how to get the 'focus' from the buttons on the left-hand side onto the board. Is this even possible, and if so, any recommendations on functions to use/override or even some sample source that does something similar.

How does remote control input work with plugins? Can I 'see' the keys ('commands') pressed by the user or do I need to create multiple 'focusable' items?

Basically, I want to be able to move a highlight/selection box around the board.
sub
Offline

Administrator

NextPVR HQ, New Zealand
Posts: 106,708
Threads: 767
Joined: Nov 2003
#2
2009-01-01, 03:18 PM
It depends how you've created your plugin. Generally you need to manage the focus yourself, responding to keypresses to decide which item should next get the focus, then deactivating the old control and activating the new one.

So if you were implementing a plugin based on BaseButtonUiTask, you have to override the OnKeyDown() method to monitor keystrokes, and the GetRenderList() function to make sure your controls get drawn (calling base class GetRenderList() implementation first, and adding your controls render list to that).
bgowland
Offline

Posting Freak

West Yorkshire, UK
Posts: 4,583
Threads: 384
Joined: Dec 2004
#3
2009-01-01, 05:11 PM
Sentient Wrote:I wanted to create a simple board game - until I realised I don't know how to get the 'focus' from the buttons on the left-hand side onto the board.

In a simple scenario with two button controls - "Start Game" and "Main Menu" you could try something like this...

Create a bool with class scope...
Code:
public class MyGamePlugin : BaseButtonUiTask
{
    private bool BoardHasFocus = false;
    ...

Override the handleCommand() method to call a StartGame() method when the "Start Game" button is clicked (the default case lets pvrx2 handle the "Main Menu" button)...
Code:
protected override void handleCommand(string command)
{
    switch (command)
    {
        case "Start Game":
            StartGame();
            break;
        default:
            base.handleCommand(command);
            break;
    }
}
Create methods which do stuff including toggling BoardHasFocus...
Code:
private void StartGame()
{
    BoardHasFocus = true;
    ...
}

private void EndGame()
{
    BoardHasFocus = false;
    ...
}

Override OnKeyDown() so that if BoardHasFocus is true, pvrx2 never gets to see the key presses. If it's false, base.OnKeyDown() will effectively handle keys focused on the button controls.
Code:
public override bool OnKeyDown(KeyEventArgs e)
{
    bool Success = true;

    if (BoardHasFocus) // Handle all keys yourself
        if (e.Control) //Process Ctrl-key combinations
            switch (e.KeyCode)
            {
                case Keys.S: // Ctrl-S is the normal key used in plugins for "Stop" - it corresponds to the remote "Stop" button
                    EndGame();
                    break;
                default:
                    break;
            }
        else // Process non Ctrl keys as normal
            switch (e.KeyCode)
            {
                case Keys.Up:
                    // Do whatever
                    break;
                default:
                    break;
            }
    else // BoardHasFocus is false - let pvrx2 handle the key
        Success = base.OnKeyDown(e)
    return Success;
}

Hope that helps.

Cheers,
Brian
« Next Oldest | Next Newest »

Users browsing this thread: 1 Guest(s)



Possibly Related Threads…
Thread Author Replies Views Last Post
  Web API only_new Question Gazavant 6 2,685 2021-04-04, 06:54 PM
Last Post: sub
  Another Artwork question scJohn 15 8,169 2019-09-10, 05:33 PM
Last Post: nonob
  WEB API GuidService/Listing question(s) scJohn 6 4,294 2017-08-09, 02:18 PM
Last Post: scJohn
  skin question pBS 2 3,347 2016-06-18, 07:03 PM
Last Post: pBS
  Another SQL question bgowland 15 7,244 2014-05-21, 08:09 AM
Last Post: bgowland
  Absolute newbie trying to realize an idea - where to start? Oopsjoppe 13 5,606 2013-11-11, 05:33 PM
Last Post: Oopsjoppe
  Timing.Info question mvallevand 2 2,073 2013-04-19, 03:54 AM
Last Post: mvallevand
  N-PVR db3 EPG_EVENT time format question bgowland 3 2,099 2011-03-12, 05:26 AM
Last Post: bgowland
  Ping UncleJohnsBand (question about npvr soap) ioan 2 2,051 2011-02-18, 01:12 AM
Last Post: UncleJohnsBand
  Skin question - how to centre a list UiList control on screen? McBainUK 2 1,848 2011-02-17, 08:46 AM
Last Post: McBainUK

  • View a Printable Version
  • Subscribe to this thread
Forum Jump:

© Designed by D&D, modified by NextPVR - Powered by MyBB

Linear Mode
Threaded Mode