File: selectctrl.py

package info (click to toggle)
snowballz 0.9.5.1-2
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 10,888 kB
  • ctags: 1,242
  • sloc: python: 7,511; makefile: 53; sh: 2
file content (88 lines) | stat: -rw-r--r-- 2,556 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
""" An panel for making working with selected units easier. """

from OpenGL.GL import *
import data
import pygame
from pygame.locals import *
from textures import Texture

_display = False
_selected_units = {"worker":0, "snowballer":0}

def update():
    global _display, _selected_units
    if data.selected_units:
        _display = True
        _selected_units = {"worker":0, "snowballer":0}
        for u in data.selected_units:
            _selected_units[u.type] += 1
    else:
        _display = False


def draw():

    #glColor4f(0, 0, 0, 0.6)
    #data.draw_box(data.view.w-64, 0, 64, 160)
    glColor4f(1,1,1,1)
    Texture.get("data/selectctrl.png").render(data.view.w-64, 0, invert_y=False)


    t = data.penguins["walk"].images[("idle", (0,1))]

    if _selected_units["snowballer"]:
        to = data.penguins["snowballerwalk"].images[("idle", (0,1))]
        x = data.view.w-64+16
        y = 111
        glColor4f(1,1,1,1)
        t.render(x, y, invert_y=False)
        glColor3f(*data.player.glcolor)
        to.render(x, y, invert_y=False)
        data.chat_font.render(x+8, y-19, str(_selected_units["snowballer"]),
                (0,0,0))

    if _selected_units["worker"]:
        to = data.penguins["workerwalk"].images[("idle", (0,1))]
        x = data.view.w-64+16
        y = 58
        glColor4f(1,1,1,1)
        t.render(x, y, invert_y=False)
        glColor3f(*data.player.glcolor)
        to.render(x, y, invert_y=False)
        data.chat_font.render(x+8, y-19, str(_selected_units["worker"]),
                (0,0,0))

    if _selected_units["worker"] or _selected_units["snowballer"]:
        glColor3f(*data.player.glcolor)
        Texture.get("data/marker_leave.png").render(data.view.w-64+16, 2, 
                invert_y=False)
        glColor3f(1,1,1)


def in_range((x,y)):
    return _display and x > data.view.w-64 and y > data.view.h-160


def click((x,y)):
    ns = set()
    if y < data.view.h-160+64:
        # Snowballer.
        if not _selected_units["snowballer"]: return
        for u in data.selected_units:
            if u.type is "snowballer":
                ns.add(u)
            else:
                u.selected = False
        data.selected_units = ns
    elif y < data.view.h-160+128:
        # Worker.
        if not _selected_units["worker"]: return
        for u in data.selected_units:
            if u.type is "worker":
                ns.add(u)
            else:
                u.selected = False
        data.selected_units = ns
    else:
        import ctrl
        ctrl.disban_units()