essytas 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +19 -0
- data/README +3 -0
- data/Rakefile +44 -0
- data/bin/essytas +2 -0
- data/lib/animation.rb +74 -0
- data/lib/config.rb +63 -0
- data/lib/core.rb +242 -0
- data/lib/cursor.rb +43 -0
- data/lib/def/animations/explosion1.anim +103 -0
- data/lib/def/characters.def +132 -0
- data/lib/def/de/dialogues/test.dlg +4 -0
- data/lib/def/de/enemies.trans +6 -0
- data/lib/def/de/items.trans +84 -0
- data/lib/def/de/skills.trans +48 -0
- data/lib/def/de/spells.trans +31 -0
- data/lib/def/en/dialogues/test.dlg +4 -0
- data/lib/def/en/enemies.trans +6 -0
- data/lib/def/en/items.trans +78 -0
- data/lib/def/en/skills.trans +48 -0
- data/lib/def/en/spells.trans +31 -0
- data/lib/def/enemies.def +8 -0
- data/lib/def/enemies/wolf.bhv +11 -0
- data/lib/def/init.def +5 -0
- data/lib/def/items.def +153 -0
- data/lib/def/loot.def +2 -0
- data/lib/def/particles.def +66 -0
- data/lib/def/recipies.def +18 -0
- data/lib/def/skills.def +40 -0
- data/lib/def/spells.def +42 -0
- data/lib/def/spells.rb +16 -0
- data/lib/def/weapons.def +9 -0
- data/lib/ext/astar/AMap.rb +146 -0
- data/lib/ext/astar/node.rb +72 -0
- data/lib/ext/astar/priority_queue.rb +44 -0
- data/lib/ext/shader.rb +116 -0
- data/lib/game/alchemy/recipe.rb +26 -0
- data/lib/game/character.rb +102 -0
- data/lib/game/combat/bar.rb +119 -0
- data/lib/game/combat/battle.rb +345 -0
- data/lib/game/combat/control.rb +18 -0
- data/lib/game/combat/gui.rb +190 -0
- data/lib/game/combat/gui/select_item.rb +11 -0
- data/lib/game/combat/gui/select_spell.rb +38 -0
- data/lib/game/constitution.rb +48 -0
- data/lib/game/equipment.rb +34 -0
- data/lib/game/inventory.rb +37 -0
- data/lib/game/item.rb +54 -0
- data/lib/game/magic.rb +33 -0
- data/lib/game/map/events.rb +29 -0
- data/lib/game/map/fog.rb +41 -0
- data/lib/game/map/map.rb +247 -0
- data/lib/game/map/map_animation.rb +26 -0
- data/lib/game/map/map_loader.rb +177 -0
- data/lib/game/map/map_object.rb +208 -0
- data/lib/game/map/map_particle.rb +27 -0
- data/lib/game/map/player.rb +78 -0
- data/lib/game/map/tile.rb +35 -0
- data/lib/game/mind.rb +24 -0
- data/lib/game/npc/behaviour.rb +45 -0
- data/lib/game/npc/bubble.rb +28 -0
- data/lib/game/npc/goal.rb +93 -0
- data/lib/game/npc/npc.rb +95 -0
- data/lib/game/npc/task.rb +73 -0
- data/lib/game/osd/magic.rb +24 -0
- data/lib/game/party.rb +42 -0
- data/lib/game/skills.rb +64 -0
- data/lib/game/spell.rb +35 -0
- data/lib/game_window.rb +95 -0
- data/lib/glsl/contrast.frag +12 -0
- data/lib/glsl/fade.frag +11 -0
- data/lib/glsl/mezzotint.frag +20 -0
- data/lib/glsl/noise.frag +20 -0
- data/lib/glsl/pixelate.frag +42 -0
- data/lib/glsl/radialblur.frag +28 -0
- data/lib/glsl/sepia.frag +15 -0
- data/lib/glsl/shockwave.frag +24 -0
- data/lib/glsl/tv_screen.frag +17 -0
- data/lib/graphics/animations/credits.txt +1 -0
- data/lib/graphics/animations/explosion2.png +0 -0
- data/lib/graphics/backgrounds/white_ties_grass.png +0 -0
- data/lib/graphics/chars/ejera.png +0 -0
- data/lib/graphics/chars/salyjea.png +0 -0
- data/lib/graphics/chars/tharat.png +0 -0
- data/lib/graphics/combat/tharat.png +0 -0
- data/lib/graphics/cursors/normal.png +0 -0
- data/lib/graphics/fog/clouds1.png +0 -0
- data/lib/graphics/gui/bar_center.png +0 -0
- data/lib/graphics/gui/bar_left.png +0 -0
- data/lib/graphics/gui/bar_right.png +0 -0
- data/lib/graphics/gui/button_background.png +0 -0
- data/lib/graphics/gui/button_close.png +0 -0
- data/lib/graphics/gui/button_close_hi.png +0 -0
- data/lib/graphics/gui/button_highlight.png +0 -0
- data/lib/graphics/gui/charequip_background.png +0 -0
- data/lib/graphics/gui/charselect_background.png +0 -0
- data/lib/graphics/gui/container_background.png +0 -0
- data/lib/graphics/gui/drop_item.png +0 -0
- data/lib/graphics/gui/equip_Etarae.png +0 -0
- data/lib/graphics/gui/equip_Mensch.png +0 -0
- data/lib/graphics/gui/equipslot_background.png +0 -0
- data/lib/graphics/gui/iteminfo_background.png +0 -0
- data/lib/graphics/gui/msg_background.png +0 -0
- data/lib/graphics/gui/scrollbar_background.png +0 -0
- data/lib/graphics/gui/scroller.png +0 -0
- data/lib/graphics/gui/tile_32.png +0 -0
- data/lib/graphics/gui/tile_32_highlight.png +0 -0
- data/lib/graphics/icons/items/arrow.png +0 -0
- data/lib/graphics/icons/items/bandage.png +0 -0
- data/lib/graphics/icons/items/boots_leather.png +0 -0
- data/lib/graphics/icons/items/bow.png +0 -0
- data/lib/graphics/icons/items/credits.txt +8 -0
- data/lib/graphics/icons/items/harness_leather.png +0 -0
- data/lib/graphics/icons/items/knife.png +0 -0
- data/lib/graphics/icons/items/shirt_linen.png +0 -0
- data/lib/graphics/items/none.png +0 -0
- data/lib/graphics/menu/ingame_background.png +0 -0
- data/lib/graphics/menu/ingame_background.xcf +0 -0
- data/lib/graphics/menu/start_background.png +0 -0
- data/lib/graphics/missing.png +0 -0
- data/lib/graphics/osd/magic_bg.png +0 -0
- data/lib/graphics/particles/leaf.png +0 -0
- data/lib/graphics/particles/smoke.png +0 -0
- data/lib/graphics/pixel.png +0 -0
- data/lib/graphics/tiles/test.png +0 -0
- data/lib/gui/base.rb +278 -0
- data/lib/gui/button.rb +93 -0
- data/lib/gui/char_equip.rb +118 -0
- data/lib/gui/char_selector.rb +54 -0
- data/lib/gui/context_menu.rb +115 -0
- data/lib/gui/draggable.rb +18 -0
- data/lib/gui/grid.rb +118 -0
- data/lib/gui/image.rb +17 -0
- data/lib/gui/inventory.rb +42 -0
- data/lib/gui/item_info.rb +33 -0
- data/lib/gui/slider.rb +10 -0
- data/lib/gui/textfield.rb +57 -0
- data/lib/layer.rb +64 -0
- data/lib/load.rb +31 -0
- data/lib/main.rb +18 -0
- data/lib/maps/def/test.bhv +26 -0
- data/lib/maps/def/test.rb +14 -0
- data/lib/maps/test.tmx +133 -0
- data/lib/maps/test2.tmx +94 -0
- data/lib/maps/test3.tmx +29 -0
- data/lib/maps/test3_lower.tmx +25 -0
- data/lib/maps/test3_upper.tmx +25 -0
- data/lib/maps/test_left.tmx +25 -0
- data/lib/maps/test_upper.tmx +25 -0
- data/lib/music/Butterfly Tea - A New Hope 2K11.mp3 +0 -0
- data/lib/music/Greendjohn - Rebirth.mp3 +0 -0
- data/lib/music/credits.txt +8 -0
- data/lib/parse.rb +605 -0
- data/lib/parse_tmx.rb +114 -0
- data/lib/particles.rb +127 -0
- data/lib/sample.rb +29 -0
- data/lib/save.rb +44 -0
- data/lib/song.rb +41 -0
- data/lib/sounds/click1.wav +0 -0
- data/lib/sounds/credits.txt +2 -0
- data/lib/sounds/error1.wav +0 -0
- data/lib/sprite.rb +35 -0
- data/lib/states/menus.rb +17 -0
- data/lib/states/menus/alchemy.rb +53 -0
- data/lib/states/menus/equip.rb +79 -0
- data/lib/states/menus/ingame.rb +34 -0
- data/lib/states/menus/magic.rb +31 -0
- data/lib/states/menus/options.rb +54 -0
- data/lib/states/menus/start.rb +38 -0
- data/lib/states/states.rb +154 -0
- data/lib/tileset.rb +42 -0
- data/lib/tools/world.rb +103 -0
- data/lib/tools/worldmap_editor.rb +221 -0
- data/lib/translate.rb +368 -0
- metadata +255 -0
data/lib/glsl/fade.frag
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
uniform sampler2D texUnit0;
|
|
2
|
+
|
|
3
|
+
uniform int t;
|
|
4
|
+
|
|
5
|
+
float rand(vec2 co) {
|
|
6
|
+
return fract(sin(dot(co.xy, vec2(12.9898, 78.233))) * 43758.5453);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
void main(void) {
|
|
10
|
+
vec4 color;
|
|
11
|
+
|
|
12
|
+
color = texture2D(texUnit0, gl_TexCoord[0].xy);
|
|
13
|
+
|
|
14
|
+
vec3 mezzo = vec3(0.0);
|
|
15
|
+
if(rand(gl_TexCoord[0].xy + float(t)/640.0) <= color.r) { mezzo.r = 1.0; }
|
|
16
|
+
if(rand(gl_TexCoord[0].xy + float(t)/640.0) <= color.g) { mezzo.g = 1.0; }
|
|
17
|
+
if(rand(gl_TexCoord[0].xy + float(t)/640.0) <= color.b) { mezzo.b = 1.0; }
|
|
18
|
+
|
|
19
|
+
gl_FragColor.rgb = mezzo;
|
|
20
|
+
}
|
data/lib/glsl/noise.frag
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
uniform sampler2D texUnit0;
|
|
2
|
+
|
|
3
|
+
uniform float intensity;
|
|
4
|
+
uniform int t;
|
|
5
|
+
|
|
6
|
+
float rand(vec2 co) {
|
|
7
|
+
return fract(sin(dot(co.xy, vec2(12.9898, 78.233))) * 43758.5453);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
void main(void) {
|
|
11
|
+
vec4 color;
|
|
12
|
+
|
|
13
|
+
color = texture2D(texUnit0, gl_TexCoord[0].xy);
|
|
14
|
+
|
|
15
|
+
vec4 influence = min(color, 1.0-color);
|
|
16
|
+
|
|
17
|
+
float noise = 1.0 - 2.0*rand(gl_TexCoord[0].xy + float(t)/640.0);
|
|
18
|
+
|
|
19
|
+
gl_FragColor = color + intensity*influence*noise;
|
|
20
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
#define KERNEL_SIZE 9
|
|
2
|
+
|
|
3
|
+
uniform int pixelSize;
|
|
4
|
+
uniform sampler2D tex;
|
|
5
|
+
uniform int width;
|
|
6
|
+
uniform int height;
|
|
7
|
+
|
|
8
|
+
vec2 texCoords[KERNEL_SIZE];
|
|
9
|
+
|
|
10
|
+
void main(void)
|
|
11
|
+
{
|
|
12
|
+
vec4 avgColor;
|
|
13
|
+
vec2 texCoordsStep = 1.0/(vec2(float(width),float(height))/float(pixelSize));
|
|
14
|
+
vec2 pixelBin = floor(gl_TexCoord[0].st/texCoordsStep);
|
|
15
|
+
vec2 inPixelStep = texCoordsStep/3.0;
|
|
16
|
+
vec2 inPixelHalfStep = inPixelStep/2.0;
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
texCoords[0] = vec2(inPixelHalfStep.x, inPixelStep.y*2.0 + inPixelHalfStep.y) + pixelBin * texCoordsStep;
|
|
20
|
+
texCoords[1] = vec2(inPixelStep.x + inPixelHalfStep.x, inPixelStep.y*2.0 + inPixelHalfStep.y) + pixelBin * texCoordsStep;
|
|
21
|
+
texCoords[2] = vec2(inPixelStep.x*2.0 + inPixelHalfStep.x, inPixelStep.y*2.0 + inPixelHalfStep.y) + pixelBin * texCoordsStep;
|
|
22
|
+
texCoords[3] = vec2(inPixelHalfStep.x, inPixelStep.y + inPixelHalfStep.y) + pixelBin * texCoordsStep;
|
|
23
|
+
texCoords[4] = vec2(inPixelStep.x + inPixelHalfStep.x, inPixelStep.y + inPixelHalfStep.y) + pixelBin * texCoordsStep;
|
|
24
|
+
texCoords[5] = vec2(inPixelStep.x*2.0 + inPixelHalfStep.x, inPixelStep.y + inPixelHalfStep.y) + pixelBin * texCoordsStep;
|
|
25
|
+
texCoords[6] = vec2(inPixelHalfStep.x, inPixelHalfStep.y) + pixelBin * texCoordsStep;
|
|
26
|
+
texCoords[7] = vec2(inPixelStep.x + inPixelHalfStep.x, inPixelHalfStep.y) + pixelBin * texCoordsStep;
|
|
27
|
+
texCoords[8] = vec2(inPixelStep.x*2.0 + inPixelHalfStep.x, inPixelHalfStep.y) + pixelBin * texCoordsStep;
|
|
28
|
+
|
|
29
|
+
avgColor = texture2D(tex, texCoords[0]) +
|
|
30
|
+
texture2D(tex, texCoords[1]) +
|
|
31
|
+
texture2D(tex, texCoords[2]) +
|
|
32
|
+
texture2D(tex, texCoords[3]) +
|
|
33
|
+
texture2D(tex, texCoords[4]) +
|
|
34
|
+
texture2D(tex, texCoords[5]) +
|
|
35
|
+
texture2D(tex, texCoords[6]) +
|
|
36
|
+
texture2D(tex, texCoords[7]) +
|
|
37
|
+
texture2D(tex, texCoords[8]);
|
|
38
|
+
|
|
39
|
+
avgColor /= float(KERNEL_SIZE);
|
|
40
|
+
|
|
41
|
+
gl_FragColor = avgColor;
|
|
42
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
uniform sampler2D Texture;
|
|
2
|
+
|
|
3
|
+
uniform float BlurFactor;
|
|
4
|
+
uniform float BrightFactor;
|
|
5
|
+
|
|
6
|
+
uniform float origin_x;
|
|
7
|
+
uniform float origin_y;
|
|
8
|
+
|
|
9
|
+
uniform int passes;
|
|
10
|
+
|
|
11
|
+
void main(void)
|
|
12
|
+
{
|
|
13
|
+
vec2 Origin = vec2(origin_x, 1.0 - origin_y);
|
|
14
|
+
|
|
15
|
+
vec2 TexCoord = vec2(gl_TexCoord[0].xy);
|
|
16
|
+
|
|
17
|
+
vec4 SumColor = vec4(0.0, 0.0, 0.0, 0.0);
|
|
18
|
+
TexCoord += vec2(1.0 / 1024.0, 1.0 / 768.0) * 0.5 - Origin;
|
|
19
|
+
|
|
20
|
+
for (int i = 0; i < passes; i++)
|
|
21
|
+
{
|
|
22
|
+
float scale = 1.0 - BlurFactor * (float(i) / float(passes - 1));
|
|
23
|
+
SumColor += texture2D(Texture, TexCoord * scale + Origin);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
gl_FragColor = SumColor / float(passes) * BrightFactor;
|
|
27
|
+
//gl_FragColor = texture2D(Texture, gl_TexCoord[0].xy + vec2(0.1));
|
|
28
|
+
}
|
data/lib/glsl/sepia.frag
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
uniform sampler2D tex;
|
|
2
|
+
|
|
3
|
+
void main(void)
|
|
4
|
+
{
|
|
5
|
+
vec4 Sepia1 = vec4( 0.2, 0.05, 0.0, 1.0 );
|
|
6
|
+
vec4 Sepia2 = vec4( 1.0, 0.9, 0.5, 1.0 );
|
|
7
|
+
|
|
8
|
+
vec4 Color = texture2D(tex, vec2(gl_TexCoord[0]));
|
|
9
|
+
|
|
10
|
+
float SepiaMix = dot(vec3(0.3, 0.59, 0.11), vec3(Color));
|
|
11
|
+
Color = mix(Color, vec4(SepiaMix), vec4(0.5));
|
|
12
|
+
vec4 Sepia = mix(Sepia1, Sepia2, SepiaMix);
|
|
13
|
+
|
|
14
|
+
gl_FragColor = mix(Color, Sepia, 1.0);
|
|
15
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
uniform sampler2D tex;
|
|
2
|
+
|
|
3
|
+
uniform float x, y, min, max, ratio, refraction;
|
|
4
|
+
|
|
5
|
+
void main(void)
|
|
6
|
+
{
|
|
7
|
+
vec2 source_coords = gl_TexCoord[0].xy;
|
|
8
|
+
vec3 color = texture2D(tex, source_coords).rgb;
|
|
9
|
+
|
|
10
|
+
vec2 rel = source_coords - vec2(x,1.0-y);
|
|
11
|
+
rel.x *= ratio;
|
|
12
|
+
|
|
13
|
+
float dist = sqrt(rel.x*rel.x + rel.y*rel.y);
|
|
14
|
+
float inner = (dist - min)/(max - min);
|
|
15
|
+
|
|
16
|
+
if(dist >= min && dist <= max)
|
|
17
|
+
{
|
|
18
|
+
float depth = 0.5 + 0.5*cos((inner + 0.5) * 2.0 * 3.14159);
|
|
19
|
+
source_coords -= depth * rel/dist * refraction;
|
|
20
|
+
color = texture2D(tex, source_coords).rgb;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
gl_FragColor.rgb = color;
|
|
24
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
uniform sampler2D texUnit0;
|
|
2
|
+
|
|
3
|
+
uniform float column_width;
|
|
4
|
+
|
|
5
|
+
void main(void)
|
|
6
|
+
{
|
|
7
|
+
vec3 color = texture2D(texUnit0, gl_TexCoord[0].xy).rgb;
|
|
8
|
+
|
|
9
|
+
float column_index = gl_TexCoord[0].x / column_width;
|
|
10
|
+
int ci = int(column_index);
|
|
11
|
+
while(ci >= 3) { ci -= 3; } // % doesn't seem to work
|
|
12
|
+
|
|
13
|
+
gl_FragColor.rgb = color * 0.125;
|
|
14
|
+
if(ci==0) { gl_FragColor.r = color.r; }
|
|
15
|
+
if(ci==1) { gl_FragColor.g = color.g; }
|
|
16
|
+
if(ci==2) { gl_FragColor.b = color.b; }
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
explosion2.png - http://opengameart.org/user/68 (http://opengameart.org/content/fire-spell-explosion)
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
data/lib/gui/base.rb
ADDED
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
|
|
2
|
+
# gui logic
|
|
3
|
+
|
|
4
|
+
module Core::GUI
|
|
5
|
+
|
|
6
|
+
class Window # make hash?
|
|
7
|
+
attr_reader :state, :x, :y, :w, :h, :close
|
|
8
|
+
# height includes titlebar
|
|
9
|
+
attr_accessor :xoff, :yoff, :zoff # completely unused, just used for windows in windows
|
|
10
|
+
attr_accessor :parent
|
|
11
|
+
def initialize(x, y, w, h, titlestr, close=true, bg=nil, move=false, z=-1)
|
|
12
|
+
@state = Core.window.state
|
|
13
|
+
@xoff = @yoff = @zoff = 0
|
|
14
|
+
if bg
|
|
15
|
+
@bg = Core.sprite(bg)
|
|
16
|
+
else
|
|
17
|
+
@bg = nil
|
|
18
|
+
end
|
|
19
|
+
@x, @y, @w, @h, @z = x, y, w, h, z
|
|
20
|
+
if @z < 0
|
|
21
|
+
@z = Core::GUI_Z
|
|
22
|
+
end
|
|
23
|
+
@elements = {}
|
|
24
|
+
@bar = [
|
|
25
|
+
Core.sprite("gui/bar_left", true),
|
|
26
|
+
Core.sprite("gui/bar_center", true),
|
|
27
|
+
Core.sprite("gui/bar_right", true)
|
|
28
|
+
]
|
|
29
|
+
@titlefont = Core.font("arial", 24)
|
|
30
|
+
@title = titlestr
|
|
31
|
+
@tfw = @titlefont.text_width(@title)
|
|
32
|
+
@remove = false
|
|
33
|
+
if close
|
|
34
|
+
@close = ImageButton.new(@w-24, @y, "gui/button_close", lambda { @remove = true })
|
|
35
|
+
else
|
|
36
|
+
@close = nil
|
|
37
|
+
end
|
|
38
|
+
@move = move
|
|
39
|
+
@changed = false
|
|
40
|
+
@dragging = false
|
|
41
|
+
@parent = nil
|
|
42
|
+
@save_pos = false
|
|
43
|
+
end
|
|
44
|
+
def empty
|
|
45
|
+
@elements = {}
|
|
46
|
+
end
|
|
47
|
+
def include?(sym)
|
|
48
|
+
return get(sym) != nil
|
|
49
|
+
end
|
|
50
|
+
def [](sym)
|
|
51
|
+
return get(sym)
|
|
52
|
+
end
|
|
53
|
+
def get(sym)
|
|
54
|
+
return @elements[sym]
|
|
55
|
+
end
|
|
56
|
+
def close!
|
|
57
|
+
@remove = true
|
|
58
|
+
end
|
|
59
|
+
def remove?
|
|
60
|
+
return @remove
|
|
61
|
+
end
|
|
62
|
+
# Set the title
|
|
63
|
+
def title=(str)
|
|
64
|
+
@title = str
|
|
65
|
+
@tfw = @titlefont.text_width(@title)
|
|
66
|
+
end
|
|
67
|
+
# Add an element
|
|
68
|
+
def add(name, el)
|
|
69
|
+
@elements.store(name, el)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# Enable position saving
|
|
73
|
+
def save_pos(xsym, ysym)
|
|
74
|
+
@xsym, @ysym = xsym, ysym
|
|
75
|
+
@save_pos = true
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def update
|
|
79
|
+
@elements.each_value { |el|
|
|
80
|
+
el.update
|
|
81
|
+
if el.remove?
|
|
82
|
+
@elements.delete(@elements.key(el))
|
|
83
|
+
end
|
|
84
|
+
}
|
|
85
|
+
if @close
|
|
86
|
+
@close.x, @close.y, @close.zoff = @x+@w-24, @y, @zoff
|
|
87
|
+
@close.update
|
|
88
|
+
end
|
|
89
|
+
if @move
|
|
90
|
+
m = [Core.window.mouse_x, Core.window.mouse_y]
|
|
91
|
+
if Core.inside?(m.x, m.y, @x, @y, @x+@w-24, @y+24) or @dragging
|
|
92
|
+
if Core.window.button_down?(Gosu::MsLeft)
|
|
93
|
+
if !@dragging
|
|
94
|
+
@dragging = true
|
|
95
|
+
@dragx = m.x - @x
|
|
96
|
+
@dragy = m.y - @y
|
|
97
|
+
else
|
|
98
|
+
@x = m.x - @dragx
|
|
99
|
+
@y = m.y - @dragy
|
|
100
|
+
end
|
|
101
|
+
else
|
|
102
|
+
@dragging = false
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
if @dragging
|
|
107
|
+
if @x > 1024 - @w
|
|
108
|
+
@x = 1024 - @w
|
|
109
|
+
elsif @x < 0
|
|
110
|
+
@x = 0
|
|
111
|
+
end
|
|
112
|
+
if @y > 744
|
|
113
|
+
@y = 744
|
|
114
|
+
elsif @y < 0
|
|
115
|
+
@y = 0
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
if @save_pos
|
|
119
|
+
Core.config[@xsym] = @x
|
|
120
|
+
Core.config[@ysym] = @y
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def draw
|
|
125
|
+
@bg.draw(@x, @y+24, @z, @w/@bg.width.to_f, @h/@bg.height.to_f) if @bg
|
|
126
|
+
@elements.each_value { |el|
|
|
127
|
+
el.xoff = @x
|
|
128
|
+
el.yoff = @y + 24 # titlebar
|
|
129
|
+
el.draw
|
|
130
|
+
}
|
|
131
|
+
@bar[0].draw(@x, @y, @z)
|
|
132
|
+
@bar[1].draw(@x+16, @y, @z, (@w-32)/@bar[1].width)
|
|
133
|
+
@bar[2].draw(@x+@w-16, @y, @z)
|
|
134
|
+
@titlefont.draw(@title, @x+(@w/2)-(@tfw/2), @y+1, @z+1, 1, 1, Gosu::Color::BLACK)
|
|
135
|
+
@close.draw if @close
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
class Element
|
|
140
|
+
attr_accessor :x, :y, :xoff, :yoff, :zoff, :w, :h
|
|
141
|
+
# x and y are relative to the windows topleft corner plus title bar
|
|
142
|
+
def initialize(x, y, w, h)
|
|
143
|
+
@remove = false
|
|
144
|
+
@xoff = @yoff = @zoff = 0
|
|
145
|
+
@x, @y, @w, @h = x, y, w, h
|
|
146
|
+
end
|
|
147
|
+
def update
|
|
148
|
+
end
|
|
149
|
+
def draw
|
|
150
|
+
end
|
|
151
|
+
def remove?
|
|
152
|
+
return @remove
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
# scrollable
|
|
157
|
+
class Container < Element
|
|
158
|
+
attr_reader :ch
|
|
159
|
+
# ch = content element height
|
|
160
|
+
def initialize(x, y, w, h, ch)
|
|
161
|
+
super(x, y, w, h)
|
|
162
|
+
@bg = Core.sprite("gui/container_background")
|
|
163
|
+
@scrollbar = Scrollbar.new(x+w-24, y, 24, h)
|
|
164
|
+
@ch = ch
|
|
165
|
+
@items = []
|
|
166
|
+
@item = nil
|
|
167
|
+
@changed = false
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
def add(element)
|
|
171
|
+
element.x = @x
|
|
172
|
+
element.y = @y + @yoff + ((@items.size+1)*@ch)
|
|
173
|
+
@items.push(element)
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
def hovered
|
|
177
|
+
i = 0
|
|
178
|
+
@items.each { |it|
|
|
179
|
+
if it.hovered?
|
|
180
|
+
return i
|
|
181
|
+
end
|
|
182
|
+
i += 1
|
|
183
|
+
}
|
|
184
|
+
return -1
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
def update
|
|
188
|
+
# TODO scrollbar probably doesnt work
|
|
189
|
+
@scrollbar.update
|
|
190
|
+
@scrollbar.xoff, @scrollbar.yoff, @scrollbar.zoff = @xoff, @yoff, @zoff
|
|
191
|
+
offset = @scrollbar.offset * -@ch
|
|
192
|
+
@items.each { |item|
|
|
193
|
+
item.xoff, item.zoff = @xoff, @zoff
|
|
194
|
+
item.yoff = @yoff# + (offset/@ch) - @ch
|
|
195
|
+
if item.y + item.yoff + item.h < @scrollbar.y + @scrollbar.yoff
|
|
196
|
+
next
|
|
197
|
+
end
|
|
198
|
+
item.update
|
|
199
|
+
}
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
def draw
|
|
203
|
+
@scrollbar.draw
|
|
204
|
+
@bg.draw(@x+@xoff, @y+@yoff, Core::GUI_Z, (@w-24)/@bg.width.to_f, @h/@bg.height.to_f)
|
|
205
|
+
@items.each { |item|
|
|
206
|
+
if item.y + item.yoff + item.h < @scrollbar.y + @scrollbar.yoff
|
|
207
|
+
next
|
|
208
|
+
end
|
|
209
|
+
item.draw
|
|
210
|
+
}
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
def selected
|
|
214
|
+
return @item
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
def changed?
|
|
218
|
+
if @changed
|
|
219
|
+
@changed = false
|
|
220
|
+
return true
|
|
221
|
+
else
|
|
222
|
+
return false
|
|
223
|
+
end
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
private
|
|
227
|
+
|
|
228
|
+
def clicked(item)
|
|
229
|
+
@changed = true
|
|
230
|
+
@item = item
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
end
|
|
234
|
+
|
|
235
|
+
class Scrollbar < Element
|
|
236
|
+
include Gosu
|
|
237
|
+
attr_accessor :sh
|
|
238
|
+
attr_reader :h
|
|
239
|
+
def initialize(x, y, w, h)
|
|
240
|
+
super
|
|
241
|
+
@bg = Core.sprite("gui/scrollbar_background")
|
|
242
|
+
@scroller = Core.sprite("gui/scroller")
|
|
243
|
+
@held = false
|
|
244
|
+
@sy = @y
|
|
245
|
+
@sh = 48
|
|
246
|
+
end
|
|
247
|
+
def offset
|
|
248
|
+
return ((@sy-@y)/((@y)-(@y+@h-@sh)+1))*-100
|
|
249
|
+
end
|
|
250
|
+
def update
|
|
251
|
+
x = Core.window.mouse_x
|
|
252
|
+
y = Core.window.mouse_y
|
|
253
|
+
if Core.inside?(x, y, @x, @sy, @x+@w, @sy+@sh) and Core.window.button_down?(MsLeft) and !@held
|
|
254
|
+
@held = true
|
|
255
|
+
@offset = @sy-y
|
|
256
|
+
end
|
|
257
|
+
if @held
|
|
258
|
+
@sy = y + @offset
|
|
259
|
+
if @sy < @y
|
|
260
|
+
@sy = @y
|
|
261
|
+
elsif @sy+@sh > @y+@h
|
|
262
|
+
@sy = @y+@h-@sh-1
|
|
263
|
+
end
|
|
264
|
+
if !Core.window.button_down?(MsLeft)
|
|
265
|
+
@held = false
|
|
266
|
+
end
|
|
267
|
+
end
|
|
268
|
+
end
|
|
269
|
+
def draw
|
|
270
|
+
@bg.draw(@x+@xoff, @y+@yoff, Core::GUI_Z + 14, @w/@bg.width, @h/@bg.height.to_f)
|
|
271
|
+
@scroller.draw(@x+@xoff, @sy+@yoff, Core::GUI_Z + 15, 1, @sh/@scroller.height.to_f)
|
|
272
|
+
end
|
|
273
|
+
end
|
|
274
|
+
|
|
275
|
+
end
|
|
276
|
+
|
|
277
|
+
require_relative "button.rb"
|
|
278
|
+
require_relative "context_menu.rb"
|