Initial commit

This commit is contained in:
2026-02-02 04:50:13 +01:00
commit 5b11698731
22592 changed files with 7677434 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,115 @@
/* 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/>.
*
*/
#ifndef M4_BURGER_GUI_GAME_MENU_H
#define M4_BURGER_GUI_GAME_MENU_H
#include "graphics/surface.h"
#include "m4/m4_types.h"
#include "m4/graphics/gr_buff.h"
#include "m4/gui/gui_menu_items.h"
#include "m4/gui/game_menu.h"
#include "m4/gui/gui_univ.h"
namespace M4 {
namespace Burger {
namespace GUI {
using M4::GUI::guiMenu;
using M4::GUI::menuItemButton;
using M4::GUI::menuItemMsg;
using M4::GUI::menuItemHSlider;
using M4::GUI::menuItemVSlider;
using M4::GUI::menuItemTextField;
using M4::GUI::Sprite;
using M4::GUI::CALLBACK;
using M4::GUI::ItemHandlerFunction;
class GameMenu {
private:
static void destroyMenu();
static void cb_Game_Quit(void *, void *);
static void cb_Game_Resume(void *, void *);
static void cb_Game_Save(void *, void *);
static void cb_Game_Load(void *, void *);
static void cb_Game_Main(void *, void *);
static void cb_Game_Options(void *, void *);
public:
static void show(RGB8 *myPalette);
};
class OptionsMenu {
private:
static void destroyMenu();
static void cb_Options_Game_Cancel(void *, void *);
static void cb_Options_Game_Done(void *, void *);
static void cb_Options_Digi(menuItemHSlider *myItem, guiMenu *myMenu);
static void cb_Options_Digestability(menuItemHSlider *myItem, guiMenu *myMenu);
static void setDigiVolume(uint16 volume);
static void setDigiVolumePerc(uint8 volumePerc);
static uint16 getDigiVolume();
static uint8 getDigiVolumePerc();
public:
static void show(RGB8 *myPalette);
};
class SaveLoadMenu : public M4::GUI::SaveLoadMenuBase {
private:
static void destroyMenu(bool saveMenu);
static bool load_Handler(menuItemButton *theItem, int32 eventType, int32 event, int32 x, int32 y, void **currItem);
static void cb_SaveLoad_Save(void *, guiMenu *myMenu);
static void cb_SaveLoad_Load(menuItemButton *, guiMenu *);
static void cb_SaveLoad_Cancel(menuItemButton *, guiMenu *myMenu);
static void cb_SaveLoad_Slot(menuItemButton *myButton, guiMenu *myMenu);
static void cb_SaveLoad_VSlider(menuItemVSlider *myItem, guiMenu *myMenu);
public:
static void show(RGB8 *myPalette, bool saveMenu);
};
class ErrorMenu {
private:
static void destroyMenu();
static void cb_Err_Done(void *, void *);
public:
static void show(RGB8 *myPalette);
};
// GAME MENU FUNCTIONS
extern void CreateGameMenu(RGB8 *myPalette);
extern void CreateF2SaveMenu(RGB8 *myPalette);
extern void CreateLoadMenu(RGB8 *myPalette);
extern void CreateF3LoadMenu(RGB8 *myPalette);
// Routines used by the main menu
void CreateLoadMenuFromMain(RGB8 *myPalette);
void CreateGameMenuFromMain(RGB8 *myPalette);
} // namespace GUI
} // namespace Burger
} // namespace M4
#endif

View File

@@ -0,0 +1,42 @@
/* 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/>.
*
*/
#ifndef M4_BURGER_GUI_H
#define M4_BURGER_GUI_H
#include "m4/burger/gui/game_menu.h"
#include "m4/burger/gui/interface.h"
namespace M4 {
namespace Burger {
namespace GUI {
struct GUI_Globals {
bool saveLoadFromHotkey = false;
bool gameMenuFromMain = false;
};
} // namespace GUI
} // namespace Burger
} // namespace M4
#endif

View File

@@ -0,0 +1,918 @@
/* 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/>.
*
*/
#include "m4/burger/gui/gui_gizmo.h"
#include "m4/burger/vars.h"
#include "m4/core/errors.h"
#include "m4/core/imath.h"
#include "m4/adv_r/adv_background.h"
#include "m4/adv_r/adv_control.h"
#include "m4/graphics/gr_sprite.h"
#include "m4/gui/gui_event.h"
#include "m4/gui/gui_sys.h"
#include "m4/gui/gui_vmng.h"
#include "m4/mem/mem.h"
#include "m4/platform/keys.h"
#include "m4/m4.h"
#include "m4/platform/timer.h"
namespace M4 {
namespace Burger {
namespace GUI {
static void gizmo_dispose_gui();
static void gizmo_restore_interface(bool fade);
static void gizmo_free_gui(Gizmo *gizmo);
static bool gizmo_load_sprites(const char *name, size_t count);
static void gizmo_free_sprites();
static void gizmo_draw_sprite(M4sprite *sprite, Buffer *dest, int destX, int destY);
static Gizmo *gui_create_gizmo(M4sprite *sprite, int sx, int sy, uint scrnFlags);
static void gizmo_digi_daemon(int trigger);
static void gizmo_daemon(int trigger);
Gizmo_Globals::Gizmo_Globals() {
Common::fill(_roomFlags, _roomFlags + 15, false);
}
Gizmo_Globals::~Gizmo_Globals() {
mem_free(_gui);
}
static void gizmo_sound() {
digi_read_another_chunk();
midi_loop();
g_system->updateScreen();
g_system->delayMillis(10);
g_events->process();
gui_system_event_handler();
}
void gizmo_digi_play(const char *name, int vol, bool &done) {
if (!done) {
done = true;
digi_play(name, 2, vol);
digi_read_another_chunk();
player_set_commands_allowed(false);
while (!g_engine->shouldQuit() && digi_play_state(2))
gizmo_sound();
player_set_commands_allowed(true);
}
}
void gizmo_initialize(RGB8 *pal) {
if (!_GIZMO(initialized)) {
_GIZMO(initialized) = true;
// Remember whether interface was visible when gizmo was initialized
if (INTERFACE_VISIBLE) {
_GIZMO(interface_visible) = true;
interface_hide();
} else {
_GIZMO(interface_visible) = false;
}
_GIZMO(palette) = pal;
krn_fade_to_grey(pal, 5, 1);
}
}
void gizmo_shutdown(void *, void *) {
gizmo_dispose_gui();
gizmo_restore_interface(true);
}
static void gizmo_digi_daemon(int trigger) {
switch (trigger) {
case 5000:
if (player_been_here(503)) {
if (_G(flags)[kBORK_STATE] == 16)
gizmo_digi_play("510w005", 255, _GIZMO(roomFlags)[3]);
else
gizmo_digi_play("510w004", 255, _GIZMO(roomFlags)[2]);
}
break;
case 5001:
if (player_been_here(507)) {
if (_G(flags)[V223] == 2)
gizmo_digi_play("510w008", 255, _GIZMO(roomFlags)[5]);
else
gizmo_digi_play("510w007", 255, _GIZMO(roomFlags)[4]);
}
break;
case 5002:
if (player_been_here(504)) {
if (_G(flags)[V210] == 5002)
gizmo_digi_play("510w011", 255, _GIZMO(roomFlags)[7]);
else
gizmo_digi_play("510w010", 255, _GIZMO(roomFlags)[6]);
}
break;
case 5003:
if (player_been_here(508)) {
if (_G(flags)[V227] != 0)
gizmo_digi_play("510w014", 255, _GIZMO(roomFlags)[9]);
else
gizmo_digi_play("510w013", 255, _GIZMO(roomFlags)[8]);
}
break;
case 5004:
if (player_been_here(506)) {
if (_G(flags)[V218] == 5003)
gizmo_digi_play("510w017", 255, _GIZMO(roomFlags)[11]);
else
gizmo_digi_play("510w016", 255, _GIZMO(roomFlags)[10]);
}
break;
case 5005:
if (_G(flags)[kStairsBorkState] == 5003)
gizmo_digi_play("510w019", 255, _GIZMO(roomFlags)[13]);
else
gizmo_digi_play("510w018", 255, _GIZMO(roomFlags)[12]);
break;
case 5006:
gizmo_digi_play("510w020", 255, _GIZMO(roomFlags)[14]);
break;
default:
break;
}
}
static void gizmo_restore_sprite(int spriteIndex) {
if (!_GIZMO(gui))
return;
Buffer *dest = _GIZMO(gui)->_grBuff->get_buffer();
if (!dest)
return;
if (spriteIndex >= 22)
gizmo_draw_sprite(_GIZMO(sprites)[spriteIndex], dest, 270, 38);
int32 status = 0;
ScreenContext *ctx = vmng_screen_find(_GIZMO(gui), &status);
if (ctx && status == 1)
RestoreScreens(270, 38, 381, 93);
}
static void gizmo_digi_wait(int spriteIndex1, int spriteIndex2) {
player_set_commands_allowed(false);
digi_read_another_chunk();
int spriteNum = spriteIndex1;
while (digi_play_state(2)) {
// Cycle displayed sprite
gizmo_restore_sprite(spriteNum);
spriteNum = (spriteNum == spriteIndex2) ? spriteIndex1 : spriteNum + 1;
uint32 timer = timer_read_60();
while (!g_engine->shouldQuit() && (timer_read_60() - timer) < 6)
gizmo_sound();
}
gizmo_restore_sprite(57);
player_set_commands_allowed(true);
}
static void gizmo_daemon(int trigger) {
switch (trigger) {
case 5000:
switch (imath_ranged_rand(1, 3)) {
case 1:
digi_play("510b001a", 2, 255, -1);
break;
case 2:
digi_play("510b001b", 2, 255, -1);
break;
default:
digi_play("510b001c", 2, 255, -1);
break;
}
gizmo_digi_wait(32, 36);
break;
case 5001:
switch (imath_ranged_rand(1, 3)) {
case 1:
digi_play("510b002a", 2, 255, -1);
break;
case 2:
digi_play("510b002b", 2, 255, -1);
break;
default:
digi_play("510b002c", 2, 255, -1);
break;
}
gizmo_digi_wait(27, 31);
break;
case 5002:
switch (imath_ranged_rand(1, 3)) {
case 1:
digi_play("510b003a", 2, 255, -1);
break;
case 2:
digi_play("510b003b", 2, 255, -1);
break;
default:
digi_play("510b003c", 2, 255, -1);
break;
}
gizmo_digi_wait(32, 36);
break;
case 5003:
switch (imath_ranged_rand(1, 2)) {
case 1:
digi_play("510b004a", 2, 255, -1);
break;
case 2:
digi_play("510b004b", 2, 255, -1);
break;
default:
break;
}
gizmo_digi_wait(37, 41);
break;
case 5004:
switch (imath_ranged_rand(1, 3)) {
case 1:
digi_play("510b005a", 2, 255, -1);
break;
case 2:
digi_play("510b005b", 2, 255, -1);
break;
default:
digi_play("510b005c", 2, 255, -1);
break;
}
gizmo_digi_wait(42, 46);
break;
case 5005:
switch (imath_ranged_rand(1, 3)) {
case 1:
digi_play("510b006a", 2, 255, -1);
break;
case 2:
digi_play("510b006b", 2, 255, -1);
break;
default:
digi_play("510b006c", 2, 255, -1);
break;
}
gizmo_digi_wait(47, 51);
break;
case 5006:
switch (imath_ranged_rand(1, 3)) {
case 1:
digi_play("510b007a", 2, 255, -1);
break;
case 2:
digi_play("510b007b", 2, 255, -1);
break;
default:
digi_play("510b007c", 2, 255, -1);
break;
}
gizmo_digi_wait(52, 56);
break;
default:
break;
}
gizmo_digi_daemon(trigger);
}
static void gizmo_restore_interface(bool fade) {
if (_GIZMO(initialized)) {
_GIZMO(currentItem) = nullptr;
if (_GIZMO(lowMemory2)) {
if (!adv_restoreBackground())
error_show(FL, 0, "unable to restore background");
}
if (_GIZMO(lowMemory1)) {
if (!adv_restoreCodes())
error_show(FL, 0, "unable to restore screen codes");
}
krn_fade_from_grey(_GIZMO(palette), 5, 1, fade ? 1 : 2);
if (_GIZMO(interface_visible))
interface_show();
mouse_unlock_sprite();
game_pause(false);
_GIZMO(initialized) = false;
}
}
static void gizmo_dispose_gui() {
if (_GIZMO(gui)) {
vmng_screen_dispose(_GIZMO(gui));
gizmo_free_gui(_GIZMO(gui));
gizmo_free_sprites();
_GIZMO(gui) = nullptr;
}
}
static void gizmo_free_gui(Gizmo *gizmo) {
if (!gizmo)
return;
for (GizmoItem *item = gizmo->_items; item; item = gizmo->_items) {
gizmo->_items = item->_next;
(*item->_fnFree)(item);
}
GrBuff *grBuff = gizmo->_grBuff;
if (grBuff)
delete grBuff;
mem_free(gizmo);
}
static bool gizmo_load_sprites(const char *name, size_t count) {
if (LoadSpriteSeries(name, &_GIZMO(seriesHandle), &_GIZMO(celsOffset),
&_GIZMO(palOffset), _GIZMO(palette)) > 0) {
gr_pal_set_range(_GIZMO(palette), 64, 192);
_GIZMO(assetName) = mem_strdup(name);
_GIZMO(spriteCount) = count;
_GIZMO(sprites) = (M4sprite **)mem_alloc(count * sizeof(M4sprite *), "*sprites array");
for (size_t idx = 0; idx < count; ++idx) {
_GIZMO(sprites)[idx] = CreateSprite(_GIZMO(seriesHandle), _GIZMO(celsOffset),
idx, nullptr, nullptr);
}
return true;
}
return false;
}
static void gizmo_free_sprites() {
if (_GIZMO(assetName)) {
rtoss(_GIZMO(assetName));
mem_free(_GIZMO(assetName));
_GIZMO(assetName) = nullptr;
_GIZMO(seriesHandle) = nullptr;
_GIZMO(celsOffset) = -1;
_GIZMO(palOffset) = -1;
for (int idx = 0; idx < _GIZMO(spriteCount); ++idx)
mem_free(_GIZMO(sprites)[idx]);
mem_free(_GIZMO(sprites));
_GIZMO(sprites) = nullptr;
_GIZMO(spriteCount) = 0;
}
}
void gizmo_draw_sprite(M4sprite *sprite, Buffer *dest, int destX, int destY) {
Buffer src;
DrawRequest dr;
if (sprite && dest) {
HLock(sprite->sourceHandle);
sprite->data = (uint8 *)((intptr)*sprite->sourceHandle + sprite->sourceOffset);
src.stride = src.w = sprite->w;
src.h = sprite->h;
src.encoding = sprite->encoding & 0x7f;
src.data = sprite->data;
dr.Src = &src;
dr.Dest = dest;
dr.x = destX;
dr.y = destY;
dr.scaleX = dr.scaleY = 100;
dr.srcDepth = 0;
dr.depthCode = nullptr;
dr.Pal = nullptr;
dr.ICT = nullptr;
gr_sprite_draw(&dr);
HUnLock(sprite->sourceHandle);
}
}
static void gizmo_draw(ScreenContext *s, RectList *r, Buffer *dest, int32 destX, int32 destY) {
if (!s)
return;
void *scrnContent = s->scrnContent;
if (!scrnContent)
return;
Gizmo *gizmo = (Gizmo *)s->scrnContent;
if (!gizmo)
return;
Buffer *src = gizmo->_grBuff->get_buffer();
if (!src)
return;
if (dest) {
for (RectList *rect = r; rect; rect = rect->next) {
gr_buffer_rect_copy_2(src, dest,
rect->x1 - s->x1, rect->y1 - s->y1, destX, destY,
rect->x2 - rect->x1 + 1, rect->y2 - rect->y1 + 1);
}
} else {
for (RectList *rect = r; rect; rect = rect->next) {
vmng_refresh_video(rect->x1, rect->y1,
rect->x1 - s->x1, rect->y1 - s->y1, rect->x2 - s->x1, rect->y2 - s->y1,
src);
}
}
}
static bool gizmo_eventHandler(void *s, int32 eventType, int32 event, int32 x, int32 y, bool *z) {
Gizmo *gizmo = (Gizmo *)s;
bool flag = false;
int32 status = 0;
ScreenContext *ctx = vmng_screen_find(s, &status);
// WORKAROUND: gui_system_event_handler may call without z being set
bool dummyZ = false;
if (!z)
z = &dummyZ;
*z = false;
if (!ctx || status != 1)
return false;
if (eventType == EVENT_KEY) {
if (event == KEY_ESCAPE && gizmo->_fnEscape) {
_GIZMO(currentItem) = nullptr;
(*gizmo->_fnEscape)();
return true;
} else if (event == KEY_RETURN && gizmo->_fnEnter) {
_GIZMO(currentItem) = nullptr;
(*gizmo->_fnEnter)();
return true;
}
}
const int xs = x + ctx->x1;
const int ys = y + ctx->y1;
if (_GIZMO(currentItem)) {
flag = (*_GIZMO(currentItem)->_fnEvents)(_GIZMO(currentItem),
eventType, event, xs, ys, &_GIZMO(currentItem));
if (_GIZMO(currentItem))
*z = true;
if (flag)
return true;
}
if (eventType == EVENT_MOUSE) {
GizmoItem *item;
for (item = gizmo->_items; item; item = item->_next) {
if (item->_btnRect.contains(xs, ys))
break;
}
if (item && item->_fnEvents) {
item->_fnEvents(item, eventType, event, xs, ys, &_GIZMO(currentItem));
if (_GIZMO(currentItem))
*z = true;
return true;
}
} else if (eventType == EVENT_KEY) {
for (GizmoItem *item = gizmo->_items; item && !flag; item = item->_next) {
if (item->_fnEvents)
flag = (*item->_fnEvents)(item, eventType, event, -1, -1, nullptr);
}
return flag;
}
switch (event) {
case 2:
case 14:
if (!(ctx->scrnFlags & SF_IMMOVABLE)) {
*z = true;
_GIZMO(savedFlag) = true;
_GIZMO(savedX) = x;
_GIZMO(savedY) = y;
}
if (xs < 230 || xs > 420 || ys > 374)
gizmo_shutdown();
break;
case 4:
case 16:
if (_GIZMO(savedFlag)) {
MoveScreenDelta(ctx, _GIZMO(savedX), _GIZMO(savedY));
_GIZMO(savedX) = x;
_GIZMO(savedY) = y;
}
break;
case 5:
case 17:
*z = false;
_GIZMO(savedFlag) = false;
break;
default:
break;
}
return true;
}
static void gizmo_item_draw(GizmoItem *item, Gizmo *gizmo, int x, int y) {
if (!item || !item->_button || !gizmo)
return;
Buffer *src = nullptr;
if (item->_hasBuffer) {
if (!item->_grBuff)
return;
src = item->_grBuff->get_buffer();
if (!src)
return;
}
Buffer *dest = gizmo->_grBuff->get_buffer();
if (!dest)
return;
GizmoButton *btn = item->_button;
M4sprite *sprite = nullptr;
switch (btn->_state) {
case IN_CONTROL:
sprite = _GIZMO(sprites)[15 + btn->_index];
break;
case OVER_CONTROL:
sprite = _GIZMO(sprites)[8 + btn->_index];
break;
default:
sprite = _GIZMO(sprites)[1 + btn->_index];
break;
}
if (src) {
gr_buffer_rect_copy_2(src, dest, 0, 0, x, y, src->w, src->h);
item->_grBuff->release();
}
gizmo_draw_sprite(sprite, dest, x, y);
gizmo->_grBuff->release();
}
static void gizmo_item_free(GizmoItem *item) {
if (!item)
return;
if (item->_grBuff)
delete item->_grBuff;
if (item->_button)
mem_free(item->_button);
mem_free(item);
}
static GrBuff *gizmo_create_buffer(Gizmo *gizmo, int sx, int sy, int w, int h) {
if (!gizmo || !gizmo->_grBuff)
return nullptr;
GrBuff *grBuff = new GrBuff(w, h);
Buffer *src = gizmo->_grBuff->get_buffer();
Buffer *dest = grBuff->get_buffer();
assert(src && dest);
gr_buffer_rect_copy_2(src, dest, sx, sy, 0, 0, w, h);
gizmo->_grBuff->release();
grBuff->release();
return grBuff;
}
static bool gizmo_item_contains(GizmoItem *item, int x, int y) {
return item->_btnRect.contains(x, y);
}
static GizmoItem *gizmo_findItem(int id, Gizmo *gizmo) {
for (GizmoItem *item = gizmo->_items; item; item = item->_next) {
if (item->_id == id)
return item;
}
return nullptr;
}
static bool gizmo_item_events(GizmoItem *item, int eventType, int event, int x, int y,
GizmoItem **currentItem) {
if (!item || !item->_button || eventType != EVENT_MOUSE)
return false;
GizmoButton *btn = item->_button;
if (btn->_state == SELECTED)
return false;
bool flag1 = false;
bool flag2 = false;
bool flag3 = false;
switch (event) {
case _ME_move:
if (gizmo_item_contains(item, x, y)) {
if (!player_commands_allowed())
return false;
*currentItem = item;
if (btn->_state != IN_CONTROL) {
btn->_state = IN_CONTROL;
flag1 = true;
}
} else {
*currentItem = nullptr;
if (btn->_state != NOTHING) {
btn->_state = NOTHING;
flag1 = true;
flag3 = false;
}
}
break;
case _ME_L_click:
case _ME_doubleclick:
if (gizmo_item_contains(item, x, y)) {
if (!player_commands_allowed())
return false;
btn->_state = OVER_CONTROL;
*currentItem = item;
flag1 = true;
} else {
*currentItem = nullptr;
if (btn->_state != NOTHING) {
btn->_state = NOTHING;
flag1 = true;
}
}
break;
case _ME_L_hold:
case _ME_doubleclick_hold:
break;
case _ME_L_drag:
case _ME_doubleclick_drag:
if (!*currentItem)
return true;
if (gizmo_item_contains(item, x, y)) {
if (!player_commands_allowed())
return false;
if (btn->_state != OVER_CONTROL) {
btn->_state = OVER_CONTROL;
flag1 = true;
}
} else {
if (btn->_state != IN_CONTROL) {
btn->_state = IN_CONTROL;
flag1 = true;
}
}
break;
case _ME_L_release:
case _ME_doubleclick_release:
if (gizmo_item_contains(item, x, y)) {
if (!player_commands_allowed())
return false;
if (*currentItem)
flag2 = true;
else
*currentItem = item;
} else {
*currentItem = nullptr;
btn->_state = NOTHING;
flag1 = true;
flag3 = false;
}
break;
default:
break;
}
if (flag1) {
(*item->_fnDraw)(item, item->_gizmo, item->_bounds.left, item->_bounds.top);
int32 status;
ScreenContext *ctx = vmng_screen_find(item->_gizmo, &status);
if (ctx && status == 1)
RestoreScreens(item->_bounds.left + ctx->x1, item->_bounds.top + ctx->y1,
item->_bounds.right + ctx->x1, item->_bounds.bottom + ctx->y1);
}
if (flag2 && item->_select) {
(*item->_select)();
flag3 = true;
int32 status;
ScreenContext *ctx = vmng_screen_find(item->_gizmo, &status);
if (ctx && status == 1) {
if (!gizmo_findItem(item->_id, item->_gizmo))
*currentItem = nullptr;
} else {
*currentItem = nullptr;
}
}
return flag3;
}
static GizmoItem *gizmo_add_item(Gizmo *gizmo, int id,
int boundsX, int boundsY, int boundsW, int boundsH,
int rect1X, int rect1Y, int rect1W, int rect1H,
GizmoItemFnSelect select, int btnIndex, bool selected = false,
bool hasBuffer = false, int arg9 = 0,
GizmoItemFnEvents events = gizmo_item_events) {
if (!gizmo)
return nullptr;
// Create new item
GizmoItem *item = (GizmoItem *)mem_alloc(sizeof(GizmoItem), "*gui gizmo item");
if (!item)
error("gizmo_add_item - Not enough emory to create item (%zu bytes)", sizeof(GizmoItem));
// Put the new item at the head of the list
item->_next = gizmo->_items;
item->_prior = nullptr;
item->_gizmo = gizmo;
if (gizmo->_items)
gizmo->_items->_prior = item;
gizmo->_items = item;
// Set fields
item->_id = id;
item->_bounds = Common::Rect(boundsX, boundsY, boundsX + boundsW - 1,
boundsY + boundsH - 1);
item->_btnRect = Common::Rect(rect1X, rect1Y, rect1X + rect1W - 1, rect1Y + rect1H - 1);
item->_select = select;
item->_hasBuffer = hasBuffer;
if (hasBuffer) {
item->_grBuff = gizmo_create_buffer(gizmo, rect1X, rect1Y, rect1W, rect1H);
} else {
item->_grBuff = nullptr;
}
GizmoButton *btn = (GizmoButton *)mem_alloc(sizeof(GizmoButton), "*gizmo button");
if (!btn)
error("gizmo_add_item - Not enough emory to create btn (%zu bytes)", sizeof(GizmoButton));
btn->_state = selected ? SELECTED : NOTHING;
btn->_index = btnIndex;
btn->_field8 = arg9;
btn->_field10 = id - 1000;
item->_button = btn;
item->_fnDraw = gizmo_item_draw;
item->_fnFree = gizmo_item_free;
item->_fnEvents = events;
(*item->_fnDraw)(item, gizmo, boundsX, boundsY);
int32 status = 0;
ScreenContext *ctx = vmng_screen_find(gizmo, &status);
if (ctx && status == 1) {
RestoreScreens(ctx->x1 + item->_bounds.left, ctx->y1 + item->_bounds.top,
ctx->x1 + item->_bounds.right, ctx->y1 + item->_bounds.bottom);
}
return item;
}
static Gizmo *gui_create_gizmo(M4sprite *sprite, int sx, int sy, uint scrnFlags) {
if (!sprite)
return nullptr;
Gizmo *gui = (Gizmo *)mem_alloc(sizeof(Gizmo), "*gui gizmo");
if (!gui)
return nullptr;
GrBuff *grBuff = new GrBuff(sprite->w, sprite->h);
gui->_grBuff = grBuff;
gui->_items = nullptr;
gui->_fnEnter = nullptr;
gui->_fnEscape = nullptr;
gui->_fnEvents = gizmo_eventHandler;
Buffer *dest = gui->_grBuff->get_buffer();
Buffer *src = _G(gameDrawBuff)->get_buffer();
if ((_G(gameDrawBuff)->h - sy) >= dest->h) {
gr_buffer_rect_copy_2(src, dest, sx, sy, 0, 0, dest->w, dest->h);
} else {
gr_buffer_rect_copy_2(src, dest, sx, sy, 0, 0, dest->w, _G(gameDrawBuff)->h - sy);
}
_G(gameDrawBuff)->release();
if (sprite->sourceHandle)
gizmo_draw_sprite(sprite, dest, 0, 0);
gui->_grBuff->release();
ScreenContext *ctx = vmng_screen_create(sx, sy, sx + sprite->w, sy + sprite->h,
69, scrnFlags, gui, (RefreshFunc)gizmo_draw, gizmo_eventHandler);
return ctx ? gui : nullptr;
}
void gizmo_anim(RGB8 *pal) {
if (!_GIZMO(initialized))
gizmo_initialize(pal);
if (!gizmo_load_sprites("500gizmo", 58))
return;
Gizmo *gizmo = gui_create_gizmo(_GIZMO(sprites)[0], 0, 0, 505);
_GIZMO(gui) = gizmo;
assert(gizmo);
gizmo_add_item(gizmo, 1, 234, 153, 178, 48, 251, 163, 144, 25,
[]() { gizmo_daemon(5000); }, 0);
gizmo_add_item(gizmo, 2, 234, 178, 178, 48, 254, 188, 136, 25,
[]() { gizmo_daemon(5001); }, 1);
gizmo_add_item(gizmo, 3, 235, 203, 178, 48, 256, 212, 128, 27,
[]() { gizmo_daemon(5002); }, 2);
gizmo_add_item(gizmo, 6, 234, 230, 178, 48, 260, 239, 119, 25,
[]() { gizmo_daemon(5003); }, 3);
gizmo_add_item(gizmo, 5, 234, 255, 178, 48, 264, 264, 109, 25,
[]() { gizmo_daemon(5004); }, 4);
gizmo_add_item(gizmo, 6, 234, 278, 178, 48, 266, 289, 102, 25,
[]() { gizmo_daemon(5005); }, 5);
gizmo_add_item(gizmo, 7, 234, 300, 178, 48, 268, 314, 96, 25,
[]() { gizmo_daemon(5006); }, 6);
vmng_screen_show(gizmo);
mouse_lock_sprite(0);
}
} // namespace GUI
} // namespace Burger
} // namespace M4

View File

@@ -0,0 +1,113 @@
/* 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/>.
*
*/
#ifndef M4_BURGER_GUI_GIZMO_H
#define M4_BURGER_GUI_GIZMO_H
#include "common/rect.h"
#include "m4/m4_types.h"
#include "m4/gui/gui_vmng_core.h"
#include "m4/graphics/gr_buff.h"
#include "m4/burger/gui/inventory.h"
namespace M4 {
namespace Burger {
namespace GUI {
#define _GIZMO(X) g_vars->_gizmo._##X
struct Gizmo;
struct GizmoItem;
struct Gizmo_Globals {
bool _initialized = false;
bool _interface_visible = false;
Gizmo *_gui = nullptr;
RGB8 *_palette = nullptr;
bool _lowMemory1 = false;
bool _lowMemory2 = false;
GizmoItem *_currentItem = nullptr;
MemHandle _seriesHandle = nullptr;
int32 _celsOffset = 0;
int32 _palOffset = 0;
char *_assetName = nullptr;
int _spriteCount = 0;
M4sprite **_sprites = nullptr;
bool _roomFlags[15];
bool _savedFlag = false;
int _savedX = 0;
int _savedY = 0;
Gizmo_Globals();
~Gizmo_Globals();
};
struct Gizmo {
GrBuff *_grBuff = nullptr;
GizmoItem *_items = nullptr;
void (*_fnEnter)() = nullptr;
void (*_fnEscape)() = nullptr;
EventHandler _fnEvents = nullptr;
};
struct GizmoButton {
ControlStatus _state = NOTHING;
int _index = 0;
int _field8 = 0;
int _fieldC = 0;
int _field10 = 0;
};
typedef void (*GizmoItemFnSelect)();
typedef void (*GizmoItemFnDraw)(GizmoItem *item, Gizmo *gizmo, int x, int y);
typedef void (*GizmoItemFnFree)(GizmoItem *item);
typedef bool (*GizmoItemFnEvents)(GizmoItem *item, int eventType, int event, int x, int y,
GizmoItem **currentItem);
struct GizmoItem {
GizmoItem *_next = nullptr;
GizmoItem *_prior = nullptr;
Gizmo *_gizmo = nullptr;
GrBuff *_grBuff = nullptr;
GizmoButton *_button = nullptr;
int _id = 0;
Common::Rect _bounds;
Common::Rect _btnRect;
bool _hasBuffer = false;
GizmoItemFnSelect _select = nullptr;
GizmoItemFnDraw _fnDraw = nullptr;
GizmoItemFnFree _fnFree = nullptr;
GizmoItemFnEvents _fnEvents = nullptr;
};
void gizmo_anim(RGB8 *pal);
void gizmo_initialize(RGB8 *pal);
void gizmo_shutdown(void *v1 = nullptr, void *v2 = nullptr);
void gizmo_digi_play(const char *name, int vol, bool &done);
} // namespace GUI
} // namespace Burger
} // namespace M4
#endif

View File

@@ -0,0 +1,546 @@
/* 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/>.
*
*/
#include "m4/burger/gui/interface.h"
#include "m4/core/cstring.h"
#include "m4/core/errors.h"
#include "m4/graphics/gr_series.h"
#include "m4/gui/gui_event.h"
#include "m4/burger/burger.h"
#include "m4/burger/vars.h"
#include "m4/adv_r/other.h"
namespace M4 {
namespace Burger {
namespace GUI {
Interface::Interface() : M4::Interface() {
_x1 = 0;
_y1 = 374;
_x2 = SCREEN_WIDTH;
_y2 = SCREEN_HEIGHT;
}
bool Interface::init(int arrow, int wait, int look, int grab, int use) {
M4::Interface::init(arrow, wait, look, grab, use);
_sprite = series_load("999intr", 22, nullptr);
if (_sprite != 22)
error_show(FL, 'SLF!');
mouse_set_sprite(arrow);
if (!_G(gameInterfaceBuff)) {
_G(gameInterfaceBuff) = new GrBuff(_x2 - _x1, _y2 - _y1);
setup();
return true;
} else {
return false;
}
}
Interface::~Interface() {
delete _interfaceBox;
delete _inventory;
delete _textField;
delete _btnTake;
delete _btnManipulate;
delete _btnHandle;
delete _btnAbductFail;
delete _btnMenu;
delete _btnScrollLeft;
delete _btnScrollRight;
}
void Interface::show() {
M4::Interface::show();
_interfaceBox->_must_redraw_all = true;
vmng_screen_show(_G(gameInterfaceBuff));
_visible = true;
track_hotspots_refresh();
}
void Interface::setup() {
_interfaceBox = new InterfaceBox(RectClass(0, 0, SCREEN_WIDTH - 1, 105));
_inventory = new GUI::Inventory(RectClass(188, 22, 539, 97), _sprite, 9, 1, 39, 75, 3);
_textField = new TextField(200, 1, 470, 21);
_btnTake = new ButtonClass(RectClass(60, 35, 92, 66), "take", 4, 3, 3, 4, 5, INTERFACE_SPRITES);
_btnManipulate = new ButtonClass(RectClass(105, 35, 137, 66), "manipulate", 7, 6, 6, 7, 8, INTERFACE_SPRITES);
_btnHandle = new ButtonClass(RectClass(15, 35, 47, 66), "handle", 5, 0, 0, 1, 2, INTERFACE_SPRITES);
_interfaceBox->add(_btnTake);
_interfaceBox->add(_btnManipulate);
_interfaceBox->add(_btnHandle);
if (_G(executing) == WHOLE_GAME) {
_btnAbductFail = new ButtonClass(RectClass(580, 10, 620, 69), "abductfail", 10, 69, 69, 70, 71, INTERFACE_SPRITES);
_btnMenu = new ButtonClass(RectClass(582, 70, 619, 105), "menu", 11, 76, 76, 77, 78, INTERFACE_SPRITES);
_interfaceBox->add(_btnAbductFail);
_interfaceBox->add(_btnMenu);
} else {
_btnAbductFail = new ButtonClass(RectClass(580, 22, 620, 75), "abductfail", 10, 69, 69, 70, 71, INTERFACE_SPRITES);
_interfaceBox->add(_btnAbductFail);
}
_btnScrollLeft = new ButtonClass(RectClass(168, 22, 188, 97), "scroll left", 8, 59, 60, 61, 62, INTERFACE_SPRITES);
_btnScrollRight = new ButtonClass(RectClass(539, 22, 559, 97), "scroll right", 9, 63, 64, 65, 66, INTERFACE_SPRITES);
_interfaceBox->add(_btnScrollLeft);
_interfaceBox->add(_btnScrollRight);
}
void Interface::cancel_sentence() {
_textField->set_string(" ");
_G(player).need_to_walk = false;
_G(player).ready_to_walk = false;
_G(player).command_ready = false;
_prepText[0] = '\0';
_nounText[0] = '\0';
_verbText[0] = '\0';
_iconSelected = false;
track_hotspots_refresh();
}
void Interface::freshen_sentence() {
_textField->set_string(" ");
_G(player).need_to_walk = false;
_G(player).ready_to_walk = _G(player).need_to_walk;
_G(player).command_ready = _G(player).ready_to_walk;
_prepText[0] = '\0';
_nounText[0] = '\0';
track_hotspots_refresh();
}
bool Interface::set_interface_palette(RGB8 *myPalette) {
gr_pal_set_RGB8(&myPalette[1], 0, 68, 0);
gr_pal_set_RGB8(&myPalette[2], 0, 134, 0);
gr_pal_set_RGB8(&myPalette[3], 0, 204, 0);
gr_pal_set_RGB8(&myPalette[4], 28, 8, 90);
gr_pal_set_RGB8(&myPalette[5], 204, 204, 250);
gr_pal_set_RGB8(&myPalette[6], 204, 204, 102);
gr_pal_set_RGB8(&myPalette[7], 5, 1, 0);
gr_pal_set_RGB8(&myPalette[8], 102, 51, 222);
gr_pal_set_RGB8(&myPalette[9], 85, 117, 255);
gr_pal_set_RGB8(&myPalette[10], 68, 68, 68);
gr_pal_set_RGB8(&myPalette[11], 51, 255, 0);
gr_pal_set_RGB8(&myPalette[12], 51, 51, 115);
gr_pal_set_RGB8(&myPalette[13], 119, 119, 119);
gr_pal_set_RGB8(&myPalette[14], 151, 153, 150);
gr_pal_set_RGB8(&myPalette[15], 153, 0, 0);
gr_pal_set_RGB8(&myPalette[16], 153, 53, 9);
gr_pal_set_RGB8(&myPalette[17], 117, 246, 255);
gr_pal_set_RGB8(&myPalette[18], 88, 0, 0);
gr_pal_set_RGB8(&myPalette[19], 195, 0, 83);
gr_pal_set_RGB8(&myPalette[20], 204, 102, 61);
gr_pal_set_RGB8(&myPalette[21], 204, 153, 118);
gr_pal_set_RGB8(&myPalette[22], 204, 255, 204);
gr_pal_set_RGB8(&myPalette[23], 207, 158, 73);
gr_pal_set_RGB8(&myPalette[24], 238, 0, 0);
gr_pal_set_RGB8(&myPalette[25], 248, 51, 31);
gr_pal_set_RGB8(&myPalette[26], 255, 131, 0);
gr_pal_set_RGB8(&myPalette[27], 255, 153, 102);
gr_pal_set_RGB8(&myPalette[28], 255, 204, 153);
gr_pal_set_RGB8(&myPalette[29], 255, 252, 144);
gr_pal_set_RGB8(&myPalette[30], 255, 255, 0);
gr_pal_set_RGB8(&myPalette[31], 255, 255, 255);
gr_pal_set_range(myPalette, 1, 31);
return true;
}
void Interface::track_hotspots_refresh() {
_hotspot = nullptr;
--_savedX;
bool z = false;
eventHandler(_G(gameInterfaceBuff), EVENT_MOUSE, 1,
_G(MouseState).CursorColumn, _G(MouseState).CursorRow, &z);
}
bool Interface::eventHandler(void *bufferPtr, int32 eventType, int32 event, int32 x, int32 y, bool *z) {
if (eventType != EVENT_MOUSE)
return false;
if (_G(kernel).fading_to_grey && event == _ME_L_release) {
kernel_unexamine_inventory_object(_G(master_palette), 5, 1);
return true;
}
if (player_commands_allowed()) {
if (x == _savedX && y == _savedY && event != _ME_L_click &&
event != _ME_L_release && event != _ME_L_hold && event != _ME_L_drag)
return true;
_savedX = x;
_savedY = y;
ControlStatus status = _interfaceBox->track(event, x - _x1, y - _y1);
switch (status) {
case NOTHING:
_state = NOTHING;
break;
case SELECTED:
trackIcons();
break;
default:
_state = IN_CONTROL;
break;
}
if (_state == NOTHING || _state == OVER_CONTROL) {
status = _inventory->track(event, x - _x1, y - _y1);
handleState(status);
_state = status ? OVER_CONTROL : NOTHING;
}
if (_state == NOTHING) {
int32 scrStatus;
ScreenContext *screen = vmng_screen_find(_G(gameDrawBuff), &scrStatus);
if (!screen)
return false;
if (y >= _y1) {
if (!_iconSelected)
mouse_set_sprite(kArrowCursor);
_textField->set_string(" ");
}
if (trackHotspots(event, x - screen->x1, y - screen->y1) == SELECTED)
dispatch_command();
}
}
if (_interfaceBox->_must_redraw_all) {
_textField->_must_redraw = true;
_inventory->_must_redraw_all = true;
}
_interfaceBox->draw(_G(gameInterfaceBuff));
_textField->draw(_G(gameInterfaceBuff));
_inventory->draw(_G(gameInterfaceBuff));
return true;
}
void Interface::refresh_right_arrow() {
if (_inventory->need_right() || _inventory->need_left()) {
_btnScrollRight->set_sprite_unknown(63);
_btnScrollRight->set_sprite_relaxed(64);
_btnScrollRight->set_sprite_picked(66);
_btnScrollRight->set_sprite_over(65);
_btnScrollRight->unhide();
} else {
// _btnScrollRight->hide();
// _btnScrollLeft->hide();
}
}
void Interface::refresh_left_arrow() {
if (_inventory->need_right() || _inventory->need_left()) {
_btnScrollLeft->set_sprite_unknown(59);
_btnScrollLeft->set_sprite_relaxed(60);
_btnScrollLeft->set_sprite_picked(62);
_btnScrollLeft->set_sprite_over(61);
_btnScrollLeft->unhide();
} else {
// _btnScrollRight->hide();
// _btnScrollLeft->hide();
}
}
void Interface::trackIcons() {
KernelTriggerType oldMode = _G(kernel).trigger_mode;
_G(kernel).trigger_mode = KT_DAEMON;
switch (_interfaceBox->_highlight_index) {
case 4:
t_cb();
break;
case 5:
l_cb();
break;
case 6:
mouse_set_sprite(_arrow);
_iconSelected = false;
if (_btnScrollRight->is_hidden())
refresh_right_arrow();
else
_btnScrollRight->hide();
if (_btnScrollLeft->is_hidden())
refresh_left_arrow();
else
_btnScrollLeft->hide();
break;
case 7:
u_cb();
break;
case 8:
if (!_btnScrollLeft->is_hidden()) {
if (_inventory->need_left()) {
_inventory->_scroll = (_inventory->_scroll <= 0) ? 0 :
_inventory->_scroll - _inventory->_cells_v;
}
refresh_right_arrow();
refresh_left_arrow();
_inventory->_must_redraw_all = true;
} else {
return;
}
break;
case 9:
if (!_btnScrollRight->is_hidden()) {
if (_inventory->need_right())
_inventory->_scroll += _inventory->_cells_v;
refresh_right_arrow();
refresh_left_arrow();
_inventory->_must_redraw_all = true;
} else {
return;
}
break;
case 10:
term_message("Abduct/Fail Button Pressed");
if (_G(game).section_id == 1) {
term_message("Abduct me now!");
_G(wilbur_should) = 10017;
kernel_trigger_dispatch_now(kCHANGE_WILBUR_ANIMATION);
} else if (_G(game).section_id == 7) {
_G(walker).wilbur_speech("999w023");
} else {
term_message("Fail me now!");
_G(wilbur_should) = 10015;
kernel_trigger_dispatch_now(kCHANGE_WILBUR_ANIMATION);
}
break;
case 11:
// Game menu
other_save_game_for_resurrection();
if (g_engine->useOriginalSaveLoad()) {
CreateGameMenu(_G(master_palette));
} else {
g_engine->openMainMenuDialog();
}
break;
}
_G(kernel).trigger_mode = oldMode;
}
ControlStatus Interface::trackHotspots(int event, int x, int y) {
const HotSpotRec *hotspot = g_engine->_activeRoom->custom_hotspot_which(x, y);
if (!hotspot)
hotspot = hotspot_which(_G(currentSceneDef).hotspots, x, y);
if (hotspot != _hotspot) {
if (!hotspot) {
_textField->set_string(" ");
_hotspot = nullptr;
return NOTHING;
}
if (!_iconSelected) {
if (!mouse_set_sprite(hotspot->cursor_number))
mouse_set_sprite(kArrowCursor);
Common::strlcpy(_verbText, hotspot->verb, 40);
}
Common::String tmp = (g_engine->getLanguage() == Common::EN_ANY) ?
hotspot->vocab : hotspot->prep;
tmp.toUppercase();
_textField->set_string(tmp.c_str());
tmp = hotspot->vocab;
tmp.toUppercase();
Common::strlcpy(_nounText, tmp.c_str(), 40);
_hotspot = hotspot;
}
if (event == 5 && hotspot) {
_G(player).walk_x = x;
_G(player).walk_y = y;
_G(player).click_x = x;
_G(player).click_y = y;
if (hotspot->feet_x != 0x7fff)
_G(player).walk_x = hotspot->feet_x;
if (hotspot->feet_y != 0x7fff)
_G(player).walk_y = hotspot->feet_y;
_G(player).walk_facing = hotspot->facing;
_hotspot = nullptr;
return SELECTED;
} else {
return IN_CONTROL;
}
}
void Interface::dispatch_command() {
--_savedX;
cstrncpy(_G(player).verb, _verbText, 40);
cstrncpy(_G(player).noun, _nounText, 40);
cstrncpy(_G(player).prep, _prepText, 40);
_G(player).waiting_for_walk = true;
_G(player).ready_to_walk = true;
_G(player).need_to_walk = true;
_G(player).command_ready = true;
_G(kernel).trigger = -1;
_G(kernel).trigger_mode = KT_PREPARSE;
_iconSelected = false;
mouse_set_sprite(_arrow);
_G(player).walker_trigger = -1;
g_engine->_activeRoom->pre_parser();
g_engine->_activeSection->pre_parser();
g_engine->global_pre_parser();
}
void Interface::handleState(ControlStatus status) {
int highlight = _inventory->_highlight;
int index = _inventory->_scroll + highlight;
switch (status) {
case NOTHING:
_hotspot = nullptr;
cstrncpy(_nounText, " ", 40);
_textField->set_string(" ");
break;
case OVER_CONTROL:
if (highlight < -1 || (highlight != -1 && (
highlight < 128 || highlight > 129))) {
_hotspot = nullptr;
cstrncpy(_nounText, _inventory->_items[index]._name.c_str(), 40);
if (g_engine->getLanguage() == Common::EN_ANY) {
_textField->set_string(_inventory->_items[index]._name.c_str());
} else {
_textField->set_string(_inventory->_items[index]._verb.c_str());
}
}
break;
case SELECTED:
if (highlight != -1 && _inventory->_items[index]._cell != -1) {
if (_iconSelected) {
_hotspot = nullptr;
cstrncpy(_nounText, _inventory->_items[index]._name.c_str(), 40);
if (g_engine->getLanguage() == Common::EN_ANY) {
_textField->set_string(_inventory->_items[index]._name.c_str());
} else {
_textField->set_string(_inventory->_items[index]._verb.c_str());
}
term_message("got %d", index);
dispatch_command();
_G(player).ready_to_walk = true;
_G(player).need_to_walk = false;
_G(player).waiting_for_walk = false;
} else {
_hotspot = nullptr;
cstrncpy(_verbText, _inventory->_items[index]._name.c_str(), 40);
if (g_engine->getLanguage() == Common::EN_ANY) {
_textField->set_string(_inventory->_items[index]._name.c_str());
} else {
_textField->set_string(_inventory->_items[index]._verb.c_str());
}
mouse_set_sprite(_inventory->_items[index]._cursor);
_iconSelected = true;
}
}
break;
default:
break;
}
}
void Interface::l_cb() {
if (player_commands_allowed() && INTERFACE_VISIBLE) {
Common::strcpy_s(_verbText, "look at");
mouse_set_sprite(_look);
_iconSelected = true;
_G(cursor_state) = kLOOK;
}
}
void Interface::u_cb() {
if (player_commands_allowed() && INTERFACE_VISIBLE) {
Common::strcpy_s(_verbText, "gear");
mouse_set_sprite(_use);
_iconSelected = true;
_G(cursor_state) = kUSE;
}
}
void Interface::t_cb() {
if (player_commands_allowed() && INTERFACE_VISIBLE) {
Common::strcpy_s(_verbText, "take");
mouse_set_sprite(_grab);
_iconSelected = true;
_G(cursor_state) = kTAKE;
}
}
void Interface::a_cb() {
if (player_commands_allowed() && INTERFACE_VISIBLE) {
Common::strcpy_s(_verbText, "<><><><><><><><>");
mouse_set_sprite(_arrow);
_iconSelected = false;
_G(cursor_state) = kARROW;
if (_hotspot && !mouse_set_sprite(_hotspot->cursor_number))
mouse_set_sprite(kArrowCursor);
}
}
} // namespace GUI
} // namespace Burger
} // namespace M4

View File

@@ -0,0 +1,96 @@
/* 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/>.
*
*/
#ifndef M4_BURGER_INTERFACE_H
#define M4_BURGER_INTERFACE_H
#include "m4/adv_r/adv_interface.h"
#include "m4/adv_r/adv_hotspot.h"
#include "m4/graphics/graphics.h"
#include "m4/graphics/gr_buff.h"
#include "m4/burger/gui/inventory.h"
namespace M4 {
namespace Burger {
namespace GUI {
struct Interface : public M4::Interface {
private:
void setup();
void trackIcons();
ControlStatus trackHotspots(int event, int x, int y);
void dispatch_command();
void handleState(ControlStatus status);
public:
int _sprite = 22; // main_interface_sprite;
bool _shown = false;
GUI::InterfaceBox *_interfaceBox = nullptr;
GUI::Inventory *_inventory = nullptr;
GUI::TextField *_textField = nullptr;
GUI::ButtonClass *_btnTake = nullptr;
GUI::ButtonClass *_btnManipulate = nullptr;
GUI::ButtonClass *_btnHandle = nullptr;
GUI::ButtonClass *_btnAbductFail = nullptr;
GUI::ButtonClass *_btnMenu = nullptr;
GUI::ButtonClass *_btnScrollLeft = nullptr;
GUI::ButtonClass *_btnScrollRight = nullptr;
const HotSpotRec *_hotspot = nullptr;
int _savedX = 0, _savedY = 0;
char _prepText[40] = { 0 };
char _nounText[40] = { 0 };
char _verbText[40] = { 0 };
bool _iconSelected = false;
int _state = 0;
Interface();
~Interface() override;
bool init(int arrow, int wait, int look, int grab, int use) override;
void cancel_sentence() override;
void freshen_sentence() override;
bool set_interface_palette(RGB8 *myPalette) override;
void track_hotspots_refresh() override;
bool eventHandler(void *bufferPtr, int32 eventType, int32 event, int32 x, int32 y, bool *z) override;
void show() override;
void refresh_right_arrow();
void refresh_left_arrow();
void l_cb();
void u_cb();
void t_cb();
void a_cb();
};
} // namespace Interface
} // namespace Burger
} // namespace M4
#endif

View File

@@ -0,0 +1,289 @@
/* 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/>.
*
*/
#include "m4/burger/gui/inventory.h"
#include "m4/burger/vars.h"
#include "m4/core/errors.h"
#include "m4/graphics/gr_line.h"
#include "m4/graphics/gr_series.h"
#include "m4/gui/gui_vmng_screen.h"
namespace M4 {
namespace Burger {
namespace GUI {
Inventory::Inventory(const RectClass &r, int32 sprite, int16 cells_h, int16 cells_v, int16 cell_w, int16 cell_h, int16 tag)
: RectClass(r) {
_sprite = sprite;
for (int16 iter = 0; iter < INVENTORY_CELLS_COUNT; iter++) {
_items[iter]._cell = -1;
_items[iter]._cursor = -1;
}
_num_cells = 0;
_tag = tag;
_cells_h = cells_h;
_cells_v = cells_v;
_cell_w = cell_w;
_cell_h = cell_h;
// If requested cell configuration doesn't fit, blow up.
if ((cells_h * cell_w > (_x2 - _x1)) || (cells_v * cell_h > (_y2 - _y1))) {
error_show(FL, 'CGIC');
}
_highlight = -1;
_must_redraw_all = true;
_must_redraw1 = -1;
_must_redraw2 = -1;
_scroll = 0;
_right_arrow_visible = false;
}
Inventory::~Inventory() {
}
bool Inventory::add(const Common::String &name, const Common::String &verb, int32 invSprite, int32 cursor) {
// Don't add something twice
for (int16 iter = 0; iter < _num_cells; iter++) {
if (name.equals(_items[iter]._name))
return true;
}
if (_num_cells >= INVENTORY_CELLS_COUNT) {
error_show(FL, 'CGIA');
return false;
}
// Shift existing items up by one
for (int i = _num_cells; i > 0; --i)
_items[i] = _items[i - 1];
Entry &item = _items[0];
item._name = name;
item._verb = verb;
item._cell = invSprite;
item._cursor = cursor;
++_num_cells;
_must_redraw_all = true;
if (_GI(visible))
_G(interface).show();
return true;
}
bool Inventory::need_left() const {
return (_scroll != 0);
}
bool Inventory::need_right() const {
if ((_num_cells - _scroll - MAX_INVENTORY) > 0)
return true;
return false;
}
void Inventory::set_scroll(int32 new_scroll) {
_scroll = new_scroll;
_must_redraw_all = true;
}
bool Inventory::remove(const Common::String &name) {
for (int16 iter = 0; iter < _num_cells; iter++) {
// Found the thing?
if (name.equals(_items[iter]._name)) {
// Eat up its slot by moving everything down
for (; iter < _num_cells; ++iter)
_items[iter] = _items[iter + 1];
--_num_cells;
_must_redraw_all = true;
_scroll = 0;
if (_GI(visible))
_G(interface).show();
return true;
}
}
// Didn't find that thing.
return false;
}
int16 Inventory::inside(int16 x, int16 y) const {
if ((x < _x1) || (x >= (_x2 - 1)) || (y < _y1 + 2) ||
(y > _y1 + _cells_v * _cell_h - 2))
return -1;
x -= _x1;
y -= _y1;
return (int16)((x / _cell_w) * _cells_v + (y / _cell_h));
}
int16 Inventory::cell_pos_x(int16 index) {
if (_cells_h > _cells_v) { // Horizontal orientation, fill left to right
return (int16)((index / _cells_v) * _cell_w);
} else { // Vertical orientation, fill top to bottom
return (int16)((index / _cells_h) * _cell_w);
}
}
int16 Inventory::cell_pos_y(int16 index) {
if (_cells_h > _cells_v) {
// Horizontal orientation, fill left to right
return (int16)((index % _cells_v) * _cell_h);
} else {
// Vertical orientation, fill top to bottom
return (int16)((index % _cells_h) * _cell_h);
}
}
void Inventory::highlight_part(int16 index) {
if (_highlight == index)
return;
_must_redraw1 = _highlight;
_highlight = index;
_must_redraw2 = _highlight;
}
void Inventory::draw(GrBuff *myBuffer) {
if (!_GI(visible))
return;
if (!_must_redraw1 && !_must_redraw2 && !_must_redraw_all)
return;
int16 cell_iter;
Buffer *myBuff = myBuffer->get_buffer();
if (_must_redraw_all) {
gr_color_set(__BLACK);
gr_buffer_rect_fill(myBuff, _x1, _y1, _x2 - _x1, _y2 - _y1);
}
_right_arrow_visible = false;
for (cell_iter = 0; (cell_iter + _scroll < _num_cells) && (cell_iter < MAX_INVENTORY); cell_iter++) {
int16 left = (int16)(_x1 + cell_pos_x(cell_iter));
int16 top = (int16)(_y1 + cell_pos_y(cell_iter));
int16 leftOffset = left + _cell_w;
int16 topOffset = top + _cell_h;
if (_must_redraw1 == cell_iter || _must_redraw2 == cell_iter || _must_redraw_all) {
// This does the button update....
_G(interface).refresh_right_arrow();
_G(interface).refresh_left_arrow();
// Draw icon here
gr_color_set(__BLACK);
gr_buffer_rect_fill(myBuff, left, top, leftOffset - left, topOffset - top);
series_show_frame(_sprite, _items[cell_iter + _scroll]._cell, myBuff,
left + (_cell_w - 31) / 2, top + (_cell_h - 31) / 2);
// Draw box around icon
if (_highlight == cell_iter) {
left += 2;
top += 20;
gr_line(left, top, left + 35, top, __GREEN, myBuff);
gr_line(left + 35, top, left + 35, top + 35, __GREEN, myBuff);
gr_line(left, top, left, top + 35, __GREEN, myBuff);
gr_line(left, top + 35, left + 35, top + 35, __GREEN, myBuff);
}
}
}
// Draw inventory slot frames
for (cell_iter = 0; cell_iter < MAX_INVENTORY; ++cell_iter) {
series_show_frame(_sprite, 67, myBuff, cell_iter * 39 + 188, 22);
series_show_frame(_sprite, 68, myBuff, cell_iter * 39 + 188, 92);
}
ScreenContext *iC = vmng_screen_find(_G(gameInterfaceBuff), nullptr);
RestoreScreensInContext(_x1, _y1, _x2, _y2, iC);
_must_redraw1 = _must_redraw2 = -1;
_must_redraw_all = false;
myBuffer->release();
}
ControlStatus Inventory::track(int32 eventType, int16 x, int16 y) {
if (!_GI(visible))
return NOTHING;
ControlStatus result = NOTHING;
int16 over = inside(x, y);
bool button_clicked = eventType == _ME_L_click || eventType == _ME_L_hold || eventType == _ME_L_drag;
// If Button is pressed
if (button_clicked) {
// If we are not tracking, start tracking
if (interface_tracking == -1) {
highlight_part(over);
interface_tracking = over;
result = IN_CONTROL;
} else {
// Else if we are over something we are tracking
if (interface_tracking == over) {
highlight_part(over);
result = IN_CONTROL;
} else {
// Else highlight nothing
highlight_part(-1);
result = NOTHING;
}
}
} else {
// If Button isn't pressed
// If we unpressed on something we were tracking
if (interface_tracking == over) {
if (interface_tracking == -1)
result = NOTHING;
else
result = SELECTED;
} else {
if (over + _scroll < _num_cells)
result = OVER_CONTROL;
else
result = NOTHING;
}
// Stop tracking anything
highlight_part(over);
interface_tracking = -1;
}
if (result == NOTHING && button_clicked)
return TRACKING;
return result;
}
} // namespace GUI
} // namespace Burger
} // namespace M4

View File

@@ -0,0 +1,99 @@
/* 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/>.
*
*/
#ifndef M4_BURGER_GUI_INVENTORY_H
#define M4_BURGER_GUI_INVENTORY_H
#include "m4/gui/gui_cheapo.h"
namespace M4 {
namespace Burger {
namespace GUI {
using namespace M4::GUI;
constexpr int16 INVENTORY_CELLS_COUNT = 128;
constexpr int16 ARROW_WIDTH = 8;
constexpr int16 MAX_INVENTORY = 9;
constexpr int16 LEFT_ARROW_TAG = 128;
constexpr int16 RIGHT_ARROW_TAG = 129;
constexpr int16 LEFT_ARROW_TAG_DORMANT = 130;
constexpr int16 RIGHT_ARROW_TAG_DORMANT = 134;
constexpr int16 LEFT_ARROW_TAG_ROLL = 131;
constexpr int16 RIGHT_ARROW_TAG_ROLL = 135;
constexpr int16 LEFT_ARROW_TAG_DOWN = 132;
constexpr int16 RIGHT_ARROW_TAG_DOWN = 136;
constexpr int16 LEFT_ARROW_TAG_NONFUNC = 133;
constexpr int16 RIGHT_ARROW_TAG_NONFUNC = 137;
class Inventory : public RectClass {
struct Entry {
Common::String _name;
Common::String _verb;
int16 _cell = -1;
int16 _cursor = -1;
};
private:
int32 _sprite = 0;
int16 _tag = 0;
int16 _num_cells = 0;
bool _right_arrow_visible = false;
int16 cell_pos_x(int16 index);
int16 cell_pos_y(int16 index);
int16 interface_tracking = -1;
public:
int16 _scroll = 0;
int16 _cells_h = 0, _cells_v = 0;
int16 _cell_w = 0, _cell_h = 0;
int16 _must_redraw1 = 0, _must_redraw2 = 0;
int16 _highlight = 0;
bool _must_redraw_all = false;
Entry _items[INVENTORY_CELLS_COUNT];
public:
Inventory(const RectClass &r, int32 sprite, int16 cells_h, int16 cells_v, int16 cell_w, int16 cell_h, int16 tag);
~Inventory();
void draw(GrBuff *interface_buffer);
int16 inside(int16 x, int16 y) const override;
ControlStatus track(int32 eventType, int16 x, int16 y);
bool add(const Common::String &name, const Common::String &verb, int32 cel, int32 cursor);
bool remove(const Common::String &name);
void highlight_part(int16 index);
bool need_left() const;
bool need_right() const;
void set_scroll(int32 new_scroll);
};
} // namespace GUI
} // namespace Burger
} // namespace M4
#endif