mirror of
https://github.com/scummvm/scummvm.git
synced 2026-06-20 05:45:29 +00:00
136 lines
3.9 KiB
C++
136 lines
3.9 KiB
C++
/* ScummVM - Graphic Adventure Engine
|
|
*
|
|
* ScummVM is the legal property of its developers, whose names
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
* file distributed with this source distribution.
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*
|
|
*/
|
|
|
|
/*
|
|
* This code is based on the CRAB engine
|
|
*
|
|
* Copyright (c) Arvind Raja Yadav
|
|
*
|
|
* Licensed under MIT
|
|
*
|
|
*/
|
|
|
|
#include "crab/ui/ModMenu.h"
|
|
|
|
namespace Crab {
|
|
|
|
using namespace pyrodactyl::ui;
|
|
|
|
void ModMenu::load(const Common::String &filename) {
|
|
XMLDoc conf(filename);
|
|
if (conf.ready()) {
|
|
rapidxml::xml_node<char> *node = conf.doc()->first_node("mod_menu");
|
|
|
|
if (nodeValid("bg", node))
|
|
bg.load(node->first_node("bg"));
|
|
|
|
if (nodeValid("menu", node))
|
|
menu.load(node->first_node("menu"));
|
|
|
|
if (nodeValid("preview", node)) {
|
|
auto prnode = node->first_node("preview");
|
|
img.pos.load(prnode);
|
|
loadStr(img.no_preview_path, "path", prnode);
|
|
}
|
|
|
|
if (nodeValid("offset", node)) {
|
|
rapidxml::xml_node<char> *offnode = node->first_node("offset");
|
|
|
|
// Stuff displayed on the slot button
|
|
td_b[DATA_SAVENAME].load(offnode->first_node("mod_name"));
|
|
td_b[DATA_LASTMODIFIED].load(offnode->first_node("last_modified"));
|
|
|
|
// Stuff displayed when you hover over a slot button
|
|
td_h[DATA_AUTHOR].load(offnode->first_node("author"));
|
|
td_h[DATA_VERSION].load(offnode->first_node("version"));
|
|
td_h[DATA_INFO].load(offnode->first_node("info"));
|
|
td_h[DATA_WEBSITE].load(offnode->first_node("website"));
|
|
|
|
// Titles for the stuff displayed when you hover over a slot button
|
|
hov[DATA_AUTHOR].load(offnode->first_node("author_title"));
|
|
hov[DATA_VERSION].load(offnode->first_node("info_title"));
|
|
hov[DATA_INFO].load(offnode->first_node("version_title"));
|
|
hov[DATA_WEBSITE].load(offnode->first_node("website_title"));
|
|
}
|
|
|
|
extension = g_engine->_filePath->mod_ext;
|
|
directory = g_engine->_filePath->mod_path;
|
|
ScanDir();
|
|
}
|
|
}
|
|
|
|
bool ModMenu::handleEvents(const Common::Event &Event) {
|
|
int choice = menu.handleEvents(Event);
|
|
if (choice >= 0) {
|
|
g_engine->_filePath->mod_cur = slot_info[menu.Index() + choice].path;
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
#if 0
|
|
bool ModMenu::handleEvents(const SDL_Event &Event) {
|
|
int choice = menu.handleEvents(Event);
|
|
if (choice >= 0) {
|
|
g_engine->_filePath->mod_cur = slot_info[menu.Index() + choice].path;
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
#endif
|
|
|
|
void ModMenu::draw() {
|
|
bg.draw();
|
|
menu.draw();
|
|
for (auto i = menu.Index(), count = 0u; i < menu.IndexPlusOne() && i < slot_info.size(); i++, count++) {
|
|
auto base_x = menu.BaseX(count), base_y = menu.BaseY(count);
|
|
td_b[DATA_SAVENAME].draw(slot_info[i].name, base_x, base_y);
|
|
td_b[DATA_LASTMODIFIED].draw(slot_info[i].last_modified, base_x, base_y);
|
|
}
|
|
|
|
if (menu.HoverIndex() >= 0) {
|
|
int i = menu.HoverIndex();
|
|
|
|
if (!img.loaded || prev_hover != i) {
|
|
img.loaded = true;
|
|
prev_hover = i;
|
|
if (!img.preview.load(slot_info[i].preview))
|
|
img.preview.load(img.no_preview_path);
|
|
}
|
|
|
|
hover = true;
|
|
img.preview.draw(img.pos.x, img.pos.y);
|
|
|
|
td_h[DATA_AUTHOR].draw(slot_info[i].author);
|
|
td_h[DATA_VERSION].draw(slot_info[i].version);
|
|
td_h[DATA_INFO].draw(slot_info[i].info);
|
|
td_h[DATA_WEBSITE].draw(slot_info[i].website);
|
|
|
|
for (int num = 0; num < DATA_HOVER_TOTAL; ++num)
|
|
hov[num].draw();
|
|
} else if (hover)
|
|
reset();
|
|
}
|
|
|
|
} // End of namespace Crab
|