Skip to content

Commit

Permalink
Engine: implemented skipping display boxes by touch down
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-mogilko committed Mar 5, 2025
1 parent b46f1c8 commit 3ee7cf3
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 20 deletions.
38 changes: 25 additions & 13 deletions Engine/ac/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,11 @@
// https://opensource.org/license/artistic-2-0/
//
//=============================================================================

#include "ac/display.h"
#include <math.h>

#include <stdio.h>
#include "ac/display.h"
#include "ac/common.h"
#include "font/agsfontrenderer.h"
#include "font/fonts.h"
#include "ac/character.h"
#include "ac/draw.h"
#include "ac/game.h"
Expand All @@ -27,26 +24,28 @@
#include "ac/global_audio.h"
#include "ac/global_game.h"
#include "ac/gui.h"
#include "ac/joystick.h"
#include "ac/mouse.h"
#include "ac/overlay.h"
#include "ac/sys_events.h"
#include "ac/screenoverlay.h"
#include "ac/speech.h"
#include "ac/spritecache.h"
#include "ac/string.h"
#include "ac/system.h"
#include "ac/timer.h"
#include "ac/touch.h"
#include "debug/debug_log.h"
#include "font/agsfontrenderer.h"
#include "font/fonts.h"
#include "gfx/blender.h"
#include "gfx/gfx_util.h"
#include "gui/guibutton.h"
#include "gui/guimain.h"
#include "main/game_run.h"
#include "media/audio/audio_system.h"
#include "platform/base/agsplatformdriver.h"
#include "ac/spritecache.h"
#include "gfx/gfx_util.h"
#include "util/string_utils.h"
#include "ac/mouse.h"
#include "media/audio/audio_system.h"
#include "ac/timer.h"
#include "joystick.h"

using namespace AGS::Common;
using namespace AGS::Common::BitmapHelper;
Expand Down Expand Up @@ -333,7 +332,7 @@ bool display_check_user_input(int skip)
{
state_handled = true;
}
else if ((skip & SKIP_KEYPRESS) && !play.IsIgnoringInput() && !IsAGSServiceKey(ki.Key))
else if ((skip & SKIP_KEYPRESS) != 0 && !play.IsIgnoringInput() && !IsAGSServiceKey(ki.Key))
{
play.SetWaitKeySkip(ki);
state_handled = true; // stop display
Expand All @@ -349,7 +348,7 @@ bool display_check_user_input(int skip)
{
state_handled = true;
}
else if (skip & SKIP_MOUSECLICK && !play.IsIgnoringInput())
else if ((skip & SKIP_MOUSECLICK) != 0 && !play.IsIgnoringInput())
{
play.SetWaitSkipResult(SKIP_MOUSECLICK, mbut);
state_handled = true; // stop display
Expand All @@ -366,14 +365,27 @@ bool display_check_user_input(int skip)
{
state_handled = true; // stop display
}
else if (skip & SKIP_GAMEPAD && !play.IsIgnoringInput() &&
else if ((skip & SKIP_GAMEPAD) != 0 && !play.IsIgnoringInput() &&
is_default_gamepad_skip_button_pressed(gbn))
{
play.SetWaitSkipResult(SKIP_GAMEPAD, gbn);
state_handled = true; // stop display
}
break;
}
case kInputTouch:
{
TouchInput ti;
if (!run_service_touch_controls(ti) || play.fast_forward || state_handled)
continue; // handled by engine layer, or fast-forwarded, or resolved
// TODO: check skip cutscene? we might check if it's "skip by mouse" here
if ((skip & SKIP_TOUCH) != 0 && (ti.Phase == TouchPhase::Down) && !play.IsIgnoringInput())
{
play.SetWaitSkipResult(SKIP_TOUCH);
state_handled = true; // stop display
}
break;
}
default:
ags_drop_next_inputevent();
break;
Expand Down
1 change: 1 addition & 0 deletions Engine/ac/runtime_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
#define SKIP_KEYPRESS 0x02
#define SKIP_MOUSECLICK 0x04
#define SKIP_GAMEPAD 0x08
#define SKIP_TOUCH 0x10
// Bit shift for packing skip type into result
#define SKIP_RESULT_TYPE_SHIFT 24
// Bit mask for packing skip key/button data into result
Expand Down
19 changes: 12 additions & 7 deletions Engine/ac/speech.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,31 @@ static String VoiceAssetPath;

int user_to_internal_skip_speech(SkipSpeechStyle userval)
{
// NOTE: After Gamepad and Touch controls were implemented,
// we treat "Skip by key" as "by key or gamepad button"
// and "Skip by mouse" as "by mouse or touch".
switch (userval)
{
case kSkipSpeechNone:
return SKIP_NONE;
case kSkipSpeechKeyMouseTime:
return SKIP_AUTOTIMER | SKIP_KEYPRESS | SKIP_MOUSECLICK | SKIP_GAMEPAD; // FIXME: remake this as `kSkipAny`
// TODO: remake this as "kSkipAny"?
return SKIP_AUTOTIMER | SKIP_KEYPRESS | SKIP_MOUSECLICK | SKIP_GAMEPAD | SKIP_TOUCH;
case kSkipSpeechKeyTime:
return SKIP_AUTOTIMER | SKIP_KEYPRESS;
return SKIP_AUTOTIMER | SKIP_KEYPRESS | SKIP_GAMEPAD;
case kSkipSpeechTime:
return SKIP_AUTOTIMER;
case kSkipSpeechKeyMouse:
return SKIP_KEYPRESS | SKIP_MOUSECLICK;
// TODO: remake this as "kSkipAnyInput"?
return SKIP_KEYPRESS | SKIP_MOUSECLICK | SKIP_GAMEPAD | SKIP_TOUCH;
case kSkipSpeechMouseTime:
return SKIP_AUTOTIMER | SKIP_MOUSECLICK;
return SKIP_AUTOTIMER | SKIP_MOUSECLICK | SKIP_TOUCH;
case kSkipSpeechKey:
return SKIP_KEYPRESS;
return SKIP_KEYPRESS | SKIP_GAMEPAD;
case kSkipSpeechMouse:
return SKIP_MOUSECLICK;
return SKIP_MOUSECLICK | SKIP_TOUCH;
default:
quit("user_to_internal_skip_speech: unknown userval");
debug_script_warn("user_to_internal_skip_speech: unknown userval");
return SKIP_NONE;
}
}
Expand Down
4 changes: 4 additions & 0 deletions Engine/main/game_run.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

namespace AGS { namespace Engine { class IDriverDependantBitmap; }}
struct GamepadInput;
struct TouchInput;

// Loops game frames until certain event takes place (for blocking actions)
void GameLoopUntilValueIsZero(const char *value);
Expand Down Expand Up @@ -61,6 +62,9 @@ bool run_service_mb_controls(eAGSMouseButton &mbut, Point *mpos = nullptr);
// Runs service gamepad controls, returns false if no button was pressed or if button input was claimed by the engine,
// otherwise returns true and provides the gamepad input.
bool run_service_gamepad_controls(GamepadInput &out_key);
// Runs service touch controls, returns false if not touch is active or if its event was claimed by the engine,
// otherwise returns true and provides TouchInput data
bool run_service_touch_controls(TouchInput &out_touch);
// Polls few things (exit flag and debugger messages)
// TODO: refactor this
void update_polled_stuff();
Expand Down

0 comments on commit 3ee7cf3

Please sign in to comment.