source: golgotha/src/golg/editor/commands/objects.cc @ 80

Last change on this file since 80 was 80, checked in by Sam Hocevar, 11 years ago
  • Adding the Golgotha source code. Not sure what's going to be interesting in there, but since it's all public domain, there's certainly stuff to pick up.
File size: 3.4 KB
Line 
1/********************************************************************** <BR>
2  This file is part of Crack dot Com's free source code release of
3  Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
4  information about compiling & licensing issues visit this URL</a>
5  <PRE> If that doesn't help, contact Jonathan Clark at
6  golgotha_source@usa.net (Subject should have "GOLG" in it)
7***********************************************************************/
8
9#include "map_man.hh"
10#include "map.hh"
11#include "lisp/li_init.hh"
12#include "lisp/lisp.hh"
13#include "objs/map_piece.hh"
14#include "resources.hh"
15#include "window/colorwin.hh"
16#include "window/style.hh"
17#include "gui/text_input.hh"
18#include "gui/text.hh"
19#include "app/app.hh"
20
21li_object *g1_full_health(li_object *o, li_environment *env)
22{
23  g1_object_class *olist[G1_MAX_OBJECTS];
24  sw32 t=g1_get_map()->make_object_list(olist, G1_MAX_OBJECTS);
25
26  li_call("add_undo", li_make_list(new li_int(G1_MAP_OBJECTS)));
27
28  for (int i=0; i<t; i++)
29  {
30    if (olist[i]->selected())
31      olist[i]->health=olist[i]->get_type()->defaults->health;
32  }
33
34  li_call("redraw");
35
36  return 0;
37}
38
39class g1_set_health_dialog_class : public i4_color_window_class
40{
41protected:
42  i4_text_window_class *caption;
43  i4_text_input_class *input;
44public:
45  g1_set_health_dialog_class(i4_graphical_style_class *style)
46    : i4_color_window_class(300,50,style->color_hint->neutral(),style)
47  {
48    sw32 health = 0;
49    g1_object_class *olist[G1_MAX_OBJECTS];
50    sw32 t=g1_get_map()->make_object_list(olist, G1_MAX_OBJECTS);
51    for (int i=0; i<t; i++)
52      if (olist[i]->selected())
53        health = olist[i]->health;
54
55    char buf[256];
56    sprintf(buf, "%d", health);
57       
58    caption = new i4_text_window_class(       "Health:",style);
59    add_child(10,8,caption);
60    input   = new i4_text_input_class (style, buf,100,40, this);
61    add_child(100,5,input);
62  }
63
64  virtual void receive_event(i4_event *ev)
65  {
66    switch (ev->type())
67    {
68      case i4_event::OBJECT_MESSAGE:
69      {
70        CAST_PTR(tev, i4_text_change_notify_event, ev);
71        int found=-1;
72       
73        i4_str::iterator p = tev->new_text->begin();
74        sw32 health = p.read_number();
75
76        g1_object_class *olist[G1_MAX_OBJECTS];
77        sw32 t=g1_get_map()->make_object_list(olist, G1_MAX_OBJECTS);
78       
79        li_call("add_undo", li_make_list(new li_int(G1_MAP_OBJECTS)));
80
81        for (int i=0; i<t; i++)
82          if (olist[i]->selected())
83            olist[i]->health=health;
84
85        li_call("redraw");
86
87        style->close_mp_window(parent);
88      } break;
89
90      default:
91        i4_color_window_class::receive_event(ev);
92        break;
93    }
94  }
95};
96
97static i4_event_handler_reference_class<g1_set_health_dialog_class> g1_set_health_dialog;
98
99li_object *g1_set_health(li_object *o, li_environment *env)
100{
101  if (!g1_set_health_dialog.get())
102  {
103    i4_graphical_style_class *style = i4_current_app->get_style();
104    g1_set_health_dialog = new g1_set_health_dialog_class(style);
105   
106    style->create_mp_window(-1,-1,
107                            g1_set_health_dialog->width(),
108                            g1_set_health_dialog->height(),
109                            "Set Health")
110      ->add_child(0,0,g1_set_health_dialog.get());
111  }
112  return 0;
113}
114li_automatic_add_function(g1_set_health,"set_health");
Note: See TracBrowser for help on using the repository browser.