2010-01-25 14:01:22 +01:00
|
|
|
#include <SDL_image.h>
|
|
|
|
#include <SDL_ttf.h>
|
2010-02-06 17:10:09 +01:00
|
|
|
#if defined(GEKKO)
|
|
|
|
# include <network.h>
|
|
|
|
#else
|
|
|
|
# include <arpa/inet.h>
|
|
|
|
#endif
|
2010-01-25 14:01:22 +01:00
|
|
|
|
2010-01-29 07:35:40 +01:00
|
|
|
#include <utils.hh>
|
|
|
|
|
2010-01-25 14:01:22 +01:00
|
|
|
#include "menu.hh"
|
|
|
|
#include "gui.hh"
|
|
|
|
#include "menu_messages.hh"
|
|
|
|
#include "help_box.hh"
|
|
|
|
#include "dialogue_box.hh"
|
|
|
|
#include "sdl_ttf_font.hh"
|
|
|
|
#include "virtual_keyboard.hh"
|
|
|
|
|
2010-02-28 08:59:36 +01:00
|
|
|
#include "network_server_messages.hh"
|
|
|
|
|
2010-01-25 14:01:22 +01:00
|
|
|
extern SDL_Surface *screen;
|
|
|
|
|
2010-03-04 07:15:53 +01:00
|
|
|
#if defined(GEKKO)
|
|
|
|
#define THEME_ROOT_PATH "/frodo/themes"
|
|
|
|
#define METADATA_ROOT_PATH "/frodo/metadata"
|
|
|
|
#define GAME_ROOT_PATH "/frodo/images"
|
|
|
|
#define TMP_ROOT_PATH "/frodo/tmp"
|
|
|
|
#define SAVE_GAME_ROOT_PATH "/frodo/saves"
|
|
|
|
#else
|
2010-01-25 14:01:22 +01:00
|
|
|
#define THEME_ROOT_PATH "themes"
|
|
|
|
#define METADATA_ROOT_PATH "metadata"
|
2010-03-01 12:25:47 +01:00
|
|
|
#define GAME_ROOT_PATH "images"
|
2010-01-25 14:01:22 +01:00
|
|
|
#define TMP_ROOT_PATH "tmp"
|
|
|
|
#define SAVE_GAME_ROOT_PATH "saves"
|
2010-03-04 07:15:53 +01:00
|
|
|
#endif
|
2010-01-25 14:01:22 +01:00
|
|
|
|
|
|
|
static const char *get_theme_path(const char *dir, const char *what)
|
|
|
|
{
|
|
|
|
static char buf[255];
|
|
|
|
|
|
|
|
memset(buf, 0, sizeof(buf));
|
|
|
|
snprintf(buf, 254, "%s/%s/%s",
|
|
|
|
THEME_ROOT_PATH, dir, what);
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* These are a bit of special cases... */
|
2010-02-10 19:16:55 +01:00
|
|
|
#include "network_user_menu.cpp"
|
2010-01-25 14:01:22 +01:00
|
|
|
#include "disc_menu.cpp"
|
|
|
|
#include "save_game_menu.cpp"
|
|
|
|
#include "bind_keys_menu.cpp"
|
|
|
|
#include "theme_menu.cpp"
|
|
|
|
#include "options_menu.cpp"
|
2010-02-21 11:25:39 +01:00
|
|
|
#include "network_region_menu.cpp"
|
2010-01-25 14:01:22 +01:00
|
|
|
#include "network_menu.cpp"
|
|
|
|
#include "game_info_menu.cpp"
|
|
|
|
#include "main_menu.cpp"
|
|
|
|
|
|
|
|
GuiView::GuiView()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void GuiView::updateTheme()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void GuiView::viewPushCallback()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void GuiView::viewPopCallback()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Gui::Gui()
|
|
|
|
{
|
2010-01-30 09:37:57 +01:00
|
|
|
this->is_active = false;
|
2010-01-25 14:01:22 +01:00
|
|
|
this->np = NULL;
|
|
|
|
|
|
|
|
this->focus = NULL;
|
|
|
|
|
|
|
|
this->bg_left = NULL;
|
|
|
|
this->bg_middle = NULL;
|
|
|
|
this->bg_right = NULL;
|
|
|
|
this->bg_submenu_left = NULL;
|
|
|
|
this->bg_submenu_middle = NULL;
|
|
|
|
this->bg_submenu_right = NULL;
|
|
|
|
this->background = NULL;
|
|
|
|
this->main_menu_bg = NULL;
|
|
|
|
this->infobox = NULL;
|
2010-02-28 09:02:45 +01:00
|
|
|
this->network_message_box = NULL;
|
2010-01-25 14:01:22 +01:00
|
|
|
this->status_bar_bg = NULL;
|
2010-01-30 16:38:19 +01:00
|
|
|
this->keyboard = NULL;
|
2010-01-25 14:01:22 +01:00
|
|
|
this->default_font = NULL;
|
|
|
|
this->dialogue_bg = NULL;
|
2010-02-23 21:10:45 +01:00
|
|
|
this->network_info = NULL;
|
2010-02-28 09:25:59 +01:00
|
|
|
this->bind_key_box = NULL;
|
2010-01-25 14:01:22 +01:00
|
|
|
this->small_font = NULL;
|
|
|
|
|
|
|
|
this->n_views = 0;
|
|
|
|
this->views = NULL;
|
|
|
|
this->timerController = new TimerController();
|
|
|
|
|
|
|
|
VirtualKeyboard::kbd = new VirtualKeyboard(NULL);
|
|
|
|
|
|
|
|
this->theme_base_path = THEME_ROOT_PATH;
|
|
|
|
this->metadata_base_path = METADATA_ROOT_PATH;
|
|
|
|
this->game_base_path = GAME_ROOT_PATH;
|
|
|
|
this->tmp_path = TMP_ROOT_PATH;
|
|
|
|
this->save_game_path = SAVE_GAME_ROOT_PATH;
|
|
|
|
|
|
|
|
this->cur_gameInfo = new GameInfo();
|
|
|
|
this->gameInfoChanged = false;
|
|
|
|
|
|
|
|
this->dlg = NULL;
|
|
|
|
this->kbd = NULL;
|
|
|
|
|
|
|
|
this->mv = NULL;
|
|
|
|
this->dv = NULL;
|
|
|
|
this->sgv = NULL;
|
|
|
|
this->ov = NULL;
|
|
|
|
this->nv = NULL;
|
|
|
|
this->tv = NULL;
|
|
|
|
this->giv = NULL;
|
|
|
|
this->bkv = NULL;
|
2010-02-11 19:57:08 +01:00
|
|
|
this->nuv = NULL;
|
2010-02-21 11:25:39 +01:00
|
|
|
this->nrv = NULL;
|
2010-01-25 14:01:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Gui::~Gui()
|
|
|
|
{
|
|
|
|
delete this->mv;
|
|
|
|
delete this->dv;
|
|
|
|
delete this->sgv;
|
|
|
|
delete this->ov;
|
|
|
|
delete this->nv;
|
|
|
|
delete this->tv;
|
|
|
|
delete this->giv;
|
|
|
|
delete this->bkv;
|
2010-02-11 19:57:08 +01:00
|
|
|
delete this->nuv;
|
2010-02-21 11:25:39 +01:00
|
|
|
delete this->nrv;
|
2010-01-25 14:01:22 +01:00
|
|
|
|
|
|
|
delete this->cur_gameInfo;
|
|
|
|
delete this->timerController;
|
|
|
|
|
|
|
|
if (this->status_bar)
|
|
|
|
delete this->status_bar;
|
2010-02-28 08:59:36 +01:00
|
|
|
if (this->server_msgs)
|
|
|
|
delete this->server_msgs;
|
2010-01-25 14:01:22 +01:00
|
|
|
|
|
|
|
if (this->dlg)
|
|
|
|
delete this->dlg;
|
|
|
|
|
|
|
|
if (VirtualKeyboard::kbd)
|
|
|
|
delete VirtualKeyboard::kbd;
|
|
|
|
|
|
|
|
SDL_FreeSurface(this->bg_left);
|
2010-01-30 16:38:19 +01:00
|
|
|
SDL_FreeSurface(this->keyboard);
|
2010-01-25 14:01:22 +01:00
|
|
|
SDL_FreeSurface(this->bg_middle);
|
|
|
|
SDL_FreeSurface(this->bg_right);
|
|
|
|
SDL_FreeSurface(this->bg_submenu_left);
|
|
|
|
SDL_FreeSurface(this->bg_submenu_middle);
|
|
|
|
SDL_FreeSurface(this->bg_submenu_right);
|
|
|
|
SDL_FreeSurface(this->background);
|
|
|
|
SDL_FreeSurface(this->main_menu_bg);
|
2010-02-28 09:25:59 +01:00
|
|
|
SDL_FreeSurface(this->bind_key_box);
|
2010-01-25 14:01:22 +01:00
|
|
|
SDL_FreeSurface(this->infobox);
|
|
|
|
SDL_FreeSurface(this->dialogue_bg);
|
|
|
|
SDL_FreeSurface(this->disc_info);
|
2010-02-23 21:10:45 +01:00
|
|
|
SDL_FreeSurface(this->network_info);
|
2010-02-28 09:02:45 +01:00
|
|
|
SDL_FreeSurface(this->network_message_box);
|
2010-01-25 14:01:22 +01:00
|
|
|
SDL_FreeSurface(this->selected_key);
|
|
|
|
SDL_FreeSurface(this->highlighted_key);
|
|
|
|
SDL_FreeSurface(this->status_bar_bg);
|
|
|
|
|
|
|
|
if (this->default_font)
|
|
|
|
delete this->default_font;
|
|
|
|
if (this->small_font)
|
|
|
|
delete this->small_font;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Gui::setTheme(const char *path)
|
|
|
|
{
|
|
|
|
this->bg_left = this->loadThemeImage(path, "bg_left.png");
|
|
|
|
this->bg_middle = this->loadThemeImage(path, "bg_middle.png");
|
|
|
|
this->bg_right = this->loadThemeImage(path, "bg_right.png");
|
|
|
|
this->bg_submenu_left = this->loadThemeImage(path, "bg_submenu_left.png");
|
|
|
|
this->bg_submenu_middle = this->loadThemeImage(path, "bg_submenu_middle.png");
|
|
|
|
this->bg_submenu_right = this->loadThemeImage(path, "bg_submenu_right.png");
|
|
|
|
|
|
|
|
this->background = this->loadThemeImage(path, "background.png");
|
|
|
|
this->main_menu_bg = this->loadThemeImage(path, "main_menu_bg.png");
|
|
|
|
this->status_bar_bg = this->loadThemeImage(path, "status_bar.png");
|
|
|
|
this->infobox = this->loadThemeImage(path, "infobox.png");
|
2010-01-30 16:38:19 +01:00
|
|
|
this->keyboard = this->loadThemeImage(path, "keyboard.png");
|
2010-02-28 09:02:45 +01:00
|
|
|
this->network_message_box = this->loadThemeImage(path, "network_message_box.png");
|
2010-01-25 14:01:22 +01:00
|
|
|
this->dialogue_bg = this->loadThemeImage(path, "dialogue_box.png");
|
|
|
|
this->disc_info = this->loadThemeImage(path, "disc_info.png");
|
2010-02-23 21:10:45 +01:00
|
|
|
this->network_info = this->loadThemeImage(path, "network_info.png");
|
2010-02-28 09:25:59 +01:00
|
|
|
this->bind_key_box = this->loadThemeImage(path, "bind_key_box.png");
|
2010-01-25 14:01:22 +01:00
|
|
|
|
|
|
|
this->highlighted_key = this->loadThemeImage(path, "highlighted_key.png");
|
|
|
|
this->selected_key = this->loadThemeImage(path, "selected_key.png");
|
|
|
|
|
|
|
|
this->default_font = this->loadThemeFont(path, "font.ttf", 18);
|
|
|
|
this->small_font = this->loadThemeFont(path, "font.ttf", 16);
|
|
|
|
|
|
|
|
if (!this->bg_left || !this->bg_right || !this->bg_middle ||
|
|
|
|
!this->bg_submenu_left || !this->bg_submenu_right ||
|
|
|
|
!this->bg_submenu_middle ||
|
|
|
|
!this->dialogue_bg ||
|
|
|
|
!this->disc_info ||
|
|
|
|
!this->selected_key ||
|
|
|
|
!this->highlighted_key ||
|
|
|
|
!this->status_bar_bg ||
|
2010-02-28 09:25:59 +01:00
|
|
|
!this->bind_key_box ||
|
2010-02-23 21:10:45 +01:00
|
|
|
!this->network_info ||
|
2010-01-25 14:01:22 +01:00
|
|
|
!this->default_font ||
|
|
|
|
!this->small_font)
|
|
|
|
{
|
|
|
|
SDL_FreeSurface(this->bg_left);
|
|
|
|
SDL_FreeSurface(this->bg_middle);
|
|
|
|
SDL_FreeSurface(this->bg_right);
|
|
|
|
SDL_FreeSurface(this->bg_submenu_left);
|
|
|
|
SDL_FreeSurface(this->bg_submenu_middle);
|
|
|
|
SDL_FreeSurface(this->bg_submenu_right);
|
|
|
|
SDL_FreeSurface(this->background);
|
|
|
|
SDL_FreeSurface(this->main_menu_bg);
|
2010-02-23 21:10:45 +01:00
|
|
|
SDL_FreeSurface(this->network_info);
|
2010-01-25 14:01:22 +01:00
|
|
|
SDL_FreeSurface(this->infobox);
|
|
|
|
SDL_FreeSurface(this->dialogue_bg);
|
|
|
|
SDL_FreeSurface(this->disc_info);
|
2010-02-28 09:02:45 +01:00
|
|
|
SDL_FreeSurface(this->network_message_box);
|
2010-01-25 14:01:22 +01:00
|
|
|
SDL_FreeSurface(this->selected_key);
|
2010-01-30 16:38:19 +01:00
|
|
|
SDL_FreeSurface(this->keyboard);
|
2010-02-28 09:25:59 +01:00
|
|
|
SDL_FreeSurface(this->bind_key_box);
|
2010-01-25 14:01:22 +01:00
|
|
|
SDL_FreeSurface(this->highlighted_key);
|
|
|
|
SDL_FreeSurface(this->status_bar_bg);
|
|
|
|
|
|
|
|
if (this->default_font)
|
|
|
|
delete this->default_font;
|
|
|
|
if (this->small_font)
|
|
|
|
delete this->small_font;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create the views */
|
|
|
|
if (!this->mv)
|
|
|
|
{
|
|
|
|
this->status_bar = new StatusBar();
|
2010-02-28 08:59:36 +01:00
|
|
|
this->server_msgs = new NetworkServerMessages();
|
2010-01-25 14:01:22 +01:00
|
|
|
|
|
|
|
this->mv = new MainView();
|
|
|
|
this->dv = new DiscView();
|
|
|
|
this->sgv = new SaveGameView();
|
|
|
|
this->ov = new OptionsView();
|
|
|
|
this->nv = new NetworkView();
|
|
|
|
this->tv = new ThemeView();
|
|
|
|
this->bkv = new BindKeysView();
|
|
|
|
this->giv = new GameInfoView();
|
2010-02-11 19:57:08 +01:00
|
|
|
this->nuv = new NetworkUserView();
|
2010-02-21 11:25:39 +01:00
|
|
|
this->nrv = new NetworkRegionView();
|
2010-01-25 14:01:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
VirtualKeyboard::kbd->updateTheme();
|
|
|
|
|
2010-02-28 19:31:30 +01:00
|
|
|
/* FIXME! Remove! */
|
|
|
|
{
|
|
|
|
static bool viewed = false;
|
|
|
|
|
|
|
|
if (!viewed)
|
|
|
|
{
|
|
|
|
this->activate();
|
|
|
|
this->pushDialogueBox(new DialogueBox(needs_help));
|
|
|
|
viewed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-25 14:01:22 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Gui::runLogic(void)
|
|
|
|
{
|
|
|
|
GuiView *cur_view = this->peekView();
|
|
|
|
|
|
|
|
this->status_bar->runLogic();
|
|
|
|
this->timerController->tick();
|
2010-01-30 18:59:32 +01:00
|
|
|
if (this->kbd)
|
|
|
|
this->kbd->runLogic();
|
2010-01-25 14:01:22 +01:00
|
|
|
|
|
|
|
if (!this->is_active || !cur_view)
|
|
|
|
return;
|
2010-02-28 08:59:36 +01:00
|
|
|
Gui::gui->server_msgs->runLogic();
|
2010-01-25 14:01:22 +01:00
|
|
|
if (this->dlg)
|
|
|
|
this->dlg->runLogic();
|
|
|
|
else
|
|
|
|
cur_view->runLogic();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Gui::pushView(GuiView *view)
|
|
|
|
{
|
|
|
|
int cur = this->n_views;
|
|
|
|
|
|
|
|
this->n_views++;
|
|
|
|
this->views = (GuiView**)xrealloc(this->views,
|
|
|
|
sizeof(GuiView*) * this->n_views);
|
|
|
|
this->views[cur] = view;
|
|
|
|
view->viewPushCallback();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Gui::pushDialogueBox(DialogueBox *dlg)
|
|
|
|
{
|
|
|
|
this->dlg = dlg;
|
|
|
|
}
|
|
|
|
|
|
|
|
DialogueBox *Gui::popDialogueBox()
|
|
|
|
{
|
|
|
|
DialogueBox *out = this->dlg;
|
|
|
|
this->dlg = NULL;
|
|
|
|
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
GuiView *Gui::popView()
|
|
|
|
{
|
|
|
|
GuiView *cur = this->peekView();
|
|
|
|
|
|
|
|
if (!cur)
|
|
|
|
return NULL;
|
|
|
|
cur->viewPopCallback();
|
|
|
|
|
|
|
|
this->n_views--;
|
|
|
|
if (this->n_views <= 0)
|
|
|
|
{
|
|
|
|
free(this->views);
|
|
|
|
this->views = NULL;
|
|
|
|
this->n_views = 0;
|
|
|
|
/* Deactivate when no views are left */
|
|
|
|
this->is_active = false;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
this->views = (GuiView**)xrealloc(this->views,
|
|
|
|
sizeof(GuiView*) * this->n_views);
|
2010-02-21 11:25:39 +01:00
|
|
|
if (this->peekView())
|
|
|
|
this->peekView()->viewPushCallback();
|
|
|
|
|
2010-01-25 14:01:22 +01:00
|
|
|
return cur;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Gui::exitMenu()
|
|
|
|
{
|
|
|
|
/* Pop all views */
|
|
|
|
while (this->popView())
|
|
|
|
;
|
2010-01-25 16:11:26 +01:00
|
|
|
TheC64->NewPrefs(this->np);
|
2010-01-25 17:31:05 +01:00
|
|
|
ThePrefs = *this->np;
|
2010-01-30 12:48:57 +01:00
|
|
|
|
2010-02-24 21:19:37 +01:00
|
|
|
this->saveGameInfo(this->metadata_base_path, this->cur_gameInfo->filename);
|
2010-01-25 14:01:22 +01:00
|
|
|
}
|
|
|
|
|
2010-03-06 08:25:12 +01:00
|
|
|
|
|
|
|
void Gui::pushJoystickEvent(event_t ev)
|
2010-02-21 16:58:28 +01:00
|
|
|
{
|
2010-03-06 08:25:12 +01:00
|
|
|
static event_t last = EVENT_NONE;
|
2010-02-28 11:13:23 +01:00
|
|
|
static Uint32 last_ticks;
|
|
|
|
Uint32 cur_ticks;
|
|
|
|
|
2010-03-06 08:25:12 +01:00
|
|
|
if (last == ev)
|
|
|
|
return;
|
|
|
|
|
2010-02-28 11:13:23 +01:00
|
|
|
cur_ticks = SDL_GetTicks();
|
|
|
|
if (cur_ticks - last_ticks < 150)
|
|
|
|
return;
|
|
|
|
last_ticks = cur_ticks;
|
2010-02-21 16:58:28 +01:00
|
|
|
|
2010-03-06 08:25:12 +01:00
|
|
|
this->pushEvent(ev);
|
|
|
|
last = ev;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Gui::pushEvent(event_t ev)
|
|
|
|
{
|
|
|
|
GuiView *cur_view = this->peekView();
|
|
|
|
|
2010-02-23 21:45:29 +01:00
|
|
|
if (ev == KEY_ENTER_MENU)
|
|
|
|
{
|
|
|
|
this->activate();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-02-21 16:58:28 +01:00
|
|
|
if (!this->is_active || !cur_view)
|
|
|
|
{
|
|
|
|
if (this->kbd)
|
|
|
|
this->kbd->pushEvent(ev);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this->dlg)
|
|
|
|
this->dlg->pushEvent(ev);
|
|
|
|
else if (this->kbd)
|
|
|
|
this->kbd->pushEvent(ev);
|
|
|
|
else
|
|
|
|
cur_view->pushEvent(ev);
|
|
|
|
}
|
|
|
|
|
2010-01-25 14:01:22 +01:00
|
|
|
void Gui::pushEvent(SDL_Event *ev)
|
|
|
|
{
|
2010-02-28 18:33:42 +01:00
|
|
|
if (this->kbd)
|
|
|
|
{
|
|
|
|
this->kbd->pushEvent(ev);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-02-28 11:06:59 +01:00
|
|
|
switch(ev->type)
|
2010-01-30 18:59:32 +01:00
|
|
|
{
|
2010-02-28 11:06:59 +01:00
|
|
|
case SDL_KEYDOWN:
|
|
|
|
switch (ev->key.keysym.sym)
|
|
|
|
{
|
|
|
|
case SDLK_UP:
|
|
|
|
this->pushEvent(KEY_UP);
|
|
|
|
break;
|
|
|
|
case SDLK_DOWN:
|
|
|
|
this->pushEvent(KEY_DOWN);
|
|
|
|
break;
|
|
|
|
case SDLK_LEFT:
|
|
|
|
this->pushEvent(KEY_LEFT);
|
|
|
|
break;
|
|
|
|
case SDLK_RIGHT:
|
|
|
|
this->pushEvent(KEY_RIGHT);
|
|
|
|
break;
|
|
|
|
case SDLK_PAGEDOWN:
|
|
|
|
this->pushEvent(KEY_PAGEDOWN);
|
|
|
|
break;
|
|
|
|
case SDLK_PAGEUP:
|
|
|
|
this->pushEvent(KEY_PAGEUP);
|
|
|
|
break;
|
|
|
|
case SDLK_RETURN:
|
|
|
|
case SDLK_SPACE:
|
|
|
|
this->pushEvent(KEY_SELECT);
|
|
|
|
break;
|
|
|
|
case SDLK_HOME:
|
|
|
|
case SDLK_ESCAPE:
|
|
|
|
this->pushEvent(KEY_ESCAPE);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
2010-03-01 12:36:46 +01:00
|
|
|
case SDL_QUIT:
|
|
|
|
TheC64->TheDisplay->quit_requested = true;
|
|
|
|
break;
|
2010-01-30 18:59:32 +01:00
|
|
|
}
|
2010-01-25 14:01:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Gui::draw(SDL_Surface *where)
|
|
|
|
{
|
|
|
|
GuiView *cur_view = this->peekView();
|
|
|
|
|
|
|
|
if (!this->is_active || !cur_view)
|
|
|
|
{
|
|
|
|
this->status_bar->draw(where);
|
2010-01-30 18:59:32 +01:00
|
|
|
if (this->kbd)
|
|
|
|
this->kbd->draw(where);
|
2010-01-25 14:01:22 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SDL_BlitSurface(this->background, NULL, where, NULL);
|
|
|
|
cur_view->draw(where);
|
|
|
|
if (this->kbd)
|
|
|
|
this->kbd->draw(where);
|
|
|
|
if (this->dlg)
|
|
|
|
this->dlg->draw(where);
|
|
|
|
this->status_bar->draw(where);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Gui::activate()
|
|
|
|
{
|
|
|
|
this->is_active = true;
|
2010-01-25 15:25:19 +01:00
|
|
|
|
|
|
|
this->cur_prefs = ThePrefs;
|
|
|
|
this->np = &cur_prefs;
|
|
|
|
|
2010-01-25 14:28:03 +01:00
|
|
|
this->pushView(this->mv);
|
2010-01-25 14:01:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
SDL_Surface *Gui::loadThemeImage(const char *dir, const char *what)
|
|
|
|
{
|
2010-01-25 14:49:48 +01:00
|
|
|
SDL_Surface *img = IMG_Load(get_theme_path(dir, what));
|
|
|
|
SDL_Surface *out;
|
|
|
|
|
|
|
|
if (!img)
|
|
|
|
return NULL;
|
|
|
|
out = SDL_DisplayFormatAlpha(img);
|
|
|
|
SDL_FreeSurface(img);
|
|
|
|
|
|
|
|
return out;
|
2010-01-25 14:01:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Font *Gui::loadThemeFont(const char *dir, const char *what, int size)
|
|
|
|
{
|
|
|
|
TTF_Font *fnt;
|
|
|
|
|
|
|
|
fnt = read_and_alloc_font(get_theme_path(dir, what), size);
|
|
|
|
if (!fnt)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return new Font_TTF(fnt, 255,255,255);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Gui::updateGameInfo(GameInfo *gi)
|
|
|
|
{
|
2010-02-27 09:08:26 +01:00
|
|
|
/* Ignore if empty */
|
|
|
|
if(!gi)
|
|
|
|
return;
|
2010-01-30 09:35:29 +01:00
|
|
|
|
|
|
|
/* Store the current game info */
|
2010-02-24 21:19:37 +01:00
|
|
|
this->saveGameInfo(this->metadata_base_path, this->cur_gameInfo->filename);
|
2010-01-25 14:01:22 +01:00
|
|
|
delete this->cur_gameInfo;
|
2010-01-30 09:35:29 +01:00
|
|
|
|
2010-01-25 14:01:22 +01:00
|
|
|
this->cur_gameInfo = gi;
|
|
|
|
this->gameInfoChanged = true;
|
|
|
|
}
|
|
|
|
|
2010-02-24 21:19:37 +01:00
|
|
|
void Gui::saveGameInfo(const char *base_path, const char *name)
|
2010-01-25 14:01:22 +01:00
|
|
|
{
|
2010-01-30 15:47:22 +01:00
|
|
|
/* Don't save unset games */
|
|
|
|
if (strcmp(this->cur_gameInfo->filename, "unknown") == 0)
|
|
|
|
return;
|
|
|
|
|
2010-01-25 14:01:22 +01:00
|
|
|
struct game_info *p = this->cur_gameInfo->dump();
|
|
|
|
|
|
|
|
if (p)
|
|
|
|
{
|
2010-01-30 14:03:53 +01:00
|
|
|
size_t sz = ntohl(p->sz);
|
|
|
|
|
2010-02-24 21:19:37 +01:00
|
|
|
char *new_name = (char *)xmalloc(strlen(base_path) +
|
|
|
|
8 + strlen(name));
|
2010-01-25 14:01:22 +01:00
|
|
|
FILE *fp;
|
|
|
|
|
2010-02-24 21:19:37 +01:00
|
|
|
sprintf(new_name, "%s/%s.lra", base_path,
|
|
|
|
name);
|
2010-01-30 09:35:29 +01:00
|
|
|
fp = fopen(new_name, "w");
|
|
|
|
if (fp)
|
2010-01-25 14:01:22 +01:00
|
|
|
{
|
2010-01-30 14:03:53 +01:00
|
|
|
int n = fwrite((const void*)p, 1, sz, fp);
|
2010-01-30 09:35:29 +01:00
|
|
|
|
|
|
|
if (ferror(fp))
|
|
|
|
warning("Write error on %s\n", new_name);
|
2010-01-30 14:03:53 +01:00
|
|
|
else if ((size_t)n != sz)
|
|
|
|
warning("Could only write %d bytes of %d for %s\n",
|
|
|
|
n, sz, new_name);
|
2010-01-30 09:35:29 +01:00
|
|
|
fclose(fp);
|
2010-01-25 14:01:22 +01:00
|
|
|
}
|
2010-01-30 09:35:29 +01:00
|
|
|
else
|
|
|
|
warning("Could not open %s for writing\n", new_name);
|
|
|
|
|
|
|
|
free(new_name);
|
2010-01-25 14:01:22 +01:00
|
|
|
}
|
2010-01-30 14:03:53 +01:00
|
|
|
free(p);
|
2010-01-25 14:01:22 +01:00
|
|
|
|
|
|
|
this->gameInfoChanged = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* The singleton/factory stuff */
|
|
|
|
Gui *Gui::gui;
|
|
|
|
void Gui::init()
|
|
|
|
{
|
|
|
|
Gui::gui = new Gui();
|
|
|
|
|
|
|
|
/* Set the default theme */
|
|
|
|
panic_if(!Gui::gui->setTheme("default"),
|
|
|
|
"Setting default theme failed\n");
|
|
|
|
}
|