mirror of
https://github.com/libretro/scummvm.git
synced 2025-02-12 22:51:11 +00:00
AGS: Store gui draw order in a std::vector
From upstream fcc873ef0c26439faf67100f4d70d540434ca9f5
This commit is contained in:
parent
53e1c22185
commit
6ef504bba2
@ -444,7 +444,7 @@ void unload_game_file() {
|
||||
ccUnregisterAllObjects();
|
||||
|
||||
free_do_once_tokens();
|
||||
free(_GP(play).gui_draw_order);
|
||||
_GP(play).gui_draw_order.clear();
|
||||
|
||||
resetRoomStatuses();
|
||||
|
||||
|
@ -226,7 +226,7 @@ struct GameState {
|
||||
int gamma_adjustment = 0;
|
||||
short temporarily_turned_off_character = 0; // Hide Player Charactr ticked
|
||||
short inv_backwards_compatibility = 0;
|
||||
int32_t *gui_draw_order = 0;
|
||||
std::vector<int> gui_draw_order; // used only for hit detection now
|
||||
std::vector<AGS::Shared::String> do_once_tokens = 0;
|
||||
int text_min_display_time_ms = 0;
|
||||
int ignore_user_input_after_text_timeout_ms = 0;
|
||||
|
@ -243,11 +243,11 @@ int GetGUIObjectAt(int xx, int yy) {
|
||||
int GetGUIAt(int xx, int yy) {
|
||||
data_to_game_coords(&xx, &yy);
|
||||
|
||||
int aa, ll;
|
||||
for (ll = _GP(game).numgui - 1; ll >= 0; ll--) {
|
||||
aa = _GP(play).gui_draw_order[ll];
|
||||
if (_GP(guis)[aa].IsInteractableAt(xx, yy))
|
||||
return aa;
|
||||
// Test in the opposite order (from closer to further)
|
||||
for (auto g = _GP(play).gui_draw_order.crbegin();
|
||||
g < _GP(play).gui_draw_order.crend(); ++g) {
|
||||
if (_GP(guis)[*g].IsInteractableAt(xx, yy))
|
||||
return *g;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
@ -19,6 +19,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "ags/lib/std/algorithm.h"
|
||||
#include "ags/engine/ac/gui.h"
|
||||
#include "ags/shared/ac/common.h"
|
||||
#include "ags/engine/ac/draw.h"
|
||||
@ -406,28 +407,13 @@ void replace_macro_tokens(const char *text, String &fixed_text) {
|
||||
}
|
||||
|
||||
|
||||
void update_gui_zorder() {
|
||||
int numdone = 0, b;
|
||||
|
||||
// for each GUI
|
||||
for (int a = 0; a < _GP(game).numgui; a++) {
|
||||
// find the right place in the draw order array
|
||||
int insertAt = numdone;
|
||||
for (b = 0; b < numdone; b++) {
|
||||
if (_GP(guis)[a].ZOrder < _GP(guis)[_GP(play).gui_draw_order[b]].ZOrder) {
|
||||
insertAt = b;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// insert the new item
|
||||
for (b = numdone - 1; b >= insertAt; b--)
|
||||
_GP(play).gui_draw_order[b + 1] = _GP(play).gui_draw_order[b];
|
||||
_GP(play).gui_draw_order[insertAt] = a;
|
||||
numdone++;
|
||||
}
|
||||
|
||||
bool sort_gui_less(const int g1, const int g2) {
|
||||
return _GP(guis)[g1].ZOrder < _GP(guis)[g2].ZOrder;
|
||||
}
|
||||
|
||||
void update_gui_zorder() {
|
||||
std::sort(_GP(play).gui_draw_order.begin(), _GP(play).gui_draw_order.end(), sort_gui_less);
|
||||
}
|
||||
|
||||
void export_gui_controls(int ee) {
|
||||
for (int ff = 0; ff < _GP(guis)[ee].GetControlCount(); ff++) {
|
||||
@ -529,9 +515,9 @@ int gui_on_mouse_move() {
|
||||
else {
|
||||
// Scan for mouse-y-pos GUIs, and pop one up if appropriate
|
||||
// Also work out the mouse-over GUI while we're at it
|
||||
int ll;
|
||||
for (ll = 0; ll < _GP(game).numgui; ll++) {
|
||||
const int guin = _GP(play).gui_draw_order[ll];
|
||||
// CHECKME: not sure why, but we're testing forward draw order here -
|
||||
// from farthest to nearest (this was in original code?)
|
||||
for (int guin : _GP(play).gui_draw_order) {
|
||||
if (_GP(guis)[guin].IsInteractableAt(_G(mousex), _G(mousey))) mouse_over_gui = guin;
|
||||
|
||||
if (_GP(guis)[guin].PopupStyle != kGUIPopupMouseY) continue;
|
||||
|
@ -409,7 +409,10 @@ HGameInitError InitGameState(const LoadedGameEntities &ents, GameDataVersion dat
|
||||
// labels are not clickable by default
|
||||
_GP(guilabels)[i].SetClickable(false);
|
||||
}
|
||||
_GP(play).gui_draw_order = (int32_t *)calloc(game.numgui * sizeof(int), 1);
|
||||
_GP(play).gui_draw_order.resize(game.numgui);
|
||||
for (int i = 0; i < game.numgui; ++i)
|
||||
_GP(play).gui_draw_order[i] = i;
|
||||
|
||||
update_gui_zorder();
|
||||
calculate_reserved_channel_count();
|
||||
|
||||
|
@ -154,21 +154,18 @@ static void restore_game_play_ex_data(Stream *in) {
|
||||
_GP(play).do_once_tokens[i] = rbuffer;
|
||||
}
|
||||
|
||||
in->ReadArrayOfInt32(&_GP(play).gui_draw_order[0], _GP(game).numgui);
|
||||
in->Seek(_GP(game).numgui * sizeof(int32_t)); // gui_draw_order
|
||||
}
|
||||
|
||||
static void restore_game_play(Stream *in, RestoredData &r_data) {
|
||||
int screenfadedout_was = _GP(play).screen_is_faded_out;
|
||||
int roomchanges_was = _GP(play).room_changes;
|
||||
// make sure the pointer is preserved
|
||||
int32_t *gui_draw_order_was = _GP(play).gui_draw_order;
|
||||
|
||||
ReadGameState_Aligned(in, r_data);
|
||||
r_data.Cameras[0].Flags = r_data.Camera0_Flags;
|
||||
|
||||
_GP(play).screen_is_faded_out = screenfadedout_was;
|
||||
_GP(play).room_changes = roomchanges_was;
|
||||
_GP(play).gui_draw_order = gui_draw_order_was;
|
||||
|
||||
restore_game_play_ex_data(in);
|
||||
}
|
||||
|
@ -76,12 +76,15 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool operator==(const const_reverse_iterator &rhs) {
|
||||
bool operator==(const const_reverse_iterator &rhs) const {
|
||||
return _owner == rhs._owner && _index == rhs._index;
|
||||
}
|
||||
bool operator!=(const const_reverse_iterator &rhs) {
|
||||
bool operator!=(const const_reverse_iterator &rhs) const {
|
||||
return !operator==(rhs);
|
||||
}
|
||||
bool operator<(const const_reverse_iterator &rhs) const {
|
||||
return _index > rhs._index;
|
||||
}
|
||||
};
|
||||
|
||||
using iterator = typename Common::Array<T>::iterator;
|
||||
@ -155,6 +158,12 @@ public:
|
||||
const_reverse_iterator rend() const {
|
||||
return const_reverse_iterator(this, -1);
|
||||
}
|
||||
const_reverse_iterator crbegin() const {
|
||||
return const_reverse_iterator(this, (int)Common::Array<T>::size() - 1);
|
||||
}
|
||||
const_reverse_iterator crend() const {
|
||||
return const_reverse_iterator(this, -1);
|
||||
}
|
||||
|
||||
void pop_front() {
|
||||
Common::Array<T>::remove_at(0);
|
||||
|
Loading…
x
Reference in New Issue
Block a user