1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
|
#include <plugin.h>
#include <osd.h>
extern int launcher_menu(char ***m);
extern int launcher_start(int g, int x, int y, int s, int c);
extern int launcher_stop(void);
extern int launcher_key(int key);
class GameMenu;
class GameStart;
class GameSetup;
class GamePlugin;
static const char *DESCRIPTION = "OSD Games Collection";
static const char *MAINMENUENTRY = "Games";
static int x = -8; // x position
static int y = -8; // y position
static int s = 2; // osd size
static int c = 2; // computer skill
static int g = -1; // selected game
static bool m = true; // open menu
static bool r = false; // repeat keys
class GameMenu : public cOsdMenu {
public:
GameMenu(void);
eOSState ProcessKey(eKeys k);
};
class GameStart : public cOsdObject {
public:
~GameStart(void);
void Show(void);
eOSState ProcessKey(eKeys k);
};
class GameSetup : public cMenuSetupPage {
public:
GameSetup(void);
protected:
void Store(void);
private:
int new_x, new_y, new_s, new_r, new_c;
};
class GamePlugin : public cPlugin {
public:
bool SetupParse(const char *Name, const char *Value);
const char *Version(void) { return VERSION; }
const char *Description(void) { return DESCRIPTION; }
const char *MainMenuEntry(void) { return MAINMENUENTRY; }
cMenuSetupPage *SetupMenu(void) { return new GameSetup; }
cOsdObject *MainMenuAction(void);
};
GameMenu::GameMenu(void) : cOsdMenu("Games") {
char **menu;
int games;
SetHasHotkeys();
games = launcher_menu(&menu);
for (int i=0; i<games; i++) {
Add(new cOsdItem(hk(menu[i])));
}
Display();
m = true;
}
eOSState
GameMenu::ProcessKey(eKeys k) {
eOSState state = cOsdMenu::ProcessKey(k);
switch (state) {
case osUnknown:
switch (k) {
case kRight:
case kOk:
m = false;
g = Current();
CloseSubMenu();
// calls MainMenuAction() implicitly
return (osPlugin);
break;
default: break;
}
break;
case osBack:
// close menu
return (osBack);
case osEnd:
// close menu
return (osEnd);
break;
default: break;
}
return (state);
}
void
GameStart::Show(void) {
launcher_start(g, x, y, s, c);
m = true;
}
GameStart::~GameStart(void) {
launcher_stop();
g = -1;
}
eOSState
GameStart::ProcessKey(eKeys k) {
int key = (int)k;
if (r) key &= 0x7fff;
if (launcher_key(key)) return (osEnd);
return (osContinue);
}
GameSetup::GameSetup(void) {
new_s = s; Add(new cMenuEditIntItem( "OSD Size", &new_s, 1, 3));
new_x = x; Add(new cMenuEditIntItem( "X Position", &new_x, -9, 9));
new_y = y; Add(new cMenuEditIntItem( "Y Position", &new_y, -9, 9));
new_c = c; Add(new cMenuEditIntItem("Computer Skill", &new_c, 1, 3));
new_r = r; Add(new cMenuEditBoolItem( "Key Repeat", &new_r, "Off", "On"));
}
void
GameSetup::Store(void) {
SetupStore("OsdSize", s = new_s);
SetupStore("XPosition", x = new_x);
SetupStore("YPosition", y = new_y);
SetupStore("Skill", c = new_c);
SetupStore("KeyRepeat", r = new_r);
}
cOsdObject *
GamePlugin::MainMenuAction(void) {
if (m) return new GameMenu;
return new GameStart;
}
bool
GamePlugin::SetupParse(const char *Name, const char *Value) {
if (!strcasecmp(Name, "OsdSize")) s = atoi(Value);
else if (!strcasecmp(Name, "XPosition")) x = atoi(Value);
else if (!strcasecmp(Name, "YPosition")) y = atoi(Value);
else if (!strcasecmp(Name, "Skill")) c = atoi(Value);
else if (!strcasecmp(Name, "KeyRepeat")) r = strcasecmp(Value, "Off");
else return (false);
return (true);
}
VDRPLUGINCREATOR(GamePlugin);
|