(#616) Implement hiding labels
parent
88c3572e1f
commit
ccd532131f
|
@ -62,7 +62,7 @@ Double Jump
|
|||
5
|
||||
(set args '("goal2"))
|
||||
(defun on-enter ()
|
||||
(send '(game level goal ,(car args) show)))
|
||||
(send `(game level goal ,(car args) show)))
|
||||
(defun on-leave ())
|
||||
|
||||
1033.8625 -862.22498 215.96986 569.73328 d35f5f
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
(defun on-enter ()
|
||||
(send '(game level goal ,(car args) show)))
|
||||
(send `(game level goal ,(car args) show)))
|
||||
(defun on-leave ())
|
||||
|
||||
|
|
|
@ -406,14 +406,6 @@ Rigid_rect *level_rigid_rect(Level *level,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
void level_hide_label(Level *level, const char *label_id)
|
||||
{
|
||||
trace_assert(level);
|
||||
trace_assert(label_id);
|
||||
|
||||
labels_hide(level->labels, label_id);
|
||||
}
|
||||
|
||||
struct EvalResult level_send(Level *level, Gc *gc, struct Scope *scope, struct Expr path)
|
||||
{
|
||||
trace_assert(level);
|
||||
|
@ -429,6 +421,8 @@ struct EvalResult level_send(Level *level, Gc *gc, struct Scope *scope, struct E
|
|||
|
||||
if (strcmp(target, "goal") == 0) {
|
||||
return goals_send(level->goals, gc, scope, rest);
|
||||
} else if (strcmp(target, "label") == 0) {
|
||||
return labels_send(level->labels, gc, scope, rest);
|
||||
}
|
||||
|
||||
return unknown_target(gc, "level", target);
|
||||
|
|
|
@ -37,8 +37,6 @@ Rigid_rect *level_rigid_rect(Level *level,
|
|||
void level_toggle_debug_mode(Level *level);
|
||||
void level_toggle_pause_mode(Level *level);
|
||||
|
||||
void level_hide_label(Level *level, const char *label_id);
|
||||
|
||||
struct EvalResult level_send(Level *level, Gc *gc, struct Scope *scope, struct Expr path);
|
||||
|
||||
#endif // LEVEL_H_
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
#include "system/lt.h"
|
||||
#include "system/nth_alloc.h"
|
||||
#include "system/log.h"
|
||||
#include "ebisp/interpreter.h"
|
||||
#include "broadcast.h"
|
||||
|
||||
#define LABEL_MAX_ID_SIZE 36
|
||||
|
||||
|
@ -208,18 +210,55 @@ void labels_enter_camera_event(Labels *labels,
|
|||
}
|
||||
}
|
||||
|
||||
void labels_hide(Labels *labels,
|
||||
const char *label_id)
|
||||
static struct EvalResult
|
||||
labels_action(Labels *labels,
|
||||
size_t index,
|
||||
Gc *gc,
|
||||
struct Scope *scope,
|
||||
struct Expr path)
|
||||
{
|
||||
trace_assert(labels);
|
||||
trace_assert(label_id);
|
||||
trace_assert(gc);
|
||||
trace_assert(scope);
|
||||
|
||||
const char *target = NULL;
|
||||
struct Expr rest = void_expr();
|
||||
struct EvalResult res = match_list(gc, "q*", path, &target, &rest);
|
||||
if (res.is_error) {
|
||||
return res;
|
||||
}
|
||||
|
||||
if (strcmp(target, "hide") == 0) {
|
||||
if (labels->states[index] != LABEL_STATE_HIDDEN) {
|
||||
labels->states[index] = LABEL_STATE_HIDDEN;
|
||||
labels->alphas[index] = 1.0f;
|
||||
labels->delta_alphas[index] = -3.0f;
|
||||
}
|
||||
return eval_success(NIL(gc));
|
||||
}
|
||||
|
||||
return unknown_target(gc, labels->ids[index], target);
|
||||
}
|
||||
|
||||
struct EvalResult
|
||||
labels_send(Labels *labels, Gc *gc, struct Scope *scope, struct Expr path)
|
||||
{
|
||||
trace_assert(labels);
|
||||
trace_assert(gc);
|
||||
trace_assert(scope);
|
||||
|
||||
const char *target = NULL;
|
||||
struct Expr rest = void_expr();
|
||||
struct EvalResult res = match_list(gc, "s*", path, &target, &rest);
|
||||
if (res.is_error) {
|
||||
return res;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < labels->count; ++i) {
|
||||
if (strcmp(labels->ids[i], label_id) == 0 && labels->states[i] != LABEL_STATE_HIDDEN) {
|
||||
labels->states[i] = LABEL_STATE_HIDDEN;
|
||||
labels->alphas[i] = 1.0f;
|
||||
labels->delta_alphas[i] = -3.0f;
|
||||
return;
|
||||
if (strcmp(target, labels->ids[i]) == 0) {
|
||||
return labels_action(labels, i, gc, scope, rest);
|
||||
}
|
||||
}
|
||||
|
||||
return unknown_target(gc, "label", target);
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include "math/point.h"
|
||||
#include "color.h"
|
||||
#include "ebisp/expr.h"
|
||||
|
||||
typedef struct Labels Labels;
|
||||
typedef struct Camera Camera;
|
||||
|
@ -18,7 +19,7 @@ void labels_update(Labels *label,
|
|||
void labels_enter_camera_event(Labels *label,
|
||||
const Camera *camera);
|
||||
|
||||
void labels_hide(Labels *labels,
|
||||
const char *label_id);
|
||||
struct EvalResult
|
||||
labels_send(Labels *labels, Gc *gc, struct Scope *scope, struct Expr path);
|
||||
|
||||
#endif // LABELS_H_
|
||||
|
|
|
@ -42,26 +42,6 @@ rect_apply_force(void *param, Gc *gc, struct Scope *scope, struct Expr args)
|
|||
}
|
||||
}
|
||||
|
||||
static struct EvalResult
|
||||
hide_label(void *param, Gc *gc, struct Scope *scope, struct Expr args)
|
||||
{
|
||||
trace_assert(param);
|
||||
trace_assert(gc);
|
||||
trace_assert(scope);
|
||||
|
||||
Level *level = (Level*) param;
|
||||
const char *label_id = NULL;
|
||||
|
||||
struct EvalResult result = match_list(gc, "s", args, &label_id);
|
||||
if (result.is_error) {
|
||||
return result;
|
||||
}
|
||||
|
||||
level_hide_label(level, label_id);
|
||||
|
||||
return eval_success(NIL(gc));
|
||||
}
|
||||
|
||||
void load_level_library(Gc *gc, struct Scope *scope, Level *level)
|
||||
{
|
||||
set_scope_value(
|
||||
|
@ -69,9 +49,4 @@ void load_level_library(Gc *gc, struct Scope *scope, Level *level)
|
|||
scope,
|
||||
SYMBOL(gc, "rect-apply-force"),
|
||||
NATIVE(gc, rect_apply_force, level));
|
||||
set_scope_value(
|
||||
gc,
|
||||
scope,
|
||||
SYMBOL(gc, "hide-label"),
|
||||
NATIVE(gc, hide_label, level));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue